Skip to content
Snippets Groups Projects
Commit 593f0cad authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

Give more flexibility to create a store and add some protection.

parent 533afd70
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,10 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, {
/**
* @cfg {Ext.data.Store} store the Ext.data.Store that the form should use.
* Mandatory configuration parameters.
* The store has to be defined since the actions rely on it.
*/
store: null,
/**
* Predefined configuration options
*/
......@@ -76,17 +78,14 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, {
this.addFieldToolTipsListeners();
// link the form to the data store
this.store = Ext.StoreMgr.lookup(this.store);
if (this.store) {
this.store = Ext.StoreMgr.lookup(this.store);
this.store.on('exception', this.onStoreException, this);
this.store.on('write', resetForm, this.getForm());
}
// set the default action: create
this.setAction('create');
// Store events listeners
this.store.on('exception', this.onStoreException, this);
// always reset the form after a write
// allow to enter data in a batch mode
this.store.on('write', resetForm, this.getForm());
},
/**
......@@ -118,7 +117,8 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, {
/**
* Handler to perform the current action on the store.
* The current action is set by the setAction method.
* Should not be call directly, except for delete without confirmation.
* Should not be call directly, except for delete without confirmation.
* Raise an error if the store is not defined.
*/
doAction: function () {
......@@ -129,6 +129,10 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, {
return;
}
if (!this.store) {
throw new Error('the store is undefined !!!');
}
switch (this.currentAction) {
case 'create':
......@@ -227,12 +231,10 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, {
this.currentAction = action;
this.currentRecord = record;
this.hardReset();
switch (action) {
case 'create':
this.hardReset();
this.buttonAction.setText(this.textCreate);
break;
......@@ -243,6 +245,7 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, {
case 'duplicate':
this.buttonAction.setText(this.textDuplicate);
this.hardReset();
table = App.getTableName(this.store);
tableId = App.encodeField(table, 'id');
delete record.data[tableId];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment