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' :
99 /* These get shown in the middle panel */
100 'sitem_editor_middle_pane' :
105 render: 'fm.stream().distribution().label() == null ? "" : fm.stream().distribution().label();',
106 label: fieldmapper.IDL.fmclasses.sstr.field_map.distribution.label
113 render: 'fm.unit() == null ? "" : "#" + fm.unit().id();',
118 /* These get shown in the right panel */
119 'sitem_editor_right_pane' :
124 render: 'fm.date_expected() == null ? "" : util.date.formatted_date( fm.date_expected(), "%F");',
125 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);',
126 value_key: 'date_expected'
132 render: 'fm.date_received() == null ? "" : util.date.formatted_date( fm.date_received(), "%F");',
133 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; }',
134 value_key: 'date_received'
142 /******************************************************************************************************/
143 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
145 'summarize' : serial.editor_base.editor_base_summarize,
147 /******************************************************************************************************/
148 /* Display the summarized data and inputs for editing */
150 'render' : serial.editor_base.editor_base_render,
152 /******************************************************************************************************/
153 /* This actually draws the change button and input widget for a given field */
154 'render_input' : serial.editor_base.editor_base_render_input,
156 /******************************************************************************************************/
159 'save' : function() {
161 obj.editor_base_save('open-ils.serial.item.fleshed.batch.update');
164 /******************************************************************************************************/
165 /* spawn notes interface */
167 'notes' : function() {
169 JSAN.use('util.window'); var win = new util.window();
171 urls.XUL_SERIAL_NOTES,
172 //+ '?copy_id=' + window.escape(obj.sitems[0].id()),
173 'Item Notes','chrome,resizable,modal',
174 { 'object_id' : obj.sitems[0].id(), 'function_type' : 'SIN', 'object_type' : 'item', 'constructor' : sin }
178 /******************************************************************************************************/
179 'save_attributes' : serial.editor_base.editor_base_save_attributes
183 dump('exiting serial/sitem.js\n');