]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/ssub_editor.js
Merge branch 'master' of git://git.evergreen-ils.org/Evergreen into ttopac
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / serial / ssub_editor.js
1 dump('entering serial/ssub_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.ssub_editor = function (params) {
8     try {
9         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
10         JSAN.use('util.error'); this.error = new util.error();
11     } catch(E) {
12         dump('serial/ssub_editor: ' + E + '\n');
13     }
14
15     /* This keeps track of what fields have been edited for styling purposes */
16     this.changed = {};
17
18     /* This holds the original values for prepopulating the field editors */
19     this.editor_values = {};
20
21 };
22
23 serial.ssub_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' : 'ssub',
30     'fm_type_plural' : 'ssubs',
31     'can_have_notes' : true,
32
33     'init' : function (params) {
34         var obj = this;
35
36         params.retrieve_function = 'FM_SSUB_FLESHED_BATCH_RETRIEVE.authoritative';
37
38         obj.editor_base_init(params);
39
40         /* Do it */
41         obj.summarize( obj.ssubs );
42         obj.render();
43     },
44
45     /******************************************************************************************************/
46     /* Restore backup copies */
47
48     'reset' : serial.editor_base.editor_base_reset,
49
50     /******************************************************************************************************/
51     /* Apply a value to a specific field on all the copies being edited */
52
53     'apply' : function(field, value) {
54         var obj = this;
55
56         if (field == 'start_date' || field == 'end_date') {
57             if (value == '') { value = null; }
58         }
59
60         obj.editor_base_apply(field, value);
61     },
62
63
64     /******************************************************************************************************/
65     /* These need data from the middle layer to render */
66
67     /*
68     function init_panes0() {
69     obj.special_exception = {};
70     obj.special_exception[$('catStrings').getString('staff.cat.copy_editor.field.owning_library.label')] = function(label,value) {
71             JSAN.use('util.widgets');
72             if (value>0) { // an existing call number
73                 obj.network.simple_request(
74                     'FM_ACN_RETRIEVE.authoritative',
75                     [ value ],
76                     function(req) {
77                         var cn = '??? id = ' + value;
78                         try {
79                             cn = req.getResultObject();
80                         } catch(E) {
81                             obj.error.sdump('D_ERROR','callnumber retrieve: ' + E);
82                         }
83                         util.widgets.set_text(label,obj.data.hash.aou[ cn.owning_lib() ].shortname() + ' : ' + cn.label());
84                     }
85                 );
86             } else { // a yet to be created call number
87                 if (obj.callnumbers) {
88                     util.widgets.set_text(label,obj.data.hash.aou[ obj.callnumbers[value].owning_lib ].shortname() + ' : ' + obj.callnumbers[value].label);
89                 }
90             }
91         };
92     },
93     */
94
95     /******************************************************************************************************/
96     /* These get show in the left panel */
97
98     'init_panes' : function () {
99         var obj = this;
100         obj.panes_and_field_names = {
101
102         'left_pane' :
103         [
104             [
105                 'id',
106                 { 
107                     //input: 'c = function(v){ obj.apply("distribution",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
108
109                 }
110             ],
111             [
112                 'owning_lib',
113                 {
114                     render: 'typeof fm.owning_lib() == "object" ? fm.owning_lib().shortname() : obj.data.hash.aou[ fm.owning_lib() ].shortname()',
115                     input: 'c = function(v){ obj.apply("owning_lib",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( obj.data.list.aou, function(myobj) { var sname = myobj.shortname(); for (i = sname.length; i < 20; i++) sname += " "; return [ myobj.name() ? sname + " " + myobj.name() : myobj.shortname(), myobj.id(), ( ! get_bool( obj.data.hash.aout[ myobj.ou_type() ].can_have_vols() ) ), ( obj.data.hash.aout[ myobj.ou_type() ].depth() * 2), ]; }), obj.data.list.au[0].ws_ou()); x.setAttribute("value",obj.editor_values.owning_lib); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
116                     value_key: 'owning_lib',
117                     dropdown_key: 'fm.owning_lib() == null ? null : typeof fm.owning_lib() == "object" ? fm.owning_lib().id() : fm.owning_lib()',
118                 }
119             ],
120         ],
121
122             'right_pane' :
123         [
124             [
125                 'start_date',
126                 { 
127                     render: 'fm.start_date() == null ? "" : util.date.formatted_date( fm.start_date(), "%F");',
128                     input: 'c = function(v){ obj.apply("start_date",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.start_date); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
129                     value_key: 'start_date',
130                     required: true
131                 }
132             ],
133             [
134                 'end_date',
135                 {
136                     render: 'fm.end_date() == null ? "" : util.date.formatted_date( fm.end_date(), "%F");',
137                     input: 'c = function(v){ obj.apply("end_date",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.end_date); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
138                     value_key: 'end_date'
139                 }
140             ],
141             [
142                 'expected_date_offset',
143                 { 
144                     input: 'c = function(v){ obj.apply("expected_date_offset",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.expected_date_offset); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
145                     value_key: 'expected_date_offset'
146                 }
147             ],
148         ],
149
150         };
151     },
152
153     /******************************************************************************************************/
154     /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
155
156     'summarize' : serial.editor_base.editor_base_summarize,
157
158     /******************************************************************************************************/
159     /* Display the summarized data and inputs for editing */
160
161     'render' : serial.editor_base.editor_base_render,
162
163     /******************************************************************************************************/
164     /* This actually draws the change button and input widget for a given field */
165     'render_input' : serial.editor_base.editor_base_render_input,
166
167     /******************************************************************************************************/
168     /* save the subscriptions */
169
170     'save' : function() {
171         var obj = this;
172         obj.editor_base_save('open-ils.serial.subscription.fleshed.batch.update');
173     },
174
175     /******************************************************************************************************/
176     /* spawn notes interface */
177
178     'notes' : function() {
179         var obj = this;
180         JSAN.use('util.window'); var win = new util.window();
181         win.open(
182             urls.XUL_SERIAL_NOTES, 
183             $('serialStrings').getString('staff.serial.ssub_editor.notes'),'chrome,resizable,modal',
184             { 'object_id' : obj.ssubs[0].id(), 'function_type' : 'SSUBN', 'object_type' : 'subscription', 'constructor' : ssubn }
185         );
186     },
187
188     /******************************************************************************************************/
189     'save_attributes' : serial.editor_base.editor_base_save_attributes
190 };
191
192 dump('exiting serial/ssub_editor.js\n');