MORE: convert from permacrud to pcrud -- not as big as it looks -- and move some...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Mar 2010 19:49:03 +0000 (19:49 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Mar 2010 19:49:03 +0000 (19:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15698 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/conify/global/permission/perm_list.html
Open-ILS/web/conify/global/permission/perm_list.js

index fad15ad..6d72ac6 100644 (file)
 
                <script type="text/javascript" src="perm_list.js"></script>
 
-       </head>
-
-       <body class="tundra" id='pagebody'>
-
-               <div dojoType="dijit.layout.LayoutContainer" id="grid_container" jsId="grid_container" orientation="vertical">
-                       <script type="dojo/method">
-<![CDATA[
-                               window.highlighter= {};
-                               window.highlighter.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } );
-                               window.highlighter.red = dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } );
-
-                               window.dirtyStore = [];
-
-                pCRUD.request({
-                    method : 'open-ils.permacrud.search.ppl.atomic',
-                    timeout : 10,
-                    params : [ ses, { id : { "!=" : null } }, { order_by : { ppl : 'code' } } ],
-                    onerror : function (r) { status_update(ppl_strings.ERROR_FETCHING_PERMS) },
-                    oncomplete : function (r) {
-
-                        window._perm_list = r.recv().content();
-                        window._perm_data = ppl.toStoreData( window._perm_list, 'code' );
-                        window.perm_store = new dojo.data.ItemFileWriteStore({ data : window._perm_data });
-
-                           perm_store.onSet = function (item, attr, o, n) {
-                            if (attr == 'ischanged') return;
-                            if (n == o) return;
-                            this.setValue( item, 'ischanged', 1);
-                        };
-
-                                               window.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",
-                                                                                 get : function (row) {
-                                                                                       if (!window.perm_rows) window.perm_rows = [];
-                                                                                       var r = window.perm_data_model.getRow(row);
-                                                                                       if (r) {
-                                                                                               window.perm_rows[row] = new ccs().fromHash(window.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 '<span class="perm_grid_trans_desc_'+row+'"></span>';
-                                                                                       }
-                                                                                       return '';
-                                                                                 }
-                                                                               }
-                                                                       ]
-                                                               ]
+               <script type="dojo/method"><![CDATA[
+                       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 } );
+
+                       var dirtyStore = [];
+                       var perm_rows = [];
+
+            var _perm_list = pCRUD.retrieveAll('ppl');
+            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_data_model = new dojox.grid.data.DojoData({ store: perm_store, query: { code : '*' } });
+
+                       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",
+                                                         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 '<span class="perm_grid_trans_desc_'+row+'"></span>';
+                                                               }
+                                                               return '';
+                                                         }
                                                        }
-                                               ];
-
-                        dojo.addOnUnload( function (event) {
+                                               ]
+                                       ]
+                               }
+                       ];
+
+            dojo.addOnUnload( function (event) {
+
+                perm_store.fetch({
+                    query : { ischanged : 1 },
+                    onItem : function (item, req) { try { if (this.isItem( item )) window.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) {
+                            window.current_perm = dirtyStore[i];
+                            save_perm(true);
+                        }
+                    }
+                }
 
-                            perm_store.fetch({
-                                query : { ischanged : 1 },
-                                onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
-                                scope : perm_store
-                            });
+            });
+]]>
+               </script>
 
-                            if (dirtyStore.length > 0) {
-                                var confirmation = confirm(ppl_strings.CONFIRM_EXIT_PPL);
 
-                                if (confirmation) {
-                                    for (var i in window.dirtyStore) {
-                                        window.current_perm = window.dirtyStore[i];
-                                        save_perm(true);
-                                    }
-                                }
-                            }
+       </head>
 
-                        });
-                    }
-                }).send();
-]]>
-                       </script>
+       <body class="tundra" id='pagebody'>
 
+               <div dojoType="dijit.layout.LayoutContainer" id="grid_container" jsId="grid_container" orientation="vertical">
                        <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>
                            });
     
                        var err = false;
