1 dump('entering serial/siss_editor.js\n');
4 JSAN.use('serial.editor_base');
6 if (typeof serial == 'undefined') serial = {};
7 serial.siss_editor = function (params) {
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();
13 dump('serial/siss_editor: ' + E + '\n');
16 /* This keeps track of what fields have been edited for styling purposes */
19 /* This holds the original values for prepopulating the field editors */
20 this.editor_values = {};
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,
30 'fm_type_plural' : 'sisses',
31 'can_have_notes' : false, // XXX no notes table exists yet, but it might make sense
33 'init' : function (params) {
36 params.retrieve_function = 'FM_SISS_FLESHED_BATCH_RETRIEVE.authoritative';
38 obj.editor_base_init(params);
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;
50 obj.summarize( obj.sisses );
54 /******************************************************************************************************/
55 /* Restore backup copies */
57 'reset' : serial.editor_base.editor_base_reset,
59 /******************************************************************************************************/
60 /* Apply a value to a specific field on all the copies being edited */
62 'apply' : function(field,value) {
64 if (field == 'date_published' || field == 'caption_and_pattern') {
65 if (value == '') { value = null; }
67 obj.editor_base_apply(field, value);
70 /******************************************************************************************************/
71 /* Initialize the panes */
73 'render_scap' : function(scap) {
76 if (scap == null) { // true for both 'null' AND undefined
78 } else if (typeof scap != 'object') {
83 return $('serialStrings').getFormattedString('serial.manage_subs.scap_id', [id]);
86 'init_panes' : function () {
88 obj.panes_and_field_names = {
90 /* These get shown in the left panel */
91 'siss_editor_left_pane' :
96 render: 'fm.create_date() == null ? "" : util.date.formatted_date( fm.create_date(), "%F");',
102 render: 'fm.creator().usrname() == null ? "" : fm.creator().usrname();',
108 render: 'fm.edit_date() == null ? "" : util.date.formatted_date( fm.edit_date(), "%F");',
114 render: 'fm.editor().usrname() == null ? "" : fm.editor().usrname();',
119 'siss_editor_middle_pane' :
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',
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'
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'
145 'caption_and_pattern',
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()'
155 'siss_editor_right_pane' :
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'
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);',
177 /******************************************************************************************************/
178 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
180 'summarize' : serial.editor_base.editor_base_summarize,
182 /******************************************************************************************************/
183 /* Display the summarized data and inputs for editing */
185 'render' : serial.editor_base.editor_base_render,
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,
191 /******************************************************************************************************/
192 /* update the issuances */
194 'save' : function() {
196 obj.editor_base_save('open-ils.serial.issuance.fleshed.batch.update');
199 /******************************************************************************************************/
200 /* spawn issuance notes interface */
202 'notes' : function() {
204 JSAN.use('util.window'); var win = new util.window();
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 }
212 /******************************************************************************************************/
213 'save_attributes' : serial.editor_base.editor_base_save_attributes,
215 /******************************************************************************************************/
216 /* This returns a list of scaps appropriate for the issuances being edited */
217 'get_scap_list' : function() {
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();
223 var scap_list = obj.network.request(
225 'open-ils.pcrud.search.scap',
226 [ ses(), {"subscription" : ssub_id }, {"order_by" : {"scap" : "id"} } ]
229 if (scap_list == null) {
231 } else if (!scap_list.length) {
232 scap_list = [scap_list];
237 obj.error.standard_unexpected_error_alert('get_scap_list',E);
243 dump('exiting serial/siss_editor.js\n');