(function() { window.addEventListener("tizenhwkey", function(ev) { var activePopup = null, page = null, pageId = ""; if (ev.keyName === "back") { activePopup = document.querySelector(".ui-popup-active"); page = document.getElementsByClassName("ui-page-active")[0]; pageId = page ? page.id : ""; if (pageId === "main" && !activePopup) { try { tizen.application.getCurrentApplication().exit(); } catch (ignore) { } } else { window.history.back(); } } }); }()); function parseSitemap(sitemap) { var output = parseWidgets(sitemap.homepage.widgets); document.getElementById("main_text").innerHTML = output; } function parseWidgets(widgets) { var s=""; widgets.forEach( function(wdg) { switch (wdg.type) { case "Frame": s+='
'+wdg.label+""; if (("widgets" in wdg) && wdg.widgets.length >0){ s+=parseWidgets(wdg.widgets); } s+="
"; break; case "Switch": if (wdg.mappings.length === 0) { s+=createElement(wdg.label, wdg.item.name, wdg.item.link, '
'+ ''+ '
'+ '
' ); //
//
// Single Toggle //
//
// //
//
//
// Toggle state //
//
} else if (wdg.mappings.length === 1) { s+=createElement(wdg.label, wdg.item.name, wdg.item.link, ''); } break; case "Slider": var value=0; if (wdg.item.state !== null) { value = wdg.item.state; } s+=createElement(wdg.label, wdg.item.name, wdg.item.link, ''); break; case "Selection": // var items = ''; // wdg.mappings.forEach(function(entry) { // items += '
'; // }); // s+= createElement(wdg.label, // wdg.item.name, // wdg.item.link, // '
'+items+'
'); break; case "Text": s+=createElement(wdg.label,'','',''); break; default: s+="Other
"; break; } }); return s; } function createElement(label, id, link, inner){ var inElement = ''; if (link != '' && id != '' && inner != ''){ inElement='
'+inner+'
'; } return '
'+label+''+inElement+'
'; } function updateToggle(event) { var item = event.target.parentElement.parentElement.getAttribute('data-link'); var value = event.target.checked === true ? "ON" : "OFF"; updateItem(item,value); } function updateSelector(event) { var s=3; return true; } function updateSimple(event) { var item = event.target.parentElement.getAttribute('data-link'); var value = event.target.value; updateItem(item,value); } function updateItem(item,value) { var client = new XMLHttpRequest(); client.open('POST', item, true); client.send(value.toString()); } function loadgui() { var client = new XMLHttpRequest(); client.onreadystatechange = function() { if (this.readyState === 4 && this.status === 200) { var myArr = JSON.parse(this.responseText); parseSitemap(myArr); } }; client.open('GET', 'http://habctrl:8080/rest/sitemaps/default', true); client.send(); }