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