Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 10.48 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <% if root -%>
  2.     <%# section_field = @section.section_fields.find_by_language(@authorization_record.language) or @section.section_fields.find_by_is_default_language(true)-%>
  3.     <% section_field = @sections_field[@section.id.to_s] %>
  4.     <% save_the_ids = [] %>
  5.     <% form_tag( {:controller => "sections", :action=>"save_answers"}, :id => "form_#{@section.id.to_s}", :class => "ajaxForm") do %>
  6.         <%= hidden_field_tag :section, @section.id -%>
  7.         <% if @loop_item  -%>
  8.             <%= hidden_field_tag :root_loop_item, @loop_item.id %>
  9.             <%= hidden_field_tag "section_looping_identifiers_#{@section.id.to_s}[#{@loop_item.sort_index}]" %>
  10.         <% end -%>
  11.         <% if @section.depends_on_option.present? -%>
  12.             <% section_visible = @section.dependency_condition_met?(current_user, looping_identifier ? looping_identifier : nil )  -%>
  13.             <%= hidden_field_tag "hidden[#{@section.id.to_s + (looping_identifier ? "_#{looping_identifier}" : "")}]", section_visible ? "0" : "1" -%>
  14.         <% else -%>
  15.             <% section_visible = true -%>
  16.         <% end -%>
  17.         <div id="section_<%=@section.id.to_s + (looping_identifier ? "_#{looping_identifier}" : "")%>" class="root_submit_section <%= section_visible ? "" : "hide" %>">
  18.           <div class="info_header" style="border-bottom-width: 0">
  19.             <% if not @section.is_hidden? %>
  20.                 <div class="span-16">
  21.                   <h2><%= ( @section.section_type == 0 and @loop_item.present? ) ? h(section_field.loop_title(nil, @loop_item)) : h(section_field.title) %></h2>
  22.                 </div>
  23.                 <div class="span-2 last options">
  24.                   <p><!-- floats right -->
  25.                     <a href="#" class="show_info" style="display: inline"><%= image_tag 'icons/expand.png', :title => "Expand",  :alt => "Expand"%></a>
  26.                     <a href="#" class="hide_info" style="display: none"><%= image_tag 'icons/collapse.png', :title =>"Collapse", :alt => "Collapse"%></a>
  27.                     <%= image_submit_tag 'icons/disk.png', :alt => "Save", :title => "Save", :class => 'hide save_button' -%>
  28.                   </p>
  29.                 </div>
  30.             <% end -%>
  31.           </div><!-- /.report_info_header -->
  32.           <div class="clear info <%= @section.is_hidden? ? "" : "hide" %>">
  33.             <% if not @section.is_hidden? %>
  34.                 <%#=h( ((number == 0 ? "" : number.to_s) + "- " + ( looping_identifier.nil? ? section.name : section.name.gsub(" #[#{looping_identifier.item_type}]"," "+looping_identifier.item_name)))) %>
  35.                 <% if section_field.description.present? -%>
  36.                     <p>
  37.                       <%=h section_field.description %>
  38.                     </p>
  39.                 <% end -%>
  40.             <% end -%>
  41.             <% @section.questions.each do |question| -%>
  42.                 <%= render :partial => "questions/submission", :locals => {:question => question, :loop_item => @loop_item, :looping_identifier => looping_identifier, :question_field => @questions_field[question.id.to_s], :answer_type_help_text => @answer_types.present? ? @answer_types_help[question.answer_type_id.to_s] : nil, :loop_sources => loop_sources }, :inline => true  %>
  43.             <% end -%>
  44.             <% @section.children.each do |child|
  45.                 #if not @sections_field.has_key?(child.id.to_s)
  46.                 #    @sections_field[child.id.to_s] = child.section_fields.find_by_language(@authorization_record.language) or child.section_fields.find_by_is_default_language(true)
  47.                 #end
  48.                 if child.section_type == 0
  49.                     items = child.get_next_loop_items @loop_item, loop_sources
  50.                     new_multiplier = (multiplier ? multiplier * items.size : (@loop_item ? @loop_item.siblings.size : 1)) #if the multiplier didn't exist before it is 1 for the first item'
  51.                     items.each do |item|
  52.                         if child.available_for? current_user, item
  53.                             # the looping_identifier is an unique number calculated as "root_sort_index + current_item.sort_index * root.siblings" For further levels add ancestors total items count "item.sort_index * ancestors.siblings.count"
  54.                             new_looping_identifier = (looping_identifier ? (looping_identifier + item.sort_index * new_multiplier) : item.sort_index)
  55.                             save_the_ids << [new_looping_identifier, new_multiplier, looping_identifier, item.sort_index]-%>
  56.                             <% loop_sources["loop_source_#{child.loop_source.id}"] = item -%>
  57.                             <%= render :partial => "sections/submission", :locals => {:save_the_ids => save_the_ids,:section => child, :root => false, :loop_item => item, :loop_sources => loop_sources, :multiplier => new_multiplier, :looping_identifier => new_looping_identifier,:section_field => @sections_field[child.id.to_s], :section_visible => section_visible }, :inline => true  %>
  58.                         <% end -%>
  59.                     <% end -%>
  60.                 <% else -%>
  61.                     <%= render :partial => "sections/submission", :locals => {:save_the_ids => save_the_ids,:section => child, :root => false, :loop_item => @loop_item ? @loop_item : nil, :loop_sources => loop_sources, :multiplier => multiplier, :looping_identifier => looping_identifier, :section_field => @sections_field[child.id.to_s], :section_visible => section_visible }, :inline => true  %>
  62.                 <% end -%>
  63.             <% end -%>
  64.             <p class="clear"><strong>* mandatory questions</strong></p>
  65.           </div>
  66.           <div class="clear">
  67.             <p><%= image_submit_tag 'icons/disk.png', :alt => "Save", :title => "Save" -%></p>
  68.           </div>
  69.     <% end -%>
  70.     </div><!-- /section_gen_root_section_id -->
  71. <% else -%>
  72.     <% if looping_identifier  -%>
  73.         <%= hidden_field_tag "section_looping_identifiers_#{section.id.to_s}[#{looping_identifier.to_s}]" %>
  74.     <% end -%>
  75.     <% if section.depends_on_option.present? -%>
  76.         <% section_visible = section.dependency_condition_met?(current_user, looping_identifier ? looping_identifier : nil )  -%>
  77.     <% else -%>
  78.         <% section_visible = true -%>
  79.     <% end -%>
  80.     <%= hidden_field_tag "hidden[#{section.id.to_s + (looping_identifier ? "_#{looping_identifier}" : "")}]", section_visible ? "0" : "1" -%>
  81.     <div id="section_<%=section.id.to_s + (looping_identifier ? "_#{looping_identifier}" : "")%>" class="submit_section <%= section_visible ? "" : "hide" %>">
  82.       <div class="info_header" style="border-bottom-width: 0">
  83.         <% if not section.is_hidden? %>
  84.             <div class="span-16">
  85.               <h3><%= ( section.section_type == 0 and loop_item.present? ) ? h(section_field.loop_title(nil, loop_item)) : h(section_field.title) %></h3>
  86.             </div>
  87.             <div class="span-2 last">
  88.               <p><!-- floats right -->
  89.                 <a href="#" class="show_info" style="display: inline"><%= image_tag 'icons/expand.png', :title => "Expand",  :alt => "Expand"%></a>
  90.                 <a href="#" class="hide_info" style="display: none"><%= image_tag 'icons/collapse.png', :title =>"Collapse", :alt => "Collapse"%></a>
  91.                 <%= image_submit_tag 'icons/disk.png', :alt => "Save", :title => "Save", :class => 'hide save_button'-%>
  92.               </p>
  93.             </div>
  94.         <% end -%>
  95.       </div><!-- /.report_info_header -->
  96.       <div class="info clear <%= section.is_hidden? ? "" : "hide" %>">
  97.         <% if not section.is_hidden? -%>
  98.             <%#=h( ((number == 0 ? "" : number.to_s) + "- " + ( loop_item.nil? ? section.name : section.name.gsub(" #[#{loop_item.item_type}]"," "+loop_item.item_name)))) %>
  99.             <% if section_field.description.present? -%>
  100.                 <p>
  101.                   <%=h section_field.description %>
  102.                 </p>
  103.             <% end -%>
  104.         <% end -%>
  105.         <% section.questions.each do |question| -%>
  106.             <%= render :partial => "questions/submission", :locals => {:question => question, :loop_item => loop_item, :looping_identifier => looping_identifier, :question_field => @questions_field[question.id.to_s], :answer_type_help_text => @answer_types_field.present? ? @answer_types_field[question.answer_type_id.to_s] : nil, :loop_sources => loop_sources }, :inline => true  %>
  107.         <% end -%>
  108.         <% section.children.each do |child|
  109.             #if not @sections_field.has_key?(child.id.to_s)
  110.             #    @sections_field[child.id.to_s] = child.section_fields.find_by_language(@authorization_record.language) or child.section_fields.find_by_is_default_language(true)
  111.             #end
  112.             if child.section_type == 0
  113.                 items = child.get_next_loop_items loop_item, loop_sources
  114.                 new_multiplier = (multiplier ? multiplier * items.size : (loop_item ? loop_item.siblings.size : 1)) #if the multiplier didn't exist before it is 1 for the first item'
  115.                 items.each do |item|
  116.                     if child.available_for? current_user, item
  117.                         new_looping_identifier = (looping_identifier ? (looping_identifier + item.sort_index * new_multiplier) : item.sort_index)
  118.                         save_the_ids << [new_looping_identifier, new_multiplier, looping_identifier, item.sort_index]
  119.                         loop_sources["loop_source_#{child.loop_source.id}"] = item -%>
  120.                         <%= render :partial => "sections/submission", :locals => {:save_the_ids => save_the_ids, :section => child, :root => false, :loop_item => item, :loop_sources => loop_sources, :multiplier => new_multiplier, :looping_identifier => new_looping_identifier, :section_field => @sections_field[child.id.to_s], :section_visible => section_visible }, :inline => true  %>
  121.                     <% end -%>
  122.                 <% end -%>
  123.             <% else -%>
  124.                 <%= render :partial => "sections/submission", :locals => {:save_the_ids => save_the_ids, :section => child, :root => false, :loop_item => loop_item ? loop_item : nil, :loop_sources => loop_sources, :multiplier => multiplier, :looping_identifier => looping_identifier, :section_field => @sections_field[child.id.to_s], :section_visible => section_visible }, :inline => true  %>
  125.             <% end -%>
  126.         <% end -%>
  127.       </div>
  128.     </div><!-- /section_gen_section_id -->
  129. <% end -%>
  130. <div id="show_the_ids">
  131.   <ul>
  132.     <% save_the_ids.each do |newid, m, lid, si | %>
  133.         <li><%= lid.to_s + " + " + m.to_s + " * " + si.to_s + " = " + newid.to_s %></li>
  134.     <% end %>
  135.   </ul>
  136. </div>