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 */
44 xulG.url_prefix("XUL_SERIAL_PATTERN_WIZARD"),
48 self.controls.pattern_code.value = value;
49 self.controls.pattern_code.onchange();
57 /* set up onchange handlers for control fields */
58 this.controls.type.onchange = function() {
59 self.has_changed(true);
60 self.datum.type(this.getValue());
62 this.controls.pattern_code.onchange = function() {
63 self.has_changed(true);
64 self.datum.pattern_code(this.value);
66 this.controls.active.onchange = function() {
67 self.has_changed(true);
68 self.datum.active(this.checked ? "t" : "f");
71 this.load_fm_object(datum);
74 this.load_fm_object = function(datum) {
75 if (typeof datum != "undefined") {
78 this.controls.type.setValue(datum.type());
79 this.controls.pattern_code.value = datum.pattern_code();
80 this.controls.active.checked = openils.Util.isTrue(datum.active());
81 this.controls.id.innerHTML = datum.id() || "";
82 this.controls.create_date.innerHTML =
83 openils.Util.timeStamp(datum.create_date());
85 /* Once created, scap objects' pattern_code field is meant to
88 * See http://list.georgialibraries.org/pipermail/open-ils-dev/2010-May/006079.html
90 * The DB trigger mentioned was never created to enforce this
91 * immutability at that level, but this should keep users from
92 * doing the wrong thing by mistake.
94 this.controls.pattern_code.readOnly = true;
95 this.wizard_button.disabled = true;
97 this.has_changed(false);
99 this.datum = new scap();
100 this.datum.subscription(this.manager.sub_id);
104 try { self.controls[k].onchange(); } catch (E) { ; }
110 this.has_changed = function(has) {
111 if (typeof has != "undefined") {
112 this._has_changed = has;
113 this.save_button.disabled = !has;
114 dojo.attr(this.element, "changed", String(has));
117 return this._has_changed;
120 this.init.apply(this, arguments);
123 function SCAPEditor() {
126 this.init = function(sub_id, pcrud) {
127 this.sub_id = sub_id;
128 this.pcrud = pcrud || new openils.PermaCrud();
132 this.load_existing();
135 this.reset = function() {
136 this.virtRowCount = 0;
139 dojo.empty(this.body);
142 this.setup = function() {
143 var template = dojo.query("#scap_editor tbody tr")[0];
144 this.body = template.parentNode;
145 this.template = this.body.removeChild(template);
147 dojo.query("#scap_editor button[name='add']")[0].onclick =
148 function() { self.add_row(); };
150 openils.Util.show("scap_editor");
153 this.load_existing = function() {
154 this.pcrud.search("scap", {
155 "subscription": this.sub_id
157 "order_by": {"scap": "create_date"},
158 "onresponse": function(r) {
159 if (r = openils.Util.readResponse(r)) {
160 r.forEach(function(datum) { self.add_row(datum); });
167 this.add_row = function(datum) {
169 if (typeof datum == "undefined") {
170 id = --(this.virtRowCount);
171 this.rows[id] = new SCAPRow(id, this);
174 this.rows[id] = new SCAPRow(id, this, datum);
177 dojo.place(this.rows[id].element, this.body, "last");
180 this.save_row = function(row) {
185 "oncomplete": function(r, list) {
186 openils.Util.readResponse(r);
187 var new_id = list[0].id();
189 delete self.rows[old_id];
190 self.rows[new_id] = row;
191 row.load_fm_object(list[0]);
192 row.has_changed(false);
199 "oncomplete": function(r, list) {
200 openils.Util.readResponse(r);
201 row.has_changed(false);
208 this.remove_row = function(row) {
209 function _remove(row) {
210 dojo.destroy(self.rows[row.id].element);
211 delete self.rows[row.id];
214 if (row.id < 0) { /* virtual row */
216 } else { /* real row */
217 this.pcrud.eliminate(
219 "oncomplete": function(r, list) {
220 openils.Util.readResponse(r);
228 this.init.apply(this, arguments);
231 function SCAPImporter() {
234 this.init = function(sub) {
237 this.template = dojo.byId("record_template");
238 this.template = this.template.parentNode.removeChild(this.template);
239 this.template.removeAttribute("id");
241 dojo.byId("scaps_from_bib").onclick = function() { self.launch(); };
244 this.launch = function() {
246 progress_dialog.show(true);
248 fieldmapper.standardRequest(
250 "open-ils.serial.caption_and_pattern.find_legacy_by_bib_record"], {
251 "params": [openils.User.authtoken, this.sub.record_entry()],
252 "timeout": 10, /* sync */
253 "onresponse": function(r) {
254 if (r = openils.Util.readResponse(r)) {
261 progress_dialog.hide();
262 if (this.any_records())
263 scaps_from_bib_dialog.show();
265 alert("No related records with any caption and pattern fields.");
268 this.reset = function() {
269 dojo.empty("record_holder");
273 this.any_records = function() {
274 return Boolean(this._records.length);
277 this.add_record = function(obj) {
278 var row = dojo.clone(this.template);
280 var checkbox = dojo.query("input[type='checkbox']", row)[0];
281 obj._checkbox = checkbox;
283 this._records.push(obj);
285 if (obj.classname == "bre") {
287 node_by_name("obj_class", row).innerHTML = "Bibliographic";
288 node_by_name("obj_id", row).innerHTML = obj.tcn_value();
291 node_by_name("obj_owner_container", row), "inline"
293 node_by_name("obj_owner", row).innerHTML = obj.owner();
297 node_by_name("obj_class", row).innerHTML = "Legacy serial";
298 node_by_name("obj_id", row).innerHTML = obj.id();
299 node_by_name("obj_owner", row).innerHTML = obj.owning_lib();
301 node_by_name("obj_owner_container", row), "inline"
305 if (!openils.Util.isTrue(obj.active()))
306 openils.Util.show(node_by_name("obj_inactive", row), "inline");
308 node_by_name("obj_create", row).innerHTML =
310 dojo.string.substitute(
312 obj.creator().family_name(),
313 obj.creator().first_given_name(),
314 obj.creator().second_given_name(),
315 ].map(function(o) { return o || ""; })
316 ) + " on " + openils.Util.timeStamp(obj.create_date());
318 node_by_name("obj_edit", row).innerHTML =
320 dojo.string.substitute(
322 obj.editor().family_name(),
323 obj.editor().first_given_name(),
324 obj.editor().second_given_name(),
325 ].map(function(o) { return o || ""; })
326 ) + " on " + openils.Util.timeStamp(obj.edit_date());
328 dojo.place(row, "record_holder", "last");
331 this.import = function() {
332 var documents = this._records.filter(
333 function(o) { return o._checkbox.checked; }
335 function(o) { return o.marc(); }
338 if (!documents.length) {
340 alert("You have selected no records from which to import.");
342 progress_dialog.show(true);
343 fieldmapper.standardRequest(
345 "open-ils.serial.caption_and_pattern.create_from_records"],{
346 "params": [openils.User.authtoken,this.sub.id(),documents],
348 "onresponse": function(r) {
349 if (r = openils.Util.readResponse(r)) {
350 cap_editor.add_row(r);
355 progress_dialog.hide();
359 this.init.apply(this, arguments);