estimancy/projestimate

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

Summary

Maintainability
Test Coverage
<%= simple_form_for @user do |f| %>

  <%= hidden_field_tag :current_tab, '', :class => 'current_tab' %>

  <%= f.error_notification %>
  <div class="tabs">
      <ul>
        <li><a href="#tabs-1"><%= t(:global) %></a></li>
        <li><a href="#tabs-5"><%= I18n.t(:settings) %></a></li>
        <% if params[:organization_id].present? %>
          <li><a href="#tabs-groups"><%= I18n.t(:groups) %></a></li>
        <% end %>
        <% if current_user.super_admin == true and !params[:organization_id].present? %>
          <li><a href="#tabs-organizations"><%= I18n.t(:organizations) %></a></li>
        <% end %>
      </ul>

      <div id="tabs-1">
        <div id="accordion1" class="accordion">
          <div class="accordion-group accordion-caret">
            <div class="accordion-heading">
              <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapseOne">
                <i class="fa fa-caret-down"></i>
                <b><%= I18n.t 'identity' %></b>
              </a>
            </div>
            <div id="collapseOne" class="accordion-body in collapse">
              <div class="accordion-inner">

                <%= hidden_field_tag 'organization_id', params[:organization_id] %>

                <table>
                  <tr>
                    <td><%= f.input :first_name, :label => I18n.t('first_name'), :input_html => {:autofocus => (controller.action_name == 'new'), :class => 'input-large'} %></td>
                    <td><%= f.input :last_name, :label => I18n.t('last_name'), :input_html => {:class => 'input-xlarge'} %>   </td>
                  </tr>
                  <tr>
                    <td><%= f.input :initials, :label => I18n.t('initials'), :input_html => {:class => 'input-small'} %></td>
                    <td>
                      <% if can? :manage, User %>
                       <%= f.input :login_name, :label => I18n.t('login_name') %>
                      <% else %>
                        <%= f.input :login_name, :label => I18n.t('login_name'), :disabled => true %>
                      <% end %>
                    </td>
                  </tr>

                  <tr>
                    <td colspan="2">
                      <%= f.input :email, :label => I18n.t('email'), :input_html => {:class => 'input-xxlarge'} %>
                    </td>
                  </tr>

                  <% if current_user.super_admin? %>
                    <tr>
                      <td colspan="2"><%= f.input :super_admin, :label => I18n.t(:is_super_admin), hint: I18n.t(:text_help_super_admin), :input_html => {:class => 'input-xxlarge'} %></td>
                    </tr>
                  <% end %>
                </table>
              </div>
            </div>
          </div>
        </div>

        <div id="accordion2" class="accordion">
          <div class="accordion-group accordion-caret">
            <div class="accordion-heading">
              <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
                <i class="fa fa-caret-down"></i>
                <b><%= I18n.t(:authentication) %></b>
              </a>
            </div>
            <div id="collapseTwo" class="accordion-body in collapse">
              <div class="accordion-inner">
                <table>

                  <tr>
                    <% if can? :manage, User %>
                      <td colspan="2"><%= f.input :auth_type, :label => I18n.t('auth_type'), :as => :select, :collection => AuthMethod.all, :include_blank => false %></td>
                    <% else %>
                      <td colspan="2"><%= f.input :auth_type, :label => I18n.t('auth_type'), :as => :select, :collection => AuthMethod.all, :disabled => true, :include_blank => false %></td>
                    <% end %>
                  </tr>

                  <% if @user.new_record? %>
                    <tr class="password_row">
                      <td><%= f.input :password, :as => :password, :autocomplete => "off", :label => I18n.t('password'), :input_html => {:value => (@generated_password if @generated_password), :class => 'input-xlarge', :disabled => !(@user.auth_method && @user.auth_method.name == 'Application') }, :required => false %></td>
                      <td><%= f.input :password_confirmation, :as => :password, :label => I18n.t('password_confirmation'), :input_html => {:value => (@generated_password if @generated_password), :class => 'input-xlarge', :disabled => !(@user.auth_method && @user.auth_method.name == 'Application') } %></td>
                    </tr>
                  <% else %>
                    <tr><td><%= f.input :current_password, :label => I18n.t(:current_password), required: false, :input_html => {:value => (@user_current_password if @user_current_password), :class => 'input-xlarge', :disabled => !(@user.auth_method && @user.auth_method.name == 'Application') }, :placeholder => I18n.t(:leave_it_blank_if_no_change) %></td></tr>
                    <tr class="password_row">
                      <td><%= f.input :password, :as => :password, :autocomplete => "off", :label => I18n.t('new_password'), :input_html => {:value => (@user_password if @user_password), :class => 'input-xlarge', :disabled => !(@user.auth_method && @user.auth_method.name == 'Application') }, :placeholder => I18n.t(:leave_it_blank_if_no_change) %></td>
                      <td><%= f.input :password_confirmation, :as => :password, :label => I18n.t('confirm_new_password'), :input_html => {:value => (@user_password_confirmation if @user_password_confirmation), :class => 'input-xlarge', :disabled => !(@user.auth_method && @user.auth_method.name == 'Application') }, :placeholder => I18n.t(:leave_it_blank_if_no_change) %></td>
                    </tr>
                  <% end %>

                  <script type="text/javascript">
                      $(document).ready(function () {

                          $('#user_auth_type').change(function () {
                              if ($('.password_row input').is(':disabled')) {
                                  $('.password_row input').prop("disabled", false);
                              }
                              else {
                                  $('.password_row input').prop("disabled", true);
                              }
                          });
                      });
                  </script>
                </table>
              </div>
            </div>
          </div>
        </div>

        <div id="accordion3" class="accordion">
          <div class="accordion-group accordion-caret">
            <div class="accordion-heading">
              <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapseThree">
                <i class="fa fa-caret-down"></i>
                <b><%= I18n.t(:informations) %></b>
              </a>
            </div>
            <div id="collapseThree" class="accordion-body collapse in">
              <div class="accordion-inner">
                <table>
                  <tr>
                    <td>
                      <%= f.input :created_at, :label => I18n.t('created_at') do %>
                        <%= f.text_field :created_at, :value => (I18n.l(@user.created_at) unless @user.created_at.nil?), :disabled => true, :input_html => {:class => 'input-xxlarge'} %>
                      <% end %>
                    </td>

                    <td>
                      <%= f.input :updated_at, :label => I18n.t('updated_at') do %>
                        <%= f.text_field :updated_at, :value => (I18n.l(@user.updated_at) unless @user.updated_at.nil?), :disabled => true, :input_html => {:class => 'input-xxlarge'} %>
                      <% end %>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <%= f.input :last_login, :label => I18n.t('last_login') do %>
                        <%= f.text_field :last_login, :value => (I18n.l(@user.last_login) unless @user.last_login.nil?), :disabled => true %>
                      <% end %>
                    </td>

                    <td>
                      <%= f.input :previous_login, :label => I18n.t('previous_login') do %>
                        <%= f.text_field :previous_login, :value => (I18n.l(@user.previous_login) unless @user.previous_login.nil?), :disabled => true %>
                      <% end %>
                    </td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div id="tabs-5">
        <table>
          <tr>
            <td><%= f.input :language_id, :label => I18n.t('label_language'), :as => :select, :collection => Language.defined_or_local.map { |i| [i.name, i.id] }.sort, include_blank: '(auto)', :selected => @user.language_id %></td>
            <td><%= f.input :time_zone, :label => I18n.t('time_zone'), :input_html => {:class => 'input-xlarge'}, :as => :select, :collection => ActiveSupport::TimeZone.all.map { |i| [i.to_s, i.name] }, :include_blank => false, :selected => @user.time_zone || 'Paris' %></td>
          </tr>
          <tr>
            <td><%= f.input :number_precision, :label => I18n.t(:number_precision), :input_html => {:class => 'input-large'} %></td>
            <td><%= f.input :object_per_page, :label => I18n.t('object_per_page'), :input_html => {:class => 'input-small'}, :as => :select, :collection => [5, 10, 25, 50, 100], :include_blank => true, :selected => @user.object_per_page %></td>
          </tr>
          <!--
          <p><%= I18n.t(:assistance) %></p>
          <p><%= I18n.t(:notifications) %></p>
          <p><%= I18n.t(:display_format) %></p>
          <p><%= I18n.t(:decimal) %></p>
          <p><%= I18n.t(:thousands) %></p>
          <p><%= I18n.t(:first_day) %></p>
          <p><%= I18n.t(:first_week) %></p>
          <p><%= I18n.t(:export_preferences) %></p>
          -->
        </table>
      </div>

      <% if params[:organization_id].present? %>
        <div id="tabs-groups">
          <table id="table_list_1" class="table tablesorterPager table-striped table-bordered table-condensed">
            <thead>
              <tr>
                <th><%= I18n.t(:name) %></th>
                <th><%= I18n.t(:description) %></th>
                <th><%= I18n.t(:selected) %></th>
                <th><%= I18n.t(:actions) %></th>
              </tr>
            </thead>

            <tbody>

            <% @organization.groups.each do |group| %>
              <tr>
                <td><%= group.name %></td>
                <td><%= group.description %></td>
                <% gu = GroupsUsers.where(group_id: group.id, user_id: @user.id).first %>
                <td class="center"><%= check_box_tag "groups[#{group.id}]", "accepted", !gu.nil? %></td>
                <td class="center">
                  <%= link_to '', edit_group_path(group, :anchor => 'tabs-1'), :class => 'icon-pencil', :title => I18n.t('edit') %>
                  <%= link_to '', group, confirm: I18n.t('are_you_sure'), method: :delete, :class => 'icon-trash', :style => 'color:red', :title => I18n.t('delete') %>
                </td>
                </td>
              </tr>
            <% end %>
            <%= render :partial => 'layouts/footer_table' %>
            </tbody>
          </table>
        </div>
      <% end %>

      <% if current_user.super_admin == true and !params[:organization_id].present? %>
        <div id="tabs-organizations">
          <table id="table_list_1" class="table tablesorterPager table-striped table-bordered table-condensed">
            <thead>
              <tr>
                <th><%= I18n.t(:name) %></th>
                <th><%= I18n.t(:selected) %></th>
              </tr>
            </thead>

            <tbody>
              <% Organization.all.each do |organization| %>
                <tr>
                  <td><%= organization.name %></td>
                  <% go = OrganizationsUsers.where(organization_id: organization.id, user_id: @user.id).first %>
                  <td class="center">
                    <%= check_box_tag "organizations[#{organization.id}]", "accepted", !go.nil? %>
                  </td>
                </tr>
              <% end %>
              <%= render :partial => 'layouts/footer_table' %>
            </tbody>
          </table>
        </div>
      <% end %>

      <div class="actions">
        <% if can? :manage, User %>
          <% if action_name.in?(%w(new 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 %>
        <% if @organization.nil? %>
          <%= link_to I18n.t('back'), users_path, :class => 'btn' %>
        <% else %>
          <%= link_to I18n.t('back'), organization_users_path(organization_id: @organization.id), :class => 'btn' %>
        <% end %>
      </div>
    </div>
  <% end %>