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

Wednesday, October 19, 2011

Blogger: change the case of existing Labels


1. Log in to Blogger, and go to the Posting > Edit Posts tab.
2. Select all the posts with the label you want to change (eg "fred"), by clicking on this Label in the left-hand panel, and then clicking Select All.
3. Use the Label Action... drop-down menu (just above the list of posts) to: 
4. Give them a new temporary label that's not already in use (eg "xxx-temp") - when you have done this, they will all have at least two labels.
5. Remove the label that you want to change
6. Select all the posts with the temporary label
7. Give them the label that you want to change to (eg "Fred")
8. Remove the temporary label that you added in the 2nd step.


Source: 

Javascript: simple confirm example

function confirmation() {
var answer = confirm("Leave tizag.com?")
if (answer){
alert("Bye bye!")
window.location = "http://www.google.com/";
}
else{
alert("Thanks for sticking around!")
}
}

Source:
http://www.tizag.com/javascriptT/javascriptconfirm.php

AS400 : Update and Join Sql commands

I searched for a while and I found Nothing. It looks like it is mandatory to use sentences like
UPDATE PROJECT
SET DEPTNO =
       (SELECT WORKDEPT FROM EMPLOYEE
        WHERE PROJECT.RESPEMP = EMPLOYEE.EMPNO)
WHERE RESPEMP='000030'

instead of using sentences with Join command :(

Note: If you find another way to do this, please let me know :) 


References: 
http://www2.systeminetwork.com/resources/clubtech/TNT400/bo400ng/sqlupdatejoin.htm
http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/QB3AQ802/5.2 
http://www.experts-exchange.com/Database/DB2/Q_22535124.html

Tuesday, October 11, 2011

MSSQL Concat string


SELECT FirstName + ' ' + LastName As FullName FROM Customers
Source:
http://www.sqlbook.com/SQL/SQL-CONCATENATE-24.aspx

MSSQL: UNION in query

SELECT * FROM Table1
UNION
SELECT * FROM Table2

Note: the items called in the select sentence have to be the same quantity 

Source:
http://msdn.microsoft.com/es-es/library/ms191141.aspx