]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/conify/global/permission/perm_list.js
MORE: convert from permacrud to pcrud -- not as big as it looks -- and move some...
[working/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.AutoIDL');
19 dojo.require('fieldmapper.dojoData');
20 dojo.require('openils.widget.TranslatorPopup');
21 dojo.require('openils.PermaCrud');
22 dojo.require('dojo.parser');
23 dojo.require('dojo.string');
24 dojo.require('dojo.data.ItemFileWriteStore');
25 dojo.require('dijit.form.TextBox');
26 dojo.require('dijit.form.ValidationTextBox');
27 dojo.require('dijit.form.Textarea');
28 dojo.require('dijit.layout.ContentPane');
29 dojo.require('dijit.layout.LayoutContainer');
30 dojo.require('dijit.layout.BorderContainer');
31 dojo.require('dojox.widget.Toaster');
32 dojo.require('dojox.fx');
33 dojo.require('dojox.grid.Grid');
34 dojo.requireLocalization("openils.conify", "conify");
35
36 // some handy globals
37 var cgi = new CGI();
38 var cookieManager = new HTTP.Cookies();
39 var ses = cookieManager.read('ses') || cgi.param('ses');
40 var pCRUD = new openils.PermaCrud({authtoken : ses});
41
42 var ppl_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
43
44 var current_perm;
45 var virgin_out_id = -1;
46
47 var highlighter = {};
48
49 function status_update (markup) {
50         if (parent !== window && parent.status_update) parent.status_update( markup );
51 }
52
53 function save_perm () {
54
55         var modified_ppl = new ppl().fromStoreItem( current_perm );
56         modified_ppl.ischanged( 1 );
57         modified_ppl.description( dojo.string.trim( modified_ppl.description() ) );
58         modified_ppl.code( dojo.string.trim( modified_ppl.code() ) );
59
60         pCRUD.update(modified_ppl, {
61                 onerror : function (r) {
62                         highlighter.red.play();
63                         status_update( dojo.string.substitute(ppl_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
64                 },
65                 oncomplete : function (r) {
66                         perm_store.setValue( current_perm, 'ischanged', 0 );
67                         highlighter.green.play();
68                         status_update( dojo.string.substitute(ppl_strings.SUCCESS_SAVE, [perm_store.getValue(current_perm, 'code')]) );
69                 }
70         });
71 }
72
73 function save_them_all (event) {
74
75         perm_store.fetch({
76                 query : { ischanged : 1 },
77                 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
78                 scope : perm_store
79         });
80
81         var confirmation = true;
82
83
84         if (event && dirtyStore.length > 0) {
85                 confirmation = confirm( ppl_strings.CONFIRM_EXIT_PPL );
86         }
87
88         if (confirmation) {
89                 for (var i in window.dirtyStore) {
90                         window.current_perm = window.dirtyStore[i];
91                         save_perm(true);
92                 }
93
94                 window.dirtyStore = [];
95         }
96 }
97
98 dojo.addOnUnload( save_them_all );
99