From 2deadf5ca64c2f28c60fdaecbc4e552e1ceed7d9 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 3 Jul 2011 21:32:10 +0200 Subject: [PATCH] added children to middleware response for public entities (fixes #87 again) --- htdocs/frontend/javascripts/init.js | 10 +++---- htdocs/frontend/javascripts/wui.js | 4 +-- lib/View/JSON.php | 42 +++++------------------------ 3 files changed, 13 insertions(+), 43 deletions(-) diff --git a/htdocs/frontend/javascripts/init.js b/htdocs/frontend/javascripts/init.js index 608bc44..fb9c41a 100644 --- a/htdocs/frontend/javascripts/init.js +++ b/htdocs/frontend/javascripts/init.js @@ -74,14 +74,10 @@ $(document).ready(function() { vz.entities.loadCookie(); // load uuids from cookie vz.options.loadCookies(); // load options from cookie vz.parseUrlParams(); // parse additional url params (new uuid etc..) - + // initialize user interface vz.wui.init(); vz.wui.initEvents(); - - if (vz.entities.length == 0) { - $('#entity-add').dialog('open'); - } // chaining ajax request with jquery deferred object vz.capabilities.load().done(function() { @@ -95,6 +91,10 @@ $(document).ready(function() { }, true); $.when.apply($, queue).done(function() { + if (vz.entities.length == 0) { + vz.wui.dialogs.init(); + } + vz.entities.showTable(); vz.entities.loadData().done(vz.wui.drawPlot); }); diff --git a/htdocs/frontend/javascripts/wui.js b/htdocs/frontend/javascripts/wui.js index 45a8894..f4c5f79 100644 --- a/htdocs/frontend/javascripts/wui.js +++ b/htdocs/frontend/javascripts/wui.js @@ -114,7 +114,6 @@ vz.wui.dialogs.init = function() { $('#entity-create-middleware').val(vz.middleware[0].url); $('#entity-subscribe-cookie').attr('checked', 'checked'); $('#entity-public-cookie').attr('checked', 'checked'); - // actions $('#entity-subscribe input[type=button]').click(function() { @@ -148,6 +147,7 @@ vz.wui.dialogs.init = function() { try { entity.cookie = Boolean($('#entity-public-cookie').attr('checked')); + entity.middleware = $('#entity-public-middleware option:selected').val(); vz.entities.push(entity); vz.entities.saveCookie(); @@ -167,7 +167,7 @@ vz.wui.dialogs.init = function() { $('#entity-add').dialog('close'); }); - // update event handler + // update event handler after lazy loading $('button[name=entity-add]').unbind('click', this.init); $('button[name=entity-add]').click(function() { $('#entity-add.dialog').dialog('open'); diff --git a/lib/View/JSON.php b/lib/View/JSON.php index 6d3d5c2..1b7ad11 100644 --- a/lib/View/JSON.php +++ b/lib/View/JSON.php @@ -71,7 +71,7 @@ class JSON extends View { $this->addData($data); } elseif ($data instanceof Model\Entity) { - $this->addEntity($data); + $this->json['entity'] = self::convertEntity($entity); } elseif ($data instanceof \Exception) { $this->addException($data); @@ -99,20 +99,6 @@ class JSON extends View { echo $json; } - /** - * Add Entity to output queue - * - * @param Model\Entity $entity - */ - protected function addEntity(Model\Entity $entity) { - if ($entity instanceof Model\Aggregator) { - $this->json['entity'] = self::convertAggregator($entity); - } - else { - $this->json['entity'] = self::convertEntity($entity); - } - } - /** * Converts entity to array for json_encode() * @@ -124,33 +110,17 @@ class JSON extends View { $jsonEntity['uuid'] = (string) $entity->getUuid(); $jsonEntity['type'] = $entity->getType(); - foreach ($entity->getProperties() as $key => $value) { $jsonEntity[$key] = $value; } - - return $jsonEntity; - } - - /** - * Converts aggregator to array for json_encode - * - * @param Model\Aggregator $aggregator - * @return array - */ - protected static function convertAggregator(Model\Aggregator $aggregator) { - $jsonAggregator = self::convertEntity($aggregator); - - foreach ($aggregator->getChildren() as $entity) { - if ($entity instanceof Model\Channel) { - $jsonAggregator['children'][] = self::convertEntity($entity); - } - elseif ($entity instanceof Model\Aggregator) { - $jsonAggregator['children'][] = self::convertAggregator($entity); + + if ($entity instanceof Model\Aggregator) { + foreach ($entity->getChildren() as $child) { + $jsonEntity['children'][] = self::convertEntity($child); } } - return $jsonAggregator; + return $jsonEntity; } /**