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 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();
14 dump('serial/siss_editor: ' + E + '\n');
17 /* This keeps track of what fields have been edited for styling purposes */
20 /* This holds the original values for prepopulating the field editors */
21 this.editor_values = {};
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,
31 'fm_type_plural' : 'sisses',
32 'can_have_notes' : false, // XXX no notes table exists yet, but it might make sense
34 'init' : function (params) {
37 params.retrieve_function = 'FM_SISS_FLESHED_BATCH_RETRIEVE.authoritative';
39 obj.editor_base_init(params);
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;
51 obj.summarize( obj.sisses );
55 /******************************************************************************************************/
56 /* Restore backup copies */
58 'reset' : serial.editor_base.editor_base_reset,
60 /******************************************************************************************************/
61 /* Apply a value to a specific field on all the copies being edited */
63 'apply' : function(field,value) {
65 if (field == 'date_published' || field == 'caption_and_pattern') {
66 if (value == '') { value = null; }
68 obj.editor_base_apply(field, value);
71 /******************************************************************************************************/
72 /* Initialize the panes */
74 'render_scap' : function(scap) {
77 if (scap == null) { // true for both 'null' AND undefined
79 } else if (typeof scap != 'object') {
84 return $('serialStrings').getFormattedString('serial.manage_subs.scap_id', [id]);
87 'init_panes' : function () {
89 obj.panes_and_field_names = {
91 /* These get shown in the left panel */
92 'siss_editor_left_pane' :
97 render: 'fm.create_date() == null ? "" : util.date.formatted_date( fm.create_date(), "%F");',
103 render: 'fm.creator().usrname() == null ? "" : fm.creator().usrname();',
109 render: 'fm.edit_date() == null ? "" : util.date.formatted_date( fm.edit_date(), "%F");',
115 render: 'fm.editor().usrname() == null ? "" : fm.editor().usrname();',
120 'siss_editor_middle_pane' :
122 /*rjs7 don't think we need these anymore [
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);',
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');