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 openils.Util.trimString(
33 self.controls.pattern_code.value
36 "Are you sure you want to erase this pattern code\n" +
37 "and create a new one via the Wizard?" /* XXX i18n */
43 netscape.security.PrivilegeManager.enablePrivilege(
47 xulG.url_prefix("/xul/server/serial/pattern_wizard.xul"),
51 self.controls.pattern_code.value = value;
52 self.controls.pattern_code.onchange();
60 /* set up onchange handlers for control fields */
61 this.controls.type.onchange = function() {
62 self.has_changed(true);
63 self.datum.type(this.getValue());
65 this.controls.pattern_code.onchange = function() {
66 self.has_changed(true);
67 self.datum.pattern_code(this.value);
69 this.controls.active.onchange = function() {
70 self.has_changed(true);
71 self.datum.active(this.checked ? "t" : "f");
74 this.load_fm_object(datum);
77 this.load_fm_object = function(datum) {
78 if (typeof datum != "undefined") {
81 this.controls.type.setValue(datum.type());
82 this.controls.pattern_code.value = datum.pattern_code();
83 this.controls.active.checked = openils.Util.isTrue(datum.active());
84 this.controls.id.innerHTML = datum.id() || "";
85 this.controls.create_date.innerHTML =
86 openils.Util.timeStamp(datum.create_date());
88 /* Once created, scap objects' pattern_code field is meant to
91 * See http://list.georgialibraries.org/pipermail/open-ils-dev/2010-May/006079.html
93 * The DB trigger mentioned was never created to enforce this
94 * immutability at that level, but this should keep users from
95 * doing the wrong thing by mistake.
97 this.controls.pattern_code.readOnly = true;
98 this.wizard_button.disabled = true;
100 this.has_changed(false);
102 this.datum = new scap();
103 this.datum.subscription(this.manager.sub_id);
107 try { self.controls[k].onchange(); } catch (E) { ; }
113 this.has_changed = function(has) {
114 if (typeof has != "undefined") {
115 this._has_changed = has;
116 this.save_button.disabled = !has;
117 dojo.attr(this.element, "changed", String(has));
120 return this._has_changed;
123 this.init.apply(this, arguments);
126 function SCAPEditor() {
129 this.init = function(sub_id, pcrud) {
130 this.sub_id = sub_id;
131 this.pcrud = pcrud || new openils.PermaCrud();
135 this.load_existing();
138 this.reset = function() {
139 this.virtRowCount = 0;
142 dojo.empty(this.body);
145 this.setup = function() {
146 var template = dojo.query("#scap_editor tbody tr")[0];
147 this.body = template.parentNode;
148 this.template = this.body.removeChild(template);
150 dojo.query("#scap_editor button[name='add']")[0].onclick =
151 function() { self.add_row(); };
153 openils.Util.show("scap_editor");
156 this.load_existing = function() {
157 this.pcrud.search("scap", {
158 "subscription": this.sub_id
160 "order_by": {"scap": "create_date"},
161 "onresponse": function(r) {
162 if (r = openils.Util.readResponse(r)) {
163 r.forEach(function(datum) { self.add_row(datum); });
170 this.add_row = function(datum) {
172 if (typeof datum == "undefined") {
173 id = --(this.virtRowCount);
174 this.rows[id] = new SCAPRow(id, this);
177 this.rows[id] = new SCAPRow(id, this, datum);
180 dojo.place(this.rows[id].element, this.body, "last");
183 this.save_row = function(row) {
188 "oncomplete": function(r, list) {
189 openils.Util.readResponse(r);
190 var new_id = list[0].id();
192 delete self.rows[old_id];
193 self.rows[new_id] = row;
194 row.load_fm_object(list[0]);
195 row.has_changed(false);
202 "oncomplete": function(r, list) {
203 openils.Util.readResponse(r);
204 row.has_changed(false);
211 this.remove_row = function(row) {
212 function _remove(row) {
213 dojo.destroy(self.rows[row.id].element);
214 delete self.rows[row.id];
217 if (row.id < 0) { /* virtual row */
219 } else { /* real row */
220 this.pcrud.eliminate(
222 "oncomplete": function(r, list) {
223 openils.Util.readResponse(r);
231 this.init.apply(this, arguments);
234 function SCAPImporter() {
237 this.init = function(sub) {
240 this.template = dojo.byId("record_template");
241 this.template = this.template.parentNode.removeChild(this.template);
242 this.template.removeAttribute("id");
244 dojo.byId("scaps_from_bib").onclick = function() { self.launch(); };
247 this.launch = function() {
249 progress_dialog.show(true);
251 fieldmapper.standardRequest(
253 "open-ils.serial.caption_and_pattern.find_legacy_by_bib_record"], {
254 "params": [openils.User.authtoken, this.sub.record_entry()],
255 "timeout": 10, /* sync */
256 "onresponse": function(r) {
257 if (r = openils.Util.readResponse(r)) {
264 progress_dialog.hide();
265 if (this.any_records())
266 scaps_from_bib_dialog.show();
268 alert("No related records with any caption and pattern fields.");
271 this.reset = function() {
272 dojo.empty("record_holder");
276 this.any_records = function() {
277 return Boolean(this._records.length);
280 this.add_record = function(obj) {
281 var row = dojo.clone(this.template);
283 var checkbox = dojo.query("input[type='checkbox']", row)[0];
284 obj._checkbox = checkbox;
286 this._records.push(obj);
288 if (obj.classname == "bre") {
290 node_by_name("obj_class", row).innerHTML = "Bibliographic";
291 node_by_name("obj_id", row).innerHTML = obj.tcn_value();
294 node_by_name("obj_owner_container", row), "inline"
296 node_by_name("obj_owner", row).innerHTML = obj.owner();
300 node_by_name("obj_class", row).innerHTML = "Legacy serial";
301 node_by_name("obj_id", row).innerHTML = obj.id();
302 node_by_name("obj_owner", row).innerHTML = obj.owning_lib();
304 node_by_name("obj_owner_container", row), "inline"
308 if (!openils.Util.isTrue(obj.active()))
309 openils.Util.show(node_by_name("obj_inactive", row), "inline");
311 node_by_name("obj_create", row).innerHTML =
313 dojo.string.substitute(
315 obj.creator().family_name(),
316 obj.creator().first_given_name(),
317 obj.creator().second_given_name(),
318 ].map(function(o) { return o || ""; })
319 ) + " on " + openils.Util.timeStamp(obj.create_date());
321 node_by_name("obj_edit", row).innerHTML =
323 dojo.string.substitute(
325 obj.editor().family_name(),
326 obj.editor().first_given_name(),
327 obj.editor().second_given_name(),
328 ].map(function(o) { return o || ""; })
329 ) + " on " + openils.Util.timeStamp(obj.edit_date());
331 dojo.place(row, "record_holder", "last");
334 this.import = function() {
335 var documents = this._records.filter(
336 function(o) { return o._checkbox.checked; }
338 function(o) { return o.marc(); }
341 if (!documents.length) {
343 alert("You have selected no records from which to import.");
345 progress_dialog.show(true);
346 fieldmapper.standardRequest(
348 "open-ils.serial.caption_and_pattern.create_from_records"],{
349 "params": [openils.User.authtoken,this.sub.id(),documents],
351 "onresponse": function(r) {
352 if (r = openils.Util.readResponse(r)) {
353 cap_editor.add_row(r);
358 progress_dialog.hide();
362 this.init.apply(this, arguments);