]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/siss_editor.js
f42abced40222e9189ebe2df6638e6d027519ebf
[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' : true,
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 "C/P : #" + 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                 $('catStrings').getString('staff.cat.copy_editor.field.creation_date.label') + ' ', //adding extra spaces to satisfy summarize uniqueness requirements
96                 {
97                     render: 'fm.create_date() == null ? "<Unset>" : util.date.formatted_date( fm.create_date(), "%F");',
98                 }
99             ],
100             [
101                 $('catStrings').getString('staff.cat.copy_editor.field.creator.label') + ' ',
102                 {
103                     render: 'fm.creator().usrname() == null ? "<Unset>" : fm.creator().usrname();',
104                 }
105             ],
106             [
107                 $('catStrings').getString('staff.cat.copy_editor.field.last_edit_date.label') + ' ',
108                 {
109                     render: 'fm.edit_date() == null ? "<Unset>" : util.date.formatted_date( fm.edit_date(), "%F");',
110                 }
111             ],
112             [
113                 $('catStrings').getString('staff.cat.copy_editor.field.last_editor.label') + ' ',
114                 {
115                     render: 'fm.editor().usrname() == null ? "<Unset>" : 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                     render: 'fm.holding_code();',
141                     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);',
142                     value_key: 'holding_code'
143                 }
144             ],
145             [
146                 'Caption/Pattern',
147                 {
148                     render: 'obj.render_scap(fm.caption_and_pattern());',
149                     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); }',
150                     value_key: 'caption_and_pattern',
151                     dropdown_key: 'fm.caption_and_pattern() == null ? null : typeof fm.caption_and_pattern() == "object" ? fm.caption_and_pattern().id() : fm.caption_and_pattern()'
152                 }
153             ]
154         ],
155
156         'siss_editor_right_pane' :
157         [
158             [
159                 'Date Published',
160                 {
161                     render: 'fm.date_published() == null ? "" : util.date.formatted_date( fm.date_published(), "%F");',
162                     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);',
163                     value_key: 'date_published'
164                 }
165             ],
166             [
167                 'Issuance Label',
168                 {
169                     render: 'fm.label() == null ? "" : fm.label();',
170                     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);',
171                     value_key: 'label'
172                 }
173             ],
174         ],
175
176         };
177     },
178
179     /******************************************************************************************************/
180     /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
181
182     'summarize' : serial.editor_base.editor_base_summarize,
183
184     /******************************************************************************************************/
185     /* Display the summarized data and inputs for editing */
186
187     'render' : serial.editor_base.editor_base_render,
188
189     /******************************************************************************************************/
190     /* This actually draws the change button and input widget for a given field */
191     'render_input' : serial.editor_base.editor_base_render_input,
192
193     /******************************************************************************************************/
194     /* update the issuances */
195
196     'save' : function() {
197         var obj = this;
198         obj.editor_base_save('open-ils.serial.issuance.fleshed.batch.update');
199     },
200
201     /******************************************************************************************************/
202     /* spawn issuance notes interface */
203
204     'notes' : function() {
205         var obj = this;
206         JSAN.use('util.window'); var win = new util.window();
207         win.open(
208             urls.XUL_SERIAL_NOTES, 
209             'Issuance Notes','chrome,resizable,modal',
210             { 'object_id' : obj.sisses[0].id(), 'function_type' : 'SISSN', 'object_type' : 'issuance', 'constructor' : sissn }
211         );
212     },
213
214     /******************************************************************************************************/
215     'save_attributes' : serial.editor_base.editor_base_save_attributes,
216
217     /******************************************************************************************************/
218     /* This returns a list of scaps appropriate for the issuances being edited */
219     'get_scap_list' : function() {
220         var obj = this;
221         try {
222             /* we will only show this list if dealing with one subscription, default to first siss*/
223             var ssub_id = typeof obj.sisses[0].subscription() == 'object' ? obj.sisses[0].subscription().id() : obj.sisses[0].subscription();
224
225             var scap_list = obj.network.request(
226                 'open-ils.pcrud',
227                 'open-ils.pcrud.search.scap',
228                 [ ses(), {"subscription" : ssub_id }, {"order_by" : {"scap" : "id"} } ]
229             );
230
231             if (scap_list == null) {
232                 return [];
233             } else if (!scap_list.length) {
234                 scap_list = [scap_list];
235             }
236
237             return scap_list;
238         } catch(E) {
239             obj.error.standard_unexpected_error_alert('get_scap_list',E);
240             return [];
241         }
242     }
243 };
244
245 dump('exiting serial/siss_editor.js\n');