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