PDA

View Full Version : How to move label action to controller



ssurajita111
20 Oct 2012, 11:05 PM
I want to move a label click action to the js controller (suggested MVC pattern). My piece of code ::
xtype : 'label',
width : 30,
html : '<img src="'+ contextPath+'/resources/images/download-black.png" width="20" height="20" />',
align : 'right',
listeners : {
render : function(component) {
component.getEl().on('click', function(e) {
LandDownloadWin = new Ext.create('COP.view.Landing.SegmentDetails.LandDownloadWin');
LandDownloadWin.showAt(600,300);
});
}
}

vietits
21 Oct 2012, 5:59 PM
You can use fireEvent() to fire a custom event from label component and then catch this event from controller.


xtype : 'label',
width : 30,
html : '<img src="'+ contextPath+'/resources/images/download-black.png" width="20" height="20" />',
align : 'right',
listeners : {
render : function(component) {
component.getEl().on('click', function(e) {
//LandDownloadWin = new Ext.create('COP.view.Landing.SegmentDetails.LandDownloadWin');
//LandDownloadWin.showAt(600,300);
component.fireEvent('click', component); // fire custom event
});
}
}

In controller


init: function(){
this.control({
'.... label': { // label selector
click: function(label){
LandDownloadWin = new Ext.create('COP.view.Landing.SegmentDetails.LandDownloadWin');
LandDownloadWin.showAt(600,300);
}
}
});
}