Acq: bugfixes for "Import Catalog Records by ID"
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 16 Jun 2010 17:41:25 +0000 (17:41 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 16 Jun 2010 17:41:25 +0000 (17:41 +0000)
Previously, this interface did not correctly interpret realistic CSV data as
produced by the Reporter module, as it was intended to do.

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

Open-ILS/web/js/dojo/openils/Util.js
Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js
Open-ILS/web/js/ui/default/acq/picklist/from_bib.js

index 912edc5..f535e22 100644 (file)
@@ -282,5 +282,11 @@ if(!dojo._hasResource["openils.Util"]) {
         return K;
     }
 
+    openils.Util.uniqueElements = function(L) {
+        var o = {};
+        for (var k in L) o[L[k]] = true;
+        return openils.Util.objectProperties(o);
+    }
+
 }
 
index 3bb1dcd..0927129 100644 (file)
@@ -63,11 +63,14 @@ if (!dojo._hasResource["openils.widget.XULTermLoader"]) {
                         alert(this._.TERM_LIMIT);
                         return;
                     }
-                    var data = this.parseUnimaginatively(
+                    var data = this[
+                        this.parseCSV ? "parseAsCSV" : "parseUnimaginatively"
+                    ](
                         openils.XUL.contentFromFileOpenDialog(
                             this._.CHOOSE_FILE, this.args.fileSizeLimit
                         )
                     );
+
                     if (data.length + this.terms.length >=
                         this.args.termLimit) {
                         alert(this._.TERM_LIMIT_SOME);
@@ -83,6 +86,17 @@ if (!dojo._hasResource["openils.widget.XULTermLoader"]) {
                     alert(E);
                 }
             },
+            "parseAsCSV": function(data) {
+                return this.parseUnimaginatively(data).
+                    map(
+                        function(o) {
+                            return o.match(/^".+"$/) ? o.slice(1,-1) : o;
+                        }
+                    ).
+                    filter(
+                        function(o) { return Boolean(o.match(/^\d+$/)); }
+                    );
+            },
             "parseUnimaginatively": function(data) {
                 if (!data) return [];
                 else return data.split("\n").
index 9a4329f..4853d16 100644 (file)
@@ -7,9 +7,14 @@ var pager = null;
 var usingPl = null;
 
 function fetchRecords() {
-    var data = termLoader.attr("value");
+    var data = openils.Util.uniqueElements(termLoader.attr("value"));
     var result_count = 0;
-    pager.total = data.length;
+    // Don't show a total for now... This total is the total number of
+    // search terms, but a user would take it to mean the total number of
+    // results, which we don't have a straightfoward way of getting without
+    // doing the search more that once.
+
+    // pager.total = data.length;
 
     progressDialog.show(true);
     fieldmapper.standardRequest(
@@ -60,7 +65,7 @@ function beginSearch() {
 
 function init() {
     new openils.widget.XULTermLoader(
-        {"parentNode": "acq-frombib-upload"}
+        {"parentNode": "acq-frombib-upload", "parseCSV": true}
     ).build(function(w) { termLoader = w; });
     liTable = new AcqLiTable();
     pager = new LiTablePager(fetchRecords, liTable);