]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/siss_editor.js
Improve Firefox/XULRunner Support
[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         JSAN.use('util.error'); this.error = new util.error();
10         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
11         JSAN.use('util.network'); this.network = new util.network();
12     } catch(E) {
13         dump('serial/siss_editor: ' + E + '\n');
14     }
15
16     /* This keeps track of what fields have been edited for styling purposes */
17     this.changed = {};
18
19     /* This holds the original values for prepopulating the field editors */
20     this.editor_values = {};
21 };
22
23 serial.siss_editor.prototype = {
24     // we could do this with non-standard '__proto__' property instead
25     'editor_base_init' : serial.editor_base.editor_base_init,
26     'editor_base_apply' : serial.editor_base.editor_base_apply,
27     'editor_base_save' : serial.editor_base.editor_base_save,
28
29     'fm_type' : 'siss',
30     'fm_type_plural' : 'sisses',
31     'can_have_notes' : false, // XXX no notes table exists yet, but it might make sense
32
33     'init' : function (params) {
34         var obj = this;
35         
36         params.retrieve_function = 'FM_SISS_FLESHED_BATCH_RETRIEVE.authoritative';
37
38         obj.editor_base_init(params);
39
40         obj.multi_ssub_edit = false;
41         var ssub = obj.sisses[0].subscription();
42         for (var i = 1; i < obj.sisses.length; i++) {
43             if (obj.sisses[i].subscription() != ssub) {
44                 obj.multi_ssub_edit = true;
45                 break;
46             }
47         }
48
49         /* Do it */
50         obj.summarize( obj.sisses );
51         obj.render();
52     },
53
54     /******************************************************************************************************/
55     /* Restore backup copies */
56
57     'reset' : serial.editor_base.editor_base_reset,
58
59     /******************************************************************************************************/
60     /* Apply a value to a specific field on all the copies being edited */
61
62     'apply' : function(field,value) {
63         var obj = this;
64         if (field == 'date_published' || field == 'caption_and_pattern') {
65             if (value == '') { value = null; }
66         }
67         obj.editor_base_apply(field, value);
68     },
69
70     /******************************************************************************************************/
71     /* Initialize the panes */
72
73     'render_scap' : function(scap) {
74         var obj = this;
75         var id;
76         if (scap == null) { // true for both 'null' AND undefined
77             return "";
78         } else if (typeof scap != 'object') {
79             id = scap;
80         } else {
81             id = scap.id()
82         }
83         return $('serialStrings').getFormattedString('serial.manage_subs.scap_id', [id]);
84     },
85
86     'init_panes' : function () {
87         var obj = this;
88         obj.panes_and_field_names = {
89
90     /* These get shown in the left panel */
91             'siss_editor_left_pane' :
92         [
93             [
94                 'create_date',
95                 {
96                     render: 'fm.create_date() == null ? "" : util.date.formatted_date( fm.create_date(), "%F");',
97                 }
98             ],
99             [
100                 'creator',
101                 {
102                     render: 'fm.creator().usrname() == null ? "" : fm.creator().usrname();',
103                 }
104             ],
105             [
106                 'edit_date',
107                 {
108                     render: 'fm.edit_date() == null ? "" : util.date.formatted_date( fm.edit_date(), "%F");',
109                 }
110             ],
111             [
112                 'editor',
113                 {
114                     render: 'fm.editor().usrname() == null ? "" : fm.editor().usrname();',
115                 }
116             ],
117         ],
118
119         'siss_editor_middle_pane' :
120         [
121             [
122                 'holding_type',
123                 {
124                     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.setAttribute("value",obj.editor_values.holding_type); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
125                     value_key: 'holding_type',
126                     required: true
127                 }
128             ],
129 /* deprecated            [
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("multiline",true); x.setAttribute("cols",40); 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');