Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/20241126-maintenance-release' in…
Browse files Browse the repository at this point in the history
…to staging
  • Loading branch information
amtuannguyen committed Jan 8, 2025
2 parents 3fc31c5 + 93315c8 commit 244a5bb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
65 changes: 50 additions & 15 deletions app/assets/javascripts/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,59 @@ var COURSE;
$(document).ready(function() {


$(".click_redirect").click(function() {
var path = $(this).data("redirect-path");
location.href=path;
});
let isSelectionMade = false;

$('#requester_name').autocomplete({
source: $('#requester_name').data('autocomplete-source'),
appendTo: "#change_owner_form .modal-body",
focus: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
},
select: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
$("#requester_id").val(ui.item.value);
}
source: $('#requester_name').data('autocomplete-source'),
appendTo: "#change_owner_form .modal-body",
focus: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
},
select: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
$("#requester_id").val(ui.item.value);
isSelectionMade = true;
enableSubmitButton();
disableTyping();
}
});

$('#requester_name').on('input change', function() {
if (isSelectionMade) {
enableSubmitButton();
}
});

function disableTyping() {
$('#requester_name').attr('readonly', true);
}

function enableTyping() {
$('#requester_name').attr('readonly', false);
}

function enableSubmitButton() {
const requesterIdValue = $('#requester_id').val().trim();
if (requesterIdValue !== "") {
$('#change_owner_submit').prop('disabled', false);
} else {
$('#change_owner_submit').prop('disabled', true);
}
}

$('#requester_name').on('keyup', function() {
if (isSelectionMade) {
$(this).val('');
$("#requester_id").val('');
isSelectionMade = false;
enableSubmitButton();
enableTyping();
}
});



$("#request_course_attributes_term, #request_course_attributes_year").on("input_load change", function(e) {

Expand Down
6 changes: 4 additions & 2 deletions app/views/requests/_change_owner.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
<%= simple_form_for @request, url: change_owner_request_path do |f| %>
<div class="modal-body">
<label>Look up a new request owner by name</label>
<%= f.collection_select :requester_id, User.all, :id, :name, { prompt: "Choose a new owner" }, { class: "input-lg form-control" } %>
<%= text_field :requester, :name, data: { autocomplete_source: users_path }, aria: { label: "Change owner"}, class: "input-lg form-control" %>
<%= hidden_field :nil, nil, name: "requester_id", id: "requester_id" %>
<p class="weak">This change will be recorded in the audit trail</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel Changes</button>
<%= f.button :submit, "Change Owner", data: { confirm: "Are you sure? "}, class: "btn btn-success" %>
<%= f.button :submit, "Change Owner", data: { confirm: "Are you sure?" }, class: "btn btn-success", id: "change_owner_submit", disabled: "disabled" %>

</div>
<% end %>
</div>
Expand Down

0 comments on commit 244a5bb

Please sign in to comment.