@ -785,11 +785,13 @@ function addSchedule(event) {
} ) ;
$ ( line ) . find ( ".button-del-schedule" ) . on ( "click" , delSchedule ) ;
$ ( line ) . find ( ".button-more-schedule" ) . on ( "click" , moreSchedule ) ;
$ ( line ) . find ( "input[name='schUTC']" ) . prop ( "id" , "schUTC" + ( numSchedules + 1 ) )
. next ( ) . prop ( "for" , "schUTC" + ( numSchedules + 1 ) ) ;
$ ( line ) . find ( "input[name='schEnabled']" ) . prop ( "id" , "schEnabled" + ( numSchedules + 1 ) )
. next ( ) . prop ( "for" , "schEnabled" + ( numSchedules + 1 ) ) ;
line . appendTo ( "#schedules" ) ;
$ ( line ) . find ( "input[type='checkbox']" ) . prop ( "checked" , false ) ;
initCheckboxes ( ) ;
return line ;
}
@ -809,7 +811,15 @@ function initRelays(data) {
// Add relay fields
var line = $ ( template ) . clone ( ) ;
$ ( ".id" , line ) . html ( i ) ;
$ ( ":checkbox" , line ) . prop ( 'checked' , data [ i ] ) . attr ( "data" , i ) ;
$ ( ":checkbox" , line ) . prop ( 'checked' , data [ i ] ) . attr ( "data" , i )
. prop ( "id" , "relay" + i )
. on ( "change" , function ( event ) {
console . log ( "sending message" ) ;
var id = parseInt ( $ ( event . target ) . attr ( "data" ) , 10 ) ;
var status = $ ( event . target ) . prop ( "checked" ) ;
doToggle ( id , status ) ;
} ) ;
$ ( "label.toggle" , line ) . prop ( "for" , "relay" + i )
line . appendTo ( "#relays" ) ;
// Populate the relay SELECTs
@ -820,57 +830,13 @@ function initRelays(data) {
}
function initCheckboxes ( ) {
var setCheckbox = function ( element , value ) {
var container = $ ( ".toggle-container" , $ ( element ) ) ;
if ( value ) {
container . css ( "-webkit-clip-path" , "inset(0 0 0 50%)" ) ;
container . css ( "clip-path" , "inset(0 0 0 50%)" ) ;
container . css ( "backgroundColor" , "#00c000" ) ;
} else {
container . css ( "-webkit-clip-path" , "inset(0 50% 0 0)" ) ;
container . css ( "clip-path" , "inset(0 50% 0 0)" ) ;
container . css ( "backgroundColor" , "#c00000" ) ;
}
}
$ ( ".checkbox-container" )
. each ( function ( ) {
var status = $ ( this ) . next ( ) . prop ( 'checked' ) ;
setCheckbox ( this , status ) ;
} )
. off ( 'click' )
. on ( 'click' , function ( ) {
var checkbox = $ ( this ) . next ( ) ;
var status = checkbox . prop ( 'checked' ) ;
status = ! status ;
checkbox . prop ( 'checked' , status ) ;
setCheckbox ( this , status ) ;
if ( "relay" == checkbox . attr ( 'name' ) ) {
var id = parseInt ( checkbox . attr ( 'data' ) , 10 ) ;
doToggle ( id , status ) ;
}
} ) ;
}
function createCheckboxes ( ) {
$ ( "input[type='checkbox']" ) . each ( function ( ) {
var text_on = $ ( this ) . attr ( "on" ) || "YES" ;
var text_off = $ ( this ) . attr ( "off" ) || "NO" ;
var toggles = "<div class=\"toggle\"><p>" + text_on + "</p></div><div class=\"toggle\"><p>" + text_off + "</p></div>" ;
var content = "<div class=\"checkbox-container\"><div class=\"inner-container\">" + toggles
+ "</div><div class=\"inner-container toggle-container\">" + toggles + "</div></div>" ;
$ ( this ) . before ( content ) . hide ( ) ;
if ( $ ( this ) . prop ( "name" ) ) $ ( this ) . prop ( "id" , $ ( this ) . prop ( "name" ) ) ;
$ ( this ) . parent ( ) . addClass ( "toggleWrapper" ) ;
$ ( this ) . after ( '<label for="' + $ ( this ) . prop ( "name" ) + '" class="toggle"><span class="toggle__handler"></span></label>' )
} ) ;
@ -1499,7 +1465,6 @@ function processData(data) {
}
resetOriginals ( ) ;
initCheckboxes ( ) ;
}