]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/ssub_editor.js
c807f72b70d3bd54302006328e19afde4442b698
[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                     render: '"ID : " + fm.id();', 
108                     //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);',
109
110                 }
111             ],
112             [
113                 'Owning Lib',
114                 {
115                     render: 'typeof fm.owning_lib() == "object" ? fm.owning_lib().shortname() : obj.data.hash.aou[ fm.owning_lib() ].shortname()',
116                     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);',
117                     value_key: 'owning_lib',
118                     dropdown_key: 'fm.owning_lib() == null ? null : typeof fm.owning_lib() == "object" ? fm.owning_lib().id() : fm.owning_lib()',
119                 }
120             ],
121         ],
122
123             'right_pane' :
124         [
125             [
126                 'Start Date',
127                 { 
128                     render: 'fm.start_date() == null ? "" : util.date.formatted_date( fm.start_date(), "%F");',
129                     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);',
130                     value_key: 'start_date'
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                 'Date Offset',
143                 { 
144                     render: 'fm.expected_date_offset() == null ? "" : fm.expected_date_offset();',
145                     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);',
146                     value_key: 'expected_date_offset'
147                 }
148             ],
149         ],
150
151         };
152     },
153
154     /******************************************************************************************************/
155     /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
156
157     'summarize' : serial.editor_base.editor_base_summarize,
158
159     /******************************************************************************************************/
160     /* Display the summarized data and inputs for editing */
161
162     'render' : serial.editor_base.editor_base_render,
163
164     /******************************************************************************************************/
165     /* This actually draws the change button and input widget for a given field */
166     'render_input' : serial.editor_base.editor_base_render_input,
167
168     /******************************************************************************************************/
169     /* save the subscriptions */
170
171     'save' : function() {
172         var obj = this;
173         obj.editor_base_save('open-ils.serial.subscription.fleshed.batch.update');
174     },
175
176     /******************************************************************************************************/
177     /* spawn notes interface */
178
179     'notes' : function() {
180         var obj = this;
181         JSAN.use('util.window'); var win = new util.window();
182         win.open(
183             urls.XUL_SERIAL_NOTES, 
184             'Subscription Notes','chrome,resizable,modal',
185             { 'object_id' : obj.ssubs[0].id(), 'function_type' : 'SSUBN', 'object_type' : 'subscription', 'constructor' : ssubn }
186         );
187     },
188
189     /******************************************************************************************************/
190     'save_attributes' : serial.editor_base.editor_base_save_attributes
191 };
192
193 dump('exiting serial/ssub_editor.js\n');