Updated perm_list to work with dojo 1.4
authorJoseph Lewis <joehms22@gmail.com>
Mon, 4 Jun 2012 19:13:22 +0000 (13:13 -0600)
committerThomas Berezansky <tsbere@mvlc.org>
Wed, 10 Oct 2012 14:22:36 +0000 (10:22 -0400)
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/web/conify/global/permission/perm_list.html
Open-ILS/web/conify/global/permission/perm_list.js

index 680cf61..22c50e3 100644 (file)
@@ -1,3 +1,8 @@
+<!DOCTYPE HTML PUBLIC 
+       "-//W3C//DTD HTML 4.01 Transitional//EN"
+       "http://www.w3.org/TR/html4/loose.dtd" [
+       <!--#include virtual="/opac/locale/${locale}/conify.dtd"-->
+]>
 <!--
 # Copyright (C) 2008  Georgia Public Library Service / Equinox Software, Inc
 # Mike Rylander <miker@esilibrary.com>
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 -->
-<!DOCTYPE html PUBLIC 
-       "-//W3C//DTD XHTML 1.0 Transitional//EN" 
-       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
-       <!--#include virtual="/opac/locale/${locale}/conify.dtd"-->
-]>
-<html xmlns="http://www.w3.org/1999/xhtml">
+
+<html>
        <head>
                <title>&conify.perm_list.permission_list.title;</title>
 
                <style type="text/css">
-                       @import url('/js/dojo/dojox/grid/_grid/tundraGrid.css');
+                       @import url('/js/dojo/dojox/grid/resources/Grid.css');
+                       @import url('/js/dojo/dojox/grid/resources/tundraGrid.css');
                        @import url('/js/dojo/dojo/resources/dojo.css');
                        @import url('/js/dojo/dijit/themes/tundra/tundra.css');
                        @import url('/js/dojo/dojox/widget/Toaster/Toaster.css');
                </style>
-
+               
                <style type="text/css">
                        html, body {
                                height: 100%;
                                width: 100%;
                                height: 100%;
                        }
+                       
+                       .dojoxGrid table {
+                               margin: 0;
+                       }
                </style>
 
                <!-- The OpenSRF API writ JS -->
 
                <!-- Dojo goodness -->
                <script type="text/javascript" src="/js/dojo/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
-               <script type="text/javascript" src="/js/dojo/dojo/openils_dojo.js" djConfig="parseOnLoad: true"></script>
+           <script type="text/javascript" src="/js/dojo/dojo/openils_dojo.js" djConfig="parseOnLoad: true"></script>
                <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
-               <script language='javascript'>dojo.require('fieldmapper.AutoIDL')</script>
-
                <script type="text/javascript" src="perm_list.js"></script>
