]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/permission/perm_list.js
55ea8591eea75eebdf2bd56d1b398c5120c4d769
[Evergreen.git] / Open-ILS / web / conify / global / permission / perm_list.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.I18N');
20 dojo.require('dojo.parser');
21 dojo.require('dojo.string');
22 dojo.require('dojo.data.ItemFileWriteStore');
23 dojo.require('dijit.form.TextBox');
24 dojo.require('dijit.form.ValidationTextBox');
25 dojo.require('dijit.form.Textarea');
26 dojo.require('dijit.layout.ContentPane');
27 dojo.require('dijit.layout.LayoutContainer');
28 dojo.require('dijit.layout.BorderContainer');
29 dojo.require('dojox.widget.Toaster');
30 dojo.require('dojox.fx');
31 dojo.require('dojox.grid.Grid');
32 dojo.require('dojox.grid._data.model');
33 dojo.require("dojox.grid.editors");
34
35 // some handy globals
36 var cgi = new CGI();
37 var cookieManager = new HTTP.Cookies();
38 var ses = cookieManager.read('ses') || cgi.param('ses');
39 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
40
41 var current_perm;
42 var virgin_out_id = -1;
43
44 var highlighter = {};
45
46 function status_update (markup) {
47         if (parent !== window && parent.status_update) parent.status_update( markup );
48 }
49
50 function save_perm () {
51
52         var modified_ppl = new ppl().fromStoreItem( current_perm );
53         modified_ppl.ischanged( 1 );
54         modified_ppl.description( dojo.string.trim( modified_ppl.description() ) );
55         modified_ppl.code( dojo.string.trim( modified_ppl.code() ) );
56
57         pCRUD.request({
58                 method : 'open-ils.permacrud.update.ppl',
59                 timeout : 10,
60                 params : [ ses, modified_ppl ],
61                 onerror : function (r) {
62                         highlighter.red.play();
63                         status_update( 'Problem saving data for ' + perm_store.getValue( current_perm, 'code' ) );
64                 },
65                 oncomplete : function (r) {
66                         var res = r.recv();
67                         if ( res && res.content() ) {
68                                 perm_store.setValue( current_perm, 'ischanged', 0 );
69                                 highlighter.green.play();
70                                 status_update( 'Saved changes to ' + perm_store.getValue( current_perm, 'code' ) );
71                         } else {
72                                 highlighter.red.play();
73                                 status_update( 'Problem saving data for ' + perm_store.getValue( current_perm, 'code' ) );
74                         }
75                 },
76         }).send();
77 }
78
79 function save_them_all (event) {
80
81         perm_store.fetch({
82                 query : { ischanged : 1 },
83                 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
84                 scope : perm_store
85         });
86
87         var confirmation = true;
88
89
90         if (event && dirtyStore.length > 0) {
91                 confirmation = confirm(
92                         'There are unsaved modified Permissions!  '+
93                         'OK to save these changes, Cancel to abandon them.'
94                 );
95         }
96
97         if (confirmation) {
98                 for (var i in window.dirtyStore) {
99                         window.current_perm = window.dirtyStore[i];
100                         save_perm(true);
101                 }
102
103                 window.dirtyStore = [];
104         }
105 }
106
107 dojo.addOnUnload( save_them_all );
108