partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit d0db3f36ede5c547a270553f89495ef428e9a88b
parent 9533df73128bff4f18064a56b349659709bb4f17
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri,  4 Sep 2015 18:53:55 +0200

Added association support for updateRecord as well

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.form.Basic-AssociationSupport.js | 50+++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.form.Basic-AssociationSupport.js b/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.form.Basic-AssociationSupport.js @@ -17,5 +17,53 @@ Ext.define("PartKeepr.form.Basic", { } return this.setValues(values); - } + }, + /** + * Persists the values in this form into the passed {@link Ext.data.Model} object in a beginEdit/endEdit block. + * If the record is not specified, it will attempt to update (if it exists) the record provided to loadRecord. + * @param {Ext.data.Model} [record] The record to edit + * @return {Ext.form.Basic} this + */ + updateRecord: function(record) { + record = record || this._record; + if (!record) { + //<debug> + Ext.raise("A record is required."); + //</debug> + return this; + } + + var fields = record.self.fields, + values = this.getFieldValues(), + obj = {}, + associations = {}, + i = 0, + len = fields.length, + name; + + for (; i < len; ++i) { + name = fields[i].name; + + if (values.hasOwnProperty(name)) { + if (record.hasField(name)) { + obj[name] = values[name]; + } else { + associations[name] = values[name]; + } + } + } + + record.beginEdit(); + record.set(obj); + + for (i in associations) { + if (record.associations[i]) { + var setterName = record.associations[i].setterName; + record[setterName](associations[i]); + } + } + record.endEdit(); + + return this; + }, }); \ No newline at end of file