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