partkeepr

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

commit ff8041e9e47101de7e121ae8a59dd94bc1ede54c
parent 1af19dc3c08883e45df688da9e718ef1d683afed
Author: Felicitus <felicitus@felicitus.org>
Date:   Tue, 21 Jun 2011 08:56:22 +0200

Added a JsonWriter with support for associations
Diffstat:
Mfrontend/js/PartKeepr.js | 2+-
Afrontend/js/Util/JsonWithAssociationsWriter.js | 26++++++++++++++++++++++++++
Mutil/gen-jsb3-file.php | 2+-
3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/frontend/js/PartKeepr.js b/frontend/js/PartKeepr.js @@ -268,7 +268,7 @@ PartKeepr.getRESTProxy = function (service) { totalProperty : 'response.totalCount' }, writer: { - type: 'json' + type: 'jsonwithassociations' } }; diff --git a/frontend/js/Util/JsonWithAssociationsWriter.js b/frontend/js/Util/JsonWithAssociationsWriter.js @@ -0,0 +1,25 @@ +Ext.define("PartKeepr.JsonWithAssociations", { + extend: 'Ext.data.writer.Json', + alias: 'writer.jsonwithassociations', + + /** + * @cfg {Array} associations Which associations to include. + */ + associations: [], + + getRecordData: function(record) { + var me = this, i, key, subStore, + data = me.callParent(arguments); + + for (i=0;i<me.associations.length;i++) { + key = me.associations[i]; + data[key] = []; + subStore = record[record.associations.getByKey(key).storeName]; + subStore.each(function (subRecord) { + data[key].push(ReConsole.writer.JsonWithAssociations.superclass.getRecordData.call(this, subRecord)); + }, me); + } + + return data; + } +});+ \ No newline at end of file diff --git a/util/gen-jsb3-file.php b/util/gen-jsb3-file.php @@ -86,7 +86,7 @@ foreach ($records as $key => $record) { if (!$bHasRequires) { /* Hardcoded check for i18n, as it isn't a class but a script, and needs to put in front of everything */ - if ($record->getFilename() == "frontend/js/Util/i18n.js" || $record->getFilename() == "frontend/js/PartKeepr.js") { + if ($record->getFilename() == "frontend/js/Util/i18n.js" || $record->getFilename() == "frontend/js/PartKeepr.js" || $record->getFilename() == "frontend/js/Util/JsonWithAssociationsWriter.js") { array_unshift($rootList, $record); } else { $rootList[] = $record;