-                           pCRUD.request({
-                           method : 'open-ils.permacrud.create.ppl',
-                               timeout : 10,
-                           params : [ ses, new_fm_obj ],
+                           pCRUD.create(new_fm_objnew_fm_obj, {
                                onerror : function (r) {
                                highlighter.red.play();
                                    status_update( ppl_strings.ERROR_CALLING_METHOD_PPL );
                                err = true;
                                },
-                               oncomplete : function (r) {
-                               var res = r.recv();
-                                   if ( res && res.content() ) {
-                                   var new_item_hash = res.content().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();
-                               } else {
-                                       highlighter.red.play();
-                                   status_update( ppl_strings.ERROR_CREATING_PERMISSION );
-                                       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();
                                }
-                       }).send();
+                       });
 ]]> 
                        </script>
                                </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">
                                        <!--
                                        <script type="dojo/connect" event="onSet" args="item,attr,oldVal,newVal">
                                                                var modified_ppl = new ppl().fromStoreItem( current_perm );
                                                                modified_ppl.isdeleted( 1 );
                        
-                                                               pCRUD.request({
-                                                                       method : 'open-ils.permacrud.delete.ppl',
-                                                                       timeout : 10,
-                                                                       params : [ ses, modified_ppl ],
+                                                               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 res = r.recv();
-                                                                               if ( res && res.content() ) {
-                       
-                                                                                       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]) );
-                                                                               } else {
-                                                                                       highlighter.red.play();
-                                                                                       status_update( dojo.string.substitute(ppl_strings.ERROR_DELETING, [old_name]) );
-                                                                               }
+                                                                               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]) );
                                                                        }
-                                                               }).send();
+                                                               });
                
                                                        }
                                                }
index ad845ca..18c8fce 100644 (file)
@@ -18,6 +18,7 @@
 dojo.require('fieldmapper.AutoIDL');
 dojo.require('fieldmapper.dojoData');
 dojo.require('openils.widget.TranslatorPopup');
+dojo.require('openils.PermaCrud');
 dojo.require('dojo.parser');
 dojo.require('dojo.string');
 dojo.require('dojo.data.ItemFileWriteStore');
@@ -36,7 +37,7 @@ dojo.requireLocalization("openils.conify", "conify");
 var cgi = new CGI();
 var cookieManager = new HTTP.Cookies();
 var ses = cookieManager.read('ses') || cgi.param('ses');
-var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
+var pCRUD = new openils.PermaCrud({authtoken : ses});
 
 var ppl_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
 
@@ -56,26 +57,17 @@ function save_perm () {
        modified_ppl.description( dojo.string.trim( modified_ppl.description() ) );
        modified_ppl.code( dojo.string.trim( modified_ppl.code() ) );
 
-       pCRUD.request({
-               method : 'open-ils.permacrud.update.ppl',
-               timeout : 10,
-               params : [ ses, modified_ppl ],
+       pCRUD.update(modified_ppl, {
                onerror : function (r) {
                        highlighter.red.play();
                        status_update( dojo.string.substitute(ppl_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
                },
                oncomplete : function (r) {
-                       var res = r.recv();
-                       if ( res && res.content() ) {
-                               perm_store.setValue( current_perm, 'ischanged', 0 );
-                               highlighter.green.play();
-                               status_update( dojo.string.substitute(ppl_strings.SUCCESS_SAVE, [perm_store.getValue(current_perm, 'code')]) );
-                       } else {
-                               highlighter.red.play();
-                               status_update( dojo.string.substitute(ppl_strings.ERROR_SAVING_DATA, [perm_store.getValue(current_perm, 'code')]) );
-                       }
-               },
-       }).send();
+                       perm_store.setValue( current_perm, 'ischanged', 0 );
+                       highlighter.green.play();
+                       status_update( dojo.string.substitute(ppl_strings.SUCCESS_SAVE, [perm_store.getValue(current_perm, 'code')]) );
+               }
+       });
 }
 
 function save_them_all (event) {