[open-ils-commits] [GIT] Evergreen ILS branch master updated. 2c4841f00487b0653f69fa2fa7f7917353a1e6a5

Evergreen Git git at git.evergreen-ils.org
Thu Oct 6 09:34:58 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  2c4841f00487b0653f69fa2fa7f7917353a1e6a5 (commit)
      from  1ba8903c40413f692ff0146ece061417eafcdafd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2c4841f00487b0653f69fa2fa7f7917353a1e6a5
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date:   Tue Oct 4 17:51:35 2011 -0400

    Really add *entire* selection list to a purchase order, when desired,
    
    and generally do what a user would expect when, in Acq, the user
    executes an operation on "all items".
    
    This addresses LaunchPad bug #810030.
    
    The fundamental issue is that an AcqLiTable, which is used in several
    different ways in different interfaces, may be representing items on a
    selection list (for example), but it doesn't necessarily know all of the
    items that belong to that selection list.  It only knows what it has drawn.
    
    This addresses that deficiency by teaching the getSelected() method
    some new tricks so that it can consult the server in the various ways
    appropriate to getting a list of /all/ the items on a selection list, a
    purchase order, a virtual PO, a set of search results, etc.
    
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

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 23ed428..1178515 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
@@ -183,19 +183,80 @@ function AcqLiTable() {
     };
 
 
+    this.getAll = function(callback, id_only) {
+        /* For some uses of the li table, we may not really know about "all"
+         * the lineitems that the user thinks we know about. If we're a paged
+         * picklist, for example, we only know about the lineitems we've
+         * displayed, but not necessarily all the lineitems on the picklist.
+         * So we reach out to pcrud to inform us.
+         */
+
+        var oncomplete = function(r) {
+            var id_list = openils.Util.readResponse(r);
+            if (id_only)
+                callback(id_list);
+            else
+                self.fetchLineitemsById(id_list, callback);
+        };
+
+        if (this.isPL) {
+            this.pcrud.search(
+                "jub", {"picklist": this.isPL}, {
+                    "id_list": true,    /* sic, even if id_only */
+                    "async": true,
+                    "oncomplete": oncomplete
+                }
+            );
+            return;
+        } else if (this.isPO) {
+            this.pcrud.search(
+                "jub", {"purchase_order": this.isPO}, {
+                    "id_list": true,
+                    "async": true,
+                    "oncomplete": oncomplete
+                }
+            );
+            return;
+        } else if (this.isUni && this.pager) {
+            this.pager.getAllLineitemIDs(oncomplete);
+            return;
+        }
+
+        /* If execution reaches this point, we don't need or can't perform
+         * any special tricks to find out the "real" list of "all" lineitems
+         * in this context, so we fall back to the old method.
+         */
+        callback(this.getSelected(true, null, id_only));
+    };
+
     /** @param all If true, assume all are selected */
