[open-ils-commits] r15614 - in trunk/Open-ILS/web: css/skin/default js/ui/default/acq/common (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Feb 22 15:08:09 EST 2010


Author: senator
Date: 2010-02-22 15:08:04 -0500 (Mon, 22 Feb 2010)
New Revision: 15614

Modified:
   trunk/Open-ILS/web/css/skin/default/acq.css
   trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
Log:
Acq: Distribution formula dropdown in lineitem detail editor shows use count.


Modified: trunk/Open-ILS/web/css/skin/default/acq.css
===================================================================
--- trunk/Open-ILS/web/css/skin/default/acq.css	2010-02-22 18:55:06 UTC (rev 15613)
+++ trunk/Open-ILS/web/css/skin/default/acq.css	2010-02-22 20:08:04 UTC (rev 15614)
@@ -144,6 +144,7 @@
 .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; }

Modified: trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2010-02-22 18:55:06 UTC (rev 15613)
+++ trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2010-02-22 20:08:04 UTC (rev 15614)
@@ -35,7 +35,7 @@
     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 @@
         this.copyCache = {};
         this.copyWidgetCache = {};
         this.oldCopyWidgetCache = {};
-        this.dfaCache = [];
+        this.dfaCache = {};
         this.dfeOffset = 0;
 
         acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
@@ -609,7 +609,7 @@
     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 @@
             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 @@
 
         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 @@
         dojo.connect(reset, 'onClick', 
             function() {
                 self.restoreCopyFieldsBeforeDF();
-                self.dfaCache = [];
+                self.dfaCache = {};
                 self.dfeOffset = 0;
+                self._updateFormulaStore();
                 reset.attr("disabled", "true");
             }
         );
@@ -715,11 +720,27 @@
         }
 
         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 @@
         }
     };
 
+    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 = "<span class='acq-lit-distrib-form-use-count'>[" +
+                obj.use_count + "]</span>&nbsp; " + 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 @@
         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 @@
             );
         }
 
-        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 = {};
         }
     }
 



More information about the open-ils-commits mailing list