finally using our definitions to translate entity type & properties

This commit is contained in:
Steffen Vogel 2011-03-07 17:31:28 +01:00
parent f22838c84d
commit c4c34308d3
5 changed files with 60 additions and 55 deletions

View file

@ -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&uuml;r ' + this.title,
width: 450,
width: 480,
resizable: false
});
};
@ -74,24 +64,43 @@ Entity.prototype.getDOM = function() {
var data = $('<tbody>');
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 = '<span style="background-color: ' + this[property] + '">' + this[property] + '</span>';
case 'type':
var title = 'Typ';
var value = this.definition.translation[vz.options.language];
break;
case 'uuid':
var title = 'UUID';
var value = '<a href="' + vz.options.backendUrl + '/entity/' + this[property] + '.json">' + this[property] + '</a>';
break;
case 'color':
var title = 'Farbe';
var value = '<span style="background-color: ' + this[property] + '">' + this[property] + '</span>';
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($('<tr>')
.append($('<td>')
.addClass('key')
.text(property)
.text(title)
)
.append($('<td>')
.addClass('value')

View file

@ -305,7 +305,7 @@ vz.entities.show = function() {
.addClass((entity.type == 'group') ? 'group' : 'channel')
)
)
.append($('<td>').text(entity.type)) // channel type
.append($('<td>').text(vz.capabilities.definitions.get('entities', entity.type).translation[vz.options.language])) // channel type
.append($('<td>').addClass('min')) // min
.append($('<td>').addClass('max')) // max
.append($('<td>').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];
}
}
}

View file

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

View file

@ -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

View file

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