UNPKG

htd-lync

Version:

This library is meant to be used to interact with an HTD Lync 12

210 lines (181 loc) 6.33 kB
$("#zoneLink2").on("click", function() { console.log("home") goToHomePage(); }); function makeVolumeDropDown(zone, volume) { if (systems[systemIdx].zones[zone].dndOn == true) { alert("Zone is in DND"); return; } console.log("makeVolumeDropDown 7") var list = []; var obj = new Object(); // obj.text = "Mute"; // obj.value = "0"; // list.push(obj); for (var i = 1; i <= 60; i++) { var obj = new Object(); obj.text = i + ""; obj.value = i + ""; list.push(obj); } //console.log(list); var config = { title: "Select Volume", items: list, selectedValue: systems[systemIdx].zones[zone].vol + "", doneButtonLabel: "Select", cancelButtonLabel: "Cancel" }; // Show the picker window.plugins.listpicker.showPicker(config, function(volume) { if (volume == 0) { systems[systemIdx].zones[zone].muteOn = true; zoneMuteOn(zone); } else { //zones[zone].muteOn = false; setVolumeForZone(zone, volume); zonePowerOn(zone); } }, function() { //alert("You have cancelled"); } ); } function makeVolumeHeader(zone) { //console.log("make volume header", zone, zones[zone].vol, zones[zone].muteOn) var html = '<div id="volumeDropDown-' + zone + '" class="dropBtn selectVolume" zone="' + zone + '">' + systems[systemIdx].zones[zone].vol + '</div>'; if ((systems[systemIdx].zones[zone].muteOn == true || systems[systemIdx].zones[zone].vol == 0) && systems[systemIdx].zones[zone].powerOn == true) { html = '<div id="volumeDropDown-' + zone + '" class="dropBtn selectVolume mute" zone="' + zone + '">Mute</div>'; } return html; } function makeSourceHeaderSystemStatus(zone) { //ßconsole.log("makeSourceHeaderSystemStatus: zone: " + zone) var source = systems[systemIdx].zones[zone].source * 1; if (!systems[systemIdx].sources) { return; } if (source >= systems[systemIdx].sources.length) { console.log("changing source from " + source + " to " + systems[systemIdx].sources.length - 1) source = systems[systemIdx].sources.length - 1; } //console.log(sources[source]); //console.log(sources[source].appName); var html = ""; if (source > 0) { if (systems[systemIdx].sources[source].appName && source > 0 && systems[systemIdx].sources[source].appName) { html = '<div class="dropBtnSource selectSource" zone="' + zone + '">' + systems[systemIdx].sources[source].appName + '</div>'; } } return html; } function makeSourceListSystemStatus(zone) { if (systems[systemIdx].zones[zone].dndOn == true) { alert("Zone is in DND"); return; } var list = []; var obj = new Object(); for (var i = 1; i <= systems[systemIdx].sources.length; i++) { var obj = new Object(); if (systems[systemIdx].sources[i]) { if (systems[systemIdx].sources[i].enabled) { obj.text = systems[systemIdx].sources[i].appName + ""; obj.value = i + ""; list.push(obj); } } } //console.log(list); var config = { title: "Select a Source", items: list, selectedValue: systems[systemIdx].zones[zone].source + "", doneButtonLabel: "Select", cancelButtonLabel: "Cancel" }; // Show the picker window.plugins.listpicker.showPicker(config, function(source) { setSourceForZone(zone, source); systems[systemIdx].zones[zone].source = source; }, function() { //alert("You have cancelled"); } ); } $(document).on('change', '.dropBtnSource', function() { var source = (this.value) var zone = ($(this).attr('zone')) setSourceForZone(zone, source); }); var stuckLoading = false; function createZoneList() { if (!systems[systemIdx].zones) { stuckLoading = true; console.log("no zones") $("#zoneList").html("<h2 class='loadingText'>Loading system. This might take a minute...</h2><h4>If the system doesnt load tap the System Status text above to pull the data again.</h4>"); setTimeout(checkStruckLoading, 30000); return; } stuckLoading = false; var html = '<ul>'; for (i = 1; i < systems[systemIdx].zones.length; i++) { if (systems[systemIdx].zones[i].appName !== "None" && systems[systemIdx].zones[i].appName !== "" && systems[systemIdx].zones[i].appName !== "none" && systems[systemIdx].zones[i].enabled == true) { //console.log(zones[i]) var powerState = "active"; if (systems[systemIdx].zones[i].powerOn == false) { powerState = ""; } var dndState = "dnd"; if (systems[systemIdx].zones[i].dndOn == true) { dndState = "dndOn"; } html += '<li>'; html += ' <div class="list-box">'; html += ' <div class="list-grid list-grid-left ' + powerState + '">'; html += ' <div class="list-icon" onclick="toggleZonePower(' + i + ', false)">'; html += ' </div>'; html += ' <div class="list-title">'; html += ' <span><a class="' + dndState + '" href="#" zoneNumber="' + i + '" onclick="goToMusicPage(' + i + ')">' + systems[systemIdx].zones[i].appName + '</a></span>'; html += ' </div>'; html += ' </div>'; html += ' <div class="list-grid list-grid-right">'; html += ' <div class="list-volume">'; html += makeVolumeHeader(i); html += ' </div>'; html += ' <div class="list-cat">'; html += makeSourceHeaderSystemStatus(i); html += ' </div>'; html += ' </div>'; html += ' </div>'; html += '</li>'; } } html += "</ul>"; html += '<div class="button-wrapper" id="systemStatusButtons">'; html += '<div class="buttons">'; html += '<div class="button-item" id="allOn"><a href="javascript:;" onClick="allOn();">All On</a></div>'; html += '<div class="button-item" id="allOff"><a href="javascript:;" onClick="allOff();">All Off</a></div>'; html += '</div>'; $("#zoneList").html(html); $(".selectVolume").on('click', function() { var zone = ($(this).attr('zone')) makeVolumeDropDown(zone); }); $(".selectSource").on('click', function() { var zone = ($(this).attr('zone')) makeSourceListSystemStatus(zone); }); } //console.log(zones); $("#allOn").on("click", function() { allOn(); }); $("#allOff").on("click", function() { allOff(); });