NMFord
12 Jan 2012, 12:12 PM
Hey guys,
I am still new to Sencha Touch so I have probably made a rookie error but it is a problem that is driving me up the wall.
In the code below, you can see I have a function that is passed information from the controller and adds a bottom docked toolbar with paging buttons on it. The issue is, every time someone makes a new search or clicks a paging button I am creating a new 'botBar'. How do I write my script to check for an existing botBar and destroy it before making a new one?
Here are the screenshots so you can see the issue, what you see is what happens when the paging buttons are pressed:
http://imgur.com/a/NIYAo#0
Here is the code for the view:
BioGene.views.SearchListView = Ext.extend(Ext.Panel, {
layout: 'fit',
type: 'vbox',
scroll: 'vertical',
readIntoView: function (jsonData,pagingData) {
if (pagingData.next){
this.nextButton = new Ext.Button({
iconCls: 'arrow_right',
iconMask: true,
handler: function () {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'search',
slideDirection: 'left',
query: pagingData.query,
page: pagingData.page+1
});
},
scope: this
});
}
else {
this.nextButton = new Ext.Button({
iconCls: 'arrow_right',
iconMask: false,
scope: this
});
}
if (pagingData.previous){
this.prevButton = new Ext.Button({
iconCls: 'arrow_left',
iconMask: true,
handler: function () {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'search',
slideDirection: 'right',
query: pagingData.query,
page: pagingData.page-1
});
},
scope: this
});
}
else {
this.prevButton = new Ext.Button({
iconCls: 'arrow_right',
iconMask: false,
scope: this
});
}
var botBar = new Ext.Toolbar({
title: pagingData.start+' - '+pagingData.end+' of '+jsonData.count,
defaults: {
ui: 'plain'
},
dock: 'bottom',
layout: 'hbox',
items: [
this.prevButton,
{ xtype: 'spacer' },
this.nextButton
]
});
BioGene.views.searchListView.dockedItems.add(botBar);
//BioGene.views.searchListView.topToolbar.add(nextButton);
BioGene.views.searchListView.doComponentLayout();
},
initComponent: function () {
this.backButton = new Ext.Button({
text: 'Search',
ui: 'normal',
handler: this.onCloseTap,
scope: this
});
this.topToolbar = new Ext.Toolbar({
title: 'Genes',
items: [
//{ xtype: 'spacer' },
this.backButton
]
});
this.dataList = new Ext.List({
id: "dataList",
singleSelect: false,
store: BioGene.stores.geneStore,
onItemDisclosure: function(record, btn, index) {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'search',
query: record.get('gene_symbol')
});
},
itemTpl: '<tpl for="."><b>{gene_symbol}</b><br /><small><span style="color:#505050">{gene_organism}</span></small></tpl>',
scroll: 'vertical'
});
this.items = [this.dataList];
this.dockedItems = [this.topToolbar];
BioGene.views.SearchListView.superclass.initComponent.call(this);
},
onCloseTap: function () {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'index',
slideDirection: 'right'
});
}
});
I am still new to Sencha Touch so I have probably made a rookie error but it is a problem that is driving me up the wall.
In the code below, you can see I have a function that is passed information from the controller and adds a bottom docked toolbar with paging buttons on it. The issue is, every time someone makes a new search or clicks a paging button I am creating a new 'botBar'. How do I write my script to check for an existing botBar and destroy it before making a new one?
Here are the screenshots so you can see the issue, what you see is what happens when the paging buttons are pressed:
http://imgur.com/a/NIYAo#0
Here is the code for the view:
BioGene.views.SearchListView = Ext.extend(Ext.Panel, {
layout: 'fit',
type: 'vbox',
scroll: 'vertical',
readIntoView: function (jsonData,pagingData) {
if (pagingData.next){
this.nextButton = new Ext.Button({
iconCls: 'arrow_right',
iconMask: true,
handler: function () {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'search',
slideDirection: 'left',
query: pagingData.query,
page: pagingData.page+1
});
},
scope: this
});
}
else {
this.nextButton = new Ext.Button({
iconCls: 'arrow_right',
iconMask: false,
scope: this
});
}
if (pagingData.previous){
this.prevButton = new Ext.Button({
iconCls: 'arrow_left',
iconMask: true,
handler: function () {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'search',
slideDirection: 'right',
query: pagingData.query,
page: pagingData.page-1
});
},
scope: this
});
}
else {
this.prevButton = new Ext.Button({
iconCls: 'arrow_right',
iconMask: false,
scope: this
});
}
var botBar = new Ext.Toolbar({
title: pagingData.start+' - '+pagingData.end+' of '+jsonData.count,
defaults: {
ui: 'plain'
},
dock: 'bottom',
layout: 'hbox',
items: [
this.prevButton,
{ xtype: 'spacer' },
this.nextButton
]
});
BioGene.views.searchListView.dockedItems.add(botBar);
//BioGene.views.searchListView.topToolbar.add(nextButton);
BioGene.views.searchListView.doComponentLayout();
},
initComponent: function () {
this.backButton = new Ext.Button({
text: 'Search',
ui: 'normal',
handler: this.onCloseTap,
scope: this
});
this.topToolbar = new Ext.Toolbar({
title: 'Genes',
items: [
//{ xtype: 'spacer' },
this.backButton
]
});
this.dataList = new Ext.List({
id: "dataList",
singleSelect: false,
store: BioGene.stores.geneStore,
onItemDisclosure: function(record, btn, index) {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'search',
query: record.get('gene_symbol')
});
},
itemTpl: '<tpl for="."><b>{gene_symbol}</b><br /><small><span style="color:#505050">{gene_organism}</span></small></tpl>',
scroll: 'vertical'
});
this.items = [this.dataList];
this.dockedItems = [this.topToolbar];
BioGene.views.SearchListView.superclass.initComponent.call(this);
},
onCloseTap: function () {
Ext.dispatch({
controller: BioGene.controllers.bioGeneController,
action: 'index',
slideDirection: 'right'
});
}
});