]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/conify/global/permission/grp_tree.js
1ee39d365695ef39cf3207719943682b119649a0
[working/Evergreen.git] / Open-ILS / web / conify / global / permission / grp_tree.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.PermaCrud');
21 dojo.require('openils.widget.TranslatorPopup');
22 dojo.require('dojo.parser');
23 dojo.require('dojo.data.ItemFileWriteStore');
24 dojo.require('dojo.date.stamp');
25 dojo.require('dojo.cookie');
26 dojo.require('dijit.form.NumberSpinner');
27 dojo.require('dijit.form.TextBox');
28 dojo.require('dijit.form.TimeTextBox');
29 dojo.require('dijit.form.ValidationTextBox');
30 dojo.require('dijit.form.CheckBox');
31 dojo.require('dijit.form.FilteringSelect');
32 dojo.require('dijit.form.Textarea');
33 dojo.require('dijit.form.Button');
34 dojo.require('dijit.Dialog');
35 dojo.require('dijit.Tree');
36 dojo.require('dijit.layout.ContentPane');
37 dojo.require('dijit.layout.TabContainer');
38 dojo.require('dijit.layout.LayoutContainer');
39 dojo.require('dijit.layout.SplitContainer');
40 dojo.require('dojox.widget.Toaster');
41 dojo.require('dojox.fx');
42 dojo.require('dojox.grid.Grid');
43 dojo.requireLocalization("openils.conify", "conify");
44
45 // some handy globals
46 var cgi = new CGI();
47 var ses = dojo.cookie('ses') || cgi.param('ses');
48 var server = {};
49 server.pcrud = new openils.PermaCrud({ authtoken : ses });
50 server.actor = new OpenSRF.ClientSession('open-ils.actor');
51
52 var pgt_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
53
54 var virgin_out_id = -1;
55
56 var highlighter = {};
57
58 function status_update (markup) {
59         if (parent !== window && parent.status_update) parent.status_update( markup );
60 }
61
62 function save_group () {
63
64         var modified_pgt = new pgt().fromStoreItem( current_group );
65         modified_pgt.ischanged( 1 );
66
67         new_kid_button.disabled = false;
68         save_group_button.disabled = false;
69         delete_group_button.disabled = false;
70
71         server.pcrud.update(modified_pgt, {
72                 onerror : function (r) {
73                         highlighter.editor_pane.red.play();
74                         status_update( dojo.string.substitute( pgt_strings.ERROR_SAVING_DATA, [group_store.getValue( current_group, 'name' )]) );
75                 },
76                 oncomplete : function (r) {
77                         group_store.setValue( current_group, 'ischanged', 0 );
78                         highlighter.editor_pane.green.play();
79                         status_update( dojo.string.substitute(pgt_strings.SUCCESS_SAVE, [group_store.getValue( current_group, 'name' )]) );
80                 },
81         });
82 }
83
84 function save_perm_map (storeItem) {
85
86         var modified_pgpm = new pgpm().fromStoreItem( storeItem );
87         modified_pgpm.ischanged( 1 );
88
89         server.pcrud.update(modified_pgpm, {
90                 onerror : function (r) {
91                         highlighter.editor_pane.red.play();
92                         status_update( dojo.string.substitute(pgt_strings.ERROR_SAVING_PERM_DATA, [group_store.getValue( current_group, 'name' )]) );
93                 },
94                 oncomplete : function (r) {
95                         perm_map_store.setValue( storeItem, 'ischanged', 0 );
96                         highlighter.editor_pane.green.play();
97                         status_update( dojo.string.substitute(pgt_strings.SUCCESS_SAVE_PERM, [group_store.getValue( current_group, 'name' )]) );
98                 },
99         });
100 }
101
102 function save_them_all (event) {
103
104         var dirtyMaps = [];
105
106     perm_map_store.fetch({
107         query : { ischanged : 1 },
108         onItem : function (item, req) { try { if (this.isItem( item )) dirtyMaps.push( item ); } catch (e) { /* meh */ } },
109         scope : perm_map_store
110     });
111
112     var confirmation = true;
113
114
115     if (event && dirtyMaps.length > 0) {
116         confirmation = confirm( pgt_strings.CONFIRM_EXIT);
117     }
118
119     if (confirmation) {
120         for (var i in dirtyMaps) {
121             save_perm_map(dirtyMaps[i]);
122         }
123     }
124 }
125
126 dojo.addOnUnload( save_them_all );
127