adding translation for description
[Evergreen.git] / Open-ILS / web / conify / global / permission / perm_list.html
1 <!--
2 # Copyright (C) 2008  Georgia Public Library Service / Equinox Software, Inc
3 # Mike Rylander <miker@esilibrary.com>
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 -->
15 <html xmlns="http://www.w3.org/1999/xhtml">
16         <head>
17                 <title>Confiy :: Global :: Permission :: Permission List</title>
18
19                 <style type="text/css">
20                         @import url("/js/dojo/dojox/grid/_grid/tundraGrid.css");
21                         @import url("/js/dojo/dojo/resources/dojo.css");
22                         @import url("/js/dojo/dijit/themes/tundra/tundra.css");
23                         @import url("/js/dojo/dojox/widget/Toaster/Toaster.css");
24                 </style>
25
26                 <style>
27                         html, body {
28                                 height: 100%;
29                                 width: 100%;
30                                 margin: 0px 0px 0px 0px;
31                                 padding: 0px 0px 0px 0px;
32                                 overflow: hidden;
33                         }
34
35                         #perm_grid {
36                                 border: 0px;
37                                 width: 100%;
38                                 height: 100%;
39                         }
40
41                         #grid_container {
42                                 width: 100%;
43                                 height: 100%;
44                         }
45                 </style>
46
47                 <!-- The OpenSRF API writ JS -->
48                 <script language='javascript' src='/opac/common/js/utils.js' type='text/javascript'></script>
49                 <script language='javascript' src='/opac/common/js/Cookies.js' type='text/javascript'></script>
50                 <script language='javascript' src='/opac/common/js/CGI.js' type='text/javascript'></script>
51                 <script language='javascript' src='/opac/common/js/JSON_v1.js' type='text/javascript'></script>
52
53                 <!-- Dojo goodness -->
54                 <script type="text/javascript" src="/js/dojo/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
55                 <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
56
57                 <script type="text/javascript" src="perm_list.js"></script>
58
59         </head>
60
61         <body class="tundra" id='pagebody'>
62
63                 <div dojoType="dijit.layout.LayoutContainer" id="grid_container" jsId="grid_container" orientation="vertical">
64                         <script type="dojo/method">
65                                 window.highlighter= {};
66                                 window.highlighter.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } );
67                                 window.highlighter.red = dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } );
68
69                                 window.dirtyStore = [];
70
71                 pCRUD.request({
72                     method : 'open-ils.permacrud.search.ppl.atomic',
73                     timeout : 10,
74                     params : [ ses, { id : { "!=" : null } }, { order_by : { ppl : 'code' } } ],
75                     onerror : function (r) { status_update('Problem fetching perms') },
76                     oncomplete : function (r) {
77
78                         window._perm_list = r.recv().content();
79                         window._perm_data = ppl.toStoreData( window._perm_list, 'code' );
80                         window.perm_store = new dojo.data.ItemFileWriteStore({ data : window._perm_data });
81
82                             perm_store.onSet = function (item, attr, o, n) {
83                             if (attr == 'ischanged') return;
84                             if (n == o) return;
85                             this.setValue( item, 'ischanged', 1);
86                         };
87
88                                                 window.perm_grid_layout = [
89                                                         {       cells : [
90                                                                         [
91                                                                                 { name : "Code",        field : "code",        width : "300px", editor : dojox.grid.editors.Dijit, rowSpan : "2" },
92                                                                                 { name : "Description", field : "description", width : "auto",  editor : dojox.grid.editors.Editor, style : "minHeight:1em;" }
93                                                                         ],
94                                                                         [
95                                                                                 { name : "Translation",
96                                                                                   width : "10em",
97                                                                                   height : "2em",
98                                                                                   get : function (row) {
99                                                                                         if (!window.perm_rows) window.perm_rows = [];
100                                                                                         var r = window.perm_data_model.getRow(row);
101                                                                                         if (r) {
102                                                                                                 window.perm_rows[row] = new ccs().fromHash(window.perm_data_model.getRow(row));
103                                                                                                 setTimeout(
104                                                                                                         'dojo.query(".perm_grid_trans_desc_' + row + '").'+
105                                                                                                                 'instantiate(openils.I18N.translationWidget,{field:"description",'+
106                                                                                                                 'targetObject:"window.perm_rows['+row+']",unique:"' + row + '"});'+
107                                                                                                                 'perm_grid.rowHeightChanged('+row+')',
108                                                                                                         0
109                                                                                                 );
110                                                                                                 var oldnode = dojo.byId('description_translation_' + row);
111                                                                                                 if (oldnode) dijit.byNode(oldnode).destroyRecursive();
112                                                                                                 return '<span class="perm_grid_trans_desc_'+row+'"></span>';
113                                                                                         }
114                                                                                         return '';
115                                                                                   }
116                                                                                 }
117                                                                         ]
118                                                                 ]
119                                                         }
120                                                 ];
121
122                         dojo.addOnUnload( function (event) {
123
124                             perm_store.fetch({
125                                 query : { ischanged : 1 },
126                                 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
127                                 scope : perm_store
128                             });
129
130                             if (dirtyStore.length > 0) {
131                                 var confirmation = confirm(
132                                     'There are unsaved modified Permissions!  '+
133                                     'OK to save these changes, Cancel to abandon them.'
134                                 );
135
136                                 if (confirmation) {
137                                     for (var i in window.dirtyStore) {
138                                         window.current_perm = window.dirtyStore[i];
139                                         save_perm(true);
140                                     }
141                                 }
142                             }
143
144                         });
145                     }
146                 }).send();
147
148                         </script>
149
150                         <div dojoType="dijit.layout.LayoutContainer" orientation="horizontal" style="margin-top: 5px;" layoutAlign="top">
151                                 <span>New Permission:</span>
152                                 <div dojoType="dijit.form.TextBox" id="new_perm_code" jsId="new_perm_code" label="New Code"></div>
153                                 <button dojoType="dijit.form.Button" id="save_new_perm_code" jsId="save_new_perm_code" label="Add"> 
154                                         <script type="dojo/connect" event="onClick">
155
156                                                 var new_code = new_perm_code.getValue();
157                                                 if (!new_code) return;
158
159                         var new_fm_obj = new ppl().fromHash({
160                                 isnew           : 1,
161                             code            : new_code
162                             });
163     
164                         var err = false;
165                             pCRUD.request({
166                             method : 'open-ils.permacrud.create.ppl',
167                                 timeout : 10,
168                             params : [ ses, new_fm_obj ],
169                                 onerror : function (r) {
170                                 highlighter.red.play();
171                                     status_update( 'Problem calling method to create new Permission' );
172                                 err = true;
173                                 },
174                                 oncomplete : function (r) {
175                                 var res = r.recv();
176                                     if ( res && res.content() ) {
177                                     var new_item_hash = res.content().toHash();
178                                     perm_store.newItem( new_item_hash );
179                                                                         status_update( 'New ' + new_item_hash.code + ' permission created' );
180                                                                         perm_grid.model.sort(-1);
181                                                                         highlighter.green.play();
182                                 } else {
183                                         highlighter.red.play();
184                                     status_update( 'Problem creating new Permission' );
185                                         err = true;
186                                 }
187                                 }
188                         }).send();
189     
190                         </script>
191                                 </button>
192                         </div>
193
194                         <div dojoType="dijit.layout.ContentPane" style="width:100%; height:100%;" layoutAlign="client">
195                                 <div dojoType="dojox.grid.data.DojoData" id="perm_data_model"jsId="perm_data_model" store="perm_store" query="{ code : '*' }"></div>
196                                 <div id="perm_grid" dojoType="dojox.Grid" model="perm_data_model" structure="perm_grid_layout" jsId="perm_grid">
197                                         <!!--
198                                         <script type="dojo/connect" event="onSet" args="item,attr,oldVal,newVal">
199                                         </script>
200                                         -->
201                                 </div>
202                         </div>
203
204                         <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 5px;" layoutAlign="bottom">
205                 
206                                 <button jsId="save_ppl_button" dojoType="dijit.form.Button" label="Save Changes" onClick="save_them_all()"></button>
207                 
208                                 <button jsId="delete_ppl_button" dojoType="dijit.form.Button" label="Delete Selected">
209                                         <script type="dojo/connect" event="onClick">
210
211                                                 var selected_rows = perm_grid.selection.getSelected();
212                 
213                                                 var selected_items = [];
214                                                 for (var i in selected_rows) {
215                                                         selected_items.push(
216                                                                 perm_grid.model.getRow( selected_rows[i] ).__dojo_data_item
217                                                         );
218                                                 }
219
220                                                 perm_grid.selection.clear();
221
222                                                 for (var i in selected_items) {
223                                                         current_perm = selected_items[i];
224
225                                                         if ( confirm('Are you sure you want to delete ' + perm_store.getValue( current_perm, 'code' ) + '?')) {
226
227                                                                 perm_store.setValue( current_perm, 'isdeleted', 1 );
228                         
229                                                                 var modified_ppl = new ppl().fromStoreItem( current_perm );
230                                                                 modified_ppl.isdeleted( 1 );
231                         
232                                                                 pCRUD.request({
233                                                                         method : 'open-ils.permacrud.delete.ppl',
234                                                                         timeout : 10,
235                                                                         params : [ ses, modified_ppl ],
236                                                                         onerror : function (r) {
237                                                                                 highlighter.red.play();
238                                                                                 status_update( 'Problem deleting ' + perm_store.getValue( current_perm, 'code' ) );
239                                                                         },
240                                                                         oncomplete : function (r) {
241                                                                                 var res = r.recv();
242                                                                                 if ( res && res.content() ) {
243                         
244                                                                                         var old_name = perm_store.getValue( current_perm, 'code' );
245                 
246                                                                                         perm_store.fetch({
247                                                                                                 query : { id : perm_store.getValue( current_perm, 'id' ) },
248                                                                                                 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
249                                                                                                 scope : perm_store
250                                                                                         });
251                         
252                                                                                         current_perm = null;
253                         
254                                                                                         highlighter.green.play();
255                                                                                         status_update( old_name + ' deleted' );
256                                                                                 } else {
257                                                                                         highlighter.red.play();
258                                                                                         status_update( 'Problem deleting ' + old_name );
259                                                                                 }
260                                                                         }
261                                                                 }).send();
262                 
263                                                         }
264                                                 }
265         
266                                         </script>
267                                 </button>
268         
269                         </div>
270                 </div>
271         
272         </body>
273 </html>