-
-               <script type="text/javascript"><![CDATA[
-                       var dirtyStore = [];
-                       var perm_rows = [];
-
-            var _perm_list = pCRUD.retrieveAll('ppl', { order_by : { ppl : 'code' } });
-            var _perm_data = ppl.toStoreData( _perm_list, 'code' );
-            var perm_store = new dojo.data.ItemFileWriteStore({ data : _perm_data });
-
-
-            perm_store.onSet = function (item, attr, o, n) {
-                if (attr == 'ischanged') return;
-                if (n == o) return;
-                this.setValue( item, 'ischanged', 1);
-            };
-
-
-                       var perm_grid_layout = [
-                               {       cells : [
-                                               [
-                                                       { name : ppl_strings.LABEL_CODE,        field : "code",        width : "300px", editor : dojox.grid.editors.Dijit, rowSpan : "2" },
-                                                       { name : ppl_strings.LABEL_DESCRIPTION, field : "description", width : "auto",  editor : dojox.grid.editors.Editor, style : "minHeight:1em;" }
-                                               ],
-                                               [
-                                                       { name : ppl_strings.LABEL_TRANSLATION,
-                                                         width : "10em",
-                                                         height : "2em",
-                                                         formatter : function (value) {
-                                return '<span class="perm_grid_trans_desc_'+value+'"></span>';
-                              },
-                                                         get : function (row) {
-                                                               var r = perm_data_model.getRow(row);
-                                                               if (r) {
-                                                                       perm_rows[row] = new ccs().fromHash(perm_data_model.getRow(row));
-                                                                       setTimeout(
-                                                                               'dojo.query(".perm_grid_trans_desc_' + row + '").'+
-                                                                                       'instantiate(openils.widget.TranslatorPopup,{field:"description",'+
-                                                                                       'targetObject:"window.perm_rows['+row+']"});'+
-                                                                                       'perm_grid.rowHeightChanged('+row+')',
-                                                                               0
-                                                                       );
-                                                                       var oldnode = dojo.byId('description_translation_' + row);
-                                                                       if (oldnode) dijit.byNode(oldnode).destroyRecursive();
-                                                                       return row;
-                                                               }
-                                                               return '';
-                                                         }
-                                                       }
-                                               ]
-                                       ]
-                               }
-                       ];
-
-            dojo.addOnUnload( function (event) {
-
-                perm_store.fetch({
-                    query : { ischanged : 1 },
-                    onItem : function (item, req) { try { if (this.isItem( item )) dirtyStore.push( item ); } catch (e) { /* meh */ } },
-                    scope : perm_store
-                });
-
-                if (dirtyStore.length > 0) {
-                    var confirmation = confirm(ppl_strings.CONFIRM_EXIT_PPL);
-
-                    if (confirmation) {
-                        for (var i in dirtyStore) {
-                            current_perm = dirtyStore[i];
-                            save_perm(true);
-                        }
-                    }
-                }
-
-            });
-]]>
-               </script>
-
-
        </head>
 
        <body class="tundra" id='pagebody'>
                        <div dojoType="dijit.layout.LayoutContainer" orientation="horizontal" style="margin-top: 5px;" layoutAlign="top">
                                <span>&conify.perm_list.new_permission.label;</span>
                                <div dojoType="dijit.form.TextBox" id="new_perm_code" jsId="new_perm_code" label="&conify.perm_list.new_code.label;"></div>
-                               <button dojoType="dijit.form.Button" id="save_new_perm_code" jsId="save_new_perm_code" label="&conify.perm_list.add_button.label;"> 
-                                       <script type="dojo/connect" event="onClick">
-<![CDATA[
-                                               var new_code = new_perm_code.getValue();
-                                               if (!new_code) return;
-
-                       var new_fm_obj = new ppl().fromHash({
-                               isnew           : 1,
-                           code            : new_code
-                           });
-    
-                       var err = false;
-                           pCRUD.create(new_fm_obj, {
-                               onerror : function (r) {
-                               highlighter.red.play();
-                                   status_update( ppl_strings.ERROR_CALLING_METHOD_PPL );
-                               err = true;
-                               },
-                               oncomplete : function (r, list) {
-                                   var new_item_hash = list[0].toHash();
-                                   perm_store.newItem( new_item_hash );
-                                                               status_update( dojo.string.substitute(ppl_strings.SUCCESS_CREATING_PERMISSION, [new_item_hash.code]) );
-                                                               perm_grid.model.sort(-1);
-                                                               highlighter.green.play();
-                               }
-                       });
-]]> 
-                       </script>
-                               </button>
+                               <button dojoType="dijit.form.Button" id="save_new_perm_code" jsId="save_new_perm_code" label="&conify.perm_list.add_button.label;" onClick="saveNewPermCode()"></button>
                        </div>
 
                        <div dojoType="dijit.layout.ContentPane" style="width:100%; height:100%;" layoutAlign="client">
