New editor test

This commit is contained in:
JonatanRek 2019-09-18 09:39:54 +02:00
parent 73125f70ce
commit 215ffd7fc6

114
test.php
View File

@ -33,11 +33,65 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function foo(element){ function foo(element){
var id = element.attr("name").match(/\d+/)[0]
$("[name='variable["+id+"][value]']").remove();
$("[name='variable["+id+"][equaler]']").remove();
if (element.val() == "atDeviceValue") { if (element.val() == "atDeviceValue") {
var input = $("<input name=''/>"); var arrVarOperator = [
{val : '>', text: '>'},
{val : '<', text: '<'},
];
var varOperator = $('<select name="variable['+id+'][equaler]">');
$(arrVarOperator).each(function() {
varOperator.append($('<option>').attr('value',this.val).text(this.text));
});
element.parent().append(varOperator);
var input = $("<input/>");
input.attr("type","text"); input.attr("type","text");
input.attr("name",element.attr("name")); input.attr("name","variable["+id+"][value]");
element.parent().append(input); element.parent().append(input);
} else if (element.val() == "time") {
var arrVarOperator = [
{val : '>', text: '>'},
{val : '<', text: '<'},
];
var varOperator = $('<select name="variable['+id+'][equaler]">');
$(arrVarOperator).each(function() {
varOperator.append($('<option>').attr('value',this.val).text(this.text));
});
element.parent().append(varOperator);
var input = $("<input/>");
input.attr("type","time");
input.attr("name","variable["+id+"][value]");
element.parent().append(input);
}else {
var arrVarOperator = [
{val : '=', text: '=='},
{val : '!=', text: '!='},
];
var varOperator = $('<select name="variable['+id+'][equaler]">');
$(arrVarOperator).each(function() {
varOperator.append($('<option>').attr('value',this.val).text(this.text));
});
element.parent().append(varOperator);
var arrVarValue = [
{val : 'true', text: 'True'},
{val : 'false', text: 'False'},
];
var varValue = $('<select name="variable['+id+'][value]">');
$(arrVarValue).each(function() {
varValue.append($('<option>').attr('value',this.val).text(this.text));
});
element.parent().append(varValue);
} }
} }
$("#addButton,#restartAddButton").click( function (event) { $("#addButton,#restartAddButton").click( function (event) {
@ -55,45 +109,45 @@ $("#addButton,#restartAddButton").click( function (event) {
{val : 'someOneHome', text: 'Nekdo Doma'}, {val : 'someOneHome', text: 'Nekdo Doma'},
]; ];
var varSelect = $('<select name="variable['+numItems+'][]">'); var varSelect = $('<select name="variable['+numItems+'][what]">');
$(arrVarSelect).each(function() { $(arrVarSelect).each(function() {
varSelect.append($('<option>').attr('value',this.val).text(this.text)); varSelect.append($('<option>').attr('value',this.val).text(this.text));
}); });
varSelect.attr("onchange", "foo($(this))"); varSelect.attr("onchange", "foo($(this))");
/*onchange = function(e) { /*onchange = function(e) {
console.log(this.value); console.log(this.value);
if (this.value == 'atDeviceValue') { if (this.value == 'atDeviceValue') {
alert("ok"); alert("ok");
} }
};*/ };*/
var arrVarOperator = [ var arrVarOperator = [
{val : '>', text: '>'}, {val : '>', text: '>'},
{val : '<', text: '<'}, {val : '<', text: '<'},
{val : '=', text: '=='}, {val : '=', text: '=='},
{val : '!=', text: '!='}, {val : '!=', text: '!='},
]; ];
var varOperator = $('<select name="variable['+numItems+'][]">'); var varOperator = $('<select name="variable['+numItems+'][equaler]">');
$(arrVarOperator).each(function() { $(arrVarOperator).each(function() {
varOperator.append($('<option>').attr('value',this.val).text(this.text)); varOperator.append($('<option>').attr('value',this.val).text(this.text));
}); });
var arrVarValue = [ var arrVarValue = [
{val : 'true', text: 'True'}, {val : 'true', text: 'True'},
{val : 'false', text: 'False'}, {val : 'false', text: 'False'},
]; ];
var varValue = $('<select name="variable['+numItems+'][]">'); var varValue = $('<select name="variable['+numItems+'][value]">');
$(arrVarValue).each(function() { $(arrVarValue).each(function() {
varValue.append($('<option>').attr('value',this.val).text(this.text)); varValue.append($('<option>').attr('value',this.val).text(this.text));
}); });
var newDiv = $("<div class=var>").append(varSelect); var newDiv = $("<div class=var>").append(varSelect);
newDiv = newDiv.append(varOperator); newDiv = newDiv.append(varOperator);
newDiv = newDiv.append(varValue); newDiv = newDiv.append(varValue);
$(this).parent().append(newDiv); $(this).parent().append(newDiv);
}); });