]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/permission/grp_tree.html
move locale parsing out to a separate javascript file; translations of group names...
[Evergreen.git] / Open-ILS / web / conify / global / permission / grp_tree.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.w2.org/1999/xhtml">
16         <head>
17                 <title>Confiy :: Global :: Permission :: Group Tree</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                         {
29                                 height: 100%;
30                                 width: 100%;
31                                 margin: 0px 0px 0px 0px;
32                                 padding: 0px 0px 0px 0px;
33                                 overflow: hidden;
34                         }
35
36                         th
37                         {
38                                 text-align: right;
39                                 font-weight: bold;
40                                 padding-left: 20px;
41                                 padding-right: 5px;
42                         }
43
44             #perm_grid {
45                 border: 0px;
46                 width: 100%;
47                 height: 100%;
48             }
49
50             #grid_container {
51                 width: 75%;
52                 height: 100%;
53             }
54
55                 </style>
56
57                 <!-- The OpenSRF API writ JS -->
58                 <script language='javascript' src='/opac/common/js/utils.js' type='text/javascript'></script>
59                 <script language='javascript' src='/opac/common/js/Cookies.js' type='text/javascript'></script>
60                 <script language='javascript' src='/opac/common/js/CGI.js' type='text/javascript'></script>
61                 <script language='javascript' src='/opac/common/js/JSON_v1.js' type='text/javascript'></script>
62
63                 <!-- Fieldmapper objects XXX need to dojo-ize this -->
64                 <script language='javascript' src='/opac/common/js/fmall.js' type='text/javascript'></script>
65
66                 <!-- Dojo goodness -->
67                 <script type="text/javascript" src="../admin.js"></script>
68                 <script type="text/javascript" src="/js/dojo/dojo/dojo.js"></script>
69                 <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
70
71                 <script type="text/javascript" src="grp_tree.js"></script>
72
73         </head>
74
75         <body class="tundra" id='pagebody'>
76
77                 <div dojoType="dijit.layout.SplitContainer" orientation="horizontal" style="height: 100%">
78
79                         <div dojoType="dijit.layout.ContentPane" sizeShare="100">
80                                 <script type="dojo/method">
81                                         window.dirtyStore = [];
82
83                     server.pCRUD.request({
84                         method : 'open-ils.permacrud.search.pgt.atomic',
85                         timeout : 10,
86                         params : [ ses, { id : { "!=" : null } }, { order_by : { pgt : 'name' } } ],
87                         onerror : function (r) { status_update('Problem fetching groups') },
88                         oncomplete : function (r) {
89                             window._group_list = r.recv().content();
90                             window._group_data = pgt.toStoreData( window._group_list );
91                             window.group_store = new dojo.data.ItemFileWriteStore({ data : window._group_data });
92                             window.group_store.onSet = function (item, attr, o, n) {
93                                 if (attr == 'ischanged') return;
94                                 if (n == o) return;
95                                 this.setValue( item, 'ischanged', 1);
96                             };
97                             dojo.addOnUnload( function (event) {
98
99                                 window.group_store.fetch({
100                                     query : { ischanged : 1 },
101                                     queryOptions : { deep : true },
102                                     onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
103                                     scope : window.group_store
104                                 });
105
106                                 if (dirtyStore.length > 0) {
107                                     var confirmation = confirm(
108                                         'There are unsaved modified Groups!  '+
109                                         'OK to save these changes, Cancel to abandon them.'
110                                     );
111
112                                     if (confirmation) {
113                                         for (var i in window.dirtyStore) {
114                                             window.current_group = window.dirtyStore[i];
115                                             save_group(true);
116                                         }
117                                     }
118                                 }
119
120                             });
121                         }
122                     }).send();
123
124                     server.actor.request({
125                         method : 'open-ils.actor.org_types.retrieve',
126                         timeout : 10,
127                         onerror : function (r) { status_update('Problem fetching types') },
128                         oncomplete : function (r) {
129                             window._ou_type_list = r.recv().content();
130                             window._ou_type_data = aout.toStoreData( window._ou_type_list );
131                             window.ou_type_store = new dojo.data.ItemFileReadStore({ data : window._ou_type_data });
132                         }
133                     }).send();
134
135                     server.actor.request({
136                         method : 'open-ils.actor.permissions.retrieve',
137                         timeout : 10,
138                         onerror : function (r) { status_update('Problem fetching perms') },
139                         oncomplete : function (r) {
140     
141                             window._perm_list = r.recv().content();
142
143                             window._perm_data = ppl.toStoreData( window._perm_list, 'code' );
144                             window._perm_name_data = ppl.toStoreData( window._perm_list, 'code', { identifier : 'code' } );
145
146                             window.perm_store = new dojo.data.ItemFileWriteStore({ data : window._perm_data });
147                             window.perm_name_store = new dojo.data.ItemFileWriteStore({ data : window._perm_name_data });
148     
149    
150                         }
151                     }).send();
152
153                     server.pCRUD.request({
154                         method : 'open-ils.permacrud.search.pgpm.atomic',
155                         timeout : 10,
156                         params : [ ses, { id : { "!=" : null } } ],
157                         onerror : function (r) { status_update('Problem fetching perm maps') },
158                         oncomplete : function (r) {
159                             window._perm_map_list = r.recv().content();
160                             window._perm_map_data = pgpm.toStoreData( window._perm_map_list, 'id' );
161                             window.perm_map_store = new dojo.data.ItemFileWriteStore({ data : window._perm_map_data });
162
163                                                         window.perm_map_store.onSet = function (item, attr, o, n) {
164                                                                 if (attr == 'ischanged') return;
165                                                                 if (n == o) return;
166
167                                                                 this.setValue( item, 'ischanged', 1);
168
169                                                                 if (attr == 'grantable' && typeof n != 'string')
170                                                                         this.setValue(item, 'grantable', n ? 't' : 'f');
171                                                         }
172
173                             dojo.addOnUnload( function (event) { save_them_all(); });
174                         }
175  
176                     }).send();
177
178                                 </script>
179                                 <div
180                                   id="group_tree"
181                                   label="Permission Groups"
182                                   query="{'_top':'true'}"
183                                   dojoType="dijit.Tree"
184                                   store="group_store"
185                                   minSize="200"
186                                   jsId="group_tree"
187                                 >
188
189                                         <script type="dojo/method" event="onClick" args="item,node">
190
191                                                 right_pane_toggler.show();
192
193                                                 current_group = item;
194                                                 window.current_fm_group = new pgt().fromStoreItem(item);
195
196                                                 perm_map_model.query = { grp : current_group ? current_group.id[0] : -1 };
197                                                 perm_map_model.refresh();
198                                                 perm_grid.refresh();
199
200                                                 highlighter.editor_pane.green.play();
201                                                 status_update( 'Now editing ' + this.store.getValue( item, 'name' ) );
202
203                                                 new_kid_button.disabled = false;
204                                                 save_group_button.disabled = false;
205                                                 delete_group_button.disabled = false;
206
207                                                 var main_settings_fields = [ 'name', 'perm_interval', 'description'];
208                                                 for ( var i in main_settings_fields ) {
209                                                         var field = main_settings_fields[i];
210                                                         var value = this.store.getValue( current_group, field );
211
212                                                         if (!value) {
213                                                                 window["editor_pane_" + field].setValue( '' ); // unset the value
214                                                                 if (field != 'description') window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
215                                                         } else window["editor_pane_" + field].setValue( value );
216                                                 }
217
218                                                 if ( this.store.getValue( current_group, '_trueRoot' ) == 'true' ) {
219                                                         editor_pane_parent.disabled = true;
220                                                         editor_pane_parent.setValue(null);
221                                                         editor_pane_parent.setDisplayedValue('');
222                                                         editor_pane_parent.validate(false);
223                                                 } else {
224                                                         editor_pane_parent.disabled = false;
225                                                         editor_pane_parent.validate(true);
226                                                         editor_pane_parent.setValue( this.store.getValue( current_group, 'parent' ) );
227                                                 }
228
229                                                 editor_pane_application_perm.setValue( this.store.getValue( current_group, 'application_perm' ) );
230
231                                                 editor_pane_usergroup.setChecked( this.store.getValue( current_group, 'usergroup' ) == 't' ? true : false );
232
233                                         </script>
234
235                                         <script type="dojo/method" event="getLabel" args="item,pI">
236                                                 var label = this.store.getValue(item,'name');
237                                                 if (this.store.getValue(item,'ischanged') == 1) label = '* ' + label;
238                                                 return label;
239                                         </script>
240
241                                 </div>
242                         </div>
243
244                         <div id="right_pane" dojoType="dijit.layout.ContentPane"  sizeShare="300">
245                                 <script type="dojo/method">
246                                         window.right_pane_toggler = new dojo.fx.Toggler({ node: 'right_pane'});
247                                         window.right_pane_toggler.hide();
248                                 </script>
249
250                                 <div dojoType="dijit.layout.TabContainer">
251                                         <div id="editor_pane" dojoType="dijit.layout.ContentPane" title="Group Configuration">
252                                                 <script type="dojo/method">
253                                                         highlighter.group_tree = {};
254                                                         highlighter.editor_pane = {};
255                                                         highlighter.group_tree.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'group_tree', duration : 500 } );
256                                                         highlighter.group_tree.red = dojox.fx.highlight( { color : '#FF2018', node : 'group_tree', duration : 500 } );
257                                                         highlighter.editor_pane.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'editor_pane', duration : 500 } );
258                                                         highlighter.editor_pane.red = dojox.fx.highlight( { color : '#FF2018', node : 'editor_pane', duration : 500 } );
259                                                 </script>
260         
261                                                 <table class="tundra" style="margin:10px;">
262                                                         <tr>
263                                                                 <th>Group Name</th>
264                                                                 <td>
265                                                                         <span id="editor_pane_name" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_name" regExp=".+" required="true">
266                                                                                 <script type="dojo/connect" event="onChange">
267                                                                                         if (current_group) {
268                                                                                                 group_store.setValue( current_group, "name", this.getValue() );
269                                                                                         }
270                                                                                 </script>
271                                                                         </span>
272                                                                         <span dojoType="openils.I18N.translationWidget" targetObject="current_fm_group" field="name"></span>
273                                                                 </td>
274                                                         </tr>
275                                                         <tr>
276                                                                 <th>Description</th>
277                                                                 <td>
278                                                                         <span>
279                                                                                 <textarea
280                                                                                   id="editor_pane_description"
281                                                                                   dojoType="dijit.form.Textarea"
282                                                                                   jsId="editor_pane_description"
283                                                                                   onChange="if (current_group) group_store.setValue( current_group, "description", this.getValue() );"
284                                                                                 ></textarea>
285                                                                         </span>
286                                                                         <span dojoType="openils.I18N.translationWidget" targetObject="current_fm_group" field="description"></span>
287                                                                 </td>
288                                                         </tr>
289                                                         <tr>
290                                                                 <th>Permission Interval</th>
291                                                                 <td>
292                                                                         <span id="editor_pane_perm_interval" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_perm_interval" regExp="^\d+ (?:y.*|mo.*|d.*)$" required="true">
293                                                                                 <script type="dojo/connect" event="onChange">
294                                                                                         if (current_group) {
295                                                                                                 group_store.setValue( current_group, "perm_interval", this.getValue() );
296                                                                                         }
297                                                                                 </script>
298                                                                         </span>
299                                                                 </td>
300                                                         </tr>
301                                                         <tr>
302                                                                 <th>Editing Permission</th>
303                                                                 <td>
304                                                                         <div
305                                                                           id="editor_pane_application_perm"
306                                                                           dojoType="dijit.form.FilteringSelect"
307                                                                           store="perm_name_store"
308                                                                           searchAttr="code"
309                                                                           jsId="editor_pane_application_perm"
310                                                                         >
311                                                                                 <script type="dojo/connect" event="onChange">
312                                                                                         if (current_group && this.getValue()) {
313                                                                                                 group_store.setValue( current_group, "application_perm", this.getValue() );
314                                                                                         }
315                                                                                 </script>
316                                                                         </div>
317                                                                 </td>
318                                                         </tr>
319                                                         <tr>
320                                                                 <th>Parent Group</th>
321                                                                 <td>
322                                                                         <div
323                                                                           id="editor_pane_parent"
324                                                                           dojoType="dijit.form.FilteringSelect"
325                                                                           jsId="editor_pane_parent"
326                                                                           store="group_store"
327                                                                           searchAttr="name"
328                                                                           ignoreCase="true"
329                                                                           required="true"
330                                                                         >
331                                                                                 <script type="dojo/connect" event="onChange">
332                                                                                         if (current_group && this.getValue()) {
333                                                                                                 this.store.setValue( current_group, "parent", this.getValue() );
334                                                                                         }
335                                                                                 </script>
336                                                                         </div>
337                                                                 </td>
338                                                         </tr>
339                                                         <tr>
340                                                                 <th>User Group</th>
341                                                                 <td>
342                                                                         <input
343                                                                           id="editor_pane_usergroup"
344                                                                           jsId="editor_pane_usergroup"
345                                                                           type="checkbox"
346                                                                           dojoType="dijit.form.CheckBox"
347                                                                           onChange='if (current_group) group_store.setValue( current_group, "usergroup", this.checked ? "t" : "f" );'
348                                                                         />
349                                                                 </td>
350                                                         </tr>
351                                                 </table>
352         
353                                                 <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 20px;">
354         
355                                                         <button jsId="save_group_button" dojoType="dijit.form.Button" label="Save" onClick="save_group()">
356                                                                 <script type="dojo/connect" event="startup">
357                                                                         this.disabled = true;
358                                                                 </script>
359                                                         </button>
360         
361                                                         <button jsId="delete_group_button" dojoType="dijit.form.Button" label="Delete">
362                                                                 <script type="dojo/connect" event="startup">
363                                                                         this.disabled = true;
364                                                                 </script>
365                                                                 <script type="dojo/connect" event="onClick">
366         
367                                                                         if (group_store.getValue( current_group, '_trueRoot' ) == 'true') {
368                                                                                 highlighter.editor_pane.red.play();
369                                                                                 status_update( 'Cannot delete' + group_store.getValue( current_group, 'name' ) + ', you need at least one.' );
370                                                                                 return false;
371                                                                         }
372
373                                                                         if ( current_group.children ) {
374                                                                                 var kids = current_group.children;
375                                                                                 if (!dojo.isArray(kids)) kids = [kids];
376         
377                                                                                 var existing_kids = dojo.filter(
378                                                                                         kids,
379                                                                                         function(kid){ return kid.isdeleted[0] != 1 }
380                                                                                 );
381                                                                                 if ( existing_kids.length > 0) {
382                                                                                         highlighter.editor_pane.red.play();
383                                                                                         status_update( 'Cannot delete' + group_store.getValue( current_group, 'name' ) + ', ' + existing_kids.length + ' subordinates still exist.' );
384                                                                                         return;
385                                                                                 }
386                                                                         }
387         
388                                                                         if ( confirm('Are you sure you want to delete ' + current_group.name + '?')) {
389                                                                                 group_store.setValue( current_group, 'isdeleted', 1 );
390         
391                                                                                 var modified_pgt = new pgt().fromStoreItem( current_group );
392                                                                                 modified_pgt.isdeleted( 1 );
393         
394                                                                                 server.pCRUD.request({
395                                                                                         method : 'open-ils.permacrud.delete.pgt',
396                                                                                         timeout : 10,
397                                                                                         params : [ ses, modified_pgt ],
398                                                                                         onerror : function (r) {
399                                                                                                 highlighter.editor_pane.red.play();
400                                                                                                 status_update( 'Problem deleting ' + group_store.getValue( current_group, 'name' ) );
401                                                                                         },
402                                                                                         oncomplete : function (r) {
403                                                                                                 var res = r.recv();
404                                                                                                 if ( res && res.content() ) {
405         
406                                                                                                         var old_name = group_store.getValue( current_group, 'name' );
407
408                                                                                                         group_store.fetch({
409                                                                                                                 query : { id : group_store.getValue( current_group, 'id' ) },
410                                                                                                                 queryOptions : { deep : true },
411                                                                                                                 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
412                                                                                                                 scope : group_store
413                                                                                                         });
414         
415                                                                                                         current_group = null;
416         
417                                                                                                         new_kid_button.disabled = true;
418                                                                                                         save_group_button.disabled = true;
419                                                                                                         delete_group_button.disabled = true;
420                         
421                                                                                                         var main_settings_fields = [ 'name', 'perm_interval', 'description' ];
422                                                                                                         for ( var i in main_settings_fields ) {
423                                                                                                                 var field = main_settings_fields[i];
424                                                                                                                 window["editor_pane_" + field].setValue( '' ); // unset the value
425                                                                                                                 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
426                                                                                                         }
427
428                                                                                                         window["editor_pane_usergroup"].setChecked( false ); // unset the value
429                         
430                                                                                                         highlighter.editor_pane.green.play();
431                                                                                                         status_update( old_name + ' deleted' );
432                                                                                                 } else {
433                                                                                                         highlighter.editor_pane.red.play();
434                                                                                                         status_update( 'Problem deleting ' + old_name );
435                                                                                                 }
436                                                                                         }
437                                                                                 }).send();
438         
439                                                                         }
440         
441                                                                 </script>
442                                                         </button>
443         
444                                                 </div>
445         
446                                                 <button jsId="new_kid_button" dojoType="dijit.form.Button" label="New Child">
447                                                         <script type="dojo/connect" event="startup">
448                                                                 this.disabled = true;
449                                                         </script>
450                                                         <script type="dojo/connect" event="onClick">
451         
452                                                                 var new_fm_obj = new pgt().fromHash({
453                                                                         isnew                   : 1,
454                                                                         name                    : 'New Group',
455                                                                         usergroup               : 'f',
456                                                                         parent                  : group_store.getValue( current_group, 'id' )
457                                                                 });
458         
459                                                                 var err = false;
460                                                                 server.pCRUD.request({
461                                                                         method : 'open-ils.permacrud.create.pgt',
462                                                                         timeout : 10,
463                                                                         params : [ ses, new_fm_obj ],
464                                                                         onerror : function (r) {
465                                                                                 highlighter.editor_pane.red.play();
466                                                                                 status_update( 'Problem calling method to create child Group' );
467                                                                                 err = true;
468                                                                         },
469                                                                         oncomplete : function (r) {
470                                                                                 var res = r.recv();
471                                                                                 if ( res && res.content() ) {
472                                                                                         group_store.newItem(
473                                                                                                 res.content().toHash(),
474                                                                                                 { parent : current_group, attribute : 'children' }
475                                                                                         );
476                                                                                 } else {
477                                                                                         highlighter.editor_pane.red.play();
478                                                                                         status_update( 'Problem creating child Group' );
479                                                                                         err = true;
480                                                                                 }
481                                                                         },
482                                                                 }).send();
483         
484                                                                 if (!err) {
485                                                                         highlighter.editor_pane.green.play();
486                                                                         highlighter.group_tree.green.play();
487                                                                         status_update( 'New child Group created for ' + group_store.getValue( current_group, 'name' ) );
488                                                                 }
489         
490                                                         </script>
491                                                 </button>
492         
493                                         </div>
494
495                                         <div id="perm_pane" dojoType="dijit.layout.ContentPane" title="Group Permissions">
496                                                 <script type="dojo/connect" event="onShow">
497                                                         perm_map_model.query = { grp : current_group ? current_group.id[0] : -1 };
498                                                         perm_map_model.refresh();
499                                                         perm_grid.refresh();
500                                                 </script>
501                                                 <div dojoType="dijit.layout.LayoutContainer" orientation="horizontal" style="width:100%; height:100%;">
502                                                         <div id="grid_container" dojoType="dijit.layout.ContentPane" sizeShare="1" layoutAlign="left">
503                                                                 <div dojoType="dojox.grid.data.DojoData" id="perm_map_model"jsId="perm_map_model" store="perm_map_store"></div>
504         
505                                                                 <div id="perm_grid" dojoType="dojox.Grid" model="perm_map_model" jsId="perm_grid">
506                                                                         <script type="dojo/connect" event="startup">
507         
508                                                                                 function get_item_part(model_field, item_search_field, item_part, model, store, datum, row) {
509                                                                                         var formatter = true;
510         
511                                                                                         if (!row && row != '0') {
512                                                                                                 row = datum;
513                                                                                                 formatter = false;
514                                                                                         }
515         
516                                                                                         if(!model.getRow(row)) return null;
517                                                                                         var value = null;
518         
519                                                                                         if(!formatter) { //this.editor && (this.editor.alwaysOn || (this.grid.edit.info.rowIndex==row && this.grid.edit.info.cell==this))) {
520                                                                                                 return model.getRow(row)[model_field];
521                                                                                         }
522         
523                                                                                         var q = {};
524                                                                                         q[item_search_field] = model.getRow(row)[model_field];
525         
526                                                                                         store.fetch({
527                                                                                                 query : q,
528                                                                                                 onItem : function (item) { value = store.getValue( item, item_part ) }
529                                                                                         });
530
531                                                                                         return value;
532                                                                                 }
533         
534                                                     window.current_perm_grid_layout = [
535                                                         {   cells : [
536                                                                     [
537                                                                             {   name : "Code",
538                                                                                                                         field: "perm",
539                                                                                                                         formatter : dojo.partial(get_item_part, "perm", "id", "code", perm_map_model, perm_store),
540                                                                                                                         width : "auto"
541                                                                                                                 },
542                                                                                                 {       name : "Depth",
543                                                                                                                         field : "depth",
544                                                                                                                         formatter : dojo.partial(get_item_part, "depth", "depth", "name", perm_map_model, ou_type_store),
545                                                                                                                         editor : dojox.grid.editors.select,
546                                                                                                                         options : dojo.map( _ou_type_list, function (x) { return x.name() } ),
547                                                                                                                         values : dojo.map( _ou_type_list, function (x) { return x.depth() } )
548                                                                                                                 }, 
549                                                                     {   name : "Grantable",
550                                                                                                                         field : "grantable",
551                                                                                                                         editor : dojox.grid.editors.bool,
552                                                                                                                         get : function (row) {
553                                                                                                                                 var gr = get_item_part("id", "id", "grantable", perm_map_model, perm_map_model.store, row, row);
554                                                                                                                                 if (gr == 't' || gr === true) return true;
555                                                                                                                                 return false;
556                                                                                                                         },
557                                                                                                                 }
558                                                                                                 ]
559                                                                                                 ]
560                                                         }
561                                                     ];
562
563                                                                                 perm_grid.setStructure(window.current_perm_grid_layout);
564         
565                                                                         </script>
566                                                                 </div>
567                                                         </div>
568
569                                                         <div id="new_perm_container" dojoType="dijit.layout.ContentPane" sizeShare="1" layoutAlign="client">
570
571                                                                 <div dojoType="dijit.form.DropDownButton" id="new_popup" jsId="new_popup">
572                                                                         <span>New Mapping</span>
573                                                                         <div  dojoType="dijit.TooltipDialog"> 
574                                                                                 <table class="tundra">
575                                                                                         <tr>
576                                                                                                 <td>Permission:</td>
577                                                                                                 <td>
578                                                                                                         <div
579                                                                                                           dojoType="dijit.form.FilteringSelect"
580                                                                                                           Id="new_perm_select"
581                                                                                                           jsId="new_perm_select"
582                                                                                                           store="perm_store"
583                                                                                                           searchAttr="code"
584                                                                                                           ignoreCase="true"
585                                                                                                           required="true"></div>
586                                                                                                 </td>
587                                                                                         </tr>
588                                                                                         <tr>
589                                                                                                 <td>Depth:</td>
590                                                                                                 <td>
591                                                                                                         <div
592                                                                                                           dojoType="dijit.form.FilteringSelect"
593                                                                                                           Id="new_depth_select"
594                                                                                                           jsId="new_depth_select"
595                                                                                                           store="ou_type_store"
596                                                                                                           searchAttr="name"
597                                                                                                           ignoreCase="true"
598                                                                                                           required="true"></div>
599                                                                                                 </td>
600                                                                                         </tr>
601                                                                                         <tr>
602                                                                                                 <td>Grantable:</td>
603                                                                                                 <td>
604                                                                                                         <input
605                                                                                                           type="checkbox"
606                                                                                                           dojoType="dijit.form.CheckBox"
607                                                                                                           Id="new_grant_checkbox"
608                                                                                                           jsId="new_grant_checkbox"
609                                                                                                           value="t"></input>
610                                                                                                 </td>
611                                                                                         </tr>
612                                                                                 </table>
613
614                                                                                 <button dojoType="dijit.form.Button" jsId="new_mapping_add" label="Add Mapping">
615                                                                     <script type="dojo/connect" event="onClick">
616                                                 
617                                                                         var new_perm = new_perm_select.getValue();
618                                                                         if (!new_perm) return;
619                 
620                                                                         var new_type_id = new_depth_select.getValue();
621                                                                         if (!new_type_id) return;
622                 
623                                                                                                 var new_type;
624                                                                 window.ou_type_store.fetch({
625                                                                 query : { id : new_type_id },
626                                                                 onItem : function (item, req) { try { new_type = item } catch (e) { /* meh */ } },
627                                                                 });
628                 
629                                                                         var new_depth = ou_type_store.getValue( new_type, 'depth')
630                                                                         var new_grant = new_grant_checkbox.getValue();
631                                                 
632                                                                         var new_fm_obj = new pgpm().fromHash({
633                                                                             isnew       : 1,
634                                                                             perm        : new_perm,
635                                                                             depth       : new_depth,
636                                                                                                         grp                     : group_store.getValue( current_group, 'id' ),
637                                                                                                         grantable       : new_grant ? 't' : 'f'
638                                                                         });
639                                                     
640                                                                         var err = false;
641                                                                         server.pCRUD.request({
642                                                                             method : 'open-ils.permacrud.create.pgpm',
643                                                                             timeout : 10,
644                                                                             params : [ ses, new_fm_obj ],
645                                                                             onerror : function (r) {
646                                                                                 highlighter.group_tree.red.play();
647                                                                                 status_update( 'Problem calling method to create new Permission Map' );
648                                                                                 err = true;
649                                                                             },
650                                                                             oncomplete : function (r) {
651                 
652                                                                                 var res = r.recv();
653                                                                                 if ( res && res.content() ) {
654                                                                                     var new_item_hash = res.content().toHash();
655                                                                                     perm_map_store.newItem( new_item_hash );
656                                                                                     status_update( 'New permission map created' );
657                                                                                     highlighter.group_tree.green.play();
658                 
659                                                                                             perm_map_model.query = { grp : current_group ? current_group.id[0] : -1 };
660                                                                                     perm_grid.model.sort(-1);
661                                                                                             perm_map_model.refresh();
662                                                                                             perm_grid.refresh();
663                 
664                                                                                 } else {
665                                                                                     highlighter.group_tree.red.play();
666                                                                                     status_update( 'Problem creating new Permission Map' );
667                                                                                     err = true;
668                                                                                 }
669                                                                             }
670                                                                         }).send();
671
672                                                                                                 new_popup._closeDropDown();
673                     
674                                                                     </script>
675                 
676                                                                                 </button>
677                                                                         </div>
678                                                                 </div>
679
680                                                                 <button jsId="save_pgpm_button" dojoType="dijit.form.Button" label="Save Changes" onClick="save_them_all()"></button><br/>
681
682                                                 <button jsId="delete_pgpm_button" dojoType="dijit.form.Button" label="Remove Selected">
683                                                         <script type="dojo/connect" event="onClick">
684                                         
685                                                         var selected_rows = perm_grid.selection.getSelected();
686                                         
687                                                         var selected_items = [];
688                                                         for (var i in selected_rows) {
689                                                             selected_items.push(
690                                                                 perm_grid.model.getRow( selected_rows[i] ).__dojo_data_item
691                                                             );
692                                                         }
693                         
694                                                         perm_grid.selection.clear();
695                                 
696                                                             for (var i in selected_items) {
697                                                                     window.current_perm_map = selected_items[i];
698                         
699                                                                         perm_map_store.setValue( window.current_perm_map, 'isdeleted', 1 );
700                                                         
701                                                                             var modified_pgpm = new pgpm().fromStoreItem( window.current_perm_map );
702                                                                                 modified_pgpm.isdeleted( 1 );
703                                     
704                                                         server.pCRUD.request({
705                                                             method : 'open-ils.permacrud.delete.pgpm',
706                                                             timeout : 10,
707                                                                 params : [ ses, modified_pgpm ],
708                                                                     onerror : function (r) {
709                                                                                                         highlighter.editor_pane.red.play();
710                                                                                 status_update( 'Problem deleting permission mapping ' + perm_map_store.getValue( window.current_perm_map, 'id' ) );
711                                                                                 },
712                                                                                     oncomplete : function (r) {
713                                                                                             var res = r.recv();
714                                                                                                 if ( res && res.content() ) {
715                                                 
716                                                                                     perm_map_store.fetch({
717                                                                                             query : { id : perm_map_store.getValue( window.current_perm_map, 'id' ) },
718                                                                                                 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
719                                                                                                     scope : perm_map_store
720                                                                                                     });
721                             
722                                                                                                         window.current_perm_map = null;
723                                                 
724                                                                                                                 highlighter.editor_pane.green.play();
725                                                                                         status_update( 'Permission mapping deleted' );
726                                                                                         } else {
727                                                                                                                 highlighter.editor_pane.red.play();
728                                                                                                     status_update( 'Problem deleting permission mapping ' + perm_map_store.getValue( window.current_perm_map, 'id' ));
729                                                                                                     }
730                                                             }
731                                                         }).send();
732                                         
733                                                         }
734                                     
735                                                         </script>
736                                                         </button>
737         
738                                                         </div>
739                                                 </div>
740                                         </div>
741                                 </div>
742                         </div>
743                 </div>
744         </body>
745 </html>