-                <div dojoType="dojox.grid.data.DojoData" id="perm_data_model" jsId="perm_data_model" store="perm_store" query="{ code : '*' }">
-                </div>
-                               <div id="perm_grid" dojoType="dojox.Grid" model="perm_data_model" structure="perm_grid_layout" jsId="perm_grid">
-                               </div>
-                       </div>
-
-                       <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 5px;" layoutAlign="bottom">
-               
-                               <button jsId="save_ppl_button" dojoType="dijit.form.Button" label="&conify.perm_list.save_changes.label;" onClick="save_them_all()"></button>
-               
-                               <button jsId="delete_ppl_button" dojoType="dijit.form.Button" label="&conify.perm_list.delete_selected.label;">
-                                       <script type="dojo/connect" event="onClick">
-<![CDATA[
-                                               var selected_rows = perm_grid.selection.getSelected();
-               
-                                               var selected_items = [];
-                                               for (var i in selected_rows) {
-                                                       selected_items.push(
-                                                               perm_grid.model.getRow( selected_rows[i] ).__dojo_data_item
-                                                       );
-                                               }
-
-                                               perm_grid.selection.clear();
+                               <div id="perm_grid" dojoType="dojox.grid.DataGrid" store="perm_store" structure="perm_grid_layout" jsId="perm_grid"></div>
 
-                                               for (var i in selected_items) {
-                                                       current_perm = selected_items[i];
-
-                                                       if ( confirm( dojo.string.substitute(ppl_strings.CONFIRM_DELETE, [perm_store.getValue(current_perm, 'code')]) ) ) {
-
-                                                               perm_store.setValue( current_perm, 'isdeleted', 1 );
-                       
-                                                               var modified_ppl = new ppl().fromStoreItem( current_perm );
-                                                               modified_ppl.isdeleted( 1 );
-                       
-                                                               pCRUD.eliminate(modified_ppl, {
-                                                                       onerror : function (r) {
-                                                                               highlighter.red.play();
-                                                                               status_update( dojo.string.substitute(ppl_strings.ERROR_DELETING, [perm_store.getValue( current_perm, 'code' )]) );
-                                                                       },
-                                                                       oncomplete : function (r) {
-                                                                               var old_name = perm_store.getValue( current_perm, 'code' );
-
-                                                                               perm_store.fetch({
-                                                                                       query : { id : perm_store.getValue( current_perm, 'id' ) },
-                                                                                       onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
-                                                                                       scope : perm_store
-                                                                               });
-
-                                                                               current_perm = null;
-
-                                                                               highlighter.green.play();
-                                                                               status_update( dojo.string.substitute(ppl_strings.STATUS_DELETED, [old_name]) );
-                                                                       }
-                                                               });
-               
-                                                       }
-                                               }
-]]>
-                                       </script>
-                               </button>
-       
+                               <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 5px;" layoutAlign="bottom">
+                                       <button jsId="save_ppl_button" dojoType="dijit.form.Button" label="&conify.perm_list.save_changes.label;" onClick="save_them_all()"></button>
+                                       <button jsId="delete_ppl_button" dojoType="dijit.form.Button" label="&conify.perm_list.delete_selected.label;" onClick="delete_them()"></button>
+                               </div>
                        </div>
                </div>
-       
-        <script type="text/javascript">
-            var highlighter= {};
-               highlighter.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } );
-               highlighter.red = dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } );
-        </script>
-
        </body>
 </html>
index 9de5a90..280e353 100644 (file)
@@ -31,8 +31,10 @@ dojo.require('dijit.layout.LayoutContainer');
 dojo.require('dijit.layout.BorderContainer');
 dojo.require('dojox.widget.Toaster');
 dojo.require('dojox.fx');
-dojo.require('dojox.grid.Grid');
 dojo.require('openils.XUL');
+dojo.require("dojox.grid.cells.dijit");
+dojo.require("dojo.data.ItemFileWriteStore");
+dojo.require('dojox.grid.DataGrid');
 dojo.requireLocalization("openils.conify", "conify");
 
 // some handy globals
