partkeepr

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

commit f3c64c7d57512ffb9e0a762caec64566c19f3795
parent 19c32e424b634d68389ca857e79187ebbe20667c
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 21 Sep 2015 16:49:40 +0200

Added methods to retrieve and set associations

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js | 54++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js @@ -27,5 +27,56 @@ Ext.define("PartKeepr.data.HydraModel", { } return data; + }, + /** + * Returns data from all associations + * + * @return {Object} An object containing the associations as properties + */ + getAssociationData: function () + { + var roleName, values = [], role, item, store; + + for (roleName in this.associations) { + role = this.associations[roleName]; + item = role.getAssociatedItem(this); + if (!item || item.$gathering) { + continue; + } + + var getterName = this.associations[roleName].getterName; + + if (item.isStore) { + store = this[getterName](); + values[roleName] = store.getData().items; + } else { + values[roleName] = this[getterName](); + } + } + + return values; + }, + /** + * Sets data to all associations + * + * @param {Object} data The associations to set. Silently ignores non-existant associations. + */ + setAssociationData: function (data) + { + var setterName, getterName, roleName, store; + + for (roleName in data) { + if (this.associations[roleName]) { + + if (this.associations[roleName].isMany === true) { + getterName = this.associations[roleName].getterName; + store = this[getterName](); + store.add(data[roleName]); + } else { + setterName = this.associations[roleName].setterName; + this[setterName](data[roleName]); + } + } + } } -});- \ No newline at end of file +});