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');
21 var context_url_param;
23 function node_by_name(name, ctx) {
24 return dojo.query("[name='" + name + "']", ctx)[0];
27 /* typing save: add {get,set}Value() to all HTML <select> elements */
28 HTMLSelectElement.prototype.getValue = function() {
29 return this.options[this.selectedIndex].value;
31 HTMLSelectElement.prototype.setValue = function(s) {
32 for (var i = 0; i < this.options.length; i++) {
33 if (s == this.options[i].value) {
34 this.selectedIndex = i;
40 function load_sub_grid(id, oncomplete) {
41 if (!pcrud) return; /* first run, onLoad hasn't fired yet */
42 if (!sub_grid._fresh) {
43 var dist_ids = pcrud.search(
44 "sdist", {"subscription": id}, {"id_list": true}
48 "onresponse": function(r) {
49 if (r = openils.Util.readResponse(r)) {
51 var data = ssub.toStoreData([r]);
52 data.items[0].num_dist = dist_ids ? dist_ids.length : 0;
54 new dojo.data.ItemFileReadStore({"data": data})
56 sub_grid._fresh = true;
59 "oncomplete": function() {
60 if (oncomplete) oncomplete();
67 /* TODO: make these formatters caching */
68 function format_bib(bib_id) {
73 fieldmapper.standardRequest(
75 "open-ils.search.biblio.record.mods_slim.retrieve"], {
78 "oncomplete": function(r) {
79 if (r = openils.Util.readResponse(r)) {
82 parts.push(r.title());
84 parts.push(r.author());
86 parts.push(r.publisher());
91 result = parts.join(" / ");
96 return "<a href='" + oilsBasePath +
97 "/serial/list_subscription?record_entry=" + bib_id + "'>" +
102 function format_date(s) {
103 return s ? openils.Util.timeStamp(s, {"selector": "date"}) : "";
106 function format_org_unit(aou_id) {
107 return aou_id ? aou.findOrgUnit(aou_id).shortname() : "";
110 function get_id_and_label(rowIndex, item) {
111 if (!item) return {"id": "", "label": ""};
113 "id": this.grid.store.getValue(item, "id"),
114 "label": this.grid.store.getValue(item, "label")
118 function format_siss_label(blob) {
119 if (!blob.id) return "";
121 oilsBasePath + "/serial/list_item?issuance=" + blob.id +
122 context_url_param + "'>" + (blob.label ? blob.label : "[None]") +
123 "</a>"; /* XXX i18n */
126 function format_sdist_label(blob) {
127 if (!blob.id) return "";
128 var link = "<a href='" +
129 oilsBasePath + "/serial/list_stream?distribution=" + blob.id +
130 context_url_param + "'>" + (blob.label ? blob.label : "[None]") +
131 "</a>"; /* XXX i18n */
133 var sstr_list = pcrud.search(
134 "sstr",{"distribution":blob.id},{"id_list":true}
136 count = sstr_list ? sstr_list.length : 0;
137 link += " " + count + " stream(s)"; //XXX i18n
141 function append_stream_count(dist_id) {
142 var span = dojo.byId("dist_link_" + dist_id);
143 if (span.childNodes.length) /* textNodes count as childnodes */
146 "sstr", {"distribution": dist_id}, {
148 "oncomplete": function(r) {
149 var resp = openils.Util.readResponse(r);
150 var count = resp ? resp.length : 0;
153 span.innerHTML = " " + count + " stream(s)";
159 function open_batch_receive() {
161 alert("Let the interface load all the way first.");
165 var url = "XUL_SERIAL_BATCH_RECEIVE?docid=" +
166 sub.record_entry() + "&subid=" + sub.id();
169 openils.XUL.newTabEasy(url, "Batch Receive"); /* XXX i18n */
175 function toggle_clone_ident_field(dij) {
178 var disabled = !dij.attr("checked");
179 clone_ident.attr("disabled", disabled);
180 if (!disabled) clone_ident.focus();
185 function clone_subscription(form) {
186 if (form.use_ident == "yes") {
187 fieldmapper.standardRequest(
189 "open-ils.serial.biblio.record_entry.by_identifier.atomic"], {
190 "params": [form.ident, {"id_list": true}],
192 "oncomplete": function(r) {
193 r = openils.Util.readResponse(r);
194 if (!r || !r.length) {
195 alert("No matches for that indentifier."); /*XXX i18n*/
196 } else if (r.length != 1) {
197 alert("Too many matches for that identifier. Use a " +
198 "unique identifier."); /* XXX i18n */
200 _clone_subscription(r[0]);
206 _clone_subscription();
210 function _clone_subscription(bre_id) {
211 progress_dialog.show(true);
213 fieldmapper.standardRequest(
214 ["open-ils.serial", "open-ils.serial.subscription.clone"], {
215 "params": [openils.User.authtoken, sub_id, bre_id],
217 "oncomplete": function(r) {
218 progress_dialog.hide();
219 if (!(r = openils.Util.readResponse(r))) {
220 alert("Error cloning subscription."); /* XXX i18n */
223 oilsBasePath + "/serial/subscription?id=" + r;
226 /* cloning doesn't clone holdings, so nothing changes at
227 * OPAC view just because of this, so no need to try
234 function open_notes(obj_type, grid) {
235 if (grid.getSelectedRows().length != 1) {
236 alert( localeStrings.REQUIRE_ONE_ROW );
240 var id = grid.getSelectedItems()[0].id[0];
241 var args_by_obj_type = {
242 'sub' : { 'function_type' : 'SSUBN', 'object_type' : 'subscription', 'constructor' : ssubn, 'title' : dojo.string.substitute(localeStrings.NOTES_SSUB, [id]) },
243 'dist' : { 'function_type' : 'SDISTN', 'object_type' : 'distribution', 'constructor' : sdistn, 'title' : dojo.string.substitute(localeStrings.NOTES_SDIST, [id]) }
245 args_by_obj_type[obj_type].object_id = id;
249 xulG.url_prefix('XUL_SERIAL_NOTES'),
251 'chrome,resizable,modal',
252 args_by_obj_type[obj_type]
259 openils.Util.addOnLoad(
262 "distributions": distributions_tab,
263 "issuances": issuances_tab
266 cgi = new openils.CGI();
267 pcrud = new openils.PermaCrud();
269 context = cgi.param("context");
270 sub_id = cgi.param("id");
271 owning_lib = cgi.param("owning_lib");
272 record_entry = cgi.param("record_entry");
275 context_url_param = '&context=' + context;
277 context_url_param = '';
280 if (context != 'scv') {
283 (cgi.param("tab") in tab_dispatch) ?
285 tab_container.selectChild(
286 tab_dispatch[cgi.param("tab")]
291 build_sre_maps(dist_grid);
292 dist_grid.empty_store = new dojo.data.ItemFileReadStore({
294 "identifier": "record_entry",
299 dist_grid.overrideEditWidgets.record_entry =
300 new dijit.form.FilteringSelect({
301 "store" : dist_grid.empty_store,
302 "searchAttr" : "label",
303 "name" : "record_entry"
305 dist_grid.overrideEditWidgets.record_entry.shove = {};
306 if (sub_id == 'new') {
307 ssub_grid.overrideEditWidgets.record_entry =
308 new dijit.form.TextBox({
309 "disabled": true, "value": record_entry
311 ssub_grid.overrideWidgetArgs.owning_lib = {widgetValue : owning_lib, dijitArgs : {disabled : true}};
313 ssub_grid.onPostCreate = function(fmObject) {
314 sub_id = fmObject.id();
315 parent.document.getElementById(window.name).refresh_command(fmObject);
318 ssub_grid.showCreateDialog();
320 ssub_grid.onPostUpdate = function(fmObject) {
321 parent.document.getElementById(window.name).refresh_command();
323 if (cgi.param("tab") in tab_dispatch) {
324 ssub_grid._fresh = false; // force View/Edit tab to reload (otherwise, it is blank) XXX why?
325 tab_container.selectChild(tab_dispatch[cgi.param("tab")]);
327 parent.document.getElementById(window.name).style.visibility = 'visible'; // unhide the editor pane (iframe)