Ext.define('Ext.form.Panel', {
extend:'Ext.panel.Panel',
mixins: {
fieldAncestor: 'Ext.form.FieldAncestor'
},
alias: 'widget.form',
alternateClassName: ['Ext.FormPanel', 'Ext.form.FormPanel'],
requires: ['Ext.form.Basic', 'Ext.util.TaskRunner'],
layout: 'anchor',
ariaRole: 'form',
basicFormConfigs: [
'api',
'baseParams',
'errorReader',
'method',
'paramOrder',
'paramsAsHash',
'reader',
'standardSubmit',
'timeout',
'trackResetOnLoad',
'url',
'waitMsgTarget',
'waitTitle'
],
initComponent: function() {
var me = this;
if (me.frame) {
me.border = false;
}
me.initFieldAncestor();
me.callParent();
me.relayEvents(me.form, [
'beforeaction',
'actionfailed',
'actioncomplete',
'validitychange',
'dirtychange'
]);
if (me.pollForChanges) {
me.startPolling(me.pollInterval || 500);
}
},
initItems: function() {
var me = this;
me.form = me.createForm();
me.callParent();
},
afterFirstLayout: function() {
this.callParent();
this.form.initialize();
},
createForm: function() {
var cfg = {},
props = this.basicFormConfigs,
len = props.length,
i = 0,
prop;
for (; i < len; ++i) {
prop = props[i];
cfg[prop] = this[prop];
}
return new Ext.form.Basic(this, cfg);
},
getForm: function() {
return this.form;
},
loadRecord: function(record) {
return this.getForm().loadRecord(record);
},
getRecord: function() {
return this.getForm().getRecord();
},
getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) {
return this.getForm().getValues(asString, dirtyOnly, includeEmptyText, useDataValues);
},
beforeDestroy: function() {
this.stopPolling();
this.form.destroy();
this.callParent();
},
load: function(options) {
this.form.load(options);
},
submit: function(options) {
this.form.submit(options);
},
startPolling: function(interval) {
this.stopPolling();
var task = new Ext.util.TaskRunner(interval);
task.start({
interval: 0,
run: this.checkChange,
scope: this
});
this.pollTask = task;
},
stopPolling: function() {
var task = this.pollTask;
if (task) {
task.stopAll();
delete this.pollTask;
}
},
checkChange: function() {
var fields = this.form.getFields().items,
f,
fLen = fields.length,
field;
for (f = 0; f < fLen; f++) {
fields[f].checkChange();
}
}
});