MiraitSystems/enju_trunk

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

Summary

Maintainability
Test Coverage
<script>
  $(document).ready(function(){
    // check full_name_alternative
    <% unless @agent.full_name_alternative.blank? %>
      if ("<%= @agent.full_name_alternative.gsub(/[ \s\t]+$/o, "").gsub(/^[ \s\t]+/o, "") -%>" != "")
        $("#full_name_alternative").show();
    <%- end -%>
    // check address2
    var input_address2 = false;
    "<%- if @agent.zip_code_2 -%>"
      if ("<%=@agent.zip_code_2.gsub(/[ \s\t]+$/o, "").gsub(/^[ \s\t]+/o, "") -%>" != "")
        input_address2 = true;
    "<%- end -%>"
    "<%- if @agent.address_2 -%>"
      if ("<%=@agent.address_2.gsub(/[ \s\t]+$/o, "").gsub(/^[ \s\t]+/o, "") -%>" != "")
        input_address2 = true;
    "<%- end -%>"
    "<%- if @agent.telephone_number_2 -%>"
      if ("<%=@agent.telephone_number_2.gsub(/[ \s\t]+$/o, "").gsub(/^[ \s\t]+/o, "") -%>" != "")
        input_address2 = true;
    "<%- end -%>"
    "<%- if @agent.extelephone_number_2 -%>"
      if ("<%=@agent.extelephone_number_2.gsub(/[ \s\t]+$/o, "").gsub(/^[ \s\t]+/o, "") -%>" != "")
        input_address2 = true;
    "<%- end -%>"
    "<%- if @agent.fax_number_2 -%>"
      if ("<%=@agent.fax_number_2.gsub(/[ \s\t]+$/o, "").gsub(/^[ \s\t]+/o, "") -%>" != "")
        input_address2 = true;
    "<%- end -%>"
    "<%- if @agent.address_2_note -%>"
      if ("<%=@agent.address_2_note.gsub(/[ \s\t]+$/o, "").gsub(/^[ \s\t]+/o, "") -%>" != "")
        input_address2 = true;
    "<%- end -%>"
    if (input_address2 == true)
      $("#address_2").show();
    // check agent_type
    if ("<%= @agent.agent_type_id -%>" == <%= @agent_type_person %>) {
      $("#name_person").show();
      $("label[for='agent_date_of_birth']").text('<%= t('activerecord.attributes.agent.date_of_birth') -%>');
      $("label[for='agent_date_of_death']").text('<%= t('activerecord.attributes.agent.date_of_death') -%>');
    } else {
      $("div.agent_full_name_note").hide();
      $("#name_person").hide();
      $("label[for='agent_date_of_birth']").text('<%= t('activerecord.attributes.agent.date_of_establishment') -%>');
      $("label[for='agent_date_of_death']").text('<%= t('activerecord.attributes.agent.date_of_dissolution') -%>');
    }
    // change agent_type
    $("select#agent_type_id").change(function(){
      str = $("select#agent_type_id option:selected").val();
      if (str == <%= @agent_type_person -%>) {
        $("div.agent_full_name_note").show();
        $("#name_person").show();
        $("label[for='agent_date_of_birth']").text('<%= t('activerecord.attributes.agent.date_of_birth') -%>');
        $("label[for='agent_date_of_death']").text('<%= t('activerecord.attributes.agent.date_of_death') -%>');
        $("#family_users").show();
      } else {
        $("input#agent_last_name").val("");
        $("input#agent_last_name_transcription").val("");
        $("input#agent_first_name").val("");
        $("input#agent_first_name_transcription").val("");
        $("div.agent_full_name_note").hide();
        $("#name_person").hide();
        $("label[for='agent_date_of_birth']").text('<%= t('activerecord.attributes.agent.date_of_establishment') -%>');
        $("label[for='agent_date_of_death']").text('<%= t('activerecord.attributes.agent.date_of_dissolution') -%>');
        $("#family_users").hide();
      }
    });

    // seach_family
    <%- if false #TODO SystemConfiguration.get('use_family') && current_user.has_role?('Librarian') -%>
      $("#agent_telephone_number_1").change(function(){
        clear_family_search();
        search_family();
      })
      .change();
      $("#agent_last_name").change(function(){
        clear_family_search();
        search_family();
      })
      .change();
      $("#agent_address_1").change(function(){
        clear_family_search();
        search_family();
      })
      .change();
      $("#agent_agent_type_id").change(function(){
        var agent_type_id = $("#agent_agent_type_id").val();
        if (agent_type_id == 1)
          search_family();
        else
          clear_family_search();
      })
      .change();
    <%- end -%>
  });

  function search_family(){
    var tel_1 = $("#agent_telephone_number_1").val().replace(/^\s+|\s+$/g, "");
    var last_name = $("#agent_last_name").val().replace(/^\s+|\s+$/g, "");
    var address_1 = $("#agent_address_1").val().replace(/^\s+|\s+$/g, "");
    var family = "<%= @family -%>"
    var data = {"keys": {"tel_1": tel_1, "last_name": last_name, "address_1": address_1 }, "family": family, "user": "<%= @user.id -%>"};
    if ((tel_1 != "" && last_name != "" && address_1 !="") || "<%= @family -%>" != null) {
      $.ajax({
        type: "GET",
        url: "<%= url_for(:controller => :users, :action => :search_family) -%>",
        data: data,
        success: function(obj) {
          if(obj.success){
            $('#search_family').remove();
            $('#family').append(obj.html);
            $('#search_family').show();
            $("input[name='family']").change(get_family_info);
          }
        }
      });
      return false;
    }
  }

  function clear_family_search(){
    $('#search_family > div').remove();
    $('#search_family').hide();
  }
  function get_family_info(){
    var user_id = $("input:radio[name='family']:checked").val();
    $.ajax({
      type: "GET",
      url: "get_family_info",
      data: {"user_id": user_id},
      success: function(obj) {
        var zip_code_1 = obj["agent"]["agent"]["zip_code_1"];
        $('#agent_zip_code_1').val(zip_code_1);
      }
    });
  }
