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 dojo.requireLocalization('openils.serial', 'serial');
15 var localeStrings = dojo.i18n.getLocalization('openils.serial', 'serial');
22 function node_by_name(name, ctx) {
23 return dojo.query("[name='" + name + "']", ctx)[0];
26 /* typing save: add {get,set}Value() to all HTML <select> elements */
27 HTMLSelectElement.prototype.getValue = function() {
28 return this.options[this.selectedIndex].value;
30 HTMLSelectElement.prototype.setValue = function(s) {
31 for (var i = 0; i < this.options.length; i++) {
32 if (s == this.options[i].value) {
33 this.selectedIndex = i;
39 function load_sub_grid(id, oncomplete) {
40 if (!pcrud) return; /* first run, onLoad hasn't fired yet */
41 if (!sub_grid._fresh) {
42 var dist_ids = pcrud.search(
43 "sdist", {"subscription": id}, {"id_list": true}
47 "onresponse": function(r) {
48 if (r = openils.Util.readResponse(r)) {
50 var data = ssub.toStoreData([r]);
51 data.items[0].num_dist = dist_ids ? dist_ids.length : 0;
53 new dojo.data.ItemFileReadStore({"data": data})
55 sub_grid._fresh = true;
58 "oncomplete": function() {
59 if (oncomplete) oncomplete();
66 /* TODO: make these formatters caching */
67 function format_bib(bib_id) {
72 fieldmapper.standardRequest(
74 "open-ils.search.biblio.record.mods_slim.retrieve"], {
77 "oncomplete": function(r) {
78 if (r = openils.Util.readResponse(r)) {
81 parts.push(r.title());
83 parts.push(r.author());
85 parts.push(r.publisher());
90 result = parts.join(" / ");
95 return "<a href='" + oilsBasePath +
96 "/serial/list_subscription?record_entry=" + bib_id + "'>" +
101 function format_date(s) {
102 return s ? openils.Util.timeStamp(s, {"selector": "date"}) : "";
105 function format_org_unit(aou_id) {
106 return aou_id ? aou.findOrgUnit(aou_id).shortname() : "";
109 function get_id_and_label(rowIndex, item) {
110 if (!item) return {"id": "", "label": ""};
112 "id": this.grid.store.getValue(item, "id"),
113 "label": this.grid.store.getValue(item, "label")
117 function format_siss_label(blob) {
118 if (!blob.id) return "";
120 oilsBasePath + "/serial/list_item?issuance=" + blob.id +
121 "'>" + (blob.label ? blob.label : "[None]") + "</a>"; /* XXX i18n */
124 function format_sdist_label(blob) {
125 if (!blob.id) return "";
126 var link = "<a href='" +
127 oilsBasePath + "/serial/list_stream?distribution=" + blob.id +
128 "'>" + (blob.label ? blob.label : "[None]") + "</a>"; /* XXX i18n */
130 var sstr_list = pcrud.search(
131 "sstr",{"distribution":blob.id},{"id_list":true}
133 count = sstr_list ? sstr_list.length : 0;
134 link += " " + count + " stream(s)"; //XXX i18n
138 function append_stream_count(dist_id) {
139 var span = dojo.byId("dist_link_" + dist_id);
140 if (span.childNodes.length) /* textNodes count as childnodes */
143 "sstr", {"distribution": dist_id}, {
145 "oncomplete": function(r) {
146 var resp = openils.Util.readResponse(r);
147 var count = resp ? resp.length : 0;
150 span.innerHTML = " " + count + " stream(s)";
156 function open_batch_receive() {
158 alert("Let the interface load all the way first.");
162 var url = "XUL_SERIAL_BATCH_RECEIVE?docid=" +
163 sub.record_entry() + "&subid=" + sub.id();
166 openils.XUL.newTabEasy(url, "Batch Receive"); /* XXX i18n */
172 function toggle_clone_ident_field(dij) {
175 var disabled = !dij.attr("checked");
176 clone_ident.attr("disabled", disabled);
177 if (!disabled) clone_ident.focus();
182 function clone_subscription(form) {
183 if (form.use_ident == "yes") {
184 fieldmapper.standardRequest(
186 "open-ils.serial.biblio.record_entry.by_identifier.atomic"], {
187 "params": [form.ident, {"id_list": true}],
189 "oncomplete": function(r) {
190 r = openils.Util.readResponse(r);
191 if (!r || !r.length) {
192 alert("No matches for that indentifier."); /*XXX i18n*/
193 } else if (r.length != 1) {
194 alert("Too many matches for that identifier. Use a " +
195 "unique identifier."); /* XXX i18n */
197 _clone_subscription(r[0]);
203 _clone_subscription();
207 function _clone_subscription(bre_id) {
208 progress_dialog.show(true);
210 fieldmapper.standardRequest(
211 ["open-ils.serial", "open-ils.serial.subscription.clone"], {
212 "params": [openils.User.authtoken, sub_id, bre_id],
214 "oncomplete": function(r) {
215 progress_dialog.hide();
216 if (!(r = openils.Util.readResponse(r))) {
217 alert("Error cloning subscription."); /* XXX i18n */
220 oilsBasePath + "/serial/subscription?id=" + r;
223 /* cloning doesn't clone holdings, so nothing changes at
224 * OPAC view just because of this, so no need to try
231 function open_notes(obj_type, grid) {
232 if (grid.getSelectedRows().length != 1) {
233 alert( localeStrings.REQUIRE_ONE_ROW );
237 var id = grid.getSelectedItems()[0].id[0];
238 var args_by_obj_type = {
239 'sub' : { 'function_type' : 'SSUBN', 'object_type' : 'subscription', 'constructor' : ssubn, 'title' : dojo.string.substitute(localeStrings.NOTES_SSUB, [id]) },
240 'dist' : { 'function_type' : 'SDISTN', 'object_type' : 'distribution', 'constructor' : sdistn, 'title' : dojo.string.substitute(localeStrings.NOTES_SDIST, [id]) }
242 args_by_obj_type[obj_type].object_id = id;
246 xulG.url_prefix('XUL_SERIAL_NOTES'),
248 'chrome,resizable,modal',
249 args_by_obj_type[obj_type]
256 openils.Util.addOnLoad(
259 "distributions": distributions_tab,
260 "issuances": issuances_tab
263 cgi = new openils.CGI();
264 pcrud = new openils.PermaCrud();
266 context = cgi.param("context");
267 sub_id = cgi.param("id");
268 owning_lib = cgi.param("owning_lib");
269 record_entry = cgi.param("record_entry");
271 if (context != 'scv') {
274 (cgi.param("tab") in tab_dispatch) ?
276 tab_container.selectChild(
277 tab_dispatch[cgi.param("tab")]
282 build_sre_maps(dist_grid);
283 dist_grid.empty_store = new dojo.data.ItemFileReadStore({
285 "identifier": "record_entry",
290 dist_grid.overrideEditWidgets.record_entry =
291 new dijit.form.FilteringSelect({
292 "store" : dist_grid.empty_store,
293 "searchAttr" : "label",
294 "name" : "record_entry"
296 dist_grid.overrideEditWidgets.record_entry.shove = {};
297 if (sub_id == 'new') {
298 ssub_grid.overrideEditWidgets.record_entry =
299 new dijit.form.TextBox({
300 "disabled": true, "value": record_entry
302 ssub_grid.overrideWidgetArgs.owning_lib = {widgetValue : owning_lib, dijitArgs : {disabled : true}};
304 ssub_grid.onPostCreate = function(fmObject) {
305 sub_id = fmObject.id();
308 ssub_grid.showCreateDialog();