2020-03-23 14:48:49 +00:00
|
|
|
var _ws = null;
|
2020-04-06 23:17:04 +00:00
|
|
|
var _rootId = "0";
|
2020-03-31 17:10:45 +00:00
|
|
|
var _nextEleId = 0;
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
function set_app_title( suffix, className )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var ele = document.getElementById('appTitleId');
|
|
|
|
ele.innerHTML = "UI Test:" + suffix
|
|
|
|
ele.className = className
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uiOnError( msg, r)
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
console.log("Error:" + msg);
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uiGetParent( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
parent_ele = document.getElementById(r.parent_id);
|
|
|
|
|
|
|
|
if( parent_ele == null )
|
|
|
|
{
|
|
|
|
uiOnError("Parent not found. parent_id:" + r.parent_id,r);
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
return parent_ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uiCreateEle( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var parent_ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uiRemoveChildren( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
ele = document.getElementById(r.ele_id)
|
|
|
|
|
|
|
|
while (ele.firstChild)
|
|
|
|
{
|
|
|
|
ele.removeChild(ele.firstChild);
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uiDivCreate( r )
|
|
|
|
{ uiCreateEle(r) }
|
|
|
|
|
|
|
|
function uiLabelCreate( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uiSelectCreate( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
uiCreateEle(r)
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
2020-04-06 23:17:04 +00:00
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
function uiSelectClear( r )
|
|
|
|
{ uiRemoveChildren(r) }
|
|
|
|
|
|
|
|
function uiSelectInsert( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uiSelectChoose( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var select_ele;
|
|
|
|
|
|
|
|
if((select_ele = uiGetParent(r)) != null )
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
if( select_ele.hasChildNodes())
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiOnSelectClick( ele )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
cmdstr = "mode ui ele_type select op choose parent_id "+ele.parentElement.id+" option_id " + ele.id
|
|
|
|
websocket.send(cmdstr);
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function uiNumberOnKeyUp( e )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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);
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uiNumberCreate( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uiNumberSet( r )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
console.log("ele_id:" + r.ele_id + " parent_id:" + r.parent_id + " value:" + r.value)
|
|
|
|
|
|
|
|
if((ele = document.getElementById(r.parent_id)) != null)
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function dom_child_by_id( parentEle, child_id )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var childrenL = parentEle.children
|
|
|
|
for(var i=0; i<childrenL.length; i++)
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
if( childrenL[i].id == child_id )
|
|
|
|
{
|
|
|
|
return childrenL[i];
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
2020-04-06 23:17:04 +00:00
|
|
|
return null;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dom_set_option_by_text( ele_id, text )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
function dom_set_number( ele_id, val )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
dom_id_to_ele(ele_id).value = val
|
2020-03-31 17:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
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-04-06 23:17:04 +00:00
|
|
|
ele = document.createElement(ele_type);
|
|
|
|
return ele
|
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 )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
console.log("Error: " + msg )
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
function ui_send_value( ele, typeId, value )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
ws_send("value " + ele.id + " " + typeId + " : " + value)
|
2020-03-31 17:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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); }
|
2020-04-24 14:20:25 +00:00
|
|
|
function ui_send_float_value( ele, value ) { ui_send_value(ele,'f',value); }
|
2020-03-31 17:10:45 +00:00
|
|
|
function ui_send_string_value( ele, value ) { ui_send_value(ele,'s',value); }
|
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
function ui_send_echo( ele )
|
|
|
|
{
|
|
|
|
ws_send("echo " + ele.id )
|
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
function ui_print_children( eleId )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var childrenL = dom_id_to_ele(eleId).children
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
for(var i=0; i<childrenL.length; i++)
|
|
|
|
{
|
|
|
|
console.log( childrenL[i] )
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_get_parent( parentId )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
if( parentId==null || parentId.trim().length == 0 )
|
|
|
|
parentId = _rootId
|
|
|
|
|
|
|
|
parent_ele = dom_id_to_ele(parentId);
|
|
|
|
|
|
|
|
if( parent_ele == null )
|
|
|
|
{
|
|
|
|
ui_error("Parent element id: " + parentId + " not found.")
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
return parent_ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
function ui_create_ele( parent_ele, ele_type, d, dfltClassName )
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
// create the ctl object
|
|
|
|
var ele = dom_create_ele(ele_type);
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( ele == null )
|
|
|
|
ui_error(ele_type +" element create failed.");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ele.id = d.uuId;
|
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
if(d.hasOwnProperty('className') )
|
|
|
|
ele.className = d.className;
|
|
|
|
else
|
|
|
|
ele.className = dfltClassName;
|
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if(d.hasOwnProperty('appId'))
|
|
|
|
ele.appId = d.appId;
|
|
|
|
else
|
|
|
|
ele.appId = null;
|
2020-04-24 14:20:25 +00:00
|
|
|
|
|
|
|
//console.log("Created: " + ele_type + " parent:" + d.parentUuId + " id:" + ele.id + " appId:" + ele.appId)
|
2020-04-06 23:17:04 +00:00
|
|
|
|
|
|
|
parent_ele.appendChild(ele);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return ele
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
function ui_create_ctl( parent_ele, ele_type, label, d, dfltEleClassName )
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
// create an enclosing div
|
|
|
|
var div_ele = dom_create_ele("div");
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
div_ele.className = dfltEleClassName + "Div"
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
parent_ele.appendChild( div_ele );
|
|
|
|
|
|
|
|
var label_ele = div_ele
|
|
|
|
|
|
|
|
// if label is not null then create an enclosing 'label' element
|
|
|
|
if( label != null )
|
|
|
|
{
|
|
|
|
label_ele = dom_create_ele("label");
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
label_ele.innerHTML = label;
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
div_ele.appendChild(label_ele)
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
return ui_create_ele( label_ele, ele_type, d, dfltEleClassName );
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
function ui_set_class_name( ele, d, dfltClassName )
|
|
|
|
{
|
|
|
|
if( d.hasOwnProperty("className") )
|
|
|
|
ele.className = d.className;
|
|
|
|
else
|
|
|
|
ele.className = dfltClassName
|
|
|
|
|
|
|
|
return ele
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
function ui_create_div( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var div_ele = ui_create_ele( parent_ele, "div", d, "uiDiv" );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( div_ele != null )
|
|
|
|
{
|
|
|
|
var p_ele = dom_create_ele("p")
|
|
|
|
|
|
|
|
if( d.title != null && d.title.length > 0 )
|
|
|
|
p_ele.innerHTML = d.title
|
|
|
|
|
|
|
|
div_ele.appendChild( p_ele )
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
return div_ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_title( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
return ui_create_ele( parent_ele, "label", d, "uiTitle" );
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_button( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var ele = ui_create_ctl( parent_ele, "button", null, d, "uiButton" );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.innerHTML = d.title;
|
|
|
|
ele.onclick = function() { ui_send_int_value(this,1); }
|
|
|
|
}
|
|
|
|
|
|
|
|
return ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_check( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var ele = ui_create_ctl( parent_ele, "input", d.title, d, "uiCheck" )
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.type = "checkbox";
|
|
|
|
|
|
|
|
dom_set_checkbox(ele.id, d.value );
|
|
|
|
|
|
|
|
ele.onclick = function() { ui_send_bool_value(this,dom_get_checkbox(this.id)); }
|
|
|
|
}
|
|
|
|
return ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_on_select( ele )
|
|
|
|
{
|
2020-04-06 23:17:04 +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 )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var sel_ele = ui_create_ctl( parent_ele, "select", d.title, d, "uiSelect" );
|
2020-04-06 23:17:04 +00:00
|
|
|
sel_ele.onchange = function() { ui_on_select(this) }
|
|
|
|
return sel_ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_option( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var opt_ele = ui_create_ele( parent_ele, "option", d, "uiOption" );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( opt_ele != null )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
opt_ele.className = d.className;
|
2020-04-06 23:17:04 +00:00
|
|
|
opt_ele.innerHTML = d.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
return opt_ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_string( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var ele = ui_create_ctl( parent_ele, "input", d.title, d, "uiString" );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.value = d.value;
|
|
|
|
ele.addEventListener('keyup', function(e) { if(e.keyCode===13){ ui_send_string_value(this, this.value); }} );
|
|
|
|
}
|
2020-04-24 14:20:25 +00:00
|
|
|
|
|
|
|
return ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_number_keyup( e )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
if( e.keyCode===13 )
|
2020-03-31 17:10:45 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var ele = dom_id_to_ele(e.target.id)
|
|
|
|
|
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
console.log("min:"+ele.minValue+" max:"+ele.maxValue)
|
|
|
|
|
|
|
|
var val = 0;
|
|
|
|
if( ele.decpl == 0 )
|
|
|
|
val = Number.parseInt(ele.value)
|
|
|
|
else
|
|
|
|
val = Number.parseFloat(ele.value)
|
2020-04-24 14:20:25 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( !(ele.minValue<=val && val<=ele.maxValue))
|
|
|
|
ele.style.borderColor = "red"
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ele.style.borderColor = ""
|
2020-04-24 14:20:25 +00:00
|
|
|
|
|
|
|
if( ele.decpl == 0 )
|
|
|
|
{
|
|
|
|
ui_send_int_value(ele,ele.value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui_send_float_value(ele,ele.value);
|
|
|
|
}
|
2020-04-06 23:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_number( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var ele = ui_create_ctl( parent_ele, "input", d.title, d, "uiNumber" );
|
2020-04-06 23:17:04 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
return ele;
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_set_progress( ele_id, value )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var ele = dom_id_to_ele(ele_id);
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
ele.value = Math.round( ele.max * (value - ele.minValue) / (ele.maxValue - ele.minValue));
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_create_progress( parent_ele, d )
|
|
|
|
{
|
2020-04-24 14:20:25 +00:00
|
|
|
var ele = ui_create_ctl( parent_ele, "progress", d.title, d, "uiProgress" );
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( ele != null )
|
2020-03-31 17:10:45 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
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
|
|
|
}
|
2020-04-06 23:17:04 +00:00
|
|
|
return ele
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
function ui_set_value( d )
|
|
|
|
{
|
|
|
|
console.log(d)
|
|
|
|
var ele = dom_id_to_ele(d.uuId.toString())
|
|
|
|
|
|
|
|
if( ele == null )
|
|
|
|
console.log("ele not found");
|
|
|
|
else
|
|
|
|
if( !ele.hasOwnProperty("uiEleType") )
|
|
|
|
console.log("No type");
|
|
|
|
|
|
|
|
if( ele != null && ele.hasOwnProperty("uiEleType"))
|
|
|
|
{
|
|
|
|
console.log("found: "+ele.uiEleType)
|
|
|
|
|
|
|
|
switch( ele.uiEleType )
|
|
|
|
{
|
|
|
|
case "div":
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "title":
|
|
|
|
ele.innerHTML = d.value
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "button":
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "check":
|
|
|
|
console.log(d)
|
|
|
|
dom_set_checkbox(ele.id,d.value)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "select":
|
|
|
|
ele.selectedIndex = d.value
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "option":
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "string":
|
|
|
|
ele.value = d.value
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "number":
|
|
|
|
ele.value = d.value
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "progress":
|
|
|
|
ele.value = d.value
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ui_error("Unknown UI element type: " + d.type )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
function ui_create( d )
|
2020-03-31 17:10:45 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
if( typeof(d.parentUuId) == "number")
|
|
|
|
d.parentUuId = d.parentUuId.toString()
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
if( typeof(d.uuId) == "number" )
|
|
|
|
d.uuId = d.uuId.toString()
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
|
|
|
|
var parent_ele = ui_get_parent(d.parentUuId);
|
|
|
|
var ele = null;
|
|
|
|
|
|
|
|
if( parent_ele != null )
|
|
|
|
{
|
|
|
|
switch( d.type )
|
|
|
|
{
|
|
|
|
case "div":
|
|
|
|
ele = ui_create_div( parent_ele, d )
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "title":
|
|
|
|
ele = ui_create_title( parent_ele, d )
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "button":
|
|
|
|
ele = ui_create_button( parent_ele, d )
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "check":
|
|
|
|
ele = ui_create_check( parent_ele, d )
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "select":
|
|
|
|
ele = ui_create_select( parent_ele, d );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "option":
|
|
|
|
ele = ui_create_option( parent_ele, d );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "string":
|
|
|
|
ele = ui_create_string( parent_ele, d );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "number":
|
|
|
|
ele = ui_create_number( parent_ele, d );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "progress":
|
|
|
|
ele = ui_create_progress( parent_ele, d );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ui_error("Unknown UI element type: " + d.type )
|
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
if( ele != null )
|
|
|
|
{
|
|
|
|
ele.uiEleType = d.type;
|
|
|
|
ui_send_echo(ele);
|
|
|
|
}
|
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
}
|
2020-03-31 17:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
function ws_send( s )
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
//console.log(s)
|
|
|
|
|
|
|
|
_ws.send(s+"\0")
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ws_on_msg( jsonMsg )
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
//console.log(jsonMsg)
|
|
|
|
|
|
|
|
d = JSON.parse(jsonMsg.data);
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
switch( d.op )
|
2020-03-23 14:48:49 +00:00
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
case 'create':
|
|
|
|
ui_create( d )
|
|
|
|
break;
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-24 14:20:25 +00:00
|
|
|
case 'value':
|
|
|
|
ui_set_value( d )
|
|
|
|
break;
|
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
default:
|
|
|
|
ui_error("Unknown UI operation. " + d.op )
|
|
|
|
}
|
2020-03-23 14:48:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_on_open()
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
set_app_title( "Connected", "title_connected" );
|
|
|
|
_ws.send("init")
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ws_on_close()
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
set_app_title( "Disconnected", "title_disconnected" );
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:10:45 +00:00
|
|
|
function ws_form_url(urlSuffix)
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
var pcol;
|
|
|
|
var u = document.URL;
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
pcol = "ws://";
|
|
|
|
if (u.substring(0, 4) === "http")
|
|
|
|
u = u.substr(7);
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
u = u.split("/");
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
return pcol + u[0] + "/" + urlSuffix;
|
2020-03-31 17:10:45 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
function main()
|
|
|
|
{
|
2020-04-06 23:17:04 +00:00
|
|
|
rootEle = dom_id_to_ele(_rootId);
|
|
|
|
rootEle.uuId = 0;
|
|
|
|
rootEle.id = _nextEleId;
|
|
|
|
_nextEleId += 1;
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
//console.log(ws_form_url(""))
|
|
|
|
|
|
|
|
_ws = new WebSocket(ws_form_url(""),"ui_protocol")
|
|
|
|
|
|
|
|
_ws.onmessage = ws_on_msg
|
|
|
|
_ws.onopen = ws_on_open
|
|
|
|
_ws.onclose = ws_on_close;
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|