gnidhi
9 Jan 2012, 1:32 AM
I am trying to build a search ui. On top it has a search bar. Whenever user clicks on trigger button it will reload the page with new search results. This is the code of my view
Ext.define('FV.view.ux.SearchField', {
extend: 'Ext.form.field.Trigger',
alias: 'widget.searchfield',
trigger1Cls: Ext.baseCSSPrefix + 'form-clear-trigger',
trigger2Cls: Ext.baseCSSPrefix + 'form-search-trigger',
hasSearch : false,
paramName : 'query',
initComponent: function(){
this.callParent(arguments);
//this.on('specialkey',this.checkEnterKey, this);
},
afterRender: function(){
this.callParent();
this.triggerEl.item(0).setDisplayed('none');
},
onTriggerClick: function(){
this.application.getController('Feeds').checkEnterKey();
// FV.controller.Feeds.prototype.checkEnterKey(arguments);
FV.view.ux.SearchField.superclass.onTriggerClick.apply(this, arguments);
}
});
I am following MVC architecture. So I want to call my controller's checkEnterkey's function whenever user hits the trigger. Controller:
Ext.define('FV.controller.Feeds', {
extend : 'Ext.app.Controller',
stores : [ 'Feeds', 'Articles' ],
models : [ 'Feed' ],
views : [ 'feed.Add','feed.List','ux.SearchField' ],
refs : [
{
ref : 'searchField',
selector : 'searchfield'
}
],
init : function() {
this.control({
'searchfield' : {
specialkey :this.checkEnterKey
}
});
},
onLaunch : function() {
},
checkEnterKey : function(field, e){
var searchField=this.getSearchField();
var value = searchField.getValue();
console.log("query=" + value);
if (e.getKey() === e.ENTER && !Ext.isEmpty(value)) {
var resultstore = this.getArticlesStore();
var facetquery=[];
var senderpan=Ext.ComponentQuery.query('form[title="SenderName"] checkboxgroup');
var senderchecked=senderpan[0].getChecked();
Ext.Array.each(senderchecked,function(obj){
facetquery.push("senderName:\""+obj.name+"\"");
console.log(obj.name);
});
var topan=Ext.ComponentQuery.query('form[title="To"] checkboxgroup');
var tochecked=topan[0].getChecked();
Ext.Array.each(tochecked,function(obj){
facetquery.push("to:\""+obj.name+"\"");
console.log(obj.name);
});
var folderpan=Ext.ComponentQuery.query('form[title="Folder"] checkboxgroup');
var folderchecked=folderpan[0].getChecked();
Ext.Array.each(folderchecked,function(obj){
facetquery.push("folder:\""+obj.name+"\"");
console.log(obj.name);
});
resultstore.proxy.extraParams = {
q : value,
wt : 'json',
hl : 'on',
fq :facetquery,
// 'hl.fl' : 'description',
'json.nl' : 'arrarr'
};
resultstore.load();
Ext.getCmp('gridid').bindStore(resultstore);
Ext.getCmp('paging').bindStore(resultstore);
}
}
});
I tried with this.getController() in my searchfield view but it gives me error that this.getController is not a function. Then I tried using prototype FV.controller.Feeds.prototype.checkEnterKey then i was not able to refer to my searchfiled, got the following error
this.getSearchField is not a function
I checked the documentation of Ext.form.field.Trigger but I didn't find the trigger event :(
Ext.define('FV.view.ux.SearchField', {
extend: 'Ext.form.field.Trigger',
alias: 'widget.searchfield',
trigger1Cls: Ext.baseCSSPrefix + 'form-clear-trigger',
trigger2Cls: Ext.baseCSSPrefix + 'form-search-trigger',
hasSearch : false,
paramName : 'query',
initComponent: function(){
this.callParent(arguments);
//this.on('specialkey',this.checkEnterKey, this);
},
afterRender: function(){
this.callParent();
this.triggerEl.item(0).setDisplayed('none');
},
onTriggerClick: function(){
this.application.getController('Feeds').checkEnterKey();
// FV.controller.Feeds.prototype.checkEnterKey(arguments);
FV.view.ux.SearchField.superclass.onTriggerClick.apply(this, arguments);
}
});
I am following MVC architecture. So I want to call my controller's checkEnterkey's function whenever user hits the trigger. Controller:
Ext.define('FV.controller.Feeds', {
extend : 'Ext.app.Controller',
stores : [ 'Feeds', 'Articles' ],
models : [ 'Feed' ],
views : [ 'feed.Add','feed.List','ux.SearchField' ],
refs : [
{
ref : 'searchField',
selector : 'searchfield'
}
],
init : function() {
this.control({
'searchfield' : {
specialkey :this.checkEnterKey
}
});
},
onLaunch : function() {
},
checkEnterKey : function(field, e){
var searchField=this.getSearchField();
var value = searchField.getValue();
console.log("query=" + value);
if (e.getKey() === e.ENTER && !Ext.isEmpty(value)) {
var resultstore = this.getArticlesStore();
var facetquery=[];
var senderpan=Ext.ComponentQuery.query('form[title="SenderName"] checkboxgroup');
var senderchecked=senderpan[0].getChecked();
Ext.Array.each(senderchecked,function(obj){
facetquery.push("senderName:\""+obj.name+"\"");
console.log(obj.name);
});
var topan=Ext.ComponentQuery.query('form[title="To"] checkboxgroup');
var tochecked=topan[0].getChecked();
Ext.Array.each(tochecked,function(obj){
facetquery.push("to:\""+obj.name+"\"");
console.log(obj.name);
});
var folderpan=Ext.ComponentQuery.query('form[title="Folder"] checkboxgroup');
var folderchecked=folderpan[0].getChecked();
Ext.Array.each(folderchecked,function(obj){
facetquery.push("folder:\""+obj.name+"\"");
console.log(obj.name);
});
resultstore.proxy.extraParams = {
q : value,
wt : 'json',
hl : 'on',
fq :facetquery,
// 'hl.fl' : 'description',
'json.nl' : 'arrarr'
};
resultstore.load();
Ext.getCmp('gridid').bindStore(resultstore);
Ext.getCmp('paging').bindStore(resultstore);
}
}
});
I tried with this.getController() in my searchfield view but it gives me error that this.getController is not a function. Then I tried using prototype FV.controller.Feeds.prototype.checkEnterKey then i was not able to refer to my searchfiled, got the following error
this.getSearchField is not a function
I checked the documentation of Ext.form.field.Trigger but I didn't find the trigger event :(