estimancy/projestimate

View on GitHub
app/views/pemodules/_form.html.erb

Summary

Maintainability
Test Coverage
<div class="tabs">

  <ul>
    <li><a href="#tabs-1"><%= I18n.t(:pemodule_global_parameters) %></a></li>
    <% unless @pemodule.is_typed || @pemodule.alias.eql?(@initialization_module.alias) %>
        <li><a href="#tabs-2"><%= I18n.t(:pe_attributes) %></a></li>
        <li><a href="#tabs-3"><%= I18n.t(:attributes_settings) %></a></li>
    <% end %>
  </ul>

  <div id="tabs-1">
    <%= simple_form_for(@pemodule) do |f| %>

        <%= f.error_notification %>

        <%= hidden_field_tag 'id', (@pemodule.id || nil) %>
        <div>
          <table>
            <tr>
              <td><%= f.input :title, :label => I18n.t('name'), :input_html => {:class => 'input-xlarge', :autofocus => (controller.action_name == 'new')} %> </td>

              <td><%= f.input :alias, :label => I18n.t('alias'), :input_html => {:class => 'input-medium'} %></td>
            </tr>
          </table>

          <%= f.input :description, :label => I18n.t('description'), :input_html => {:class => 'input-xxlarge', :rows => 5} %>

          <%= f.label I18n.t('label_compatibility') %>
          <table style="margin-left:20px">
            <% @wets.each do |wet| %>
                <tr>
                  <td><%= wet.name %>&nbsp;&nbsp;</td>
                  <% unless @pemodule.compliant_component_type.nil? %>
                      <td><%= check_box_tag 'compliant_wet[]', wet.alias, @pemodule.compliant_component_type.include?(wet.alias) ? true : false %></td>
                  <% else %>
                      <td><%= check_box_tag 'compliant_wet[]', wet.alias, false %></td>
                  <% end %>
                </tr>
            <% end %>
          </table>
          <br/>

          <%= f.input :with_activities, :input_html => {:style => 'margin-left:0px'}, :label => I18n.t(:label_module_with_activities), :as => :radio_buttons, collection: [:no, :yes_for_input, :yes_for_output_with_ratio, :yes_for_output_without_ratio, :yes_for_input_output_with_ratio, :yes_for_input_output_without_ratio] %>
        </div>

        <hr class="bs-docs-separator">
        <table>
          <tr>
            <td>
              <%= f.association :record_status, :label => I18n.t('record_status'), :label => 'Status',
                                :collection => @pemodule.record_status_collection,
                                :input_html => {:class => 'record_status'},
                                :selected => (@pemodule.is_defined_or_nil? ? @proposed_status.id : @pemodule.record_status_id),
                                :disabled => (true if @pemodule.is_retired?) %>
            </td>
            <td>
              <%= f.input :custom_value, :label => I18n.t('custom_value'), :input_html => {:class => 'custom_value'}, :disabled => (true unless @pemodule.is_custom?) %>
            </td>
          </tr>
        </table>

        <%= f.input :change_comment, :label => I18n.t('change_comment'), :input_html => {:class => 'input-xxlarge', :rows => 2} %>


        <% if action_name == 'new' || action_name=="create" %>
            <%= submit_tag I18n.t('save_and_create'), :class => 'btn' %>
        <% end %>
        <%= submit_tag I18n.t('save'), :class => 'btn' %>
        <%= submit_tag I18n.t('apply'), :class => 'btn' %>
        <%= link_to I18n.t('back'), pemodules_path, :class => 'btn' %>
        <span class="on_success_global"></span>

    <% end -%>
  </div>

  <% unless @pemodule.is_typed || @pemodule.alias.eql?(@initialization_module.alias) %>

      <div id="tabs-2">
        <%= form_tag('/update_selected_attributes', :method => 'get', :class => 'simple_form') do -%>

            <%= hidden_field_tag 'module_id', @pemodule.id %>
            <%= hidden_field_tag 'pemodule[pe_attribute_ids][]' %>

            <table id="table_list_2" class="table tablesorterPager table-striped table-bordered table-condensed">
              <thead>
              <tr>
                <th><%= I18n.t(:pe_attribute_name) %></th>
                <th class="filter-select"><%= I18n.t(:selected) %></th>
                <th><%= I18n.t(:description) %></th>
              </tr>
              </thead>
              <tbody>
              <% @attributes.each do |attr| %>
                  <% @pemodule.pe_attributes.include?(attr) ? module_attr=@pemodule.attribute_modules.where('pe_attribute_id=?', attr).first : module_attr=nil %>
                  <tr class="<%= cycle('even', 'odd') %>">
                    <td><%= link_to(attr.name, edit_pe_attribute_path(attr), :class => 'attribute_tooltip', :style => 'color:green;', :title => display_attribute_rule(attr, module_attr)) unless attr.nil? %></td>
                    <td>
                      <span class="hidden">
                        <%= @attribute_settings.map(&:pe_attribute_id).include?(attr.id).to_s.humanize %>
                      </span>
                      <%= check_box_tag 'pemodule[pe_attribute_ids][]', attr.id, @attribute_settings.map(&:pe_attribute_id).include?(attr.id), :disabled => @pemodule == @initialization_module %>
                    <td><%= attr.description %></td>
                  </tr>
              <% end %>
              <%= render :partial => 'layouts/footer_table' %>
              </tbody>
            </table>

            <% if action_name == 'new' || action_name=="create" %>
                <%= submit_tag I18n.t('save_and_create'), :class => 'btn' %>
            <% end %>
            <%= submit_tag I18n.t('save'), :class => 'btn' %>
            <%= submit_tag I18n.t('apply'), :class => 'btn' %>
            <%= link_to I18n.t('back'), pemodules_path, :class => 'btn' %>
            <span class="on_success_attr"></span>
        <% end -%>
      </div>

      <div id="tabs-3" style="overflow-x: auto;">
        <%= form_tag('/set_attributes_module', :method => 'POST', :class => 'simple_form') do -%>
            <%= hidden_field_tag :current_tab, '', :class => 'current_tab' %>
            <%= hidden_field_tag 'pemodule[pe_attribute_ids][]' %>

            <script>
                $(document).ready(function () {
                    $('.tabs').tabs({
                        select: function (event, ui) {
                            var index_tab = ui.index + 1;
                            $(".current_tab").val("tabs-" + index_tab);

                            var re = /#/;
                            window.location.hash = ui.tab.hash.replace(re, "#");
                        }
                    });
                });
            </script>
            <%= hidden_field_tag 'module_id', @pemodule.id %>
            <div class="list_attr">
              <%= render :partial => 'attribute_settings', :object => @attribute_settings %>
            </div>

            <% if action_name == 'new' || action_name=="create" %>
                <%= submit_tag I18n.t('save_and_create'), :class => 'btn' %>
            <% end %>
            <%= submit_tag I18n.t('save'), :class => 'btn' %>
            <%= submit_tag I18n.t('apply'), :class => 'btn' %>
            <%= link_to I18n.t('back'), pemodules_path, :class => 'btn' %>
            <span class="on_success_attr_set"></span>
        <% end -%>
      </div>
  <% end %>

</div>