]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/sitem_editor.js
f0572101af82a1815574f38896793406134b3ce9
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / serial / sitem_editor.js
1 dump('entering serial/sitem_editor.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 JSAN.addRepository('/xul/server/');
5 JSAN.use('serial.editor_base');
6
7 if (typeof serial == 'undefined') serial = {};
8 serial.sitem_editor = function (params) {
9     try {
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();
13     } catch(E) {
14         dump('serial/sitem_editor: ' + E + '\n');
15     }
16
17     /* This keeps track of what fields have been edited for styling purposes */
18     this.changed = {};
19
20     /* This holds the original values for prepopulating the field editors */
21     this.editor_values = {};
22 };
23
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,
29
30     'fm_type' : 'sitem',
31     'fm_type_plural' : 'sitems',
32     'can_have_notes' : true,
33
34     'init' : function (params) {
35         var obj = this;
36
37         params.retrieve_function = 'FM_SITEM_FLESHED_BATCH_RETRIEVE.authoritative';
38
39         obj.editor_base_init(params);
40
41         /* Do it */
42         obj.summarize( obj.sitems );
43         obj.render();
44     },
45
46     /******************************************************************************************************/
47     /* Restore backup copies */
48
49     'reset' :  serial.editor_base.editor_base_reset,
50
51     /******************************************************************************************************/
52     /* Apply a value to a specific field on all the copies being edited */
53
54     'apply' : function(field,value) {
55         var obj = this;
56         JSAN.use('util.date');
57         if (field == 'date_expected') {
58             if (value == '') {
59                 alert("Date Expected cannot be unset.");
60                 return false;
61             } else if (!util.date.check('YYYY-MM-DD',value)) {
62                 alert("Invalid Date");
63                 return false;
64             }
65         } else if (field == 'date_received') { // manually unset not allowed
66             if (value == '') {
67                 alert("Date Received cannot be manually unset; use 'Reset to Expected' instead.");
68                 return false;
69             } else if (!util.date.check('YYYY-MM-DD',value)) {
70                 alert("Invalid Date");
71                 return false;
72             }
73         }
74         obj.editor_base_apply(field, value);
75         return true;
76     },
77
78     /******************************************************************************************************/
79
80     'init_panes' : function () {
81         var obj = this;
82         obj.panes_and_field_names = {
83
84         /* These get shown in the left panel */
85         'sitem_editor_left_pane' :
86         [
87             [
88                 'id',
89                 { 
90                 }
91             ],
92             [
93                 'status',
94                 { 
95                 }
96             ]
97         ],
98         /* These get shown in the middle panel */
99         'sitem_editor_middle_pane' :
100         [
101             [
102                 'distribution',
103                 {
104                     render: 'fm.stream().distribution().label() == null ? "" : fm.stream().distribution().label();',
105                     label: fieldmapper.IDL.fmclasses.sstr.field_map.distribution.label
106
107                 }
108             ],
109             [
110                 'unit',
111                 {
112                     render: 'fm.unit() == null ? "" : "#" + fm.unit().id();',
113                 }
114             ],
115         ],
116
117         /* These get shown in the right panel */
118         'sitem_editor_right_pane' :
119         [
120             [
121                 'date_expected',
122                 {
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'
126                 }
127             ],
128             [
129                 'date_received',
130                 {
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'
134                 }
135             ],
136         ],
137
138         };
139     },
140
141     /******************************************************************************************************/
142     /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
143
144     'summarize' :  serial.editor_base.editor_base_summarize,
145
146     /******************************************************************************************************/
147     /* Display the summarized data and inputs for editing */
148
149     'render' :  serial.editor_base.editor_base_render,
150
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,
154
155     /******************************************************************************************************/
156     /* save the items */
157
158     'save' : function() {
159         var obj = this;
160         obj.editor_base_save('open-ils.serial.item.fleshed.batch.update');
161     },
162
163     /******************************************************************************************************/
164     /* spawn notes interface */
165
166     'notes' : function() {
167         var obj = this;
168         JSAN.use('util.window'); var win = new util.window();
169         win.open(
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 }
174         );
175     },
176
177     /******************************************************************************************************/
178     'save_attributes' : serial.editor_base.editor_base_save_attributes
179
180 };
181
182 dump('exiting serial/sitem.js\n');