Thursday, October 27, 2011

ExtJS 4 : add/read Custom Attributes in TreeNode

Add a 'fields' array to the TreePanel:

,fields:[ 'text' , 'customfield']

and add the custom attribute to the node

,root: {
        text: 'Root',
        expanded: true,
        children: [            
            {
                text: 'Administracion General'
                ,customfield:'administracionGeneral'
                ,expanded: true
            }
        ]
    }

modify the listeners and get the custom attribute from record 'rec':

,listeners:{
        itemclick: function(view,rec,item,index,eventObj)
        {
            nodeClickAction = rec.get('customfield');
            alert(nodeClickAction);            
        }
    }


i.e

var tree = new Ext.tree.TreePanel({    
    renderTo: Ext.getBody(),
    height: 300,
    width: 250,
    fields:[ 'text' , 'customfield'],
    title: 'Files',
    listeners:{
        itemclick: function(view,rec,item,index,eventObj)
        {
            nodeClickAction = rec.get('customfield');
            alert(nodeClickAction);            
        }
   }
   ,root: {
        text: 'Root',
        expanded: true,
        children: [            
            {
                text: 'Administracion General'
                ,customfield:'administracionGeneral'
                ,expanded: true
            }
        ]
    }
});


Here is a detailed example: 

#### index.html ####


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

 <head>
  <title>Custom Tree Test</title>
  <!-- ExtJS CSS -->
  <link rel="stylesheet" type="text/css" href="./ext-4.0.7-gpl/resources/css/ext-all.css"/>   
  <!-- SCRIPT -->
  <!-- ExtJS -->   
  <script type="text/javascript" src="./ext-4.0.7-gpl/ext-all.js"></script>   
 </head>
 <body>                  
  <script type="text/javascript">
   Ext.onReady(function(){                   
    var tree3 = new Ext.tree.TreePanel({   
    // title: 'Simple Tree',
    rootVisible : false // hides root
    ,border:false // hides border
    ,fields:[ 'text' , 'onClickAction']
    //,width: 150,
    //height: 150,
    ,listeners:{
     itemclick: function(view,rec,item,index,eventObj)
      {     nodeClickAction = rec.get('onClickAction');                                                     

          alert(nodeClickAction);                                                 
      }
     }
    ,root: {
     text: 'Root',
     expanded: true,
     children: [           
      {
       text: 'Administracion General'
       ,onClickAction:'administracionGeneral'
       ,expanded: true,                             
       children: [
       {
        text: 'Bodegas'
        ,onClickAction : 'bodegaPanelId'
        ,children:[
         {
           text: 'Crear Bodega'
           ,onClickAction : 'crearBodegaPanelId'
           ,leaf: true
         },{
           text: 'Buscar Bodega'
           ,onClickAction : 'buscarBodegaPanelId'
           ,leaf: true                                            }                                                                        

]
         },{
            text: 'Tipos Producto'
            ,onClickAction : 'tipoProductoPanelId'
            ,children:[
             {
              text: 'Crear Tipo Producto'
              ,onClickAction : 'crearTipoProductoPanelId'
              ,leaf: true
            },{
             text: 'Buscar Tipo Producto'
             ,onClickAction : 'buscarTipoProductoPanelId'
             ,leaf: true                                                           }                                                                       
             ]
            },{
              text: 'Tipos Documento'
             ,onClickAction : 'tipoDocumentoPanelId'
             ,children:[
              {
                text: 'Crear Tipo Documento'
                ,onClickAction : 'crearTipoDocumentoPanelId'
                ,leaf: true
              },{

                  text: 'Buscar Tipo Documento'
                  ,onClickAction : 'buscarTipoDocumentoPanelId'
                  ,leaf: true
                                                                }                                                                       
        ]
       }                                                                   
      ]
     }                   
    ]
   }   
  });
                   
                    var west = new Ext.Panel({
                         id : 'westContentPanelId'                   
                        ,title: 'MenĂº Principal'
                        ,layout: 'fit'       
                        ,collapsible: false
                        ,region:'west'
                        ,width: 215
                        ,margins: '5 0 5 5'
                        ,items:[tree3]
                    });                                     
                   
  var viewportz = new Ext.Viewport({
    layout:'fit', // The Viewport renders itself to the document body, and automatically sizes itself to the size of the
    //browser viewport and manages window resizing
    renderTo: 'container',
    layoutConfig:{animate:true}
    ,items:[west]
     });
   });
    </script>   
   
    <div id="container">   
        </div>
   
    </body>
</html>



Reference:
http://www.sencha.com/forum/showthread.php?145512-Tree-node-custom-attributes

Sunday, October 23, 2011

ExtJS 4: Tree node click event

Add a listener to the TreePanel:

listeners:{
        itemclick: function(view,rec,item,index,eventObj)
        {            
            alert(index);           
        }
    }

i.e

var tree = new Ext.tree.TreePanel({    
    store: store,
    renderTo: Ext.getBody(),
    height: 300,
    width: 250,
    title: 'Files',
    listeners:{
        itemclick: function(view,rec,item,index,eventObj)
        {         
            alert(index);         
        }
    }
});


Reference:
http://stackoverflow.com/questions/6094411/handling-itemclick-event-on-tree-panel-extjs-4

Friday, October 21, 2011

Interesting Benckmark of Python Web Servers

CherryPy: URL Routing in App Engine

# main.py
import cherrypy
import wsgiref.handlers


class HelloWorld:
  @cherrypy.expose
  def index(self):
    return "Hello world!"
class GoodDay:
  @cherrypy.expose
  def index(self,num=None):
    reply = "Good Day!"
    if num is not None:
      for x in range(1,int(num)):
        reply += "
Good Day!"
    return (reply)


def main():
  root = HelloWorld()
  root.reply = GoodDay()
  app = cherrypy.tree.mount(root,"/")
  wsgiref.handlers.CGIHandler().run(app)


if __name__ == '__main__':
  main()



Source:
http://appmecha.wordpress.com/2008/10/21/cherrypy-routing-1/

Thursday, October 20, 2011

Simple Ajax with cherrypy and jQuery

Be aware of having installed CherryPy 3.X, that's all.

Source:
http://ginstrom.com/scribbles/2010/03/07/simple-ajax-with-cherrypy-and-jquery/

AS400 : JDBC Driver

Apache Error: Could not bind to address 0.0.0.0:80 on Windows 7

If you get this error when installing apache on windows 7



1. Just continue the installation.
2. When it finish , go to the installation directory i.e "C:\Program Files (x86)\Apache Software Foundation\Apache2.2"
3. Go to the folder "conf" in the installation directory
4. Open the "httpd.conf"
5. Go to the line that has:
Listen 80
6. Add the word "localhost":
Listen localhost:80
7.Save the changes
8. Start the apache services