Skip to content

Commit

Permalink
Refactors multi_value partials and javascript.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Scherz committed Jul 23, 2024
1 parent 9b92a54 commit 139ec5b
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 182 deletions.
184 changes: 6 additions & 178 deletions app/views/software_records/_form_general.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,184 +47,12 @@
<%= form.select(:authentication_type, t('authentication_types'), {}, { :class => 'form-control' }) %>
</div>

<!-- Multiple Departments -->
<% if current_user.role.to_s == "root_admin" %>
<div class="form-group" id="multiple_departments">
<%= form.label :departments %>
<a class="float-right text-primary anchor-underline" id="btnAddDepartments">+ add more</a>

<% if component.to_s == "new" || @software_record.departments.empty? %>
<div class="input-group" id="departments1">
<%= text_field_tag "software_record[departments][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('departments1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.departments.each_with_index do |department, index| %>
<% @id = "departments#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[departments][]", department, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<% else %>
<% if @software_record.departments.any? %>
<div class="form-group" id="multiple_departments">
<% @software_record.departments.each_with_index do |department, index| %>
<% @id = "departments#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>" style="display: none">
<%= text_field_tag "software_record[departments][]", department, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
<!-- Multiple Departments ends -->

<!-- Multiple Developers -->
<% if current_user.role.to_s != "owner" %>
<div class="form-group" id="multiple_developers">
<%= form.label :developers %>
<a class="float-right text-primary anchor-underline" id="btnAddDevelopers">+ add more</a>

<% if component.to_s == "new" || @software_record.developers.empty? %>
<div class="input-group mt-2" id="developers1">
<%= text_field_tag "software_record[developers][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('developers1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.developers.each_with_index do |developer, index| %>
<% @id = "developers#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[developers][]", developer, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<% else %>
<% if @software_record.developers.any? %>
<div class="form-group" id="multiple_developers">
<% @software_record.developers.each_with_index do |developer, index| %>
<% @id = "developers#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>" style="display: none">
<%= text_field_tag "software_record[developers][]", developer, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
<!-- Multiple Developers ends -->

<!-- Multiple Tech Leads -->
<% if current_user.role.to_s != "owner" %>
<div class="form-group" id="multiple_tech_leads">
<%= form.label :tech_leads %>
<a class="float-right text-primary anchor-underline" id="btnAddTechLeads">+ add more</a>

<% if component.to_s == "new" || @software_record.tech_leads.empty? %>
<div class="input-group mt-2" id="tech_leads1">
<%= text_field_tag "software_record[tech_leads][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('tech_leads1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.tech_leads.each_with_index do |tech_lead, index| %>
<% @id = "tech_leads#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[tech_leads][]", tech_lead, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<% else %>
<% if @software_record.tech_leads.any? %>
<div class="form-group" id="multiple_tech_leads">
<% @software_record.tech_leads.each_with_index do |tech_lead, index| %>
<% @id = "tech_leads#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>" style="display: none">
<%= text_field_tag "software_record[tech_leads][]", tech_lead, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
<!-- Multiple Tech Leads ends -->

<!-- Multiple Product Owners -->
<div class="form-group" id="multiple_product_owners">
<%= form.label "Product Lead/Contact" %>
<a class="float-right text-primary anchor-underline" id="btnAddProductOwners">+ add more</a>

<% if component.to_s == "new" || @software_record.product_owners.empty? %>
<div class="input-group mt-2" id="product_owners1">
<%= text_field_tag "software_record[product_owners][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('product_owners1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.product_owners.each_with_index do |product_owner, index| %>
<% @id = "product_owners#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[product_owners][]", product_owner, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<!-- Multiple Product Owners ends -->

<!-- Multiple Admin Users -->
<div class="form-group" id="multiple_admin_users">
<%= form.label "Admin Users" %>
<a class="float-right text-primary anchor-underline" id="btnAddAdminUsers">+ add more</a>

<% if component.to_s == "new" || @software_record.admin_users.empty? %>
<div class="input-group mt-2" id="admin_users1">
<%= text_field_tag "software_record[admin_users][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('admin_users1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.admin_users.each_with_index do |admin_user, index| %>
<% @id = "admin_users#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[admin_users][]", admin_user, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<!-- Multiple Admin Users ends -->


<%= render 'form_multi_departments', software_record: @software_record, component: component, form: form %>
<%= render 'form_multi_developers', software_record: @software_record, component: component, form: form %>
<%= render 'form_multi_tech_leads', software_record: @software_record, component: component, form: form %>
<%= render 'form_multi_product_owners', software_record: @software_record, component: component, form: form %>
<%= render 'form_multi_admin_users', software_record: @software_record, component: component, form: form %>


<% if current_user.role.to_s != "owner" %>
Expand Down
29 changes: 29 additions & 0 deletions app/views/software_records/_form_multi_admin_users.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Multiple Admin Users -->
<div class="form-group" id="multiple_admin_users">
<%= form.label "Admin Users" %>
<a class="float-right text-primary anchor-underline" id="btnAddAdminUsers">+ add more</a>