</script>
<div class='table'>
  <%- if current_user.has_role?('Librarian') -%>
    <div class="row">
      <div><%= f.label t('activerecord.models.agent_type') -%></div>
      <div><%= f.select2(:agent_type_id, @agent_types, agent.agent_type_id, :select_attribute => :id, :display_attribute => :display_name, :width => 200) -%></div>
    </div>
    <div class="row">
      <div><%= f.label :agent_identifier %></div>
      <div><%= f.text_field :agent_identifier %></div>
    </div>
  <%- end -%>

  <div id="family">
    <%= render :partial => "family_info"  %>
    <%= render :partial => "search_family"  %>
  </div>

  <div id="name_person" class="table">
      <%- if SystemConfiguration.get("family_name_first") == true -%>
        <%= render 'agents/form_family_name_first', :f => f -%>
      <%- else -%>
        <%= render 'agents/form_family_name_last', :f => f -%>
      <%- end -%>
    <div class="row">
      <div><%=f.label :full_name -%></div>
      <div>
        <%= t('activerecord.attributes.agent.full_name_note') -%><br />
        <%= f.text_field :full_name, :class => 'resource_title' -%>
      </div>
    </div>
  </div>
  <div class="row">
    <div><%=f.label :full_name_transcription -%></div>
    <div><%= f.text_field :full_name_transcription, :class => 'resource_title' -%></div>
  </div>
  <div class="row">
    <div><%= link_to_function t('activerecord.attributes.agent.full_name_alternative'), "$('#full_name_alternative').toggle()" -%></div>
    <div id="full_name_alternative" style="display: none">
      <%= f.text_area :full_name_alternative, :class => 'resource_textarea' -%>
    </div>
  </div>

  <div class="row">
    <div><%=f.label :date_of_birth -%></div>
    <div><%= f.text_field :birth_date, :class => 'date_field' -%></div>
  </div>

  <div class="row">
    <div><%=f.label :gender -%></div>
    <div><%= f.select2(:gender_id, @genders, @agent.gender_id, :width => 200, :include_blank => "",
      :select2options => {
              "placeholder" => "\"#{t('activerecord.attributes.agent.select_gender_reason')}\""
                  }
     ) %>
    </div>
  </div>

  <% if SystemConfiguration.get("agent.manage_grade") %>
  <div class="row">
    <div><%=f.label :grade -%></div>
    <div><%= f.select2(:grade_id, @grades, @agent.grade_id, :include_blank => true, :width => 200,
      :placeholder => t('activerecord.attributes.agent.select_grade_reason')) %>
    </div>
  </div>
  <% end %>

  <% unless @user.id.blank? %>
    <%- if current_user.has_role?('Librarian') -%>
      <div class="row">
        <div><%=f.label :date_of_death -%></div>
        <div><%= f.text_field :death_date, :class => 'date_field' -%></div>
      </div>
    <%- else -%>
      <%- if @agent_type_person != @user.agent.agent_type.id -%>
        <div class="row">
          <div><%=f.label :date_of_death -%></div>
          <div><%= f.text_field :death_date, :class => 'date_field' -%></div>
        </div>
      <%- end -%>
    <%- end -%>
  <% end %>

  <div class="row">
    <div><%=f.label t('activerecord.models.country') -%></div>
    <div><%= f.select2(:country_id, @countries, @agent.country_id, :select_attribute => 'id', :display_attribute => 'display_name', :width => 400) -%></div>
  </div>

  <div class="row">
    <div><%=f.label :url -%></div>
    <div><%= f.url_field :url, :class => 'resource_url' -%></div>
  </div>

  <div class="actions row">
     <div></div>
     <div><%= u_form.submit :disable_with => t('page.wait') -%></div>
  </div>

  <% if SystemConfiguration.get("penalty.user_penalty") %>
  <hr />

  <div class="row">
    <div><%= u_form.label :days_after_penalty -%></div>
    <div><%= u_form.text_field :days_after_penalty, :class => 'resource_integer' -%></div>
  </div>

  <div class="row">
    <div><%= u_form.label :in_penalty -%></div>
    <div>
      <%= t('page.boolean.false') -%><%= u_form.radio_button :in_penalty, false -%>&nbsp;
      <%= t('page.boolean.true') -%><%= u_form.radio_button :in_penalty, true -%>&nbsp;
    </div>
  </div>

  <div class="actions row">
     <div></div>
     <div><%= u_form.submit :disable_with => t('page.wait') -%></div>
  </div>

  <% end %>

  <hr />

  <div id="address_1" class="table">
    <div class="row">
      <div><%= f.label :zip_code_1 -%></div>
      <div><%= f.text_field :zip_code_1, :class => 'resource_zip_code' -%></div>
    </div>
    <div class="row">
      <div><%= f.label :address_1 -%></div>
      <div><%= f.text_area :address_1, :class => 'resource_textarea' -%></div>
    </div>
    <div class="row">
      <div><%= f.label :telephone_number_1 -%></div>
      <div class="row2">
        <%= f.select2 :telephone_number_1_type_id, telephone_types, agent.telephone_number_1_type_id, :select_attribute => :id, :display_attribute => :text, :include_blank => true, :width => 200 -%>
        <%= f.phone_field :telephone_number_1, :class => 'telephone_number' -%>
      </div>
    </div>
    <div class="row">
      <div><%=f.label :extelephone_number_1 -%></div>
      <div class="row2">
        <%= f.select2 :extelephone_number_1_type_id, telephone_types, agent.extelephone_number_1_type_id, :select_attribute => :id, :display_attribute => :text, :include_blank => true, :width => 200 -%>
        <%= f.phone_field :extelephone_number_1, :class => 'telephone_number' -%>
      </div>
    </div>
    <div class="row">
      <div><%=f.label :fax_number_1 -%></div>
      <div class="row2">
        <%= f.select2 :fax_number_1_type_id, telephone_types, agent.fax_number_1_type_id, :select_attribute => :id, :display_attribute => :text, :include_blank => true, :width => 200 -%>
        <%= f.phone_field :fax_number_1, :class => 'telephone_number' -%>
      </div>
    </div>
    <div class="row">
      <div><%=f.label :address_1_note -%></div>
      <div><%= f.text_area :address_1_note, :class => 'resource_textarea' -%></div>
    </div>
  </div>

  <div class="row">
    <div><%= link_to_function t('agent.other_address'), "$('#address_2').toggle()" -%></div>
    <div></div>
  </div>

  <div id="address_2" class="table" style="display: none">

  <hr />

    <div class="row">
      <div><%=f.label :zip_code_2 -%></div>
      <div><%= f.text_field :zip_code_2, :class => 'resource_zip_code' -%></div>
    </div>
    <div class="row">
      <div><%=f.label :address_2 -%></div>
      <div><%= f.text_area :address_2, :class => 'resource_textarea' -%></div>
    </div>
    <div class="row">
      <div><%=f.label :telephone_number_2 -%></div>
      <div class="row2">
        <%= f.select2 :telephone_number_2_type_id, telephone_types, agent.telephone_number_2_type_id, :select_attribute => :id, :display_attribute => :text, :include_blank => true, :width => 200 -%>
        <%= f.phone_field :telephone_number_2, :class => 'telephone_number' -%>
      </div>
    </div>
    <div class="row">
      <div><%=f.label :extelephone_number_2 -%></div>
      <div class="row2">
        <%= f.select2 :extelephone_number_2_type_id, telephone_types, agent.extelephone_number_2_type_id, :select_attribute => :id, :display_attribute => :text, :include_blank => true, :width => 200 -%>
        <%= f.phone_field :extelephone_number_2, :class => 'telephone_number' -%>
      </div>
    </div>
    <div class="row">
      <div><%=f.label :fax_number_2 -%></div>
      <div class="row2">
        <%= f.select2 :fax_number_2_type_id, telephone_types, agent.fax_number_2_type_id, :select_attribute => :id, :display_attribute => :text, :include_blank => true, :width => 200 -%>
        <%= f.phone_field :fax_number_2, :class => 'telephone_number' -%>
      </div>
    </div>
    <div class="row">
      <div><%=f.label :address_2_note -%></div>
      <div><%= f.text_area :address_2_note, :class => 'resource_textarea' -%></div>
    </div>
  </div>

  <%- if current_user.has_role?('Librarian') -%>
    <div class="table">
      <hr />
      <div class="row">
        <div><%=f.label :note -%></div>
        <div>
          <%- if @agent.note_update_at -%>
            &nbsp;<%= t('agent.last_update_at') -%>: <%= l(@agent.note_update_at) -%>
            <%- if @agent.note_update_by -%>
              &nbsp;<%= t('agent.last_update_by') -%>: <%= @agent.note_update_by -%>
            <%- end -%>
            <%- if @agent.note_update_library -%>
              (<%= @agent.note_update_library-%>)
            <%- end -%>
            <br />
          <%- end -%>
          <%= f.text_area :note, :class => 'resource_textarea' -%>
        </div>
      </div>
    </div>
  <%- end -%>

  <br style="clear: both;"/>

  <div class="actions row">
    <div></div>
    <div>
      <%= hidden_field_tag 'work_id', @work.id if @work -%>
      <%= hidden_field_tag 'expression_id', @expression.id if @expression -%>
      <%= hidden_field_tag 'manifestation_id', @manifestation.id if @manifestation -%>
      <%= hidden_field_tag 'item_id', @item.id if @item -%>
      <%= f.hidden_field :user_username -%>
      <%= u_form.submit :disable_with => t('page.wait') -%>
    </div>
  </div>
</div>