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);