]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/siss_editor.js
Reduce hard-coded strings in Serial Control interfaces
[Evergreen.git] / Open-ILS / xul / staff_client / server / serial / siss_editor.js
1 dump('entering serial/siss_editor.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 JSAN.use('serial.editor_base');
5
6 if (typeof serial == 'undefined') serial = {};
7 serial.siss_editor = function (params) {
8     try {
9         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
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/siss_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.siss_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' : 'siss',
31     'fm_type_plural' : 'sisses',
32     'can_have_notes' : false, // XXX no notes table exists yet, but it might make sense
33
34     'init' : function (params) {
35         var obj = this;
36         
37         params.retrieve_function = 'FM_SISS_FLESHED_BATCH_RETRIEVE.authoritative';
38
39         obj.editor_base_init(params);
40
41         obj.multi_ssub_edit = false;
42         var ssub = obj.sisses[0].subscription();
43         for (var i = 1; i < obj.sisses.length; i++) {
44             if (obj.sisses[i].subscription() != ssub) {
45                 obj.multi_ssub_edit = true;
46                 break;
47             }
48         }
49
50         /* Do it */
51         obj.summarize( obj.sisses );
52         obj.render();
53     },
54
55     /******************************************************************************************************/
56     /* Restore backup copies */
57
58     'reset' : serial.editor_base.editor_base_reset,
59
60     /******************************************************************************************************/
61     /* Apply a value to a specific field on all the copies being edited */
62
63     'apply' : function(field,value) {
64         var obj = this;
65         if (field == 'date_published' || field == 'caption_and_pattern') {
66             if (value == '') { value = null; }
67         }
68         obj.editor_base_apply(field, value);
69     },
70
71     /******************************************************************************************************/
72     /* Initialize the panes */
73
74     'render_scap' : function(scap) {
75         var obj = this;
76         var id;
77         if (scap == null) { // true for both 'null' AND undefined
78             return "";
79         } else if (typeof scap != 'object') {
80             id = scap;
81         } else {
82             id = scap.id()
83         }
84         return $('serialStrings').getFormattedString('serial.manage_subs.scap_id', [id]);
85     },
86
87     'init_panes' : function () {
88         var obj = this;
89         obj.panes_and_field_names = {
90
91     /* These get shown in the left panel */
92             'siss_editor_left_pane' :
93         [
94             [
95                 'create_date',
96                 {
97                     render: 'fm.create_date() == null ? "" : util.date.formatted_date( fm.create_date(), "%F");',
98                 }
99             ],
100             [
101                 'creator',
102                 {
103                     render: 'fm.creator().usrname() == null ? "" : fm.creator().usrname();',
104                 }
105             ],
106             [
107                 'edit_date',
108                 {
109                     render: 'fm.edit_date() == null ? "" : util.date.formatted_date( fm.edit_date(), "%F");',
110                 }
111             ],
112             [
113                 'editor',
114                 {
115                     render: 'fm.editor().usrname() == null ? "" : fm.editor().usrname();',
116                 }
117             ],
118         ],
119
120         'siss_editor_middle_pane' :
121         [
122 /*rjs7 don't think we need these anymore            [
123                 'Holding Type',
124                 {
125                     render: 'fm.holding_type();',
126                     input: 'c = function(v){ obj.apply("holding_type",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ ["basic", "basic"], ["index", "index"], ["supplement", "supplement"] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
127                 }
128             ],
129             [
130                 'Holding Link ID',
131                 {
132                     render: 'fm.holding_link_id();',
133                     input: 'c = function(v){ obj.apply("holding_link_id",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.holding_link_id); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
134                     value_key: 'holding_link_id'
135                 }
136             ],*/
137             [
138                 'holding_code',
139                 {
140                     input: 'c = function(v){ obj.apply("holding_code",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.holding_code); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
141                     value_key: 'holding_code'
142                 }
143             ],
144             [
145                 'caption_and_pattern',
146                 {
147                     render: 'obj.render_scap(fm.caption_and_pattern());',
148                     input: 'if(!obj.multi_ssub_edit) { c = function(v){ obj.apply("caption_and_pattern",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( obj.get_scap_list(), function(obj2) { return [ obj.render_scap(obj2.id()), obj2.id() ]; }).sort()); x.setAttribute("value",obj.editor_values.caption_and_pattern); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false); }',
149                     value_key: 'caption_and_pattern',
150                     dropdown_key: 'fm.caption_and_pattern() == null ? null : typeof fm.caption_and_pattern() == "object" ? fm.caption_and_pattern().id() : fm.caption_and_pattern()'
151                 }
152             ]
153         ],
154
155         'siss_editor_right_pane' :
156         [
157             [
158                 'date_published',
159                 {
160                     render: 'fm.date_published() == null ? "" : util.date.formatted_date( fm.date_published(), "%F");',
161                     input: 'c = function(v){ obj.apply("date_published",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.date_published); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
162                     value_key: 'date_published'
163                 }
164             ],
165             [
166                 'label',
167                 {
168                     input: 'c = function(v){ obj.apply("label",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.label); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
169                     value_key: 'label'
170                 }
171             ],
172         ],
173
174         };
175     },
176
177     /******************************************************************************************************/
178     /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
179
180     'summarize' : serial.editor_base.editor_base_summarize,
181
182     /******************************************************************************************************/
183     /* Display the summarized data and inputs for editing */
184
185     'render' : serial.editor_base.editor_base_render,
186
187     /******************************************************************************************************/
188     /* This actually draws the change button and input widget for a given field */
189     'render_input' : serial.editor_base.editor_base_render_input,
190
191     /******************************************************************************************************/
192     /* update the issuances */
193
194     'save' : function() {
195         var obj = this;
196         obj.editor_base_save('open-ils.serial.issuance.fleshed.batch.update');
197     },
198
199     /******************************************************************************************************/
200     /* spawn issuance notes interface */
201
202     'notes' : function() {
203         var obj = this;
204         JSAN.use('util.window'); var win = new util.window();
205         win.open(
206             urls.XUL_SERIAL_NOTES, 
207             $('serialStrings').getString('staff.serial.siss_editor.notes'),'chrome,resizable,modal',
208             { 'object_id' : obj.sisses[0].id(), 'function_type' : 'SISSN', 'object_type' : 'issuance', 'constructor' : sissn }
209         );
210     },
211
212     /******************************************************************************************************/
213     'save_attributes' : serial.editor_base.editor_base_save_attributes,
214
215     /******************************************************************************************************/
216     /* This returns a list of scaps appropriate for the issuances being edited */
217     'get_scap_list' : function() {
218         var obj = this;
219         try {
220             /* we will only show this list if dealing with one subscription, default to first siss*/
221             var ssub_id = typeof obj.sisses[0].subscription() == 'object' ? obj.sisses[0].subscription().id() : obj.sisses[0].subscription();
222
223             var scap_list = obj.network.request(
224                 'open-ils.pcrud',
225                 'open-ils.pcrud.search.scap',
226                 [ ses(), {"subscription" : ssub_id }, {"order_by" : {"scap" : "id"} } ]
227             );
228
229             if (scap_list == null) {
230                 return [];
231             } else if (!scap_list.length) {
232                 scap_list = [scap_list];
233             }
234
235             return scap_list;
236         } catch(E) {
237             obj.error.standard_unexpected_error_alert('get_scap_list',E);
238             return [];
239         }
240     }
241 };
242
243 dump('exiting serial/siss_editor.js\n');