From 9c9f0f2a5497ae4f4e13c5d008e6e4e1c6758b43 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 29 Dec 2015 13:55:45 -0500 Subject: [PATCH] JBAS-673 Create PO from multiple pages of lineitems. Maintain a list of selected lieitems across multiple pages of lineitems in a selection list. When creating a PO from selected lineitems, include all selected lineitems in the new PO. See also KMAIN-1865. Code based on 5f309573. Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/acq/common/li_table.js | 61 +++++++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index 438da0272b..77084dacf3 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -19,6 +19,17 @@ dojo.require("openils.widget.PCrudAutocompleteBox"); dojo.require('dijit.form.ComboBox'); dojo.require('openils.CGI'); +// KCLS: used for tracking selected lineitems that are +// not visibible in the current page of lineitems. +// Stores a JSON hash of lineitem ID's +var checkBoxStorage = openils.XUL.localStorage(); + +if (window.location.toString().indexOf('picklist/view/') < 0) { + // only tracking selection of multiple pages of + // lineitems on the picklist page. + checkBoxStorage.removeItem('eg.acq.piclist.selected'); +} + if (!localeStrings) { /* we can do this because javascript doesn't have block scope */ dojo.requireLocalization('openils.acq', 'acq'); var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq'); @@ -550,11 +561,23 @@ function AcqLiTable() { } this.toggleSelect = function() { - if(self.toggleState) - dojo.forEach(self.selectors, function(i){i.checked = false}); - else - dojo.forEach(self.selectors, function(i){i.checked = true}); self.toggleState = !self.toggleState; + var fromStore = self.storedLiSelection(); + + dojo.forEach(self.selectors, function(i) { + + i.checked = self.toggleState; + var id = i.parentNode.parentNode.getAttribute('li'); + + if (self.toggleState) { + fromStore[id] = true; + } else { + delete fromStore[id]; + } + }); + + checkBoxStorage.setItem( + 'eg.acq.piclist.selected', js2JSON(fromStore)); }; @@ -632,6 +655,9 @@ function AcqLiTable() { } ); + var fromStore = self.storedLiSelection(); + indices = dojo.mixin(indices, fromStore); + var result = openils.Util.objectProperties(indices); // caller provided a lineitem state filter. remove IDs for lineitems @@ -745,6 +771,12 @@ function AcqLiTable() { } return li; } + + this.storedLiSelection = function() { + return JSON2js(checkBoxStorage.getItem( + 'eg.acq.piclist.selected') || "{}"); + } + /** * Inserts a single lineitem into the growing table of lineitems @@ -768,7 +800,26 @@ function AcqLiTable() { } } - self.selectors.push(dojo.query('[name=selectbox]', row)[0]); + var liSelector = dojo.query('[name=selectbox]', row)[0]; + self.selectors.push(liSelector); + + // when selecting a lineitem, add it to the stored list + // of selected lineitems + liSelector.onclick = function() { + var fromStore = self.storedLiSelection(); + if (this.checked) { + fromStore[li.id()] = true; + } else { + delete fromStore[li.id()]; + } + checkBoxStorage.setItem( + 'eg.acq.piclist.selected', js2JSON(fromStore)); + }; + + // if a lineitem is in the set of selected lineitems, + // set the selector input to checked on page load. + var fromStore = self.storedLiSelection(); + if (fromStore[li.id()]) liSelector.checked = true; // sort the lineitem notes on edit_time if(!li.lineitem_notes()) li.lineitem_notes([]); -- 2.11.0