@@ -102,3 +104,155 @@ function save_them_all (event) {
 
 dojo.addOnUnload( save_them_all );
 
+
+
+
+var dirtyStore = [];
+var perm_rows = [];
+
+var _perm_list = pCRUD.retrieveAll('ppl', { order_by : { ppl : 'code' } });
+var _perm_data = ppl.toStoreData( _perm_list, 'code' );
+var perm_store = new dojo.data.ItemFileWriteStore({ data : _perm_data });
+
+
+perm_store.onSet = function (item, attr, o, n) {
+       if (attr == 'ischanged') return;
+       if (n == o) return;
+       this.setValue( item, 'ischanged', 1);
+};
+
+
+var perm_grid_layout = [
+       {       cells : [
+                       [
+                               { name : ppl_strings.LABEL_CODE,        field : "code",        width : "300px", rowSpan : "2", editable : true },
+                               { name : ppl_strings.LABEL_DESCRIPTION, field : "description", width : "auto", style : "minHeight:1em;", editable : true }
+                       ],
+                       [
+                               { name : ppl_strings.LABEL_TRANSLATION,
+                                 width : "10em",
+                                 height : "2em",
+                                 formatter : function (value) {
+                                       return '<span class="perm_grid_trans_desc_'+value+'"></span>';
+                                 },
+                                 get : function (row) {
+                                       var r = perm_grid.getItem(row);
+                                       if (r) {
+                                               perm_rows[row] = new ccs().fromHash(perm_grid.getItem(row));
+                                               setTimeout(
+                                                       'dojo.query(".perm_grid_trans_desc_' + row + '").'+
+                                                               'instantiate(openils.widget.TranslatorPopup,{field:"description",'+
+                                                               'targetObject:"window.perm_rows['+row+']"});'+
+                                                               'perm_grid.rowHeightChanged('+row+')',
+                                                       0
+                                               );
+                                               var oldnode = dojo.byId('description_translation_' + row);
+                                               if (oldnode) dijit.byNode(oldnode).destroyRecursive();
+                                               return row;
+                                       }
+                                       return '';
+                                 }
+                               }
+                       ]
+               ]
+       }
+];
+
+dojo.addOnUnload( function (event) {
+
+       perm_store.fetch({
+               query : { ischanged : 1 },
+               onItem : function (item, req) { try { if (this.isItem( item )) dirtyStore.push( item ); } catch (e) { /* meh */ } },
+               scope : perm_store
+       });
+
+       if (dirtyStore.length > 0) {
+               var confirmation = confirm(ppl_strings.CONFIRM_EXIT_PPL);
+
+               if (confirmation) {
+                       for (var i in dirtyStore) {
+                               current_perm = dirtyStore[i];
+                               save_perm(true);
+                       }
+               }
+       }
+
+});
+
+
+
+function saveNewPermCode()
+{
+var new_code = new_perm_code.getValue();
+       if (!new_code) return;
+
+       var new_fm_obj = new ppl().fromHash({
+               isnew           : 1,
+               code            : new_code
+       });
+
+       var err = false;
+       pCRUD.create(new_fm_obj, {
+               onerror : function (r) {
+                       highlighter.red.play();
+                       status_update( ppl_strings.ERROR_CALLING_METHOD_PPL );
+                       err = true;
+               },
+               oncomplete : function (r, list) {
+                       var new_item_hash = list[0].toHash();
+                       perm_store.newItem( new_item_hash );
+                       status_update( dojo.string.substitute(ppl_strings.SUCCESS_CREATING_PERMISSION, [new_item_hash.code]) );
+                       perm_grid.model.sort(-1);
+                       highlighter.green.play();
+               }
+       });
+}
+                                       
+function delete_them()
+{
+       var selected_rows = perm_grid.selection.getSelected();
+       var selected_items = [];
+       
+       for (var i in selected_rows) {
+               selected_items.push(
+                       perm_grid.model.getRow( selected_rows[i] ).__dojo_data_item
+               );
+       }
+
+       perm_grid.selection.clear();
+
+       for (var i in selected_items) {
+               current_perm = selected_items[i];
+
+               if ( confirm( dojo.string.substitute(ppl_strings.CONFIRM_DELETE, [perm_store.getValue(current_perm, 'code')]) ) ) {
+
+                       perm_store.setValue( current_perm, 'isdeleted', 1 );
+
+                       var modified_ppl = new ppl().fromStoreItem( current_perm );
+                       modified_ppl.isdeleted( 1 );
+
+                       pCRUD.eliminate(modified_ppl, {
+                               onerror : function (r) {
+                                       highlighter.red.play();
+                                       status_update( dojo.string.substitute(ppl_strings.ERROR_DELETING, [perm_store.getValue( current_perm, 'code' )]) );
+                               },
+                               oncomplete : function (r) {
+                                       var old_name = perm_store.getValue( current_perm, 'code' );
+
+                                       perm_store.fetch({
+                                               query : { id : perm_store.getValue( current_perm, 'id' ) },
+                                               onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
+                                               scope : perm_store
+                                       });
+
+                                       current_perm = null;
+
+                                       highlighter.green.play();
+                                       status_update( dojo.string.substitute(ppl_strings.STATUS_DELETED, [old_name]) );
+                               }
+                       });
+
+               }
+       }
+}
+