]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/conify/global/actor/org_unit.js
Save times in HH:MM format for hours of operation
[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.AutoIDL');
19 dojo.require('fieldmapper.dojoData');
20 dojo.require('openils.widget.TranslatorPopup');
21 dojo.require('openils.PermaCrud');
22 dojo.require('dojo.parser');
23 dojo.require('dojo.cookie');
24 dojo.require('dojo.data.ItemFileWriteStore');
25 dojo.require('dojo.date.stamp');
26 dojo.require('dijit.form.TextBox');
27 dojo.require('dijit.form.TimeTextBox');
28 dojo.require('dijit.form.ValidationTextBox');
29 dojo.require('dijit.form.CheckBox');
30 dojo.require('dijit.form.FilteringSelect');
31 dojo.require('dijit.Tree');
32 dojo.require('dijit.layout.ContentPane');
33 dojo.require('dijit.layout.TabContainer');
34 dojo.require('dijit.layout.LayoutContainer');
35 dojo.require('dijit.layout.SplitContainer');
36 dojo.require('dojox.widget.Toaster');
37 dojo.require('dojox.string.sprintf');
38 dojo.require('dojox.fx');
39 dojo.require('openils.XUL');
40 dojo.requireLocalization("openils.conify", "conify");
41
42 // some handy globals
43 var cgi = new CGI();
44 var ses = dojo.cookie('ses') || cgi.param('ses');
45 if(!ses && openils.XUL.isXUL()) {
46     var stash = openils.XUL.getStash();
47     ses = stash.session.key;
48 }
49 var pcrud = new openils.PermaCrud({ authtoken : ses });
50
51 var current_ou, current_ou_hoo, ou_list_store;
52 var dirtyStore = [];
53 var virgin_ou_id = -1;
54
55 var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
56
57 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
58
59 var highlighter = {};
60
61 function status_update (markup) {
62     if (parent !== window && parent.status_update) parent.status_update( markup );
63 }
64
65 function set_hoo_thisvalue(dow_open, timeval) {
66     current_ou_hoo[dow_open](dojox.string.sprintf('%02d:%02d', timeval.getHours(), timeval.getMinutes()));
67 }
68
69 function save_org () {
70
71     new_kid_button.disabled = false;
72     save_ou_button.disabled = false;
73     delete_ou_button.disabled = false;
74
75     var modified_ou = new aou().fromStoreItem( current_ou );
76     modified_ou.ischanged ( 1 );
77
78     pcrud.apply( modified_ou, {
79         timeout : 10, // makes it synchronous
80         onerror : function (r) {
81             highlighter.editor_pane.red.play();
82             status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
83         },
84         oncomplete : function (r, list) {
85             if ( list[0] ) {
86                 ou_list_store.setValue( current_ou, 'ischanged', 0 );
87                 highlighter.editor_pane.green.play();
88                 status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVE, [ou_list_store.getValue( current_ou, 'name' )] ) );
89             } else {
90                 highlighter.editor_pane.red.play();
91                 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
92             }
93         },
94     });
95
96 }
97     
98 function hoo_load () {
99     save_hoo_button.disabled = false;
100
101     var hours_list = pcrud.search( 'aouhoo',{id:ou_list_store.getValue( current_ou, 'id' )});
102
103     if (hours_list.length) {
104         current_ou_hoo = hours_list[0];
105         current_ou_hoo.ischanged(1); // XXX why?
106     } else {
107         current_ou_hoo = new aouhoo().fromHash({
108             isnew   : 1,
109             id      : ou_list_store.getValue( current_ou, 'id' )
110         });
111         for (var i = 0; i < 7; i++) {
112             current_ou_hoo['dow_' + i + '_open']('09:00:00');
113             current_ou_hoo['dow_' + i + '_close']('17:00:00');
114         }
115     }
116
117     for (var i = 0; i < 7; i++) {
118         window['dow_' + i + '_open'].setValue(
119             dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
120         );
121         window['dow_' + i + '_close'].setValue(
122             dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
123         );
124     }
125
126     highlighter.hoo_pane.green.play();
127 }
128
129
130 function addr_load () {
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     atype_list = ['billing','mailing','holds','ill'];
138     for (var addr_idx in atype_list) {
139
140         var atype = atype_list[addr_idx];
141         var cur_var_name =  'current_' + atype + '_address';
142
143         var this_addr = pcrud.search( 'aoa',{id:ou_list_store.getValue( current_ou, atype + '_address')});
144
145         if (this_addr.length) {
146             window[cur_var_name] = this_addr[0];
147             window[cur_var_name].ischanged( 1 ); // XXX why?
148         } else {
149             window[cur_var_name] = new aoa().fromHash({
150                 isnew       :   1,
151                 org_unit    :   ou_list_store.getValue( current_ou, 'id' )
152             });
153         }
154         set_addr_inputs(atype);
155     }
156
157     highlighter.addresses_pane.green.play();
158
159 }
160
161 function set_addr_inputs (type) {
162     window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
163     window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
164     window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
165     window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
166     window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
167     window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
168     window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
169     window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
170     window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );
171     window[type + '_addr_san'].setValue( window['current_' + type + '_address'].san() || '' );
172 }
173