1 dump('entering serial/sitem_editor.js\n');
4 JSAN.addRepository('/xul/server/');
5 JSAN.use('serial.editor_base');
7 if (typeof serial == 'undefined') serial = {};
8 serial.sitem_editor = function (params) {
10 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
11 JSAN.use('util.error'); this.error = new util.error();
12 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
13 JSAN.use('util.network'); this.network = new util.network();
15 dump('serial/sitem_editor: ' + E + '\n');
18 /* This keeps track of what fields have been edited for styling purposes */
21 /* This holds the original values for prepopulating the field editors */
22 this.editor_values = {};
25 serial.sitem_editor.prototype = {
26 // we could do this with non-standard '__proto__' property instead
27 'editor_base_init' : serial.editor_base.editor_base_init,
28 'editor_base_apply' : serial.editor_base.editor_base_apply,
29 'editor_base_save' : serial.editor_base.editor_base_save,
32 'fm_type_plural' : 'sitems',
33 'can_have_notes' : true,
35 'init' : function (params) {
38 params.retrieve_function = 'FM_SITEM_FLESHED_BATCH_RETRIEVE.authoritative';
40 obj.editor_base_init(params);
43 obj.summarize( obj.sitems );
47 /******************************************************************************************************/
48 /* Restore backup copies */
50 'reset' : serial.editor_base.editor_base_reset,
52 /******************************************************************************************************/
53 /* Apply a value to a specific field on all the copies being edited */
55 'apply' : function(field,value) {
57 JSAN.use('util.date');
58 if (field == 'date_expected') {
60 alert("Date Expected cannot be unset.");
62 } else if (!util.date.check('YYYY-MM-DD',value)) {
63 alert("Invalid Date");
66 } else if (field == 'date_received') { // manually unset not allowed
68 alert("Date Received cannot be manually unset; use 'Reset to Expected' instead.");
70 } else if (!util.date.check('YYYY-MM-DD',value)) {
71 alert("Invalid Date");
75 obj.editor_base_apply(field, value);
79 /******************************************************************************************************/
81 'init_panes' : function () {
83 obj.panes_and_field_names = {
85 /* These get shown in the left panel */
86 'sitem_editor_left_pane' :
91 render: '"#" + fm.id();',
98 render: 'fm.status();',
103 /* These get shown in the middle panel */
104 'sitem_editor_middle_pane' :
109 render: 'fm.stream().distribution().label() == null ? "" : fm.stream().distribution().label();',
116 render: 'fm.unit() == null ? "" : "#" + fm.unit().id();',
121 /* These get shown in the right panel */
122 'sitem_editor_right_pane' :
127 render: 'fm.date_expected() == null ? "" : util.date.formatted_date( fm.date_expected(), "%F");',
128 input: 'c = function(v){ var applied = obj.apply("date_expected",v); if (typeof post_c == "function") post_c(v, !applied);}; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.date_expected); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
129 value_key: 'date_expected'
135 render: 'fm.date_received() == null ? "" : util.date.formatted_date( fm.date_received(), "%F");',
136 input: 'if (obj.editor_values.date_received) { c = function(v){ var applied = obj.apply("date_received",v); if (typeof post_c == "function") post_c(v, !applied);}; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.date_received); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false); } else { alert("Cannot edit Date Received for unreceived items."); block = false; }',
137 value_key: 'date_received'
145 /******************************************************************************************************/
146 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
148 'summarize' : serial.editor_base.editor_base_summarize,
150 /******************************************************************************************************/
151 /* Display the summarized data and inputs for editing */
153 'render' : serial.editor_base.editor_base_render,
155 /******************************************************************************************************/
156 /* This actually draws the change button and input widget for a given field */
157 'render_input' : serial.editor_base.editor_base_render_input,
159 /******************************************************************************************************/
162 'save' : function() {
164 obj.editor_base_save('open-ils.serial.item.fleshed.batch.update');
167 /******************************************************************************************************/
168 /* spawn notes interface */
170 'notes' : function() {
172 JSAN.use('util.window'); var win = new util.window();
174 urls.XUL_SERIAL_NOTES,
175 //+ '?copy_id=' + window.escape(obj.sitems[0].id()),
176 'Item Notes','chrome,resizable,modal',
177 { 'object_id' : obj.sitems[0].id(), 'function_type' : 'SIN', 'object_type' : 'item', 'constructor' : sin }
181 /******************************************************************************************************/
182 'save_attributes' : serial.editor_base.editor_base_save_attributes
186 dump('exiting serial/sitem.js\n');