Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Deli committed Dec 20, 2024
1 parent 911f7c0 commit 16f9ccb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
15 changes: 6 additions & 9 deletions app/assets/javascripts/request_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ $(document).ready(function() {
});



$(document).on('keyup', '[id^="note-textarea_"]', function () {
checkCount($(this));
updateCharacterCount($(this));
});



$('#history_popup').on('shown.bs.modal', function (e) {

var data_url = $("#request_history_log").data("url");
Expand All @@ -30,12 +28,11 @@ $(document).ready(function() {

});

/* Checks the count of the note text area and changes color to red if limit hit */
function checkCount(textArea) {
var textAreaValue = textArea.val();
var itemId = textArea.attr('id').split('_').pop();
var remainingCounter = $(`#item_history_popup_${itemId} .remaining`);

function updateCharacterCount($textArea) {
var textAreaValue = $textArea.val();
var itemId = $textArea.attr('id').split('_').pop();
var remainingCounter = $textArea.closest('.modal').find('.remaining');

remainingCounter.text(textAreaValue.length);

if (textAreaValue.length > 255) {
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/request_history_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ class RequestHistoryController < ApplicationController
# skip_authorization_check

def index
@audits = @audits = @request.associated_audits.where.not(associated_type: 'item') # | @request.course.audits
associated_audits = @request.associated_audits.where.not(associated_type: 'item')

@audits_grouped = @audits.reverse.group_by { |a| a.created_at.at_beginning_of_day }
request_audits = @request.audits.where(auditable_type: 'Request', associated_id: nil, associated_type: nil)

@audits = (associated_audits + request_audits).sort_by(&:created_at)

@audits_grouped = @audits.reverse.group_by { |audit| audit.created_at.at_beginning_of_day }

@users = User.all
@locations = Location.active
Expand Down
34 changes: 20 additions & 14 deletions app/views/request_history/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<% if @aud.present? %>
<% is_associated = @aud.associated_id.present? %>
<% prefix = is_associated ? "#item_history_popup_#{@aud.associated_id}" : "" %>
<% log_error_selector = "#{prefix} #history_log_error" %>
<% form_reset_selector = is_associated ? "#history_popup_#{@aud.associated_id} form" : "#history_popup form" %>
<% textarea_selector = is_associated ? "#note-textarea_#{@aud.associated_id}" : nil %>
<% log_url_selector = is_associated ? "#request_history_log_#{@aud.associated_id}" : "#request_history_log" %>

<% if @aud.comment.blank? %>
$("#item_history_popup_<%= @aud.associated_id %> #history_log_error").text("Note is blank. Please fill it in.").removeClass("hide");


<% elsif @aud.comment.length > 255 %>
$("#item_history_popup_<%= @aud.associated_id %> #history_log_error").text("Note is blank. Please fill it in.").removeClass("hide");
<% else %>
$("#note-textarea_<%= @aud.associated_id %>").val("");
$("#item_history_popup_<%= @aud.associated_id %> #history_log_error").addClass("hide");
$('#history_popup_<%= @aud.associated_id %> form').trigger("reset"); <!-- Reset the form for the specific item -->

var url = $("#request_history_log_<%= @aud.associated_id %>").data("url"); <!-- Get the URL for the specific item -->
$("#request_history_log_<%= @aud.associated_id %>").load(url); <!-- Load the data for the specific item -->

<% if @aud.comment.blank? %>
$( "<%= log_error_selector %>" ).text("Note is blank. Please fill it in.").removeClass("hide");
<% elsif @aud.comment.length > 255 %>
$( "<%= log_error_selector %>" ).text("Note is more than 255 characters!").removeClass("hide");
<% else %>
$( "<%= log_error_selector %>" ).addClass("hide");
$( "<%= form_reset_selector %>" ).trigger("reset");
<% if textarea_selector %>
$( "<%= textarea_selector %>" ).val("");
<% end %>
var url = $( "<%= log_url_selector %>" ).data("url");
$( "<%= log_url_selector %>" ).load(url);
<% end %>
<% end %>

0 comments on commit 16f9ccb

Please sign in to comment.