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