Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eng 22484 ability to select multiple line items in a single click during refund #374

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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