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