Files
dojo/public/admin/candySwitch/cSwitch.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-07-18 04:28:26 -05:00
d3.select("#clink").on("click",function(){
2018-07-25 20:48:58 +00:00
var newWindow = window.open('/candy','_blank');
2018-07-18 04:28:26 -05:00
});
2018-07-19 03:45:46 -05:00
// revisa que llama dos veces a la pagina
2018-07-25 20:48:58 +00:00
var ciface ="/json/candy/";
2018-07-18 04:28:26 -05:00
d3.json(ciface+"isOn" ,function(d){
if(d != undefined){
2018-08-14 19:28:16 -05:00
if (d.a=="1") { on(); }
else if (d.a=="0") { off(); }
else if (d.a=="connection error") { cerror(); }}
2018-07-18 04:28:26 -05:00
else {console.error(ciface+"isOn");}
});
d3.select("#myonoffswitch")
.on("change",function(){
if (this.checked) { on();}
else {off();}
});
function on(){
2018-08-14 19:28:16 -05:00
d3.select("#clink").style("visibility","visible");
2018-07-18 04:28:26 -05:00
d3.json(ciface+"on",function(d){
2018-08-14 19:28:16 -05:00
if (d.a=="connection error"){ cerror();}
else if (d.a=="1"){
2018-07-18 04:28:26 -05:00
d3.select("#clink").style("visibility","visible");
d3.select("#myonoffswitch").property("checked","checked"); }
else {
d3.select("#myonoffswitch").property("checked","");
}}); }
function off(){
2018-08-14 19:28:16 -05:00
d3.select("#clink").style("visibility","hidden");
2018-07-18 04:28:26 -05:00
d3.json(ciface+"off",function(d){
2018-08-14 19:28:16 -05:00
if (d.a=="connection error"){ cerror();}
else if (d.a=="1"){
2018-07-18 04:28:26 -05:00
d3.select("#clink").style("visibility","hidden");
d3.select("#myonoffswitch").property("checked",""); }
else {
d3.select("#myonoffswitch").property("checked","checked");
}}); }
2018-08-14 19:28:16 -05:00
function cerror(){
console.error("prosody connection error");
d3.select("#clink").style("visibility","hidden");
d3.select("#myonoffswitch").property("checked","");
}
2018-07-18 04:28:26 -05:00