diff --git a/htdocs/frontend/javascripts/entity.js b/htdocs/frontend/javascripts/entity.js index 0825a29..e790b63 100644 --- a/htdocs/frontend/javascripts/entity.js +++ b/htdocs/frontend/javascripts/entity.js @@ -29,25 +29,15 @@ * @todo add validation */ var Entity = function(json) { - for (var i in json) { - switch(i) { - case 'children': - this.children = new Array; - this.children.each = vz.entities.each; - for (var j = 0; j < json.children.length; j++) { - var child = new Entity(json.children[j]); - this.children.push(child); - } - break; - - case 'type': - case 'uuid': - default: // properties - this[i] = json[i]; - } + $.extend(true, this, json); + + if (this.children) { + for (var i in this.children) { + this.children[i] = new Entity(this.children[i]); + } } - //this.definition = vz.definitions.get('entity', this.type); + this.definition = vz.capabilities.definitions.get('entities', this.type); }; /** @@ -59,7 +49,7 @@ Entity.prototype.showDetails = function() { .append(this.getDOM()) .dialog({ title: 'Details für ' + this.title, - width: 450, + width: 480, resizable: false }); }; @@ -74,24 +64,43 @@ Entity.prototype.getDOM = function() { var data = $(''); for (var property in this) { - if (this.hasOwnProperty(property) && property != 'data' && property != 'children') { + if (this.hasOwnProperty(property) && !['data', 'definition', 'children'].contains(property)) { switch(property) { - case 'color': - var value = '' + this[property] + ''; + case 'type': + var title = 'Typ'; + var value = this.definition.translation[vz.options.language]; + break; + + case 'uuid': + var title = 'UUID'; + var value = '' + this[property] + ''; break; + case 'color': + var title = 'Farbe'; + var value = '' + this[property] + ''; + break; + + case 'public': + var title = vz.capabilities.definitions.get('properties', property).translation[vz.options.language]; + var value = (this[property]) ? 'ja' : 'nein'; + break; + + case 'active': - var value = (this[property]) ? 'yes' : 'no'; + var title = 'Aktiv'; + var value = (this[property]) ? 'ja' : 'nein'; break; default: + var title = vz.capabilities.definitions.get('properties', property).translation[vz.options.language]; var value = this[property]; } data.append($('') .append($('') .addClass('key') - .text(property) + .text(title) ) .append($('') .addClass('value') diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index f8f5d0f..3eb7b93 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -305,7 +305,7 @@ vz.entities.show = function() { .addClass((entity.type == 'group') ? 'group' : 'channel') ) ) - .append($('').text(entity.type)) // channel type + .append($('').text(vz.capabilities.definitions.get('entities', entity.type).translation[vz.options.language])) // channel type .append($('').addClass('min')) // min .append($('').addClass('max')) // max .append($('').addClass('average')) // avg @@ -493,33 +493,26 @@ vz.parseUrlParams = function() { }; /** - * Load definitions from backend + * Load capabilities from backend */ -vz.definitions.load = function() { +vz.capabilities.load = function() { $.ajax({ cache: true, dataType: 'json', - url: vz.options.backendUrl + '/capabilities/definition/entity.json', + url: vz.options.backendUrl + '/capabilities/definitions.json', success: function(json) { - vz.definitions.entity = json.definition.entity - } - }); - - $.ajax({ - cache: true, - dataType: 'json', - url: vz.options.backendUrl + '/capabilities/definition/property.json', - success: function(json) { - vz.definitions.property = json.definition.property + $.extend(true, vz.capabilities, json.capabilities); + + // load entity details & properties + vz.entities.loadDetails(); } }); }; -vz.definitions.get = function(section, iname) { - for (var i in vz.definitions[section]) { - alert(vz.definitions[section][i].name); - if (vz.definitions[section][i].name == iname) { - return definition; +vz.capabilities.definitions.get = function(section, name) { + for (var i in this[section]) { + if (this[section][i].name == name) { + return this[section][i]; } } } diff --git a/htdocs/frontend/javascripts/init.js b/htdocs/frontend/javascripts/init.js index 81e3ded..d7b062b 100644 --- a/htdocs/frontend/javascripts/init.js +++ b/htdocs/frontend/javascripts/init.js @@ -42,9 +42,10 @@ var vz = { // flot instance plot: { }, - // definitions of entities & properties - // for validation, translation etc.. - definitions: { }, + // debugging and runtime information from backend + capabilities: { + definitions: { } // definitions of entities & properties + }, // options loaded from cookies in options.js options: { } @@ -59,11 +60,9 @@ $(document).ready(function() { vz.drawPlot(); }); - // parse uuids & options from cookie - vz.definitions.load(); - vz.uuids.load(); - vz.options.load(); - vz.parseUrlParams(); + vz.uuids.load(); // load uuids from cookie + vz.options.load(); // load options from cookie + vz.parseUrlParams(); // parse additional url params (new uuid etc..) // initialize user interface vz.wui.init(); @@ -74,6 +73,8 @@ $(document).ready(function() { $('#entity-add').dialog('open'); } - // load entity details & properties - vz.entities.loadDetails(); + // starting with request to backend: + // capabiltities -> entities -> data + // try to follow the callbacks ;) + vz.capabilities.load(); // load properties, entity types and other capabilities from backend }); diff --git a/htdocs/frontend/javascripts/options.js b/htdocs/frontend/javascripts/options.js index f396ba7..3529ef2 100644 --- a/htdocs/frontend/javascripts/options.js +++ b/htdocs/frontend/javascripts/options.js @@ -29,7 +29,7 @@ vz.options = { language: 'de', backendUrl: '../backend.php', tuples: 300, - precission: 2, + precission: 2, // gets updated via backend render: 'lines', refresh: false, defaultInterval: 24*60*60*1000, // 1 day diff --git a/lib/Controller/CapabilitiesController.php b/lib/Controller/CapabilitiesController.php index 1fa8443..80183a8 100644 --- a/lib/Controller/CapabilitiesController.php +++ b/lib/Controller/CapabilitiesController.php @@ -65,7 +65,9 @@ class CapabilitiesController extends Controller { } if (is_null($section) || $section == 'definitions') { - $this->view->setCaching('expires', time()+2*7*24*60*60); // cache for 2 weeks + if (!is_null($section)) { // only caching when we doesn't request dynamic informations + $this->view->setCaching('expires', time()+2*7*24*60*60); // cache for 2 weeks + } $capabilities['definitions']['entities'] = \Volkszaehler\Definition\EntityDefinition::getJSON(); $capabilities['definitions']['properties'] = \Volkszaehler\Definition\PropertyDefinition::getJSON(); @@ -75,7 +77,7 @@ class CapabilitiesController extends Controller { throw new \Exception('Invalid capability identifier!'); } - return $capabilities; + return array('capabilities' => $capabilities); } }