<% if component.to_s == "new" || @software_record.admin_users.empty? %>
<div class="input-group mt-2" id="admin_users1">
<%= text_field_tag "software_record[admin_users][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('admin_users1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.admin_users.each_with_index do |admin_user, index| %>
<% @id = "admin_users#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[admin_users][]", admin_user, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<!-- Multiple Admin Users ends -->




44 changes: 44 additions & 0 deletions app/views/software_records/_form_multi_departments.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!-- Multiple Departments -->
<% if current_user.role.to_s == "root_admin" %>
<div class="form-group" id="multiple_departments">
<%= form.label :departments %>
<a class="float-right text-primary anchor-underline" id="btnAddDepartments">+ add more</a>

<% if component.to_s == "new" || @software_record.departments.empty? %>
<div class="input-group" id="departments1">
<%= text_field_tag "software_record[departments][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('departments1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.departments.each_with_index do |department, index| %>
<% @id = "departments#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[departments][]", department, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<% else %>
<% if @software_record.departments.any? %>
<div class="form-group" id="multiple_departments">
<% @software_record.departments.each_with_index do |department, index| %>
<% @id = "departments#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>" style="display: none">
<%= text_field_tag "software_record[departments][]", department, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
<!-- Multiple Departments ends -->



43 changes: 43 additions & 0 deletions app/views/software_records/_form_multi_developers.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!-- Multiple Developers -->
<% if current_user.role.to_s != "owner" %>
<div class="form-group" id="multiple_developers">
<%= form.label :developers %>
<a class="float-right text-primary anchor-underline" id="btnAddDevelopers">+ add more</a>

<% if component.to_s == "new" || @software_record.developers.empty? %>
<div class="input-group mt-2" id="developers1">
<%= text_field_tag "software_record[developers][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('developers1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.developers.each_with_index do |developer, index| %>
<% @id = "developers#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[developers][]", developer, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<% else %>
<% if @software_record.developers.any? %>
<div class="form-group" id="multiple_developers">
<% @software_record.developers.each_with_index do |developer, index| %>
<% @id = "developers#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>" style="display: none">
<%= text_field_tag "software_record[developers][]", developer, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
<!-- Multiple Developers ends -->


29 changes: 29 additions & 0 deletions app/views/software_records/_form_multi_product_owners.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Multiple Product Owners -->
<div class="form-group" id="multiple_product_owners">
<%= form.label "Product Lead/Contact" %>
<a class="float-right text-primary anchor-underline" id="btnAddProductOwners">+ add more</a>

<% if component.to_s == "new" || @software_record.product_owners.empty? %>
<div class="input-group mt-2" id="product_owners1">
<%= text_field_tag "software_record[product_owners][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('product_owners1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.product_owners.each_with_index do |product_owner, index| %>
<% @id = "product_owners#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[product_owners][]", product_owner, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<!-- Multiple Product Owners ends -->




41 changes: 41 additions & 0 deletions app/views/software_records/_form_multi_tech_leads.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- Multiple Tech Leads -->
<% if current_user.role.to_s != "owner" %>
<div class="form-group" id="multiple_tech_leads">
<%= form.label :tech_leads %>
<a class="float-right text-primary anchor-underline" id="btnAddTechLeads">+ add more</a>

<% if component.to_s == "new" || @software_record.tech_leads.empty? %>
<div class="input-group mt-2" id="tech_leads1">
<%= text_field_tag "software_record[tech_leads][]", nil, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('tech_leads1')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% else %>
<% @software_record.tech_leads.each_with_index do |tech_lead, index| %>
<% @id = "tech_leads#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>">
<%= text_field_tag "software_record[tech_leads][]", tech_lead, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
<% end %>
</div>
<% else %>
<% if @software_record.tech_leads.any? %>
<div class="form-group" id="multiple_tech_leads">
<% @software_record.tech_leads.each_with_index do |tech_lead, index| %>
<% @id = "tech_leads#{index + 1}" %>
<div class="input-group mt-2" id="<%= @id %>" style="display: none">
<%= text_field_tag "software_record[tech_leads][]", tech_lead, required: true, class: "form-control" %>
<div class="input-group-append" id="btnRemove" onclick="remove('<%= @id %>')">
<span class="input-group-text"><i class="fas fa-minus remove"> Delete</i></span>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
<!-- Multiple Tech Leads ends -->
8 changes: 4 additions & 4 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile += %w( navigation.js )
Rails.application.config.assets.precompile += %w( filtermanagement.js )
Rails.application.config.assets.precompile += %w( inputsanitization.js )
Rails.application.config.assets.precompile += %w( multivalueinputs.js )
Rails.application.config.assets.precompile += %w[navigation.js]
Rails.application.config.assets.precompile += %w[filtermanagement.js]
Rails.application.config.assets.precompile += %w[inputsanitization.js]
Rails.application.config.assets.precompile += %w[multivalueinputs.js]

0 comments on commit 139ec5b

Please sign in to comment.