Skip to content
Snippets Groups Projects
Commit de0872fa authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Replace this by me in App.form.Panel.

parent 887ef28a
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* It contains field widget for the database table fields and * It contains field widget for the database table fields and
* two buttons *Action* and *Reset*. * two buttons *Action* and *Reset*.
* *
* The store attribute is equal the table name when the widget * The store attribute is equal to the table name when the widget
* is configured. It is replaced by an App.data.DirectStore * is configured. It is replaced by an App.data.DirectStore
* in the initialization phase of the component. * in the initialization phase of the component.
* *
...@@ -100,28 +100,29 @@ Ext.define('App.form.Panel', { ...@@ -100,28 +100,29 @@ Ext.define('App.form.Panel', {
// private method require by the ExtJs component model // private method require by the ExtJs component model
initComponent: function () { initComponent: function () {
var toolbar; var me = this,
toolbar;
// initialise the base class // initialise the base class
this.callParent(arguments); me.callParent(arguments);
// short cuts // short cuts
toolbar = this.getDockedItems()[0]; toolbar = me.getDockedItems()[0];
this.buttonAction = toolbar.getComponent('buttonAction'); me.buttonAction = toolbar.getComponent('buttonAction');
this.buttonReset = toolbar.getComponent('buttonReset'); me.buttonReset = toolbar.getComponent('buttonReset');
// button events listeners // button events listeners
this.buttonAction.on('click', this.doAction, this); me.buttonAction.on('click', me.doAction, me);
this.buttonReset.on('click', this.softReset, this); me.buttonReset.on('click', me.softReset, me);
// link the form to the data store // link the form to the data store
this.store = App.getStore(this.store); me.store = App.getStore(me.store);
this.store.getProxy().on('exception', this.onProxyException, this); me.store.getProxy().on('exception', me.onProxyException, me);
this.store.on('write', this.softReset, this); me.store.on('write', me.softReset, me);
// set the default action: create // set the default action: create
this.setAction('create'); me.setAction('create');
this.buttonReset.setText(this.textReset); me.buttonReset.setText(me.textReset);
}, },
/** /**
...@@ -134,29 +135,33 @@ Ext.define('App.form.Panel', { ...@@ -134,29 +135,33 @@ Ext.define('App.form.Panel', {
"use strict"; "use strict";
var me = this;
// add the new record after the selected one // add the new record after the selected one
if (this.currentIndex !== undefined) { if (me.currentIndex !== undefined) {
this.store.insert(this.currentIndex + 1, record); me.store.insert(me.currentIndex + 1, record);
// add the new record at the end of the store // add the new record at the end of the store
} else { } else {
this.store.add(record); me.store.add(record);
} }
// reset the index // reset the index
this.currentIndex = undefined; me.currentIndex = undefined;
}, },
// private method required by the ExtJS component model // private method required by the ExtJS component model
beforeDestroy: function () { beforeDestroy: function () {
this.buttonAction.un('click', this.doAction, this); var me = this;
this.buttonReset.un('click', this.softReset, this);
me.buttonAction.un('click', me.doAction, me);
me.buttonReset.un('click', me.softReset, me);
this.store.getProxy().un('exception', this.onProxyException, this); me.store.getProxy().un('exception', me.onProxyException, me);
this.store.un('write', this.softReset, this); me.store.un('write', me.softReset, me);
this.callParent(arguments); me.callParent(arguments);
}, },
/** /**
...@@ -167,7 +172,8 @@ Ext.define('App.form.Panel', { ...@@ -167,7 +172,8 @@ Ext.define('App.form.Panel', {
"use strict"; "use strict";
var fields = this.getForm().getFields(); var me = this,
fields = me.getForm().getFields();
fields.each(function (field) { fields.each(function (field) {
field.setDisabled(bool); field.setDisabled(bool);
...@@ -186,46 +192,47 @@ Ext.define('App.form.Panel', { ...@@ -186,46 +192,47 @@ Ext.define('App.form.Panel', {
"use strict"; "use strict";
var form = this.getForm(), var me = this,
model = this.store.getProxy().getModel(), form = me.getForm(),
model = me.store.getProxy().getModel(),
newRecord; newRecord;
// No action on non-valid form except destroy // No action on non-valid form except destroy
if (this.currantAction !== 'destroy' && !form.isValid()) { if (me.currantAction !== 'destroy' && !form.isValid()) {
return; return;
} }
if (!this.store) { if (!me.store) {
throw new Error(this.textStoreError); throw new Error(me.textStoreError);
} }
switch (this.currentAction) { switch (me.currentAction) {
case 'create': case 'create':
newRecord = model.create(); newRecord = model.create();
this.updateRecord(newRecord); me.updateRecord(newRecord);
this.addRecord(newRecord); me.addRecord(newRecord);
break; break;
case 'destroy': case 'destroy':
this.store.remove(this.currentRecord); me.store.remove(me.currentRecord);
break; break;
case 'duplicate': case 'duplicate':
newRecord = model.create(); newRecord = model.create();
this.updateRecord(newRecord); me.updateRecord(newRecord);
this.addRecord(newRecord); me.addRecord(newRecord);
break; break;
case 'update': case 'update':
this.currentRecord.beginEdit(); me.currentRecord.beginEdit();
this.updateRecord(this.currentRecord); me.updateRecord(me.currentRecord);
this.currentRecord.endEdit(); me.currentRecord.endEdit();
break; break;
} }
if (!this.store.autoSync) { if (!me.store.autoSync) {
this.store.sync(); me.store.sync();
} }
}, },
...@@ -243,13 +250,14 @@ Ext.define('App.form.Panel', { ...@@ -243,13 +250,14 @@ Ext.define('App.form.Panel', {
"use strict"; "use strict";
var errors, var me = this,
errors,
key, key,
msg = ""; msg = "";
// invalid response from the server, HTPP 400, 500 // invalid response from the server, HTPP 400, 500
if (response instanceof Ext.direct.ExceptionEvent) { if (response instanceof Ext.direct.ExceptionEvent) {
Ext.Msg.alert(this.textError, response.xhr.responseText); Ext.Msg.alert(me.textError, response.xhr.responseText);
return; return;
} }
...@@ -273,7 +281,7 @@ Ext.define('App.form.Panel', { ...@@ -273,7 +281,7 @@ Ext.define('App.form.Panel', {
} }
} }
Ext.Msg.alert(this.textError, msg); Ext.Msg.alert(me.textError, msg);
return; return;
} }
} }
...@@ -292,17 +300,18 @@ Ext.define('App.form.Panel', { ...@@ -292,17 +300,18 @@ Ext.define('App.form.Panel', {
"use strict"; "use strict";
var form = this.getForm(), var me = this,
form = me.getForm(),
table, table,
tableId; tableId;
this.buttonReset.show(); me.buttonReset.show();
this.buttonAction.show(); me.buttonAction.show();
this.disableFields(false); me.disableFields(false);
this.currentAction = action; me.currentAction = action;
this.currentRecord = record; me.currentRecord = record;
// force orginalValues to be equal to the load data // force orginalValues to be equal to the load data
// this is required by the softReset method. // this is required by the softReset method.
...@@ -311,33 +320,33 @@ Ext.define('App.form.Panel', { ...@@ -311,33 +320,33 @@ Ext.define('App.form.Panel', {
switch (action) { switch (action) {
case 'create': case 'create':
this.buttonAction.setText(this.textCreate); me.buttonAction.setText(me.textCreate);
// load an empty record filled with default values // load an empty record filled with default values
record = this.store.getProxy().getModel().create(); record = me.store.getProxy().getModel().create();
form.loadRecord(record); form.loadRecord(record);
break; break;
case 'destroy': case 'destroy':
this.buttonAction.setText(this.textDestroy); me.buttonAction.setText(me.textDestroy);
form.loadRecord(record); form.loadRecord(record);
break; break;
case 'duplicate': case 'duplicate':
this.buttonAction.setText(this.textDuplicate); me.buttonAction.setText(me.textDuplicate);
form.loadRecord(record); form.loadRecord(record);
break; break;
case 'update': case 'update':
this.buttonAction.setText(this.textUpdate); me.buttonAction.setText(me.textUpdate);
form.loadRecord(record); form.loadRecord(record);
break; break;
case 'view': case 'view':
this.buttonReset.hide(); me.buttonReset.hide();
this.buttonAction.hide(); me.buttonAction.hide();
form.loadRecord(record); form.loadRecord(record);
this.disableFields(true); me.disableFields(true);
break; break;
} }
}, },
...@@ -349,8 +358,9 @@ Ext.define('App.form.Panel', { ...@@ -349,8 +358,9 @@ Ext.define('App.form.Panel', {
softReset : function () { softReset : function () {
"use strict"; "use strict";
var me = this;
this.getForm().reset(); me.getForm().reset();
}, },
/** /**
...@@ -361,7 +371,8 @@ Ext.define('App.form.Panel', { ...@@ -361,7 +371,8 @@ Ext.define('App.form.Panel', {
"use strict"; "use strict";
var combo, var me = this,
combo,
containers, containers,
fields, fields,
rec, rec,
...@@ -375,14 +386,14 @@ Ext.define('App.form.Panel', { ...@@ -375,14 +386,14 @@ Ext.define('App.form.Panel', {
// including those encapsulated in complexe field container // including those encapsulated in complexe field container
// which encapsulated grid with cell editing... // which encapsulated grid with cell editing...
// //
fields = this.query('> field'); fields = me.query('> field');
fields = Ext.Array.merge(fields, this.query('fieldset > field')); fields = Ext.Array.merge(fields, me.query('fieldset > field'));
// get the list of field container: // get the list of field container:
// those at the first level and those encapsulated in fieldset // those at the first level and those encapsulated in fieldset
containers = this.query('> fieldcontainer'); containers = me.query('> fieldcontainer');
containers = Ext.Array.merge(containers, this.query('fieldset > fieldcontainer')); containers = Ext.Array.merge(containers, me.query('fieldset > fieldcontainer'));
// container handles two type of object: // container handles two type of object:
// - composite field merging several standard field // - composite field merging several standard field
......
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