htd-lync
Version:
This library is meant to be used to interact with an HTD Lync 12
257 lines (218 loc) • 7.08 kB
JavaScript
function goToSystemSettingsPage() {
hidePages();
$("#SystemSettingsPage").show();
createPresetControlList(Ggroup);
var html = '<div class="back-btn"><</div><h2>System Settings</h2>';
$('#pageName').html(html)
//makeGroupDropDown(Ggroup);
$(".back-btn").on("click", function() {
console.log("last page:" + lastPage)
if (lastPage == "doorbell") {
lastPage = "systemSettings";
localStorage.setItem("lastPage", lastPage);
goToSystemSettingsPage();
return;
}
lastPage = "home";
localStorage.setItem("lastPage", lastPage);
goToHomePage();
});
if (firmware == "v3") {
$('#doorbellSettingsLink').show();
} else {
$('#doorbellSettingsLink').hide();
}
loadSystemSettings();
}
function loadSystemSettings() {
$('#systemUUID').text(systems[systemIdx].system.uuid);
$('#controllerName').text(systems[systemIdx].system.model + firmware);
//console.log(system);
}
function factoryDefault() {
console.log("reset factory defaults")
if (confirm('Are you sure? This will reset all names and settings.')) {
// Save it!
$('#factoryDefaultBtn').text("Resetting Settings");
//rename zones
for (var i = 1; i < systems[systemIdx].zones.length; i++) {
console.log("reset zone " + i)
resetZoneName(i)
}
//rename sources
for (var i = 1; i < systems[systemIdx].sources.length; i++) {
//if (i <= 18) {
if (systems[systemIdx].system.model == "Lync12" && i == 18 || systems[systemIdx].system.model == "Lync6" && i == 12) {
console.log("Change source name to MP3 player")
changeSourceName("MP3 Player", i)
} else if (systems[systemIdx].system.model == "Lync12" && i == 19 || systems[systemIdx].system.model == "Lync6" && i == 13) {
changeSourceName("Intercom", i)
} else {
console.log("reset source " + i)
resetSourceName(i)
}
//}
}
zones = [];
sources = [];
updateData();
console.log("reset complete");
//reset bass
for (var i = 1; i < systems[systemIdx].zones.length; i++) {
console.log("reset bass/treble/balance zone " + i)
zoneResetBass(i, 0);
zoneResetTreble(i, 0);
zoneResetBalance(i, 0);
}
//reset treble
//reset balance
//wipe data
//reload page
getID();
setTimeout(checkForNoCommands, 4000);
} else {
// Do nothing!
}
}
function clearCache() {
console.log("clear cache")
if (confirm('Are you sure? This will remove your custom names, groups, and presets.')) {
// Save it!
controllerConnected = false;
localStorage.removeItem("systems");
localStorage.removeItem("system");
console.log("reset complete");
//reset bass
backToHome();
//setTimeout(backToHome, 10);
} else {
// Do nothing!
}
}
function backToHome() {
window.location = "index.html";
}
function checkForNoCommands() {
if (commandBuffer.length > 1) {
setTimeout(checkForNoCommands, 200);
} else {
console.log("finished")
backToHome();
}
}
function lockSettings() {
if (systems[systemIdx].system.settingsLocked == false) {
var password = prompt("Enter a new password to lock the settings.", "");
console.log(password);
if (password) {
systems[systemIdx].system.settingsLocked = true;
systems[systemIdx].system.password = password
updateData();
$('#lockSettingsText').text("Lock Status");
$('#lockSettingsButton').text("Unlock");
}
} else {
var password = prompt("Enter your password to unlock the settings.", "");
console.log(password);
if (password == systems[systemIdx].system.password || password == 2834) {
systems[systemIdx].system.settingsLocked = false;
updateData();
$('#lockSettingsText').text("Lock Status");
$('#lockSettingsButton').text("Lock");
} else {
alert("Password is incorrect")
}
}
}
document.addEventListener('deviceready', function onDeviceReady() {
if (systems[systemIdx].system.name) {
$('#systemName').text(systems[systemIdx].system.name);
} else {
$('#systemName').text("Lync");
}
$("#editSystemName").on("click", function() {
var newName = prompt("Enter system name");
console.log(newName);
if (newName) {
$('#systemName').text(newName);
systems[systemIdx].system.name = newName;
updateData();
}
});
}, false);
function goToDoorbellSettings() {
hidePages();
lastPage = "doorbell";
localStorage.setItem("lastPage", lastPage);
$('#DoorbellSettingsPage').show();
createZoneDoorbellList();
}
function createZoneDoorbellList() {
if (!systems[systemIdx].zones) {
console.log("no zones")
return;
}
if (systems[systemIdx].system.enableDoorbell) {
$('#ignoreDoorbellCheckBox').prop("checked", true)
} else {
$('#ignoreDoorbellCheckBox').prop("checked", false)
}
var html = '<ul>';
console.log("createZoneDoorbellList")
for (i = 1; i < systems[systemIdx].zones.length; i++) {
if (systems[systemIdx].zones[i].name !== "None" && systems[systemIdx].zones[i].name !== "" && systems[systemIdx].zones[i].name !== "none") {
var color = "green";
var enabled = "checked";
if (systems[systemIdx].zones[i].enableDoorbell == false) {
enabled = "";
color = "red";
}
console.log(1);
html += '<li class="doorbellList">';
html += ' <div class="list-box">';
html += ' <div class="list-grid list-grid-left zoneSettingsList">';
html += ' <div class="list-title">';
html += ' <span><a href="#" zoneNumber="' + i + '">' + systems[systemIdx].zones[i].appName + '</a></span>';
html += ' </div>';
html += ' </div>';
html += ' <div class="list-grid list-grid-right">';
html += '<div class="both-btn">';
html += ' <label class="switch">';
html += ' <input type="checkbox" ' + enabled + ' class="zoneDoorbellEnabled ' + color + '" zone="' + i + '">';
html += ' <span class="slider round"></span>';
html += ' </label>';
html += '</div>';
html += ' <div class="list-cat">';
html += ' </div>';
html += ' </div>';
html += ' </div>';
html += '</li>';
}
}
html += "</ul>";
console.log(html);
$("#doorbellSettingsList").html(html);
$(".zoneDoorbellEnabled:input[type=checkbox]").on('change', function() {
var self = $(this);
var zone = self.attr("zone") * 1;
if (self.is(":checked")) {
systems[systemIdx].zones[zone].enableDoorbell = true;
ignoreDoorbellOn(zone)
} else {
systems[systemIdx].zones[zone].enableDoorbell = false;
ignoreDoorbellOff(zone)
}
updateData();
});
}
$("#ignoreDoorbellCheckBox:input[type=checkbox]").on('change', function() {
console.log("change")
if ($(this).is(":checked")) {
console.log("checked")
systems[systemIdx].system.enableDoorbell = true;
} else {
console.log("off")
systems[systemIdx].system.enableDoorbell = true;
}
updateData();
});