-    this.getSelected = function(all) {
-        var selected = [];
+    this.getSelected = function(
+        all,
+        callback /* If you want a "good" idea of "all" lineitems, you must
+        provide a callback that accepts an array parameter, rather than
+        relying on the return value of this method itself. */,
+        id_only
+    ) {
+        if (all && callback)
+            return this.getAll(callback, id_only);
+
         var indices = {};   /* use to uniqify. needed in paging situations. */
-        dojo.forEach(self.selectors, 
+        dojo.forEach(this.selectors,
             function(i) { 
                 if(i.checked || all)
                     indices[i.parentNode.parentNode.getAttribute('li')] = true;
             }
         );
-        return openils.Util.objectProperties(indices).map(
-            function(liId) { return self.liCache[liId]; }
-        );
+
+        var result = openils.Util.objectProperties(indices);
+
+        if (!id_only)
+            result = result.map(function(liId) { return self.liCache[liId]; });
+
+        if (callback)
+            callback(result);
+        else
+            return result;
     };
 
     this.setRowAttr = function(td, liWrapper, field, type) {
@@ -261,8 +322,8 @@ function AcqLiTable() {
         var row = self.rowTemplate.cloneNode(true);
         if (!skip_final_placement) {
             self.tbody.appendChild(row);
-            self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
         }
+        self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
 
         // sort the lineitem notes on edit_time
         if(!li.lineitem_notes()) li.lineitem_notes([]);
@@ -816,6 +877,27 @@ function AcqLiTable() {
         );
     };
 
+    /* For a given list of lineitem ids, build a list of full lineitems
+     * re-using the fetching logic that is otherwise typical to use in this
+     * module.
+     *
+     * If we've already got a lineitem in the cache, just use that.
+     *
+     * Once we've built a list of lineitems, call callback(thatlist).
+     */
+    this.fetchLineitemsById = function(id_list, callback) {
+        var total = id_list.length;
+        var result_list = [];
+
+        var inner = function(li) {
+            result_list.push(li)
+            if (--total <= 0)
+                callback(result_list);
+        };
+
+        id_list.forEach(function(id) { self._fetchLineitem(id, inner); });
+    };
+
     this._fetchLineitem = function(liId, handler, force) {
 
         var li = this.liCache[liId];
@@ -2253,26 +2335,42 @@ function AcqLiTable() {
 
 
     this._createPO = function(fields) {
-        this.show('acq-lit-progress-numbers');
-        var po = new fieldmapper.acqpo();
-        po.provider(this.createPoProviderSelector.attr('value'));
-        po.ordering_agency(this.createPoAgencySelector.attr('value'));
-        po.prepayment_required(fields.prepayment_required[0] ? true : false);
+        var wantall = (fields.create_from == "all");
+
+        /* If we're a picklist or purchase order already and the user wants
+         * all lineitems, we might have pages' worth of lineitems haven't all
+         * been loaded yet, so getSelected() won't find them.  The server,
+         * however, should know about all our lineitems, so let's ask the
+         * server for a complete list.
+         */
+
+        if (wantall) {
+            this.getSelected(
+                true, function(list) {
+                    self._createPOFromLineitems(fields, list);
+                }, /* id_list */ true
+            );
+        } else {
+            this._createPOFromLineitems(fields, this.getSelected(false, null, true /* id_list */));
+        }
+    };
 
-        var selected = this.getSelected( (fields.create_from == 'all') );
-        if(selected.length == 0) return;
+    this._createPOFromLineitems = function(fields, selected) {
+        if (selected.length == 0) return;
 
-        var max = selected.length * 3;
+        this.show("acq-lit-progress-numbers");
+        var po = new fieldmapper.acqpo();
+        po.provider(this.createPoProviderSelector.attr("value"));
+        po.ordering_agency(this.createPoAgencySelector.attr("value"));
+        po.prepayment_required(fields.prepayment_required[0] ? true : false);
 
-        var self = this;
         fieldmapper.standardRequest(
-            ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
+            ["open-ils.acq", "open-ils.acq.purchase_order.create"],
             {   async: true,
                 params: [
                     openils.User.authtoken, 
-                    po, 
-                    {
-                        lineitems : selected.map(function(li) { return li.id() }),
+                    po, {
+                        lineitems : selected,
                         create_assets : fields.create_assets[0],
                     }
                 ],
@@ -2280,12 +2378,15 @@ function AcqLiTable() {
                 onresponse : function(r) {
                     var resp = openils.Util.readResponse(r);
                     self._updateProgressNumbers(resp);
-                    if(resp.complete) 
-                        location.href = oilsBasePath + '/acq/po/view/' + resp.purchase_order.id();
+                    if (resp.complete) {
+                        location.href = oilsBasePath + "/acq/po/view/" +
+                            resp.purchase_order.id();
+                    }
                 }
             }
         );
-    }
+    };
+
 
     this.batchFundWidget = null;
 
@@ -2419,39 +2520,59 @@ function AcqLiTable() {
     }
 
     this._savePl = function(values) {
-        var self = this;
-        var selected = this.getSelected( (values.which == 'all') );
-        openils.Util.show('acq-lit-generic-progress');
+        this.getSelected(
+            (values.which == 'all'),
+            function(list) { self._savePlFromLineitems(values, list); }
+        );
+    };
+
+    this._savePlFromLineitems = function(values, selected) {
+        openils.Util.show("acq-lit-generic-progress");
 
         if(values.new_name) {
             openils.acq.Picklist.create(
-                {name: values.new_name}, 
+                {name: values.new_name},
                 function(id) {
-                    self._updateLiList(id, selected, 0, 
-                        function(){
-                            location.href = oilsBasePath + '/acq/picklist/view/' + id;
-                        });
+                    self._updateLiList(
+                        id, selected, 0,
+                        function() {
+                            location.href =
+                                oilsBasePath + "/acq/picklist/view/" + id;
+                        }
+                    );
                 }
             );
         } else if(values.existing_pl) {
             // update lineitems to use an existing picklist
-            self._updateLiList(values.existing_pl, selected, 0, 
+            self._updateLiList(
+                values.existing_pl, selected, 0,
                 function(){
-                    location.href = oilsBasePath + '/acq/picklist/view/' + values.existing_pl;
-                });
+                    location.href =
+                        oilsBasePath + "/acq/picklist/view/" +
+                        values.existing_pl;
+                }
+            );
         }
-    }
+    };
 
     this._updateLiState = function(values, state) {
-        var self = this;
-        var selected = this.getSelected( (values.which == 'all') );
+        progressDialog.show(true);
+        this.getSelected(
+            (values.which == 'all'),
+            function(list) {
+                self._updateLiStateFromLineitems(values, state, list);
+            }
+        );
+    };
+
+    this._updateLiStateFromLineitems = function(values, state, selected) {
         if(!selected.length) return;
         dojo.forEach(selected, function(li) {li.state(state);});
-        self._updateLiList(null, selected, 0, 
+        self._updateLiList(null, selected, 0,
             // TODO consider inline updates for efficiency
             function() { location.href = location.href }
         );
-    }
+    };
 
     this._updateLiList = function(pl, list, idx, oncomplete) {
         if(idx >= list.length) return oncomplete();
diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js b/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js
index 53d942a..20d8a17 100644
--- a/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js
+++ b/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js
@@ -4,6 +4,9 @@ function LiTablePager() {
     this.init = function(dataLoader, liTable, offset, limit) {
         this.dataLoader = dataLoader;
         this.liTable = liTable;
+        this.liTable.isUni = true;
+        this.liTable.pager = this;  /* XXX memory leak waiting to happen? */
+
         this.displayLimit = limit || 15;
         this.displayOffset = offset || 0;
 
@@ -57,5 +60,15 @@ function LiTablePager() {
         }
     };
 
+    this.getAllLineitemIDs = function(callback) {
+        this.dataLoader({
+            "id_list": true,
+            "atomic": true,
+            "skip_paging": true,
+            "onresponse": null,
+            "oncomplete": callback
+        });
+    };
+
     this.init.apply(this, arguments);
 }
diff --git a/Open-ILS/web/js/ui/default/acq/search/unified.js b/Open-ILS/web/js/ui/default/acq/search/unified.js
index 53be741..8ff340e 100644
--- a/Open-ILS/web/js/ui/default/acq/search/unified.js
+++ b/Open-ILS/web/js/ui/default/acq/search/unified.js
@@ -603,7 +603,6 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) {
     var self = this;
 
     this.liPager = liPager;
-    this.liPager.liTable.isUni = true;
 
     this.poGrid = poGrid;
     this.plGrid = plGrid;
@@ -693,27 +692,55 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) {
         }
     };
 
-    this._dataLoader = function() {
+    this._dataLoader = function(opts) {
         /* This function must contain references to "self" only, not "this." */
         var grid = self.result_types[self.result_type].interface;
+
+        if (!opts)
+            opts = {};
+
         self.count_results = 0;
-        self.params[4].offset = grid.displayOffset;
-        self.params[4].limit = grid.displayLimit;
-
-        fieldmapper.standardRequest(
-            ["open-ils.acq", self.method_name], {
-                "params": self.params,
-                "async": true,
-                "onresponse": function(r) {
-                    if (r = openils.Util.readResponse(r)) {
-                        if (!self.count_results++)
-                            self.show(self.result_type);
-                        self.add(self.result_type, r);
-                    }
-                },
-                "oncomplete": function() { self.resultsComplete(); }
-            }
-        );
+
+        var use_params = dojo.clone(self.params);   /* need copy, not ref */
+
+        if (!opts.skip_paging) {
+            use_params[4].offset = grid.displayOffset;
+            use_params[4].limit = grid.displayLimit;
+        }
+
+        var method = self.method_name;
+        if (opts.atomic)
+            method += ".atomic";
+
+        if (opts.id_list)
+            use_params[4].id_list = true;
+
+        var request_options = {
+            "params": use_params,
+            "async": true
+        };
+
+        if (typeof opts.onresponse != "undefined") {
+            request_options.onresponse = opts.onresponse;
+        } else {
+            /* normal onresponse handler for most times we call this method */
+            request_options.onresponse = function(r) {
+                if (r = openils.Util.readResponse(r)) {
+                    if (!self.count_results++)
+                        self.show(self.result_type);
+                    self.add(self.result_type, r);
+                }
+            };
+        }
+
+        if (typeof opts.oncomplete != "undefined") {
+            request_options.oncomplete = opts.oncomplete;
+        } else {
+            /* normal oncomplete handler for most times we call this method */
+            request_options.oncomplete = function() { self.resultsComplete(); };
+        }
+
+        fieldmapper.standardRequest(["open-ils.acq", method], request_options);
     };
 
     this.add = function(which, what) {

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/web/js/ui/default/acq/common/li_table.js  |  199 ++++++++++++++++----
 .../web/js/ui/default/acq/common/li_table_pager.js |   13 ++
 Open-ILS/web/js/ui/default/acq/search/unified.js   |   65 +++++--
 3 files changed, 219 insertions(+), 58 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list