webstaff: get Load Catalog Record IDs working
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 8 Feb 2017 19:46:31 +0000 (14:46 -0500)
committerKathy Lussier <klussier@masslnc.org>
Sat, 18 Feb 2017 18:31:32 +0000 (13:31 -0500)
Provide an alternative using FileReader to the XPCOM-based
client-side file reading that this feature uses under XUL.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/dojo/openils/widget/XULTermLoader.js
Open-ILS/web/js/ui/default/staff/services/eframe.js

index db49e08..47d23d1 100644 (file)
@@ -35,13 +35,24 @@ if (!dojo._hasResource["openils.widget.XULTermLoader"]) {
                     "span", {"innerHTML": this.terms.length},
                     this.labelNode, "first"
                 );
-                this.buttonNode = dojo.create(
-                    "button", {
-                        "innerHTML": this._.BUTTON_TEXT,
-                        "onclick": function() { self.loadTerms(); }
-                    },
-                    this.domNode, "last"
-                );
+                if (window.parent.IEMBEDXUL) {
+                    this.buttonNode = dojo.create(
+                        "input", {
+                            "type" : "file",
+                            "innerHTML": this._.BUTTON_TEXT,
+                            "onchange": function(evt) { self.loadTerms(evt); }
+                        },
+                        this.domNode, "last"
+                    );
+                } else {
+                    this.buttonNode = dojo.create(
+                        "button", {
+                            "innerHTML": this._.BUTTON_TEXT,
+                            "onclick": function() { self.loadTerms(); }
+                        },
+                        this.domNode, "last"
+                    );
+                }
 
                 if (this.args.parentNode)
                     dojo.place(this.domNode, this.args.parentNode, "last");
@@ -57,31 +68,49 @@ if (!dojo._hasResource["openils.widget.XULTermLoader"]) {
             "focus": function() {
                 this.buttonNode.focus();
             },
-            "loadTerms": function() {
+            "loadTerms": function(evt) {
                 try {
                     if (this.terms.length >= this.args.termLimit) {
                         alert(this._.TERM_LIMIT);
                         return;
                     }
-                    var data = this[
-                        this.parseCSV ? "parseAsCSV" : "parseUnimaginatively"
-                    ](
-                        openils.XUL.contentFromFileOpenDialog(
-                            this._.CHOOSE_FILE, this.args.fileSizeLimit
-                        )
-                    );
+                    var data;
+                    var self = this;
 
-                    if (data.length + this.terms.length >=
-                        this.args.termLimit) {
-                        alert(this._.TERM_LIMIT_SOME);
-                        var can = this.args.termLimit - this.terms.length;
-                        if (can > 0)
-                            this.terms = this.terms.concat(data.slice(0, can));
+                    function updateTermList() {
+                        if (data.length + self.terms.length >=
+                            self.args.termLimit) {
+                            alert(self._.TERM_LIMIT_SOME);
+                            var can = self.args.termLimit - self.terms.length;
+                            if (can > 0)
+                                self.terms = self.terms.concat(data.slice(0, can));
+                        } else {
+                            self.terms = self.terms.concat(data);
+                        }
+                        self.attr("value", self.terms);
+                        self.updateCount();
+                    }
+
+                    if (evt && window.IAMBROWSER) {
+                        var reader = new FileReader();
+                        reader.onloadend = function(evt) {
+                            data = self[
+                                this.parseCSV ? "parseAsCSV" : "parseUnimaginatively"
+                            ](evt.target.result);
+                            updateTermList();
+                        };
+                        reader.readAsText(evt.target.files[0]);
                     } else {
-                        this.terms = this.terms.concat(data);
+                        data = this[
+                            this.parseCSV ? "parseAsCSV" : "parseUnimaginatively"
+                        ](
+                            openils.XUL.contentFromFileOpenDialog(
+                                this._.CHOOSE_FILE, this.args.fileSizeLimit
+                            )
+                        );
+                        updateTermList();
                     }
-                    this.attr("value", this.terms);
-                    this.updateCount();
+
                 } catch(E) {
                     alert(E);
                 }
index 7fdbd0a..b9b4dd7 100644 (file)
@@ -33,6 +33,10 @@ angular.module('egCoreMod')
         link: function (scope, element, attrs) {
             scope.autoresize = 'autoresize' in attrs;
             scope.showIframe = true;
+            // well, I *might* embed XUL; in any event, this gives a way
+            // for things like Dojo widgets to detect whether they are
+            // running in an eframe before the frame load has finished.
+            window.IEMBEDXUL = true;
             element.find('iframe').on(
                 'load',
                 function() {scope.egEmbedFrameLoader(this)}