"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");
"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);
}
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)}