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 20250202-maintenance-release-tests
  • Loading branch information
Dennis Deli authored and Dennis Deli committed Jan 9, 2025
2 parents b60e2ae + 93315c8 commit a3ab67c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 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
8 changes: 4 additions & 4 deletions app/views/requests/_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@
<%= f.input :reserve_location_id, collection: Location.active, required: true, hint: "Where do you want students to pick up your items?" %>
</div>
<div class="col-sm-3">
<%= f.input :reserve_start_date, as: :string, readonly: ! current_user.admin?, required: false, hint: "Prefilled after term selection.",
input_html: { id: "request_reserve_start_date", class: current_user.admin? ? "datepicker" : "" } %>
<%= f.input :reserve_start_date, as: :string, readonly: true, required: false, hint: "Prefilled after term selection.",
input_html: { id: "request_reserve_start_date", class: "" } %>
</div>
<div class="col-sm-3">
<%= f.input :reserve_end_date, as: :string, readonly: ! current_user.admin?, required: false,
input_html: { id: "request_reserve_end_date", class: current_user.admin? ? "datepicker" : "" } %>
<%= f.input :reserve_end_date, as: :string, readonly: true, required: false,
input_html: { id: "request_reserve_end_date", class: "" } %>
</div>
</div> <!-- row end -->
</div>
Expand Down

0 comments on commit a3ab67c

Please sign in to comment.