added children to middleware response for public entities (fixes #87 again)

This commit is contained in:
Steffen Vogel 2011-07-03 21:32:10 +02:00
parent fef62d4134
commit 2deadf5ca6
3 changed files with 13 additions and 43 deletions

View file

@ -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);
});

View file

@ -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');

View file

@ -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;
}
/**