Wednesday, May 15, 2013

DOJO Combobox On Enter Key Event

Below code can be used to setup a event to fire when a enter key is pressed inside combobox.

1:  require([  
2:  "dojo/ready", "dojo/store/JsonRest", "dijit/form/ComboBox", "dojox/storage", "dojo/request", "dojo/json"  
3:  ], function(ready, JsonRest, ComboBox, storage, request, json)  
4:    
5:  {   
6:      var comboBox = new ComboBox(  
7:      {  
8:         id: "IdCombo",  
9:         name: "NameCombo",  
10:         placeholder: "Enter text",     
11:      }, "placesomewhereid");  
12:    
13:      comboBox.startup();     
14:        
15:      require(["dojo/on", "dijit/focus", "dojo/keys", "dojo/domReady!"], function(on, focusUtil, keys)  
16:      {  
17:          on(document, "keyup", function(event)  
18:          {  
19:             if(event.keyCode == keys.ENTER && focusUtil.curNode.id == "IdCombo")  
20:             {  
21:                 //Write code here that needs to run when enter key is pressed  
22:             }        
23:          });  
24:      });  
25:  });  

Monday, May 13, 2013

Creating autocomplete text box in DOJO

Using DOJO combobox, you can create a autocomplete functionality. Below code creates a programmatic combobox and assigns a json store to combobox. A declarative input form element is used a placeholder on page.

1:  <script type="text/javascript">   
2:  require([  
3:  "dojo/ready", "dojo/store/JsonRest", "dijit/form/ComboBox"], function(ready, JsonRest, ComboBox)  
4:  {    
5:    var jsonStore = new JsonRest  
6:     ({  
7:        target: "URL for Ajax service"  
8:     });  
9:     var comboBox = new ComboBox(  
10:     {  
11:        id: "SomeUniqueID",  
12:        name: "SomeUniqueName",  
13:        value: "",  
14:        store: jsonStore,  
15:        pageSize: 3,  
16:        searchAttr: "key",  
17:        queryExpr: "${0}"  
18:     }, "StoreItemSelect");  
19:    comboBox.startup();   
20:  });   
21:  </script>  
22:  <body>  
23:     <input id="StoreItemSelect"/>  
24:  <body>  

The AJAX service should return items in below json format

 [{key: "Autocomplete value 1"},{key: "Autocomplete value 2"},{key: "Autocomplete value 3"}]  

Friday, May 10, 2013

Dojo TabContainer Tab select ContentPane reload

The usual way to implement a TabContainer is to define a ContentPane as tab childs. When a tab is selected and if you want the ContentPane to reload everytime the tab is selected then you need to specify the refreshOnShow property of ContentPane to true.

 var tc = new TabContainer(  
 {  
     style: "height: 100%; width: 100%;"  
 }, "tc1-prog");  
  var cp2 = new ContentPane(  
 {  
     title: "First Tab",  
     href: "page1.html",      
  });  
  tc.addChild(cp2);  
  var cp2 = new ContentPane({  
     title: "Second Tab",  
     href: "page2.html",   
     refreshOnShow: true     
  });  
  tc.addChild(cp2);    


In this case when "Second Tab" is selected, it refreshes every time. Refresh basically calls the dojo ready function on the page same as when loading the page using F5. "First tab" on the other hand will only load the first time its selected and will not refresh in later selects

Wednesday, April 17, 2013

Using dojo.place to add row to TableContainer

-- Assume you have a table container defined declaratively

                                                     
                                                       
 


To add a new row to this table container pro grammatically using dojo.place

dojo.place('
',"tb","first");

Tuesday, November 20, 2012

Why E-Commerce Applications Should Embrace Cloud?

Today is day before Thanksgiving and Express (a clothing brand) just sent an email to all its members about its exciting sale offer (50% of entire items). This is their once chance of the year to bring in shoppers to make good revenue. If only they could keep the site up..... If I was part of their engineering lead,  I would bring all engineers to the drawing table and rethink scalability and availability from ground up.





Saturday, July 21, 2012

Android: Set up automated backups

I am great fan of rsync backup Android app and use it a lot to sync files from/to Android with my home server. Combined with the Tasker app its a great way to automate the sync on a daily/weekly basis. This blog post lists the step by step instructions on how to setup rsync backup and Tasker to create automated backups.

Sunday, June 03, 2012

A smarter way to calculate distinct counts

I was recently writing a pig script to calculate distinct count over three fields on a big set of data and was getting an out of memory error on the reducer. The data types of these three fields are strings and The issue was the single reducer usage to calculate the distinct count. I couldn't figure out a way around the single reducer and instead used the below approach

Approach throwing the OOM error


A = LOAD '$inp' using PigStorage('\t');
H = FOREACH A GENERATE $1,$3,$23;
uq_pid = DISTINCT H parallel 20;
guq_pid = GROUP uq_pid ALL;
itr_uq_pid = foreach guq_pid {
    generate COUNT_STAR(uq_pid);
}
store itr_uq_pid into '$otp/uq_metric';


Modified approach using a constant


A = LOAD '$inp' using PigStorage('\t');
pid = FOREACH A GENERATE $1,$3,$23,1;
uq_pid = DISTINCT pid parallel 20;
constant_uq_pid = FOREACH uq_pid GENERATE $3;
guq_pid = GROUP constant_uq_pid BY $0;
itr_uq_pid = foreach guq_pid {
    generate COUNT_STAR(constant_uq_pid);
}
store itr_uq_pid into '$otp/uq_metric';