Hello,
I have a grid panel and a few buttons. What I want to happen is a particular action when the button is pressed related to the panels store.
I got this working just fine when I defined the buttons inside the panel itself:
Code:
initComponent: function(submitButton) {
currentView = this;
orgStatisticsStore = Ext.data.StoreManager.lookup('OrgStatisticsStore');
orgStatisticsProxy = orgStatisticsStore.getProxy();
......
......
items: [
{ xtype: 'component', flex: 1 },
new DMT.view.OrgStatisticsSearchForm(),
{ xtype: 'button', text: 'Submit', width: 80,
initComponent: function() {
submitButton = this;
},
listeners: {
'click': function() {
orgStatisticsStore.on({
scope: currentView,
beforesync: currentView.disableButtons,
write: currentView.submitFinished
});
orgStatisticsProxy.on({
scope: currentView,
exception: currentView.showSubmitError
});
orgStatisticsStore.sync();
}}},
{ xtype: 'button', text: 'Clear', width: 80,
initComponent: function() {
clearButton = this;
},
listeners: {
'click': function() {
currentView.disableButtons();
orgStatisticsStore.removeAll(false);
currentView.enableButtons();
}
}}
Code:
disableButtons: function(){
submitButton.disable(true);
clearButton.disable(true);
},
enableButtons: function(){
submitButton.enable(true);
clearButton.enable(true);
},
submitFinished: function() {
var messageBox = Ext.Msg.show({
title:'DMT Response from',
msg: 'Changes have been successfully sent to',
animateTarget: submitButton,
icon: Ext.Msg.INFO,
closable: false
});
setTimeout(function(){
messageBox.close();
}, 2700);
currentView.enableButtons();
},
showSubmitError: function() {
var errorMessageBox = Ext.Msg.show({
title:'DMT Response from',
msg: 'An error has occured while sending changes.',
animateTarget: submitButton,
icon: Ext.Msg.ERROR,
closable: false
});
setTimeout(function(){
errorMessageBox.close();
}, 2700);
currentView.enableButtons();
},
However, I dont think it is good practice to define these buttons in the grid panel itself, but rather the panel housing the grid panel. I sooner or later want to add a form and additional items and don't want to add it to the grid panel itself.
When I try doing this, I can add the items just fine but am having a very difficult time registering the buttons click listener to do anything to the panels store..... here a combinations of a few ways I tried to get this working, where none of them work...how should this be set up?
//Panel housing grid panel and other components: doesnt work
Code:
var submitButton = mainContentPanel.add(Ext.create('Ext.button.Button', {text: 'Submit', width: 80}));
currentComponentArray[0] = submitButton;
var clearButton = new DMT.view.button.ClearButton()
mainContentPanel.add(clearButton);
currentComponentArray[1] = clearButton;
currentComponent = mainContentPanel.add(Ext.create('DMT.view.OrgStatisticsView', submitButton));
currentComponentArray[2] = currentComponent;
mainContentPanel.setTitle('Organization Statistics Update');
var orgStatisticsStore = Ext.data.StoreManager.lookup('OrgStatisticsStore');
var orgStatisticsProxy = orgStatisticsStore.getProxy();
Ext.apply(submitButton, {
listeners: {
'click': function() {
orgStatisticsStore.on({
scope: currentComponent,
beforesync: currentComponent.disableButtons,
write: currentComponent.submitFinished
});
orgStatisticsProxy.on({
scope: currentComponent,
exception: currentComponent.showSubmitError
});
orgStatisticsStore.sync();
}}
});
//Pass button into panel for reference -- doesnt work tried with initiComponent too....
Code:
constructor: function(submitButton)
{
orgStatisticsStore = Ext.data.StoreManager.lookup('OrgStatisticsStore');
orgStatisticsProxy = orgStatisticsStore.getProxy();
orgStatsSubmitButton = submitButton;
Ext.apply(orgStatsSubmitButton, {
listeners: {
'click': function() {
orgStatisticsStore.on({
scope: currentView,
beforesync: currentView.disableButtons,
write: currentView.submitFinished
});
orgStatisticsProxy.on({
scope: currentView,
exception: currentView.showSubmitError
});
orgStatisticsStore.sync();
}}
});
this.callParent(arguments);
},