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