]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/permission/grp_tree.js
use fieldmapper.AutoIDL inside conify to allow openils.PermaCrud to function properly
[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.widget.TranslatorPopup');
21 dojo.require('dojo.parser');
22 dojo.require('dojo.data.ItemFileWriteStore');
23 dojo.require('dojo.date.stamp');
24 dojo.require('dijit.form.NumberSpinner');
25 dojo.require('dijit.form.TextBox');
26 dojo.require('dijit.form.TimeTextBox');
27 dojo.require('dijit.form.ValidationTextBox');
28 dojo.require('dijit.form.CheckBox');
29 dojo.require('dijit.form.FilteringSelect');
30 dojo.require('dijit.form.Textarea');
31 dojo.require('dijit.form.Button');
32 dojo.require('dijit.Dialog');
33 dojo.require('dijit.Tree');
34 dojo.require('dijit.layout.ContentPane');
35 dojo.require('dijit.layout.TabContainer');
36 dojo.require('dijit.layout.LayoutContainer');
37 dojo.require('dijit.layout.SplitContainer');
38 dojo.require('dojox.widget.Toaster');
39 dojo.require('dojox.fx');
40 dojo.require('dojox.grid.Grid');
41 dojo.requireLocalization("openils.conify", "conify");
42
43 // some handy globals
44 var cgi = new CGI();
45 var cookieManager = new HTTP.Cookies();
46 var ses = cookieManager.read('ses') || cgi.param('ses');
47 var server = {};
48 server.pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
49 server.actor = new OpenSRF.ClientSession('open-ils.actor');
50
51 var pgt_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
52
53 var current_group;
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.request({
72                 method : 'open-ils.permacrud.update.pgt',
73                 timeout : 10,
74                 params : [ ses, modified_pgt ],
75                 onerror : function (r) {
76                         highlighter.editor_pane.red.play();
77                         status_update( dojo.string.substitute( pgt_strings.ERROR_SAVING_DATA, [group_store.getValue( current_group, 'name' )]) );
78                 },
79                 oncomplete : function (r) {
80                         var res = r.recv();
81                         if ( res && res.content() ) {
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                         } else {
86                                 highlighter.editor_pane.red.play();
87                                 status_update( dojo.string.substitute(pgt_strings.ERROR_SAVING_DATA, [group_store.getValue( current_group, 'name' )]) );
88                         }
89                 },
90         }).send();
91 }
92
93 function save_perm_map (storeItem) {
94
95         var modified_pgpm = new pgpm().fromStoreItem( storeItem );
96         modified_pgpm.ischanged( 1 );
97
98         server.pCRUD.request({
99                 method : 'open-ils.permacrud.update.pgpm',
100                 timeout : 10,
101                 params : [ ses, modified_pgpm ],
102                 onerror : function (r) {
103                         highlighter.editor_pane.red.play();
104                         status_update( dojo.string.substitute(pgt_strings.ERROR_SAVING_PERM_DATA, [group_store.getValue( current_group, 'name' )]) );
105                 },
106                 oncomplete : function (r) {
107                         var res = r.recv();
108                         if ( res && res.content() ) {
109                                 perm_map_store.setValue( storeItem, 'ischanged', 0 );
110                                 highlighter.editor_pane.green.play();
111                                 status_update( dojo.string.substitute(pgt_strings.SUCCESS_SAVE_PERM, [group_store.getValue( current_group, 'name' )]) );
112                         } else {
113                                 highlighter.editor_pane.red.play();
114                                 status_update( dojo.string.substitute(pgt_strings.ERROR_SAVING_PERM_DATA, [group_store.getValue( current_group, 'name' )]) );
115                         }
116                 },
117         }).send();
118 }
119
120 function save_them_all (event) {
121
122         var dirtyMaps = [];
123
124     perm_map_store.fetch({
125         query : { ischanged : 1 },
126         onItem : function (item, req) { try { if (this.isItem( item )) dirtyMaps.push( item ); } catch (e) { /* meh */ } },
127         scope : perm_map_store
128     });
129
130     var confirmation = true;
131
132
133     if (event && dirtyMaps.length > 0) {
134         confirmation = confirm( pgt_strings.CONFIRM_EXIT);
135     }
136
137     if (confirmation) {
138         for (var i in dirtyMaps) {
139             save_perm_map(dirtyMaps[i]);
140         }
141     }
142 }
143
144 dojo.addOnUnload( save_them_all );
145