]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/permission/perm_list.js
Initial i18n for Conify perm_list interface
[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.widget.TranslatorPopup');
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.requireLocalization("openils.config", "pgt");
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 pgt_strings = dojo.i18n.getLocalization('openils.conify', 'pgt');
41
42 var current_perm;
43 var virgin_out_id = -1;
44
45 var highlighter = {};
46
47 function status_update (markup) {
48         if (parent !== window && parent.status_update) parent.status_update( markup );
49 }
50
51 function save_perm () {
52
53         var modified_ppl = new ppl().fromStoreItem( current_perm );
54         modified_ppl.ischanged( 1 );
55         modified_ppl.description( dojo.string.trim( modified_ppl.description() ) );
56         modified_ppl.code( dojo.string.trim( modified_ppl.code() ) );
57
58         pCRUD.request({
59                 method : 'open-ils.permacrud.update.ppl',
60                 timeout : 10,
61                 params : [ ses, modified_ppl ],
62                 onerror : function (r) {
63                         highlighter.red.play();
64                         status_update( dojo.string.substitute(pgt_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
65                 },
66                 oncomplete : function (r) {
67                         var res = r.recv();
68                         if ( res && res.content() ) {
69                                 perm_store.setValue( current_perm, 'ischanged', 0 );
70                                 highlighter.green.play();
71                                 status_update( dojo.string.substitute(pgt_strings.SUCCESS_SAVE, [perm_store.getValue(current_perm, 'code')]) );
72                         } else {
73                                 highlighter.red.play();
74                                 status_update( dojo.string.substitute(pgt_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
75                         }
76                 },
77         }).send();
78 }
79
80 function save_them_all (event) {
81
82         perm_store.fetch({
83                 query : { ischanged : 1 },
84                 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
85                 scope : perm_store
86         });
87
88         var confirmation = true;
89
90
91         if (event && dirtyStore.length > 0) {
92                 confirmation = confirm( pgt_strings.CONFIRM_EXIT );
93         }
94
95         if (confirmation) {
96                 for (var i in window.dirtyStore) {
97                         window.current_perm = window.dirtyStore[i];
98                         save_perm(true);
99                 }
100
101                 window.dirtyStore = [];
102         }
103 }
104
105 dojo.addOnUnload( save_them_all );
106