1 if (!dojo._hasResource["openils.widget.XULTermLoader"]) {
2 dojo._hasResource["openils.widget.XULTermLoader"] = true;
4 dojo.provide("openils.widget.XULTermLoader");
5 dojo.require("openils.XUL");
6 dojo.requireLocalization("openils.widget", "XULTermLoader");
9 "openils.widget.XULTermLoader", [dijit.layout.ContentPane], {
10 "constructor": function(args) {
13 this._ = openils.widget.XULTermLoader.localeStrings;
15 /* XXX Totally arbitrary defaults. Keeping them low for now
16 * since all search terms have to be turned into a URL.
17 * There will need to be a better long term solution.
19 if (!this.args.fileSizeLimit)
20 this.args.fileSizeLimit = 2048;
21 if (!this.args.termLimit)
22 this.args.termLimit = 100;
24 "build": function(callback) {
27 this.domNode = dojo.create("span");
28 this.labelNode = dojo.create(
30 "innerHTML": this._.LABEL_TEXT,
31 "style": "padding-right: 8px;"
32 }, this.domNode, "last"
34 this.countNode = dojo.create(
35 "span", {"innerHTML": this.terms.length},
36 this.labelNode, "first"
38 this.buttonNode = dojo.create(
40 "innerHTML": this._.BUTTON_TEXT,
41 "onclick": function() { self.loadTerms(); }
46 if (this.args.parentNode)
47 dojo.place(this.domNode, this.args.parentNode, "last");
51 "updateCount": function() {
52 var value = this.attr("value");
53 if (dojo.isArray(value))
54 this.terms = this.attr("value");
55 this.countNode.innerHTML = this.terms.length;
58 this.buttonNode.focus();
60 "loadTerms": function() {
62 if (this.terms.length >= this.args.termLimit) {
63 alert(this._.TERM_LIMIT);
67 this.parseCSV ? "parseAsCSV" : "parseUnimaginatively"
69 openils.XUL.contentFromFileOpenDialog(
70 this._.CHOOSE_FILE, this.args.fileSizeLimit
74 if (data.length + this.terms.length >=
75 this.args.termLimit) {
76 alert(this._.TERM_LIMIT_SOME);
77 var can = this.args.termLimit - this.terms.length;
79 this.terms = this.terms.concat(data.slice(0, can));
81 this.terms = this.terms.concat(data);
83 this.attr("value", this.terms);
89 "parseAsCSV": function(data) {
90 return this.parseUnimaginatively(data).
93 return o.match(/^".+"$/) ? o.slice(1,-1) : o;
97 function(o) { return Boolean(o.match(/^\d+$/)); }
100 "parseUnimaginatively": function(data) {
101 if (!data) return [];
102 else return data.split("\n").
103 filter(function(o) { return o.length > 0; }).
104 map(function(o) {return o.replace("\r","").split(",")[0];}).
105 filter(function(o) { return o.length > 0; });
110 openils.widget.XULTermLoader.localeStrings =
111 dojo.i18n.getLocalization("openils.widget", "XULTermLoader");