]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/permission/grp_tree.js
Improve Firefox/XULRunner Support
[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.require('openils.XUL');
44 dojo.requireLocalization("openils.conify", "conify");
45
46 // some handy globals
47 var cgi = new CGI();
48 var ses = dojo.cookie('ses') || cgi.param('ses');
49 if(!ses && openils.XUL.isXUL()) {
50     var stash = openils.XUL.getStash();
51     ses = stash.session.key;
52 }
53 var server = {};
54 server.pcrud = new openils.PermaCrud({ authtoken : ses });
55 server.actor = new OpenSRF.ClientSession('open-ils.actor');
56
57 var pgt_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
58
59 var virgin_out_id = -1;
60
61 var highlighter = {};
62
63 function status_update (markup) {
64         if (parent !== window && parent.status_update) parent.status_update( markup );
65 }
66
67 function save_group () {
68
69         var modified_pgt = new pgt().fromStoreItem( current_group );
70         modified_pgt.ischanged( 1 );
71
72         new_kid_button.disabled = false;
73         save_group_button.disabled = false;
74         delete_group_button.disabled = false;
75
76         server.pcrud.update(modified_pgt, {
77                 onerror : function (r) {
78                         highlighter.editor_pane.red.play();
79                         status_update( dojo.string.substitute( pgt_strings.ERROR_SAVING_DATA, [group_store.getValue( current_group, 'name' )]) );
80                 },
81                 oncomplete : function (r) {
82                         group_store.setValue( current_group, 'ischanged', 0 );
83                         highlighter.editor_pane.green.play();
84                         status_update( dojo.string.substitute(pgt_strings.SUCCESS_SAVE, [group_store.getValue( current_group, 'name' )]) );
85                 },
86         });
87 }
88
89 function save_perm_map (storeItem) {
90
91         var modified_pgpm = new pgpm().fromStoreItem( storeItem );
92         modified_pgpm.ischanged( 1 );
93
94         server.pcrud.update(modified_pgpm, {
95                 onerror : function (r) {
96                         highlighter.editor_pane.red.play();
97                         status_update( dojo.string.substitute(pgt_strings.ERROR_SAVING_PERM_DATA, [group_store.getValue( current_group, 'name' )]) );
98                 },
99                 oncomplete : function (r) {
100                         perm_map_store.setValue( storeItem, 'ischanged', 0 );
101                         highlighter.editor_pane.green.play();
102                         status_update( dojo.string.substitute(pgt_strings.SUCCESS_SAVE_PERM, [group_store.getValue( current_group, 'name' )]) );
103                 },
104         });
105 }
106
107 function save_them_all (event) {
108
109         var dirtyMaps = [];
110
111     perm_map_store.fetch({
112         query : { ischanged : 1 },
113         onItem : function (item, req) { try { if (this.isItem( item )) dirtyMaps.push( item ); } catch (e) { /* meh */ } },
114         scope : perm_map_store
115     });
116
117     var confirmation = true;
118
119
120     if (event && dirtyMaps.length > 0) {
121         confirmation = confirm( pgt_strings.CONFIRM_EXIT);
122     }
123
124     if (confirmation) {
125         for (var i in dirtyMaps) {
126             save_perm_map(dirtyMaps[i]);
127         }
128     }
129 }
130
131 dojo.addOnUnload( save_them_all );
132