From ee3eaa609c6b5a1f7a78bfd35c8b0958cd57c92e Mon Sep 17 00:00:00 2001 From: senator Date: Wed, 16 Jun 2010 17:41:25 +0000 Subject: [PATCH] Acq: bugfixes for "Import Catalog Records by ID" 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 | 6 ++++++ Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js | 16 +++++++++++++++- Open-ILS/web/js/ui/default/acq/picklist/from_bib.js | 11 ++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/Util.js b/Open-ILS/web/js/dojo/openils/Util.js index 912edc55b..f535e227b 100644 --- a/Open-ILS/web/js/dojo/openils/Util.js +++ b/Open-ILS/web/js/dojo/openils/Util.js @@ -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); + } + } diff --git a/Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js b/Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js index 3bb1dcd50..09271296d 100644 --- a/Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js +++ b/Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js @@ -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"). diff --git a/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js b/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js index 9a4329f3d..4853d1650 100644 --- a/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js +++ b/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js @@ -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); -- 2.11.0