$(document).ready(function() {
performTranslation();
var oldEffects = [];
var cpcolor = '#B500FF';
var mappingList = serverSchema.properties.color.properties.imageToLedMappingType.enum;
//create html
createTable('ssthead', 'sstbody', 'sstcont');
$('.ssthead').html(createTableRow([$.i18n('remote_input_origin'), $.i18n('remote_input_owner'), $.i18n('remote_input_priority'), $.i18n('remote_input_status')], true, true));
createTable('crthead', 'crtbody', 'adjust_content', true);
//create introduction
if(showOptHelp)
{
createHint("intro", $.i18n('remote_color_intro', $.i18n('remote_losthint')), "color_intro");
createHint("intro", $.i18n('remote_input_intro', $.i18n('remote_losthint')), "sstcont");
createHint("intro", $.i18n('remote_adjustment_intro', $.i18n('remote_losthint')), "adjust_content");
createHint("intro", $.i18n('remote_components_intro', $.i18n('remote_losthint')), "comp_intro");
createHint("intro", $.i18n('remote_maptype_intro', $.i18n('remote_losthint')), "maptype_intro");
}
//color adjustment
var sColor = sortProperties(serverSchema.properties.color.properties.channelAdjustment.items.properties)
var values = serverInfo.info.adjustment[0]
for(key in sColor)
{
if(sColor[key].key != "id" && sColor[key].key != "leds")
{
var title = '';
var property;
var value = values[sColor[key].key]
if(sColor[key].type == "array")
{
property = '
';
$('.crtbody').append(createTableRow([title, property], false, true));
createCP('cr_'+sColor[key].key, value, function(rgb,hex,e){
requestAdjustment(e.target.id.substr(e.target.id.indexOf("_") + 1), '['+rgb.r+','+rgb.g+','+rgb.b+']');
});
}
else if(sColor[key].type == "boolean")
{
property = '';
$('.crtbody').append(createTableRow([title, property], false, true));
$('#cr_'+sColor[key].key).off().on('change', function(e){
requestAdjustment(e.target.id.substr(e.target.id.indexOf("_") + 1), e.currentTarget.checked);
});
}
else
{
if(sColor[key].key == "brightness" || sColor[key].key == "backlightThreshold")
property = '';
else
property = '';
$('.crtbody').append(createTableRow([title, property], false, true));
$('#cr_'+sColor[key].key).off().on('change', function(e){
requestAdjustment(e.target.id.substr(e.target.id.indexOf("_") + 1), e.currentTarget.value);
});
}
}
}
function updateRemote()
{
if ($('#componentsbutton').length == 0)
{
$(hyperion).off("cmd-serverinfo",updateRemote);
}
else
{
updateInputSelect();
updateLedMapping();
updateComponents();
updateEffectlist();
}
}
function updateInputSelect()
{
$('.sstbody').html("");
var data = "";
var prios = serverInfo.info.priorities
var i;
for(i = 0; i < prios.length; i++)
{
var origin = "not impl";
var ip = "xxx.xxx.xxx.xxx";
var owner = prios[i].owner;
var active = prios[i].active;
var visible = prios[i].visible;
var priority = prios[i].priority;
var compId = prios[i].componentId;
var duration = prios[i].duration_ms/1000;
var btn_type = "default";
var btn_text = $.i18n('remote_input_setsource_btn');
var btn_state = "enabled";
if (active) btn_type = "warning";
if (visible)
{
btn_state = "disabled";
btn_type = "success";
btn_text = $.i18n('remote_input_sourceactiv_btn');
}
if(ip)
origin += '
'+$.i18n('remote_input_ip')+' '+ip+'';
if(compId == "10")
owner = $.i18n('remote_effects_label_effects')+' '+owner;
if(compId == "9")
owner = $.i18n('remote_color_label_color')+' '+'';
if(compId == "7")
owner = $.i18n('general_comp_GRABBER')+': ('+owner+')';
if(compId == "8")
owner = $.i18n('general_comp_V4L')+': ('+owner+')';
if(compId == "6")
owner = $.i18n('general_comp_BOBLIGHTSERVER');
if(compId == "5")
owner = $.i18n('general_comp_UDPLISTENER');
if(owner == "Off")
owner = $.i18n('general_btn_off');
if(duration)
owner += '
'+$.i18n('remote_input_duration')+' '+duration.toFixed(0)+$.i18n('edt_append_s')+'';
var btn = '';
if((compId == "10" || compId == "9") && priority != 254)
btn += '';
if(btn_type != 'default')
$('.sstbody').append(createTableRow([origin, owner, priority, btn], false, true));
}
var btn_auto_color = (serverInfo.info.priorities_autoselect? "btn-success" : "btn-danger");
var btn_auto_state = (serverInfo.info.priorities_autoselect? "disabled" : "enabled");
var btn_auto_text = (serverInfo.info.priorities_autoselect? $.i18n('general_btn_on') : $.i18n('general_btn_off'));
$('#auto_btn').html('');
var max_width=100;
$('.btn_input_selection').each(function() {
if ($(this).innerWidth() > max_width)
max_width = $(this).innerWidth();
});
$('.btn_input_selection').css("min-width",max_width+"px");
}
function updateLedMapping()
{
mapping = serverInfo.info.ledMAppingType;
$('#mappingsbutton').html("");
for(var ix = 0; ix < mappingList.length; ix++)
{
if(mapping == mappingList[ix])
btn_style = 'btn-success';
else
btn_style = 'btn-warning';
$('#mappingsbutton').append('
');
}
}
function updateComponents()
{
components = serverInfo.info.components;
// create buttons
$('#componentsbutton').html("");
for ( idx=0; idx '+$.i18n('general_comp_'+components[idx].name)+'';
$('#componentsbutton').append(d);
}
else // already create, update state
{
setClassByBool( $('#'+comp_btn_id) , components[idx].enabled, "btn-danger", "btn-success" );
setClassByBool( $('#'+comp_btn_id+"_icon"), components[idx].enabled, "fa-stop" , "fa-play" );
$('#'+comp_btn_id).attr("onclick",'requestSetComponentState(\''+comp_name+'\','+(!components[idx].enabled)+')');
}
}
}
function updateEffectlist()
{
var newEffects = serverInfo.info.effects;
if (newEffects.length != oldEffects.length)
{
$('#effect_select').html('');
var usrEffArr = [];
var sysEffArr = [];
for(i = 0; i < newEffects.length; i++) {
var effectName = newEffects[i].name;
if(!/^\:/.test(newEffects[i].file)){
usrEffArr.push(effectName);
}
else{
sysEffArr.push(effectName);
}
}
$('#effect_select').append(createSel(usrEffArr, $.i18n('remote_optgroup_usreffets')));
$('#effect_select').append(createSel(sysEffArr, $.i18n('remote_optgroup_syseffets')));
oldEffects = newEffects;
}
}
// colorpicker and effect
if (getStorage('rmcpcolor') != null)
cpcolor = getStorage('rmcpcolor');
createCP('cp2', cpcolor, function(rgb,hex){
requestSetColor(rgb.r, rgb.g, rgb.b);
$("#effect_select").val("__none__");
setStorage('rmcpcolor', hex);
});
$("#reset_color").off().on("click", function(){
requestPriorityClear();
$("#effect_select").val("__none__");
});
$("#effect_select").off().on("change", function(event) {
efx = $(this).val();
if(efx != "__none__")
{
requestPriorityClear();
$(hyperion).one("cmd-clear", function(event) {
setTimeout(function() {requestPlayEffect(efx)}, 100);
});
}
});
//force first update
updateRemote();
// interval updates
$(hyperion).on("cmd-serverinfo",updateRemote);
removeOverlay();
});