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 JSAN.use('util.error'); this.error = new util.error();
11 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
12 JSAN.use('util.network'); this.network = new util.network();
14 dump('serial/sitem_editor: ' + E + '\n');
17 /* This keeps track of what fields have been edited for styling purposes */
20 /* This holds the original values for prepopulating the field editors */
21 this.editor_values = {};
24 serial.sitem_editor.prototype = {
25 // we could do this with non-standard '__proto__' property instead
26 'editor_base_init' : serial.editor_base.editor_base_init,
27 'editor_base_apply' : serial.editor_base.editor_base_apply,
28 'editor_base_save' : serial.editor_base.editor_base_save,
31 'fm_type_plural' : 'sitems',
32 'can_have_notes' : true,
34 'init' : function (params) {
37 params.retrieve_function = 'FM_SITEM_FLESHED_BATCH_RETRIEVE.authoritative';
39 obj.editor_base_init(params);
42 obj.summarize( obj.sitems );
46 /******************************************************************************************************/
47 /* Restore backup copies */
49 'reset' : serial.editor_base.editor_base_reset,
51 /******************************************************************************************************/
52 /* Apply a value to a specific field on all the copies being edited */
54 'apply' : function(field,value) {
56 JSAN.use('util.date');
57 if (field == 'date_expected') {
59 alert("Date Expected cannot be unset.");
61 } else if (!util.date.check('YYYY-MM-DD',value)) {
62 alert("Invalid Date");
65 } else if (field == 'date_received') { // manually unset not allowed
67 alert("Date Received cannot be manually unset; use 'Reset to Expected' instead.");
69 } else if (!util.date.check('YYYY-MM-DD',value)) {
70 alert("Invalid Date");
74 obj.editor_base_apply(field, value);
78 /******************************************************************************************************/
80 'init_panes' : function () {
82 obj.panes_and_field_names = {
84 /* These get shown in the left panel */
85 'sitem_editor_left_pane' :
98 /* These get shown in the middle panel */
99 'sitem_editor_middle_pane' :
104 render: 'fm.stream().distribution().label() == null ? "" : fm.stream().distribution().label();',
105 label: fieldmapper.IDL.fmclasses.sstr.field_map.distribution.label
112 render: 'fm.unit() == null ? "" : "#" + fm.unit().id();',
117 /* These get shown in the right panel */
118 'sitem_editor_right_pane' :
123 render: 'fm.date_expected() == null ? "" : util.date.formatted_date( fm.date_expected(), "%F");',
124 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);',
125 value_key: 'date_expected'
131 render: 'fm.date_received() == null ? "" : util.date.formatted_date( fm.date_received(), "%F");',
132 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; }',
133 value_key: 'date_received'
141 /******************************************************************************************************/
142 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
144 'summarize' : serial.editor_base.editor_base_summarize,
146 /******************************************************************************************************/
147 /* Display the summarized data and inputs for editing */
149 'render' : serial.editor_base.editor_base_render,
151 /******************************************************************************************************/
152 /* This actually draws the change button and input widget for a given field */
153 'render_input' : serial.editor_base.editor_base_render_input,
155 /******************************************************************************************************/
158 'save' : function() {
160 obj.editor_base_save('open-ils.serial.item.fleshed.batch.update');
163 /******************************************************************************************************/
164 /* spawn notes interface */
166 'notes' : function() {
168 JSAN.use('util.window'); var win = new util.window();
170 urls.XUL_SERIAL_NOTES,
171 //+ '?copy_id=' + window.escape(obj.sitems[0].id()),
172 'Item Notes','chrome,resizable,modal',
173 { 'object_id' : obj.sitems[0].id(), 'function_type' : 'SIN', 'object_type' : 'item', 'constructor' : sin }
177 /******************************************************************************************************/
178 'save_attributes' : serial.editor_base.editor_base_save_attributes
182 dump('exiting serial/sitem.js\n');