]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/conify/global/actor/org_unit.js
move the translation widget out to openils.widget
[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
36 // some handy globals
37 var cgi = new CGI();
38 var cookieManager = new HTTP.Cookies();
39 var ses = cookieManager.read('ses') || cgi.param('ses');
40 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
41
42 var current_ou, current_ou_hoo;
43 var virgin_ou_id = -1;
44
45 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
46
47 var highlighter = {};
48
49 function status_update (markup) {
50         if (parent !== window && parent.status_update) parent.status_update( markup );
51 }
52
53 function save_org () {
54         var modified_ou = new aou().fromStoreItem( current_ou );
55         modified_ou.ischanged( 1 );
56
57         new_kid_button.disabled = false;
58         save_ou_button.disabled = false;
59         delete_ou_button.disabled = false;
60
61         pCRUD.request({
62                 method : 'open-ils.permacrud.update.aou',
63                 timeout : 10,
64                 params : [ ses, modified_ou ],
65                 onerror : function (r) {
66                         highlighter.editor_pane.red.play();
67                         status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
68                 },
69                 oncomplete : function (r) {
70                         var res = r.recv();
71                         if ( res && res.content() ) {
72                                 ou_list_store.setValue( current_ou, 'ischanged', 0 );
73                                 highlighter.editor_pane.green.play();
74                                 status_update( 'Saved changes to ' + ou_list_store.getValue( current_ou, 'name' ) );
75                         } else {
76                                 highlighter.editor_pane.red.play();
77                                 status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
78                         }
79                 },
80         }).send();
81 }
82         
83 function hoo_load () {
84         // empty result not coming through ...
85         current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
86         current_ou_hoo.isnew(1);
87
88         pCRUD.request({
89                 method : 'open-ils.permacrud.retrieve.aouhoo',
90                 params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
91                 onerror : function (r) { throw 'Problem fetching hours of operation for ' + ou_list_store.getValue( current_ou, 'name' );},
92                 oncomplete : function (r) {
93                         current_ou_hoo = null;
94
95                         var res = r.recv();
96                         if (res) {
97                                 if (res.content()) current_ou_hoo = res.content();
98                         }
99
100                         if (!current_ou_hoo) {
101                                 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
102                                 current_ou_hoo.isnew(1);
103                                 for (var i = 0; i < 7; i++) {
104                                         current_ou_hoo['dow_' + i + '_open']('09:00:00');
105                                         current_ou_hoo['dow_' + i + '_close']('17:00:00');
106                                 }
107                         }
108
109                         for (var i = 0; i < 7; i++) {
110                                 window['dow_' + i + '_open'].setValue(
111                                         dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
112                                 );
113                                 window['dow_' + i + '_close'].setValue(
114                                         dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
115                                 );
116                         }
117
118                         highlighter.hoo_pane.green.play();
119                 }
120         }).send();
121
122 }
123
124 function addr_load () {
125         // empty result not coming through ...
126
127         save_ill_address.disabled = false;
128         save_holds_address.disabled = false;
129         save_mailing_address.disabled = false;
130         save_billing_address.disabled = false;
131
132         if (ou_list_store.getValue( current_ou, 'billing_address' )) {
133                 pCRUD.request({
134                         method : 'open-ils.permacrud.retrieve.aoa',
135                         params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
136                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
137                         oncomplete : function (r) {
138                                 current_billing_address = null;
139
140                                 var res = r.recv();
141                                 if (res) {
142                                         if (res.content()) current_billing_address = res.content();
143                                 }
144
145                                 if (!current_billing_address) {
146                                         current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
147                                         current_billing_address.isnew(1);
148                                 }
149
150                                 set_addr_inputs('billing');
151                                 highlighter.addresses_pane.green.play();
152                         }
153                 }).send();
154         } else {
155                 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
156                 current_billing_address.isnew(1);
157                 set_addr_inputs('billing');
158         }
159
160         if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
161                 pCRUD.request({
162                         method : 'open-ils.permacrud.retrieve.aoa',
163                         params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
164                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
165                         oncomplete : function (r) {
166                                 current_mailing_address = null;
167
168                                 var res = r.recv();
169                                 if (res) {
170                                         if (res.content()) current_mailing_address = res.content();
171                                 }
172
173                                 if (!current_mailing_address) {
174                                         current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
175                                         current_mailing_address.isnew(1);
176                                 }
177
178                                 set_addr_inputs('mailing');
179                                 highlighter.addresses_pane.green.play();
180                         }
181                 }).send();
182         } else {
183                 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
184                 current_mailing_address.isnew(1);
185                 set_addr_inputs('mailing');
186         }
187
188         if (ou_list_store.getValue( current_ou, 'holds_address' )) {
189                 pCRUD.request({
190                         method : 'open-ils.permacrud.retrieve.aoa',
191                         params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
192                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
193                         oncomplete : function (r) {
194                                 current_holds_address = null;
195
196                                 var res = r.recv();
197                                 if (res) {
198                                         if (res.content()) current_holds_address = res.content();
199                                 }
200
201                                 if (!current_holds_address) {
202                                         current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
203                                         current_holds_address.isnew(1);
204                                 }
205
206                                 set_addr_inputs('holds');
207                                 highlighter.addresses_pane.green.play();
208                         }
209                 }).send();
210         } else {
211                 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
212                 current_holds_address.isnew(1);
213                 set_addr_inputs('holds');
214         }
215
216         if (ou_list_store.getValue( current_ou, 'ill_address' )) {
217                 pCRUD.request({
218                         method : 'open-ils.permacrud.retrieve.aoa',
219                         params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
220                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
221                         oncomplete : function (r) {
222                                 current_ill_address = null;
223
224                                 var res = r.recv();
225                                 if (res) {
226                                         if (res.content()) current_ill_address = res.content();
227                                 }
228
229                                 if (!current_ill_address) {
230                                         current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
231                                         current_ill_address.isnew(1);
232                                 }
233
234                                 set_addr_inputs('ill');
235                                 highlighter.addresses_pane.green.play();
236                         }
237                 }).send();
238         } else {
239                 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
240                 current_ill_address.isnew(1);
241                 set_addr_inputs('ill');
242         }
243
244 }
245
246 function set_addr_inputs (type) {
247         window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
248         window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
249         window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
250         window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
251         window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
252         window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
253         window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
254         window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
255         window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );
256 }
257