]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/serial/subscription.js
Serials: dojo/autogrid-based scaffolding for building serials objects
[working/Evergreen.git] / Open-ILS / web / js / ui / default / serial / subscription.js
1 dojo.require("dijit.form.Button");
2 dojo.require("dijit.form.RadioButton");
3 dojo.require("dijit.form.FilteringSelect");
4 dojo.require("dijit.form.DropDownButton");
5 dojo.require("dijit.TooltipDialog");
6 dojo.require("dijit.layout.TabContainer");
7 dojo.require("dijit.layout.ContentPane");
8 dojo.require("dojox.grid.DataGrid");
9 dojo.require("openils.widget.AutoGrid");
10 dojo.require("openils.widget.ProgressDialog");
11 dojo.require("openils.PermaCrud");
12
13 var pcrud;
14 var sub;
15
16 /* typing save: add {get,set}Value() to all HTML <select> elements */
17 HTMLSelectElement.prototype.getValue = function() {
18     return this.options[this.selectedIndex].value;
19 }
20 HTMLSelectElement.prototype.setValue = function(s) {
21     for (var i = 0; i < this.options.length; i++) {
22         if (s == this.options[i].value) {
23             this.selectedIndex = i;
24             break;
25         }
26     }
27 }
28
29 function load_sub_grid(id) {
30     if (!pcrud) return; /* first run, onLoad hasn't fired yet */
31     if (!sub_grid._fresh) {
32         pcrud.retrieve(
33             "ssub", id, {
34                 "onresponse": function(r) {
35                     if (r = openils.Util.readResponse(r)) {
36                         sub = r;
37                         sub_grid.setStore(
38                             new dojo.data.ItemFileReadStore(
39                                 {"data": ssub.toStoreData([r])}
40                             )
41                         );
42                         sub_grid._fresh = true;
43                     }
44                 }
45             }
46         );
47     }
48 }
49
50 /* TODO: make these formatters caching */
51 function format_bib(bib_id) {
52     if (!bib_id) {
53         return "";
54     } else {
55         var result;
56         fieldmapper.standardRequest(
57             ["open-ils.search",
58                 "open-ils.search.biblio.record.mods_slim.retrieve"], {
59                 "async": false,
60                 "params": [bib_id],
61                 "oncomplete": function(r) {
62                     if (r = openils.Util.readResponse(r)) {
63                         var parts = [];
64                         if (r.title())
65                             parts.push(r.title());
66                         if (r.author())
67                             parts.push(r.author());
68                         if (r.author())
69                             parts.push(r.publisher());
70
71                         if (!parts.length)
72                             parts.push(r.tcn());
73
74                         result = parts.join(" / ");
75                     }
76                 }
77             }
78         );
79         return "<a href='" + oilsBasePath + "/serial/list_subscription/" +
80             bib_id + "'>" + result + "</a>";
81     }
82 }
83
84 function format_date(s) {
85     return s ? openils.Util.timeStamp(s, {"selector": "date"}) : "";
86 }
87
88 function format_org_unit(aou_id) {
89     return aou_id ? aou.findOrgUnit(aou_id).shortname() : "";
90 }
91
92 function get_sdist(rowIndex, item) {
93     if (!item) return {"id": "", "label": ""};
94     return {
95         "id": this.grid.store.getValue(item, "id"),
96         "label": this.grid.store.getValue(item, "label")
97     };
98 }
99
100 function format_sdist_label(blob) {
101     if (!blob.id) return "";
102     var link = "<a href='" +
103         oilsBasePath + "/serial/list_stream/" + blob.id +
104         "'>" + (blob.label ? blob.label : "[None]") + "</a>" + /* XXX i18n */
105         "<span id='dist_link_" + blob.id + "'></span>";
106
107     /* XXX kludgy kludge kludge */
108     setTimeout(function() { append_stream_count(blob.id); }, 200);
109
110     return link;
111 }
112
113 function append_stream_count(dist_id) {
114     var span = dojo.byId("dist_link_" + dist_id);
115     if (span.childNodes.length) /* textNodes count as childnodes */
116         return;
117     pcrud.search(
118         "sstr", {"distribution": dist_id}, {
119             "id_list": true,
120             "oncomplete": function(r) {
121                 var resp = openils.Util.readResponse(r);
122                 var count = resp ? resp.length : 0;
123
124                 /* XXX i18n */
125                 span.innerHTML = "&nbsp;&nbsp; " + count + " stream(s)";
126             }
127         }
128     );
129 }
130
131 function open_batch_receive() {
132     if (!sub) {
133         alert("Let the interface load all the way first.");
134         return;
135     }
136
137     var url = "/xul/server/serial/batch_receive.xul?docid=" +
138         sub.record_entry() + "&subid=" + sub.id();
139
140     try {
141         openils.XUL.newTabEasy(url, "Batch Receive"); /* XXX i18n */
142     } catch (E) {
143         location.href = url;
144     }
145 }
146
147 openils.Util.addOnLoad(
148     function() {
149         pcrud = new openils.PermaCrud();
150         load_sub_grid(sub_id);
151     }
152 );