]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/conify/global/actor/org_unit.js
Add reporter Dojo resource file (reports.js.pot)
[working/Evergreen.git] / Open-ILS / web / conify / global / actor / org_unit.js
1 /*
2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008  Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------------------
16 */
17
18 dojo.require('fieldmapper.dojoData');
19 dojo.require('openils.widget.TranslatorPopup');
20 dojo.require('dojo.parser');
21 dojo.require('dojo.data.ItemFileWriteStore');
22 dojo.require('dojo.date.stamp');
23 dojo.require('dijit.form.TextBox');
24 dojo.require('dijit.form.TimeTextBox');
25 dojo.require('dijit.form.ValidationTextBox');
26 dojo.require('dijit.form.CheckBox');
27 dojo.require('dijit.form.FilteringSelect');
28 dojo.require('dijit.Tree');
29 dojo.require('dijit.layout.ContentPane');
30 dojo.require('dijit.layout.TabContainer');
31 dojo.require('dijit.layout.LayoutContainer');
32 dojo.require('dijit.layout.SplitContainer');
33 dojo.require('dojox.widget.Toaster');
34 dojo.require('dojox.fx');
35 dojo.requireLocalization("openils.conify", "conify");
36
37 // some handy globals
38 var cgi = new CGI();
39 var cookieManager = new HTTP.Cookies();
40 var ses = cookieManager.read('ses') || cgi.param('ses');
41 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
42
43 var current_ou, current_ou_hoo;
44 var virgin_ou_id = -1;
45
46 var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
47
48 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
49
50 var highlighter = {};
51
52 function status_update (markup) {
53         if (parent !== window && parent.status_update) parent.status_update( markup );
54 }
55
56 function save_org () {
57         var modified_ou = new aou().fromStoreItem( current_ou );
58         modified_ou.ischanged( 1 );
59
60         new_kid_button.disabled = false;
61         save_ou_button.disabled = false;
62         delete_ou_button.disabled = false;
63
64         pCRUD.request({
65                 method : 'open-ils.permacrud.update.aou',
66                 timeout : 10,
67                 params : [ ses, modified_ou ],
68                 onerror : function (r) {
69                         highlighter.editor_pane.red.play();
70                         status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
71                 },
72                 oncomplete : function (r) {
73                         var res = r.recv();
74                         if ( res && res.content() ) {
75                                 ou_list_store.setValue( current_ou, 'ischanged', 0 );
76                                 highlighter.editor_pane.green.play();
77                                 status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVE, [ou_list_store.getValue( current_ou, 'name' )] ) );
78                         } else {
79                                 highlighter.editor_pane.red.play();
80                                 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
81                         }
82                 },
83         }).send();
84 }
85         
86 function hoo_load () {
87         // empty result not coming through ...
88         current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
89         current_ou_hoo.isnew(1);
90
91         pCRUD.request({
92                 method : 'open-ils.permacrud.retrieve.aouhoo',
93                 params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
94                 onerror : function (r) { 
95                         throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS, [ou_list_store.getValue( current_ou, 'name' )]);
96                 },
97                 oncomplete : function (r) {
98                         current_ou_hoo = null;
99
100                         var res = r.recv();
101                         if (res) {
102                                 if (res.content()) current_ou_hoo = res.content();
103                         }
104
105                         if (!current_ou_hoo) {
106                                 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
107                                 current_ou_hoo.isnew(1);
108                                 for (var i = 0; i < 7; i++) {
109                                         current_ou_hoo['dow_' + i + '_open']('09:00:00');
110                                         current_ou_hoo['dow_' + i + '_close']('17:00:00');
111                                 }
112                         }
113
114                         for (var i = 0; i < 7; i++) {
115                                 window['dow_' + i + '_open'].setValue(
116                                         dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
117                                 );
118                                 window['dow_' + i + '_close'].setValue(
119                                         dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
120                                 );
121                         }
122
123                         highlighter.hoo_pane.green.play();
124                 }
125         }).send();
126
127 }
128
129 function addr_load () {
130         // empty result not coming through ...
131
132         save_ill_address.disabled = false;
133         save_holds_address.disabled = false;
134         save_mailing_address.disabled = false;
135         save_billing_address.disabled = false;
136
137         if (ou_list_store.getValue( current_ou, 'billing_address' )) {
138                 pCRUD.request({
139                         method : 'open-ils.permacrud.retrieve.aoa',
140                         params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
141                         onerror : function (r) {
142                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_PHYSICAL, [ou_list_store.getValue( current_ou, 'name' )]);
143                         },
144                         oncomplete : function (r) {
145                                 current_billing_address = null;
146
147                                 var res = r.recv();
148                                 if (res) {
149                                         if (res.content()) current_billing_address = res.content();
150                                 }
151
152                                 if (!current_billing_address) {
153                                         current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
154                                         current_billing_address.isnew(1);
155                                 }
156
157                                 set_addr_inputs('billing');
158                                 highlighter.addresses_pane.green.play();
159                         }
160                 }).send();
161         } else {
162                 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
163                 current_billing_address.isnew(1);
164                 set_addr_inputs('billing');
165         }
166
167         if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
168                 pCRUD.request({
169                         method : 'open-ils.permacrud.retrieve.aoa',
170                         params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
171                         onerror : function (r) {
172                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_MAILING, [ou_list_store.getValue( current_ou, 'name' )]);
173                         },
174                         oncomplete : function (r) {
175                                 current_mailing_address = null;
176
177                                 var res = r.recv();
178                                 if (res) {
179                                         if (res.content()) current_mailing_address = res.content();
180                                 }
181
182                                 if (!current_mailing_address) {
183                                         current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
184                                         current_mailing_address.isnew(1);
185                                 }
186
187                                 set_addr_inputs('mailing');
188                                 highlighter.addresses_pane.green.play();
189                         }
190                 }).send();
191         } else {
192                 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
193                 current_mailing_address.isnew(1);
194                 set_addr_inputs('mailing');
195         }
196
197         if (ou_list_store.getValue( current_ou, 'holds_address' )) {
198                 pCRUD.request({
199                         method : 'open-ils.permacrud.retrieve.aoa',
200                         params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
201                         onerror : function (r) {
202                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOLDS, [ou_list_store.getValue( current_ou, 'name' )]);
203                         },
204                         oncomplete : function (r) {
205                                 current_holds_address = null;
206
207                                 var res = r.recv();
208                                 if (res) {
209                                         if (res.content()) current_holds_address = res.content();
210                                 }
211
212                                 if (!current_holds_address) {
213                                         current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
214                                         current_holds_address.isnew(1);
215                                 }
216
217                                 set_addr_inputs('holds');
218                                 highlighter.addresses_pane.green.play();
219                         }
220                 }).send();
221         } else {
222                 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
223                 current_holds_address.isnew(1);
224                 set_addr_inputs('holds');
225         }
226
227         if (ou_list_store.getValue( current_ou, 'ill_address' )) {
228                 pCRUD.request({
229                         method : 'open-ils.permacrud.retrieve.aoa',
230                         params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
231                         onerror : function (r) {
232                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_ILL, [ou_list_store.getValue( current_ou, 'name' )]);
233                         },
234                         oncomplete : function (r) {
235                                 current_ill_address = null;
236
237                                 var res = r.recv();
238                                 if (res) {
239                                         if (res.content()) current_ill_address = res.content();
240                                 }
241
242                                 if (!current_ill_address) {
243                                         current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
244                                         current_ill_address.isnew(1);
245                                 }
246
247                                 set_addr_inputs('ill');
248                                 highlighter.addresses_pane.green.play();
249                         }
250                 }).send();
251         } else {
252                 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
253                 current_ill_address.isnew(1);
254                 set_addr_inputs('ill');
255         }
256
257 }
258
259 function set_addr_inputs (type) {
260         window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
261         window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
262         window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
263         window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
264         window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
265         window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
266         window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
267         window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
268         window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );
269 }
270