Skip to content

Commit

Permalink
Merge pull request #374 from grana-equinix/ENG-22484-Ability-to-selec…
Browse files Browse the repository at this point in the history
…t-multiple-line-items-in-a-single-click-during-refund

Eng 22484 ability to select multiple line items in a single click during refund
  • Loading branch information
pierre authored Sep 11, 2023
2 parents 9fae397 + 3c99afe commit 171992e
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion app/views/kaui/refunds/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
</div>

<div id="invoiceItems" style="display:none">
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-10">
<input type="checkbox" id="selectAll">
<%="Select All" %>
</div>
</div>
<% @invoice.items.each_with_index do |ii, index| %>
<% if ii.amount > 0 %>
<div id=<%= "div_#{ii.invoice_item_id}" %> class="form-group">
Expand Down Expand Up @@ -144,9 +151,23 @@
}
validateRefundAmount();
};
/*
* Check status of all items check-box check/uncheck status for select all chec-kbox
*/
var checkSelectAllCheckboxStatus = function(){
var checkedCheckBoxCount = 0;
var checkboxList = $('input').filter(function() { return this.id.match(/cb_adj_/) });
var checkboxListCount = checkboxList.length;
checkboxList.each(function() {
if ($(this).is(':checked')) {
checkedCheckBoxCount++;
}
});
$("#selectAll").prop('checked', checkedCheckBoxCount == checkboxListCount);
}

/*
* When clicking checkbox for each item, disable amount and recompute total refund amount
* When clicking checkbox for each item, disable amount, Changes SelectAll status and recompute total refund amount
*/
var onClickInvoiceItemAdjustment = function(event) {
var id = checkboxToTextId(this.id);
Expand All @@ -158,8 +179,30 @@
}
recomputeRefundAmountAndValidateAmount();
validateInvoiceItemAmount(id);
checkSelectAllCheckboxStatus();
};

/*
* When clicking select all checkbox - select each items, disable amount and recompute total refund amount
*/
var onClickInvoiceItemsSelectAll = function(event){
var isChecked = $('#selectAll').prop('checked');
$('input').filter(function() { return this.id.match(/tf_adj_/) }).each(function() {
var textFieldId = this.id;
var textFieldIdElm = $("#" + textFieldId);
var checkboxId = textToCheckboxId(this.id);
if(checkboxId){
$("#" + checkboxId).prop('checked', isChecked);
textFieldIdElm.prop('readonly', isChecked);
if(!isChecked){
textFieldIdElm.attr('value', textFieldIdElm.attr('originalValue'));
}
validateInvoiceItemAmount(textFieldId);
}
});
recomputeRefundAmountAndValidateAmount();
}

/*
* When selecting Invoice Adjustment or No Adjustment, hide invoice items and recompute refund Amount
*/
Expand Down Expand Up @@ -213,6 +256,11 @@
return this.id.match(/cb_adj_/);
}).click(onClickInvoiceItemAdjustment);

/*
* Attach handler onClickInvoiceItemsSelectAll for selectall checkbox
*/
$('#selectAll').click(onClickInvoiceItemsSelectAll);

/*
* Attach handler for all invoice item text areas so that:
* - We disable posting form when pressing 'ENTER'
Expand Down

0 comments on commit 171992e

Please sign in to comment.