2020-03-23 14:48:49 +00:00
|
|
|
var _ws = null;
|
2020-03-31 17:10:45 +00:00
|
|
|
var _rootJsId = "uiDivId";
|
|
|
|
var _nextEleId = 0;
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
function set_app_title( suffix, className )
|
|
|
|
{
|
|
|
|
var ele = document.getElementById('appTitleId');
|
|
|
|
ele.innerHTML = "UI Test:" + suffix
|
|
|
|
ele.className = className
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uiOnError( msg, r)
|
|
|
|
{
|
|
|
|
console.log("Error:" + msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiGetParent( r )
|
|
|
|
{
|
|
|
|
parent_ele = document.getElementById(r.parent_id);
|
|
|
|
|
|
|
|
if( parent_ele == null )
|
|
|
|
{
|
|
|
|
uiOnError("Parent not found. parent_id:" + r.parent_id,r);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent_ele;
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiCreateEle( r )
|
|
|
|
{
|
|
|
|
var parent_ele;
|
|
|
|
|
|
|
|
if((parent_ele = uiGetParent(r)) != null )
|
|
|
|
{
|
|
|
|
ele = document.createElement(r.ele_type)
|
|
|
|
ele.id = r.ele_id;
|
|
|
|
ele.className = r.value;
|
|
|
|
|
|
|
|
parent_ele.appendChild(ele)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiRemoveChildren( r )
|
|
|
|
{
|
|
|
|
ele = document.getElementById(r.ele_id)
|
|
|
|
|
|
|
|
while (ele.firstChild)
|
|
|
|
{
|
|
|
|
ele.removeChild(ele.firstChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiDivCreate( r )
|
|
|
|
{ uiCreateEle(r) }
|
|
|
|
|
|
|
|
function uiLabelCreate( r )
|
|
|
|
{
|
|
|
|
var parent_ele;
|
|
|
|
|
|
|
|
if((parent_ele = uiGetParent(r)) != null )
|
|
|
|
{
|
|
|
|
ele = document.createElement("label")
|
|
|
|
ele.htmlFor = r.ele_id
|
|
|
|
ele.innerHTML = r.value;
|
|
|
|
parent_ele.appendChild(ele)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiSelectCreate( r )
|
|
|
|
{
|
|
|
|
uiCreateEle(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiSelectClear( r )
|
|
|
|
{ uiRemoveChildren(r) }
|
|
|
|
|
|
|
|
function uiSelectInsert( r )
|
|
|
|
{
|
|
|
|
var select_ele;
|
|
|
|
|
|
|
|
if((select_ele = uiGetParent(r)) != null )
|
|
|
|
{
|
|
|
|
var option = document.createElement('option');
|
|
|
|
|
|
|
|
option.id = r.ele_id;
|
|
|
|
option.innerHTML = r.value;
|
|
|
|
option.value = r.ele_id;
|
|
|
|
option.onclick = function() { uiOnSelectClick(this) }
|
|
|
|
|
|
|
|
select_ele.appendChild(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiSelectChoose( r )
|
|
|
|
{
|
|
|
|
var select_ele;
|
|
|
|
|
|
|
|
if((select_ele = uiGetParent(r)) != null )
|
|
|
|
{
|
|
|
|
if( select_ele.hasChildNodes())
|
|
|
|
{
|
|
|
|
var children = select_ele.childNodes
|
|
|
|
for(var i=0; i<children.length; i++)
|
|
|
|
{
|
|
|
|
if( children[i].id == r.ele_id )
|
|
|
|
{
|
|
|
|
select_ele.selectedIndex = i
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiOnSelectClick( ele )
|
|
|
|
{
|
|
|
|
cmdstr = "mode ui ele_type select op choose parent_id "+ele.parentElement.id+" option_id " + ele.id
|
|
|
|
websocket.send(cmdstr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiNumberOnKeyUp( e )
|
|
|
|
{
|
|
|
|
if( e.keyCode == 13 )
|
|
|
|
{
|
|
|
|
//console.log(e)
|
|
|
|
cmdstr = "mode ui ele_type number op change parent_id "+e.srcElement.parentElement.id+" ele_id " + e.srcElement.id + " value " + e.srcElement.value
|
|
|
|
websocket.send(cmdstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uiNumberCreate( r )
|
|
|
|
{
|
|
|
|
var parent_ele;
|
|
|
|
|
|
|
|
if((parent_ele = uiGetParent(r)) != null )
|
|
|
|
{
|
|
|
|
ele = document.createElement("input")
|
|
|
|
ele.id = r.ele_id
|
|
|
|
ele.setAttribute('type','number')
|
|
|
|
ele.addEventListener('keyup',uiNumberOnKeyUp)
|
|
|
|
parent_ele.appendChild(ele)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiNumberSet( r )
|
|
|
|
{
|
|
|
|
var ele;
|
|
|
|
|
|
|
|
console.log("ele_id:" + r.ele_id + " parent_id:" + r.parent_id + " value:" + r.value)
|
|
|
|
|
|
|
|
if((ele = document.getElementById(r.parent_id)) != null)
|
|
|
|
{
|
|
|
|
switch( r.ele_id )
|
|
|
|
{
|
|
|
|
case "0": ele.min = r.value; break;
|
|
|
|
case "1": ele.max = r.value; break;
|
|
|
|
case "2": ele.step = r.value; break;
|
|
|
|
case "3": ele.value = r.value; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function dom_child_by_id( parentEle, child_id )
|
|
|
|
{
|
|
|
|
var childrenL = parentEle.children
|
|
|
|
for(var i=0; i<childrenL.length; i++)
|
|
|
|
{
|
|
|
|
if( childrenL[i].id == child_id )
|
|
|
|
{
|
|
|
|
return childrenL[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dom_set_option_by_text( ele_id, text )
|
|
|
|
{
|
|
|
|
var ele = dom_id_to_ele(ele_id);
|
|
|
|
|
|
|
|
for (var i = 0; i < ele.options.length; i++)
|
|
|
|
{
|
|
|
|
if (ele.options[i].text === text)
|
|
|
|
{
|
|
|
|
ele.selectedIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
function dom_set_number( ele_id, val )
|
|
|
|
{
|
|
|
|
dom_id_to_ele(ele_id).value = val
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
function dom_id_to_ele( id )
|
|
|
|
{ return document.getElementById(id); }
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
function dom_set_checkbox( ele_id, fl )
|
|
|
|
{ dom_id_to_ele(ele_id).checked = fl }
|
|
|
|
|
|
|
|
function dom_get_checkbox( ele_id )
|
|
|
|
{ return dom_id_to_ele(ele_id).checked }
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
function dom_create_ele( ele_type )
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = document.createElement(ele_type);
|
|
|
|
ele.id = _nextEleId;
|
|
|
|
_nextEleId += 1;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
//==============================================================================
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
function ui_error( msg )
|
|
|
|
{
|
|
|
|
console.log("Error: " + msg )
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
function ui_send_value( ele, typeId, value )
|
|
|
|
{
|
|
|
|
if( ele.hasOwnProperty('uuId') )
|
|
|
|
ws_send("value " + ele.uuId + " " + typeId + " : " + value)
|
|
|
|
else
|
|
|
|
ui_error("A value msg send failed because the value had no UuId.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_send_bool_value( ele, value ) { ui_send_value(ele,'b',value); }
|
|
|
|
function ui_send_int_value( ele, value ) { ui_send_value(ele,'i',value); }
|
|
|
|
function ui_send_string_value( ele, value ) { ui_send_value(ele,'s',value); }
|
|
|
|
|
|
|
|
function ui_send_register( ele )
|
|
|
|
{
|
|
|
|
ws_send("register " + ele.parentJsId + " " + ele.jsId + " " + ele.id + " " + ele.uuId + " " + ele.appId )
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
function ui_print_children( eleId )
|
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
var childrenL = dom_id_to_ele(eleId).children
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
for(var i=0; i<childrenL.length; i++)
|
|
|
|
{
|
|
|
|
console.log( childrenL[i] )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_get_parent( parentId )
|
|
|
|
{
|
|
|
|
if( parentId==null || parentId.trim().length == 0 )
|
2020-03-31 17:10:45 +00:00
|
|
|
parentId = _rootJsId
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
parent_ele = dom_id_to_ele(parentId);
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
if( parent_ele == null )
|
|
|
|
{
|
|
|
|
ui_error("Parent element id: " + parentId + " not found.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent_ele;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ui_create_ele( parent_ele, ele_type, d )
|
|
|
|
{
|
|
|
|
// create the ctl object
|
2020-03-31 17:10:45 +00:00
|
|
|
var ele = dom_create_ele(ele_type);
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
if( ele == null )
|
|
|
|
ui_error("'%s' element create failed.", ele_type);
|
|
|
|
else
|
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
ele.jsId = d.jsId;
|
|
|
|
|
|
|
|
ele.parentJsId = d.parentJsId;
|
|
|
|
|
|
|
|
ele.uuId = d.hasOwnProperty("uuId") ? d.uuId : null
|
|
|
|
|
|
|
|
ele.appId = d.hasOwnProperty("appId") ? d.appId : null
|
|
|
|
|
|
|
|
console.log("Created: " + ele_type + " parent:" + d.parentJsId + " id:" + ele.id + " appId:" + ele.appId + " uuId:" + ele.uuId)
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
parent_ele.appendChild(ele);
|
2020-03-31 17:10:45 +00:00
|
|
|
|
|
|
|
ui_send_register( ele );
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
return ele
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_ctl( parent_ele, ele_type, label, d )
|
|
|
|
{
|
|
|
|
// create an enclosing div
|
2020-03-31 17:10:45 +00:00
|
|
|
var div_ele = dom_create_ele("div");
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
div_ele.className = d.clas;
|
|
|
|
|
|
|
|
parent_ele.appendChild( div_ele );
|
|
|
|
|
|
|
|
var label_ele = div_ele
|
|
|
|
|
|
|
|
// if label is not null then create an enclosing 'label' element
|
|
|
|
if( label != null )
|
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
label_ele = dom_create_ele("label");
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
label_ele.innerHTML = label;
|
|
|
|
|
|
|
|
div_ele.appendChild(label_ele)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ui_create_ele( label_ele, ele_type, d );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ui_create_div( parent_ele, d )
|
|
|
|
{
|
|
|
|
var div_ele = ui_create_ele( parent_ele, "div", d );
|
|
|
|
|
|
|
|
if( div_ele != null )
|
|
|
|
{
|
|
|
|
div_ele.className = d.clas
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
var p_ele = dom_create_ele("p")
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
if( d.title != null && d.title.length > 0 )
|
|
|
|
p_ele.innerHTML = d.title
|
|
|
|
|
|
|
|
div_ele.appendChild( p_ele )
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
return div_ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_title( parent_ele, d )
|
|
|
|
{
|
|
|
|
return ui_create_ele( parent_ele, "label", d );
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_button( parent_ele, d )
|
|
|
|
{
|
|
|
|
var ele = ui_create_ctl( parent_ele, "button", null, d );
|
|
|
|
|
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.innerHTML = d.title;
|
2020-03-31 17:10:45 +00:00
|
|
|
ele.onclick = function() { ui_send_int_value(this,1); }
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
return ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_check( parent_ele, d )
|
|
|
|
{
|
|
|
|
var ele = ui_create_ctl( parent_ele, "input", d.title, d )
|
|
|
|
|
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.type = "checkbox";
|
|
|
|
|
|
|
|
dom_set_checkbox(ele.id, d.value );
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
ele.onclick = function() { ui_send_bool_value(this,dom_get_checkbox(this.id)); }
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
return ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_on_select( ele )
|
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
ui_send_int_value(ele,ele.options[ ele.selectedIndex ].appId);
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_select( parent_ele, d )
|
|
|
|
{
|
|
|
|
var sel_ele = ui_create_ctl( parent_ele, "select", d.title, d );
|
|
|
|
sel_ele.onchange = function() { ui_on_select(this) }
|
|
|
|
return sel_ele;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_option( parent_ele, d )
|
|
|
|
{
|
|
|
|
var opt_ele = ui_create_ele( parent_ele, "option", d );
|
|
|
|
|
|
|
|
if( opt_ele != null )
|
|
|
|
{
|
|
|
|
opt_ele.className = d.clas;
|
|
|
|
opt_ele.innerHTML = d.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
return opt_ele;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_string( parent_ele, d )
|
|
|
|
{
|
|
|
|
var ele = ui_create_ctl( parent_ele, "input", d.title, d );
|
|
|
|
|
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.value = d.value;
|
2020-03-31 17:10:45 +00:00
|
|
|
ele.addEventListener('keyup', function(e) { if(e.keyCode===13){ ui_send_string_value(this, this.value); }} );
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_number_keyup( e )
|
|
|
|
{
|
|
|
|
console.log(e)
|
|
|
|
if( e.keyCode===13 )
|
|
|
|
{
|
|
|
|
var ele = dom_id_to_ele(e.target.id)
|
|
|
|
console.log(ele.value)
|
|
|
|
if( ele != null )
|
2020-03-31 17:10:45 +00:00
|
|
|
{
|
|
|
|
ui_send_int_value(ele,ele.value);
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_number( parent_ele, d )
|
|
|
|
{
|
|
|
|
var ele = ui_create_ctl( parent_ele, "input", d.title, d );
|
|
|
|
|
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.value = d.value;
|
|
|
|
ele.maxValue = d.max;
|
|
|
|
ele.minValue = d.min;
|
|
|
|
ele.stepValue = d.step;
|
|
|
|
ele.decpl = d.decpl;
|
|
|
|
ele.addEventListener('keyup', ui_number_keyup );
|
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
return ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_set_progress( ele_id, value )
|
|
|
|
{
|
|
|
|
var ele = dom_id_to_ele(ele_id);
|
|
|
|
|
|
|
|
ele.value = Math.round( ele.max * (value - ele.minValue) / (ele.maxValue - ele.minValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_progress( parent_ele, d )
|
|
|
|
{
|
|
|
|
var ele = ui_create_ctl( parent_ele, "progress", d.title, d );
|
|
|
|
|
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.max = 100;
|
|
|
|
ele.maxValue = d.max;
|
|
|
|
ele.minValue = d.min;
|
|
|
|
ui_set_progress( ele.id, d.value );
|
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
return ele
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ui_create( parentId, ele_type, d )
|
|
|
|
{
|
|
|
|
var parent_ele = ui_get_parent(parentId);
|
2020-03-31 17:10:45 +00:00
|
|
|
var ele = null;
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
if( parent_ele != null )
|
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
d.parentJsId = parentId
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
switch( ele_type )
|
|
|
|
{
|
|
|
|
case "div":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_div( parent_ele, d )
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "title":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_title( parent_ele, d )
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "button":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_button( parent_ele, d )
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "check":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_check( parent_ele, d )
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "select":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_select( parent_ele, d );
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "option":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_option( parent_ele, d );
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "string":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_string( parent_ele, d );
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "number":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_number( parent_ele, d );
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "progress":
|
2020-03-31 17:10:45 +00:00
|
|
|
ele = ui_create_progress( parent_ele, d );
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ui_error("Unknown UI element type: " + ele_type )
|
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
|
|
|
|
if( d.hasOwnProperty("children") )
|
|
|
|
{
|
|
|
|
for (const ele_type in d.children)
|
|
|
|
ui_create( d.jsId, ele_type, d.children[ele_type] )
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
function ui_uuid_to_ele( uuId, ele=null )
|
|
|
|
{
|
|
|
|
if( ele == null )
|
|
|
|
ele = dom_id_to_ele( _rootJsId )
|
|
|
|
|
|
|
|
if( ele.hasOwnProperty('uuId') )
|
|
|
|
{
|
|
|
|
if( ele.uuId == uuId )
|
|
|
|
return ele
|
|
|
|
|
|
|
|
for(var i=0; i<ele.childElementCount; ++i)
|
|
|
|
ui_uuid_to_ele( uuId, ele.children[i] )
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_error("The element with uuid: " + uuId + " was not found.")
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Do breadth first search for ele's without uuId's
|
|
|
|
function ui_next_ele_to_register( parentEle )
|
|
|
|
{
|
|
|
|
for(var i=0; i<parentEle.childElementCount; ++i)
|
|
|
|
{
|
|
|
|
var ele = parentEle.children[i]
|
|
|
|
|
|
|
|
if( ele.hasOwnProperty('uuId') && ele.uuId==null)
|
|
|
|
return ele
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var i=0; i<parentEle.childElementCount; ++i)
|
|
|
|
{
|
|
|
|
var ele = ui_next_ele_to_register( parentEle.children[i])
|
|
|
|
|
|
|
|
if( ele != null )
|
|
|
|
return ele
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
function ui_set_app_uuId( d )
|
|
|
|
{
|
|
|
|
console.log(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ws_send( s )
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
|
|
|
//console.log(s)
|
2020-03-31 17:10:45 +00:00
|
|
|
|
|
|
|
_ws.send(s+"\0")
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ws_on_msg( jsonMsg )
|
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
console.log(jsonMsg)
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
d = JSON.parse(jsonMsg.data);
|
|
|
|
|
|
|
|
switch( d.op )
|
|
|
|
{
|
|
|
|
case 'create':
|
2020-03-24 12:53:42 +00:00
|
|
|
for (const ele_type in d.children)
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
ui_create( d.parent, ele_type, d.children[ele_type] )
|
2020-03-23 14:48:49 +00:00
|
|
|
//console.log(`${ele_type}: ${d.value[ele_type]}`);
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'set_app_id':
|
|
|
|
ui_set_app_uuId(d)
|
2020-03-23 14:48:49 +00:00
|
|
|
break;
|
2020-03-31 17:10:45 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
ui_error("Unknown UI operation. " + d.op )
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_on_open()
|
|
|
|
{
|
|
|
|
set_app_title( "Connected", "title_connected" );
|
|
|
|
_ws.send("init")
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_on_close()
|
|
|
|
{
|
|
|
|
set_app_title( "Disconnected", "title_disconnected" );
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
function ws_form_url(urlSuffix)
|
|
|
|
{
|
|
|
|
var pcol;
|
|
|
|
var u = document.URL;
|
|
|
|
|
|
|
|
pcol = "ws://";
|
|
|
|
if (u.substring(0, 4) === "http")
|
|
|
|
u = u.substr(7);
|
|
|
|
|
|
|
|
u = u.split("/");
|
|
|
|
|
|
|
|
return pcol + u[0] + "/" + urlSuffix;
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
function main()
|
|
|
|
{
|
2020-03-31 17:10:45 +00:00
|
|
|
rootEle = dom_id_to_ele(_rootJsId);
|
|
|
|
rootEle.uuId = 0;
|
|
|
|
rootEle.id = _nextEleId;
|
|
|
|
_nextEleId += 1;
|
|
|
|
|
|
|
|
console.log(ws_form_url(""))
|
|
|
|
|
|
|
|
_ws = new WebSocket(ws_form_url(""),"ui_protocol")
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
_ws.onmessage = ws_on_msg
|
|
|
|
_ws.onopen = ws_on_open
|
2020-03-31 17:10:45 +00:00
|
|
|
_ws.onclose = ws_on_close;
|
|
|
|
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|