From f1fa7399b3394cae42d9487d5ed059a2ec578eb8 Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 22 Feb 2010 20:08:04 +0000 Subject: [PATCH] Acq: Distribution formula dropdown in lineitem detail editor shows use count. git-svn-id: svn://svn.open-ils.org/ILS/trunk@15614 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/css/skin/default/acq.css | 1 + Open-ILS/web/js/ui/default/acq/common/li_table.js | 114 ++++++++++++++-------- 2 files changed, 77 insertions(+), 38 deletions(-) diff --git a/Open-ILS/web/css/skin/default/acq.css b/Open-ILS/web/css/skin/default/acq.css index 6b00a986e..3ae2d80ea 100644 --- a/Open-ILS/web/css/skin/default/acq.css +++ b/Open-ILS/web/css/skin/default/acq.css @@ -144,6 +144,7 @@ label[for="attr_search_type_scalar"] { vertical-align: top; } .acq-lit-li-menu-bar {width:99%; text-align:left; border:1px solid #aaa; margin:5px 0px 10px 0px;} .acq-lit-li-menu-left {text-align:left; width:300px;} .acq-lit-li-menu-right {text-align:left;} +.acq-lit-distrib-form-use-count { color: #999; font-weight: bold; } .acq-lit-table-spacer { height:20px; } .acq-lit-row td[name="selector"] { width:1.5em; font-weight:bold; color:blue; font-size:110%;} #acq-lit-notes-tbody li { margin-bottom:10px; border:1px solid #aaa; -moz-border-radius: 5px 5px 5px 5px; } 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 22c3a8be6..322d97006 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 @@ -35,7 +35,7 @@ function AcqLiTable() { this.liCache = {}; this.plCache = {}; this.poCache = {}; - this.dfaCache = []; + this.dfaCache = {}; this.dfeOffset = 0; this.toggleState = false; this.tbody = dojo.byId('acq-lit-tbody'); @@ -580,7 +580,7 @@ function AcqLiTable() { this.copyCache = {}; this.copyWidgetCache = {}; this.oldCopyWidgetCache = {}; - this.dfaCache = []; + this.dfaCache = {}; this.dfeOffset = 0; acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) }; @@ -609,7 +609,7 @@ function AcqLiTable() { this._addDistribFormulaRow = function() { var self = this; - if(!self.distribFormulaStore) { + if (!self.distribForms) { // no formulas, hide the form openils.Util.hide('acq-lit-distrib-formula-tbody'); return; @@ -619,12 +619,16 @@ function AcqLiTable() { this.distribFormulaTemplate = dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row')); - var row = dojo.byId('acq-lit-distrib-formula-tbody').appendChild(this.distribFormulaTemplate.cloneNode(true)); + var row = this.distribFormulaTemplate.cloneNode(true); + dojo.place(row, "acq-lit-distrib-formula-tbody", "only"); - var selector = new dijit.form.FilteringSelect( - {store : self.distribFormulaStore}, - nodeByName('selector', row) + this.dfSelector = new dijit.form.FilteringSelect( + {"labelAttr": "dynLabel", "labelType": "html"}, + nodeByName("selector", row) ); + this._updateFormulaStore(); + this.dfSelector.fetchProperties = + {"sort": [{"attribute": "use_count", "descending": true}]}; var apply = new dijit.form.Button( {"label": localeStrings.APPLY}, @@ -638,7 +642,7 @@ function AcqLiTable() { dojo.connect(apply, 'onClick', function() { - var form_id = selector.attr('value'); + var form_id = self.dfSelector.attr("value"); if(!form_id) return; self._applyDistribFormula(form_id); reset.attr("disabled", false); @@ -648,8 +652,9 @@ function AcqLiTable() { dojo.connect(reset, 'onClick', function() { self.restoreCopyFieldsBeforeDF(); - self.dfaCache = []; + self.dfaCache = {}; self.dfeOffset = 0; + self._updateFormulaStore(); reset.attr("disabled", "true"); } ); @@ -715,11 +720,27 @@ function AcqLiTable() { } if (entries_applied) { - this.dfaCache.push(formula.id()); + this.dfaCache[formula.id()] = ++(this.dfaCache[formula.id()]) || 1; + this._updateFormulaStore(); this.dfeOffset += entries_applied; }; }; + /** + * This function updates the DF store for the dropdown so that use_counts + * can reflect DF applications from this session before they're saved + * server-side. + */ + this._updateFormulaStore = function() { + this.dfSelector.store = new dojo.data.ItemFileReadStore( + { + "data": self._labelFormulasWithCounts( + acqdf.toStoreData(self.distribForms) + ) + } + ); + }; + this.saveCopyFieldsBeforeDF = function(copy_id) { var self = this; if (!this.oldCopyWidgetCache[copy_id]) { @@ -748,31 +769,40 @@ function AcqLiTable() { } }; + this._labelFormulasWithCounts = function(store_data) { + for (var key in store_data.items) { + var obj = store_data.items[key]; + + if (this.dfaCache[obj.id]) + obj.use_count = Number(obj.use_count) + this.dfaCache[obj.id]; + + obj.dynLabel = "[" + + obj.use_count + "]  " + obj.name; + } + return store_data; + }; + + /** + * This method formerly would not refetch the DF formulas if they'd been + * loaded already, but now it always re-fetches, since use_count changes. + */ this._fetchDistribFormulas = function(onload) { - if(this.distribForms) { - onload(); - } else { - var self = this; - fieldmapper.standardRequest( - ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve.atomic'], - { async: true, - params: [openils.User.authtoken], - oncomplete: function(r) { - self.distribForms = openils.Util.readResponse(r); - if(!self.distribForms || self.distribForms.length == 0) { - self.distribForms = []; - } else { - self.distribFormulaStore = - new dojo.data.ItemFileReadStore( - {data:acqdf.toStoreData(self.distribForms)} - ); - } - self._addDistribFormulaRow(); - onload(); + fieldmapper.standardRequest( + ["open-ils.acq", + "open-ils.acq.distribution_formula.ranged.retrieve.atomic"], + { + "async": true, + "params": [openils.User.authtoken], + "oncomplete": function(r) { + self.distribForms = openils.Util.readResponse(r); + if(!self.distribForms || self.distribForms.length == 0) { + self.distribForms = []; } + self._addDistribFormulaRow(); + onload(); } - ); - } + } + ); } this._drawBatchCopyWidgets = function() { @@ -993,6 +1023,15 @@ function AcqLiTable() { this.copyTbody.removeChild(row); } + this._dfaCacheAsList = function() { + var L = []; + for (var key in this.dfaCache) { + for (var i = 0; i < this.dfaCache[key]; i++) + L.push(key); + } + return L; + } + this.saveCopyChanges = function(liId) { var self = this; var copies = []; @@ -1033,23 +1072,22 @@ function AcqLiTable() { ); } - if (this.dfaCache.length > 0) { - var oldlength = this.dfaCache.length; - + var dfa_list = this._dfaCacheAsList(); + if (dfa_list.length > 0) { fieldmapper.standardRequest( ["open-ils.acq", "open-ils.acq.distribution_formula.record_application"], { "async": true, - "params": [openils.User.authtoken, this.dfaCache, liId], + "params": [openils.User.authtoken, dfa_list, liId], "onresponse": function(r) { var res = openils.Util.readResponse(r); - if (res && res.length != oldlength) + if (res && res.length < dfa_list.length) alert(localeStrings.DFA_NOT_ALL); } } ); - this.dfaCache = []; + this.dfaCache = {}; } } -- 2.11.0