cleaning the house
This commit is contained in:
49
public/admin/candySwitch/cSwitch.js
Executable file
49
public/admin/candySwitch/cSwitch.js
Executable file
@@ -0,0 +1,49 @@
|
||||
d3.select("#clink").on("click",function(){
|
||||
var newWindow = window.open('/candy','_blank');
|
||||
});
|
||||
// revisa que llama dos veces a la pagina
|
||||
var ciface ="/json/candy/";
|
||||
d3.json(ciface+"isOn" ,function(d){
|
||||
if(d != undefined){
|
||||
if (d.a=="1") { on(); }
|
||||
else if (d.a=="0") { off(); }
|
||||
else if (d.a=="connection error") { cerror(); }}
|
||||
else {console.error(ciface+"isOn");}
|
||||
});
|
||||
|
||||
d3.select("#myonoffswitch")
|
||||
.on("change",function(){
|
||||
if (this.checked) { on();}
|
||||
else {off();}
|
||||
});
|
||||
|
||||
function on(){
|
||||
d3.select("#clink").style("visibility","visible");
|
||||
d3.json(ciface+"on",function(d){
|
||||
if (d.a=="connection error"){ cerror();}
|
||||
else if (d.a=="1"){
|
||||
d3.select("#clink").style("visibility","visible");
|
||||
d3.select("#myonoffswitch").property("checked","checked"); }
|
||||
else {
|
||||
d3.select("#myonoffswitch").property("checked","");
|
||||
}}); }
|
||||
|
||||
function off(){
|
||||
d3.select("#clink").style("visibility","hidden");
|
||||
d3.json(ciface+"off",function(d){
|
||||
if (d.a=="connection error"){ cerror();}
|
||||
else if (d.a=="1"){
|
||||
d3.select("#clink").style("visibility","hidden");
|
||||
d3.select("#myonoffswitch").property("checked",""); }
|
||||
else {
|
||||
d3.select("#myonoffswitch").property("checked","checked");
|
||||
}}); }
|
||||
|
||||
function cerror(){
|
||||
console.error("prosody connection error");
|
||||
d3.select("#clink").style("visibility","hidden");
|
||||
d3.select("#myonoffswitch").property("checked","");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user