]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/permission/perm_list.js
Improve Firefox/XULRunner Support
[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.cookie');
25 dojo.require('dojo.data.ItemFileWriteStore');
26 dojo.require('dijit.form.TextBox');
27 dojo.require('dijit.form.ValidationTextBox');
28 dojo.require('dijit.form.Textarea');
29 dojo.require('dijit.layout.ContentPane');
30 dojo.require('dijit.layout.LayoutContainer');
31 dojo.require('dijit.layout.BorderContainer');
32 dojo.require('dojox.widget.Toaster');
33 dojo.require('dojox.fx');
34 dojo.require('dojox.grid.Grid');
35 dojo.require('openils.XUL');
36 dojo.requireLocalization("openils.conify", "conify");
37
38 // some handy globals
39 var cgi = new CGI();
40 var ses = dojo.cookie('ses') || cgi.param('ses');
41 if(!ses && openils.XUL.isXUL()) {
42     var stash = openils.XUL.getStash();
43     ses = stash.session.key;
44 }
45 var pCRUD = new openils.PermaCrud({authtoken : ses});
46
47 var ppl_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
48
49 var current_perm;
50 var virgin_out_id = -1;
51
52 var highlighter = {};
53
54 function status_update (markup) {
55         if (parent !== window && parent.status_update) parent.status_update( markup );
56 }
57
58 function save_perm () {
59
60         var modified_ppl = new ppl().fromStoreItem( current_perm );
61         modified_ppl.ischanged( 1 );
62         modified_ppl.description( dojo.string.trim( modified_ppl.description() ) );
63         modified_ppl.code( dojo.string.trim( modified_ppl.code() ) );
64
65         pCRUD.update(modified_ppl, {
66                 onerror : function (r) {
67                         highlighter.red.play();
68                         status_update( dojo.string.substitute(ppl_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
69                 },
70                 oncomplete : function (r) {
71                         perm_store.setValue( current_perm, 'ischanged', 0 );
72                         highlighter.green.play();
73                         status_update( dojo.string.substitute(ppl_strings.SUCCESS_SAVE, [perm_store.getValue(current_perm, 'code')]) );
74                 }
75         });
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( ppl_strings.CONFIRM_EXIT_PPL );
91         }
92
93         if (confirmation) {
94                 for (var i in window.dirtyStore) {
95                         window.current_perm = window.dirtyStore[i];
96                         save_perm(true);
97                 }
98
99                 window.dirtyStore = [];
100         }
101 }
102
103 dojo.addOnUnload( save_them_all );
104