Acq: the XULTermLoader dijit now returns the first columns of CSV rows
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 13 May 2010 21:07:16 +0000 (21:07 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 13 May 2010 21:07:16 +0000 (21:07 +0000)
Could be improved later to allow more control over what data you get back,
but it works fine for the current uses (reading a file of one-term-per-line
for unified search and reading a CSV file where the first column is of
interest in the Bib record->lineitem interface).

Also added a little support to the LI table/pager for remember what lineitems
are selected even after you move on to the next page.  Nothing really takes
full advantage of this yet, though.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16432 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js
Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/js/ui/default/acq/common/li_table_pager.js

index 50f2d27..3bb1dcd 100644 (file)
@@ -85,9 +85,10 @@ if (!dojo._hasResource["openils.widget.XULTermLoader"]) {
             },
             "parseUnimaginatively": function(data) {
                 if (!data) return [];
-                else return data.split(/[\n, ]/).filter(
-                    function(o) { return o.length > 0; }
-                );
+                else return data.split("\n").
+                    filter(function(o) { return o.length > 0; }).
+                    map(function(o) { return o.split(",")[0] }).
+                    filter(function(o) { return o.length > 0; });
             }
         }
     );
index 19a8754..b881630 100644 (file)
@@ -110,12 +110,14 @@ function AcqLiTable() {
     dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
     dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
 
-    this.reset = function() {
+    this.reset = function(keep_selectors) {
         while(self.tbody.childNodes[0])
             self.tbody.removeChild(self.tbody.childNodes[0]);
-        self.selectors = [];
         self.noteAcks = {};
         self.relCache = {};
+
+        if (!keep_selectors)
+            self.selectors = [];
     };
     
     this.setNext = function(handler) {
@@ -182,13 +184,16 @@ function AcqLiTable() {
     /** @param all If true, assume all are selected */
     this.getSelected = function(all) {
         var selected = [];
+        var indices = {};   /* use to uniqify. needed in paging situations. */
         dojo.forEach(self.selectors, 
             function(i) { 
                 if(i.checked || all)
-                    selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
+                    indices[i.parentNode.parentNode.getAttribute('li')] = true;
             }
         );
-        return selected;
+        return openils.Util.objectProperties(indices).map(
+            function(liId) { return self.liCache[liId]; }
+        );
     };
 
     this.setRowAttr = function(td, liWrapper, field, type) {
index d352e52..ba92d94 100644 (file)
@@ -21,7 +21,7 @@ function LiTablePager() {
         [this.batch, this.total] = this.fetcher(this.offset, this.limit);
 
         if (this.batch.length) {
-            this.liTable.reset();
+            this.liTable.reset(/* keep_selectors */ true);
             this.liTable.show("list");
             this.batch.forEach(function(li) { self.liTable.addLineitem(li); });
         }