3 var _fields = ["id", "type", "pattern_code", "active", "create_date"];
5 this.init = function(id, manager, datum) {
7 this.manager = manager;
8 this.element = dojo.clone(manager.template);
10 /* find the controls for each field */
14 self.controls[k] = dojo.query(
15 "[name='" + k + "'] [control]", self.element
20 /* set up the remover button */
21 this.remover = dojo.query("[name='remover'] button", this.element)[0];
22 this.remover.onclick = function() { manager.remove_row(self); };
24 this.save_button = dojo.query("[name='save'] button", this.element)[0];
25 this.save_button.onclick = function() { manager.save_row(self); };
27 this.wizard_button = dojo.query(
28 "[name='pattern_code'] button", this.element
30 this.wizard_button.onclick = function() {
32 netscape.security.PrivilegeManager.enablePrivilege(
36 xulG.url_prefix("/xul/server/serial/pattern_wizard.xul"),
38 "scrollbars=yes", /* XXX doesn't work this way? */
40 self.controls.pattern_code.value = value;
41 self.controls.pattern_code.onchange();
49 /* set up onchange handlers for control fields */
50 this.controls.type.onchange = function() {
51 self.has_changed(true);
52 self.datum.type(this.getValue());
54 this.controls.pattern_code.onchange = function() {
55 self.has_changed(true);
56 self.datum.pattern_code(this.value);
58 this.controls.active.onchange = function() {
59 self.has_changed(true);
60 self.datum.active(this.checked ? "t" : "f");
63 this.load_fm_object(datum);
66 this.load_fm_object = function(datum) {
67 if (typeof datum != "undefined") {
70 this.controls.type.setValue(datum.type());
71 this.controls.pattern_code.value = datum.pattern_code();
72 this.controls.active.checked = openils.Util.isTrue(datum.active());
73 this.controls.id.innerHTML = datum.id() || "";
74 this.controls.create_date.innerHTML =
75 openils.Util.timeStamp(datum.create_date());
77 this.has_changed(false);
79 this.datum = new scap();
80 this.datum.subscription(this.manager.sub_id);
84 try { self.controls[k].onchange(); } catch (E) { ; }
90 this.has_changed = function(has) {
91 if (typeof has != "undefined") {
92 this._has_changed = has;
93 this.save_button.disabled = !has;
94 dojo.attr(this.element, "changed", String(has));
97 return this._has_changed;
100 this.init.apply(this, arguments);
103 function SCAPEditor() {
106 this.init = function(sub_id, pcrud) {
107 this.sub_id = sub_id;
108 this.pcrud = pcrud || new openils.PermaCrud();
112 this.load_existing();
115 this.reset = function() {
116 this.virtRowCount = 0;
119 dojo.empty(this.body);
122 this.setup = function() {
123 var template = dojo.query("#scap_editor tbody tr")[0];
124 this.body = template.parentNode;
125 this.template = this.body.removeChild(template);
127 dojo.query("#scap_editor button[name='add']")[0].onclick =
128 function() { self.add_row(); };
130 openils.Util.show("scap_editor");
133 this.load_existing = function() {
134 this.pcrud.search("scap", {
135 "subscription": this.sub_id
137 "order_by": {"scap": "create_date"},
138 "onresponse": function(r) {
139 if (r = openils.Util.readResponse(r)) {
140 r.forEach(function(datum) { self.add_row(datum); });
147 this.add_row = function(datum) {
149 if (typeof datum == "undefined") {
150 id = --(this.virtRowCount);
151 this.rows[id] = new SCAPRow(id, this);
154 this.rows[id] = new SCAPRow(id, this, datum);
157 dojo.place(this.rows[id].element, this.body, "last");
160 this.save_row = function(row) {
165 "oncomplete": function(r, list) {
166 openils.Util.readResponse(r);
167 var new_id = list[0].id();
169 delete self.rows[old_id];
170 self.rows[new_id] = row;
171 row.load_fm_object(list[0]);
172 row.has_changed(false);
179 "oncomplete": function(r, list) {
180 openils.Util.readResponse(r);
181 row.has_changed(false);
188 this.remove_row = function(row) {
189 function _remove(row) {
190 dojo.destroy(self.rows[row.id].element);
191 delete self.rows[row.id];
194 if (row.id < 0) { /* virtual row */
196 } else { /* real row */
197 this.pcrud.eliminate(
199 "oncomplete": function(r, list) {
200 openils.Util.readResponse(r);
208 this.init.apply(this, arguments);
211 function SCAPImporter() {
214 this.init = function(sub) {
217 this.template = dojo.byId("record_template");
218 this.template = this.template.parentNode.removeChild(this.template);
219 this.template.removeAttribute("id");
221 dojo.byId("scaps_from_bib").onclick = function() { self.launch(); };
224 this.launch = function() {
226 progress_dialog.show(true);
228 fieldmapper.standardRequest(
230 "open-ils.serial.caption_and_pattern.find_legacy_by_bib_record"], {
231 "params": [openils.User.authtoken, this.sub.record_entry()],
232 "timeout": 10, /* sync */
233 "onresponse": function(r) {
234 if (r = openils.Util.readResponse(r)) {
241 progress_dialog.hide();
242 if (this.any_records())
243 scaps_from_bib_dialog.show();
245 alert("No related records with any caption and pattern fields.");
248 this.reset = function() {
249 dojo.empty("record_holder");
253 this.any_records = function() {
254 return Boolean(this._records.length);
257 this.add_record = function(obj) {
258 var row = dojo.clone(this.template);
260 var checkbox = dojo.query("input[type='checkbox']", row)[0];
261 obj._checkbox = checkbox;
263 this._records.push(obj);
265 if (obj.classname == "bre") {
267 node_by_name("obj_class", row).innerHTML = "Bibliographic";
268 node_by_name("obj_id", row).innerHTML = obj.tcn_value();
271 node_by_name("obj_owner_container", row), "inline"
273 node_by_name("obj_owner", row).innerHTML = obj.owner();
277 node_by_name("obj_class", row).innerHTML = "Legacy serial";
278 node_by_name("obj_id", row).innerHTML = obj.id();
279 node_by_name("obj_owner", row).innerHTML = obj.owning_lib();
281 node_by_name("obj_owner_container", row), "inline"
285 if (!openils.Util.isTrue(obj.active()))
286 openils.Util.show(node_by_name("obj_inactive", row), "inline");
288 node_by_name("obj_create", row).innerHTML =
290 dojo.string.substitute(
292 obj.creator().family_name(),
293 obj.creator().first_given_name(),
294 obj.creator().second_given_name(),
295 ].map(function(o) { return o || ""; })
296 ) + " on " + openils.Util.timeStamp(obj.create_date());
298 node_by_name("obj_edit", row).innerHTML =
300 dojo.string.substitute(
302 obj.editor().family_name(),
303 obj.editor().first_given_name(),
304 obj.editor().second_given_name(),
305 ].map(function(o) { return o || ""; })
306 ) + " on " + openils.Util.timeStamp(obj.edit_date());
308 dojo.place(row, "record_holder", "last");
311 this.import = function() {
312 var documents = this._records.filter(
313 function(o) { return o._checkbox.checked; }
315 function(o) { return o.marc(); }
318 if (!documents.length) {
320 alert("You have selected no records from which to import.");
322 progress_dialog.show(true);
323 fieldmapper.standardRequest(
325 "open-ils.serial.caption_and_pattern.create_from_records"],{
326 "params": [openils.User.authtoken,this.sub.id(),documents],
328 "onresponse": function(r) {
329 if (r = openils.Util.readResponse(r)) {
330 cap_editor.add_row(r);
335 progress_dialog.hide();
340 this.init.apply(this, arguments);