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