]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/permission/perm_list.js
use fieldmapper.AutoIDL inside conify to allow openils.PermaCrud to function properly
[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('dojo.parser');
22 dojo.require('dojo.string');
23 dojo.require('dojo.data.ItemFileWriteStore');
24 dojo.require('dijit.form.TextBox');
25 dojo.require('dijit.form.ValidationTextBox');
26 dojo.require('dijit.form.Textarea');
27 dojo.require('dijit.layout.ContentPane');
28 dojo.require('dijit.layout.LayoutContainer');
29 dojo.require('dijit.layout.BorderContainer');
30 dojo.require('dojox.widget.Toaster');
31 dojo.require('dojox.fx');
32 dojo.require('dojox.grid.Grid');
33 dojo.requireLocalization("openils.conify", "conify");
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 ppl_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
42
43 var current_perm;
44 var virgin_out_id = -1;
45
46 var highlighter = {};
47
48 function status_update (markup) {
49         if (parent !== window && parent.status_update) parent.status_update( markup );
50 }
51
52 function save_perm () {
53
54         var modified_ppl = new ppl().fromStoreItem( current_perm );
55         modified_ppl.ischanged( 1 );
56         modified_ppl.description( dojo.string.trim( modified_ppl.description() ) );
57         modified_ppl.code( dojo.string.trim( modified_ppl.code() ) );
58
59         pCRUD.request({
60                 method : 'open-ils.permacrud.update.ppl',
61                 timeout : 10,
62                 params : [ ses, modified_ppl ],
63                 onerror : function (r) {
64                         highlighter.red.play();
65                         status_update( dojo.string.substitute(ppl_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
66                 },
67                 oncomplete : function (r) {
68                         var res = r.recv();
69                         if ( res && res.content() ) {
70                                 perm_store.setValue( current_perm, 'ischanged', 0 );
71                                 highlighter.green.play();
72                                 status_update( dojo.string.substitute(ppl_strings.SUCCESS_SAVE, [perm_store.getValue(current_perm, 'code')]) );
73                         } else {
74                                 highlighter.red.play();
75                                 status_update( dojo.string.substitute(ppl_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
76                         }
77                 },
78         }).send();
79 }
80
81 function save_them_all (event) {
82
83         perm_store.fetch({
84                 query : { ischanged : 1 },
85                 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
86                 scope : perm_store
87         });
88
89         var confirmation = true;
90
91
92         if (event && dirtyStore.length > 0) {
93                 confirmation = confirm( ppl_strings.CONFIRM_EXIT_PPL );
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