Skip to content

Commit

Permalink
add committee member modal validation
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Oct 19, 2024
1 parent 038b38b commit f852ac9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 56 deletions.
6 changes: 3 additions & 3 deletions app/models/committee_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class CommitteeMember < ApplicationRecord
belongs_to :gem_record

## VALIDATIONS ##
validates_presence_of :first_name, message: 'Please choose a name.'
validates_presence_of :last_name, message: 'Please choose a name.'
validates_presence_of :first_name
validates_presence_of :last_name
# validates_presence_of :thesis
validates_presence_of :role, message: 'Please choose a role for this member.'
validates_presence_of :role

## SCOPES ##
scope :unique_names, -> { select('DISTINCT(full_name)').order('full_name asc') }
Expand Down
49 changes: 15 additions & 34 deletions app/views/committee_members/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
<% remote = request.xhr? ? true : false %>
<div class="modal" id="add_committee_member_modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add Committee Member</h5>
<% if request.xhr? %>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<% end %>
</div>
<%= simple_form_for [@student, @thesis, @committee_member], remote: remote do |f| %>
<div class="modal-body">
<p id="member_first_name">
<%= f.input :first_name, label: "First Name", required: true %>
</p>
<p id="member_last_name">
<%= f.input :last_name, label: "Last Name", required: true %>
</p>
<%= f.input :role, label: "Role", required: true, collection: CommitteeMember::ROLES, as: :radio_buttons %>
</div>
<div class="modal-footer">
<%= f.button :submit, "Add", class: "btn btn-primary" %>
<% if request.xhr? %>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<% else %>
<%= link_to "Cancel", :back, class: "btn" %>
<% end %>
</div>
<% end %>
</div>
</div>
</div>


<%= simple_form_for [@student, @thesis, @committee_member], remote: request.xhr? do |f| %>
<%= f.input :first_name, label: "First Name", required: true %>
<%= f.input :last_name, label: "Last Name", required: true %>
<%= f.input :role, label: "Role", required: true, collection: CommitteeMember::ROLES, as: :radio_buttons %>
<%= f.button :submit, "Add", class: "btn btn-primary" %>
<% if request.xhr? %>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-label="Cancel">Cancel</button>
<% else %>
<% if current_user.role == User::STUDENT %>
<a href="<%= student_view_thesis_process_path(@thesis, Thesis::PROCESS_UPDATE) %>" class="btn btn-secondary">Cancel</a>
<% else %>
<a href="<%= edit_student_thesis_path(@student, @thesis) %>" class="btn btn-secondary">Cancel</a>
<% end %>
<% end %>
<% end %>
15 changes: 15 additions & 0 deletions app/views/committee_members/_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="modal fade" id="add_committee_member_modal" data-bs-keyboard="false" tabindex="-1" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">
Add Committee Member
</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<%= render "form" %>
</div>
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions app/views/committee_members/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if @committee_member.errors.size == 0 %>
$("#add_committee_member_modal").modal('hide');
$("#add_committee_member").remove();
<% if @committee_member.errors.blank? %>
$("#committee_members .committee_members_list").append("<%= j render @committee_member %>");
$("#add_committee_member_modal").modal('hide');
$("#add_committee_member_modal").remove();
<% else %>
$("#add_committee_member").html("<%= j render "form" %>");
$("#add_committee_member_modal .modal-body").html('<%= j render("form") %>');
<% end %>
22 changes: 18 additions & 4 deletions app/views/committee_members/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<% title "Add Committee Member", false %>
<div class="fitted">
<%= render "form" %>
</div>
<% title "#{@student.name} - Thesis" %>
<% title_html do %>

<div class="row">
<%= render partial: "students/header" %>
</div>

<hr />

<h2><span class="fw-lighter text-secondary lead"><%= @thesis.title %></span></h2>

<h2 class="modal-title fs-5">
Add Committee Member
</h2>

<%= render "form" %>
<% end %>
9 changes: 2 additions & 7 deletions app/views/committee_members/new.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
$("#add_committee_member").remove();
$("body").append("<div id='add_committee_member'></div>");
$("#add_committee_member").append('<%= j render("form") %>');
var myModal = new bootstrap.Modal(document.getElementById('add_committee_member_modal'), {
backdrop: 'static'
});
myModal.show();
$("body").append('<%= j render("modal") %>');
(new bootstrap.Modal($('#add_committee_member_modal'))).show();
4 changes: 0 additions & 4 deletions test/system/theses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class ThesesTest < ApplicationSystemTestCase
click_link(@thesis_01.title)
click_on('Make Changes')
click_on('Add committee member')
click_on('Close')
click_on('Add committee member')

fill_in('First Name', with: 'test1')
fill_in('Last Name', with: 'test2')
Expand All @@ -73,8 +71,6 @@ class ThesesTest < ApplicationSystemTestCase
click_link(@thesis_01.title)
click_on('Make Changes')
click_on('Add committee member')
click_on('Close')
click_on('Add committee member')

fill_in('First Name', with: 'test1')
fill_in('Last Name', with: 'test2')
Expand Down

0 comments on commit f852ac9

Please sign in to comment.