var backend = '../backend';
var controller = 'php/channel.php';
var entities;
var properties;
var channels;
$(document).ready(function() {
// get entities from backend
$.getJSON(backend + '/capabilities/definition/entity.json', function(data) {
entities = data.definition.entity;
for (var i in entities) {
$('select, [name=type]').append('');
}
});
// get properties from backend
$.getJSON(backend + '/capabilities/definition/property.json', function(data) {
properties = data.definition.property;
});
// get channels from controller
$.getJSON(controller, showChannels);
$('select').change(function(event) { showEntityForm(event.target.value); });
});
function showEntityForm(type) {
$('#properties').empty();
var type = getDefinition(entities, type);
for (var i in type.optional) {
var property = getDefinition(properties, type.optional[i]);
if (property) {
var input = getPropertyForm(property);
$('#properties').append('
' + input + '
')
}
}
}
function deleteChannel(uuid) {
$.get(controller, {operation: 'delete', uuid: uuid}, function(data) {
})
}
function addChannel() {
}
function addChannelBackend(channel, backendUrl) {
}
function addChannelController(uuid) {
}
function getDefinition(definition, type) {
for (var i in definition) {
if (definition[i].name == type) {
return definition[i];
}
}
}
function getPropertyForm(property) {
var input;
switch (property.type) {
case 'string':
case 'float':
case 'integer':
input = '';
break;
case 'text':
input = '';
break;
case 'boolean':
input = '';
case 'multiple':
for (var k in property.options) {
options.push('