estimancy/projestimate

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

Summary

Maintainability
Test Coverage
<div class="tabs">

  <ul>
    <li><a href="#tabs-1"><%= @group.new_record? ? I18n.t('new_group') : "#{I18n.t(:edit_group, value: @group)}" %></a></li>
    <li><a href="#tabs-2"><%= I18n.t('users') %></a></li>
  </ul>

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

        <%= hidden_field_tag :current_tab, '', :class => 'current_tab' %>
        <% if @organization %>
            <%= f.input :organization_id, :as => :hidden, :input_html => { :value => @organization.id || params[:organization_id], class: 'input-xxlarge' } %>
        <% end %>

        <% if @group.errors.any? %>
          <div id="error_explanation">
            <h2><%= pluralize(@group.errors.count, 'error') %> prohibited this group from being saved:</h2>

            <ul>
              <% @group.errors.full_messages.each do |msg| %>
                <li><%= msg %></li>
              <% end %>
            </ul>
          </div>
        <% end %>
        <div class="div_tabs_to_disable">
          <%= f.input :name, :label => I18n.t('name'), :input_html => {:class => 'input-xxlarge', :autofocus => (controller.action_name == 'new')} %>

          <%= f.input :description, :label => I18n.t('description'), :input_html => {:class => 'input-xxlarge', :rows => 5} %>
          <table cellpadding="5">
            <tr>
              <td><%= f.input :for_global_permission, :label => I18n.t('global_permissions'), :as => :boolean, :input_html => {:class => 'input-xxlarge'} %></td>
              <td><%= f.input :for_project_security, :label => I18n.t('project_permissions'), :as => :boolean, :input_html => {:class => 'input-xxlarge'} %></td>
            </tr>
          </table>
          <% if is_master_instance? && @organization.nil? %>
            <table>
              <tr>
                <td>
                  <%= f.input :record_status_id, :as => :select, :label => I18n.t('record_status'), :required => (is_master_instance? ? true : false),
                              :collection => @group.record_status_collection,
                              :input_html => {:class => 'record_status'},
                              :selected => (@group.is_defined_or_nil? ? @proposed_status.id : @group.record_status_id),
                              :disabled => (true if @group.is_retired?) %>
                </td>
                <td>
                  <%= f.input :custom_value, :label => I18n.t('custom_value'), :input_html => {:class => 'custom_value'}, :disabled => (true unless @group.is_custom?) %>
                </td>
              </tr>
            </table>
            <%= f.input :change_comment, :label => I18n.t('change_comment'), :input_html => {:class => 'input-xxlarge', :rows => 2} %>
          <% end %>
        </div>

      <% if can? :manage, Group %>
        <% 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' %>
      <% end %>
      <%= link_to I18n.t('back'), organization_authorization_path(@organization, anchor: "tabs-group"), :class => 'btn' %>

    <% end -%>
  </div>

  <div id="tabs-2">
    <%= form_tag('/update_selected_users', :method => 'POST', :class => 'simple_form') do -%>
      <b><%= I18n.t(:text_group_associated_users, value: @group) %></b>
      <br/><br/>

      <div class="field_checkbox">
        <table id="table_list_2" class="table tablesorterPager table-striped table-bordered table-condensed">
          <%= hidden_field_tag 'group_id', @group.id %>
          <%= hidden_field_tag 'group[user_ids][]' %>
            <thead>
              <tr>
                <th><%= I18n.t(:first_name) %></th>
                <th><%= I18n.t(:last_name) %></th>
                <th><%= I18n.t(:login_name) %></th>
                <th class="filter-select"><%= I18n.t(:selected) %></th>
              </tr>
            </thead>
          <tbody>
            <% @organization.users.each do |group_user| %>
              <tr>
                <td><%= group_user.first_name %></td>
                <td><%= group_user.last_name %></td>
                <td><%= group_user.login_name %></td>
                <td class="align-center">
                  <span class="hidden">
                    <%= @group.users.map(&:id).include?(group_user.id).to_s.humanize %>
                  </span>
                  <%= check_box_tag('group[user_ids][]', group_user.id, (@group.users.map(&:id).include? group_user.id), :id => nil, :class => "group_#{group_user.id}") %>
                </td>
              </tr>
            <% end %>
            <%= render :partial => 'layouts/footer_table' %>
          </tbody>
        </table>
      </div>

      <% if can? :manage, Group %>
        <% 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' %>
      <% end %>
      <%= link_to I18n.t('back'), organization_authorization_path(@organization, anchor: "tabs-group"), :class => 'btn' %>

    <% end -%>
  </div>
</div>