]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/sitem_editor.js
Reduce hard-coded strings in Serial Control interfaces
[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                 }
92             ],
93             [
94                 'status',
95                 { 
96                 }
97             ]
98         ],
99         /* These get shown in the middle panel */
100         'sitem_editor_middle_pane' :
101         [
102             [
103                 'distribution',
104                 {
105                     render: 'fm.stream().distribution().label() == null ? "" : fm.stream().distribution().label();',
106                     label: fieldmapper.IDL.fmclasses.sstr.field_map.distribution.label
107
108                 }
109             ],
110             [
111                 'unit',
112                 {
113                     render: 'fm.unit() == null ? "" : "#" + fm.unit().id();',
114                 }
115             ],
116         ],
117
118         /* These get shown in the right panel */
119         'sitem_editor_right_pane' :
120         [
121             [
122                 'date_expected',
123                 {
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'
127                 }
128             ],
129             [
130                 'date_received',
131                 {
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'
135                 }
136             ],
137         ],
138
139         };
140     },
141
142     /******************************************************************************************************/
143     /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
144
145     'summarize' :  serial.editor_base.editor_base_summarize,
146
147     /******************************************************************************************************/
148     /* Display the summarized data and inputs for editing */
149
150     'render' :  serial.editor_base.editor_base_render,
151
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,
155
156     /******************************************************************************************************/
157     /* save the items */
158
159     'save' : function() {
160         var obj = this;
161         obj.editor_base_save('open-ils.serial.item.fleshed.batch.update');
162     },
163
164     /******************************************************************************************************/
165     /* spawn notes interface */
166
167     'notes' : function() {
168         var obj = this;
169         JSAN.use('util.window'); var win = new util.window();
170         win.open(
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 }
175         );
176     },
177
178     /******************************************************************************************************/
179     'save_attributes' : serial.editor_base.editor_base_save_attributes
180
181 };
182
183 dump('exiting serial/sitem.js\n');