make the push not update its own led and give it's value (for state save and widget sync) based on its last changed property (led state or touch on/off)

This commit is contained in:
jean-emmanuel 2016-03-29 14:48:32 +02:00
parent 6f827962e2
commit 238acbdf8d
4 changed files with 57 additions and 15 deletions

View file

@ -37,6 +37,8 @@ module.exports.create = function(widgetData,container) {
widget.value = widget.find('span')
widget.state = 0
widget.active = 0
widget.lastChanged = 'state'
widget.on('drag',function(e){e.stopPropagation()})
widget.on('draginit.push',function(){
@ -45,9 +47,9 @@ module.exports.create = function(widgetData,container) {
})
widget.fakeclick = function(){
if (!widget.state) widget.setValue(widgetData.on,true,true)
if (!widget.active) widget.setValuePrivate(widgetData.on,true,true)
$document.on('dragend.push',function(){
widget.setValue(widgetData.off,true,true)
widget.setValuePrivate(widgetData.off,true,true)
$document.off('dragend.push')
widget.on('draginit.push',function(){
widget.off('draginit.push')
@ -57,22 +59,41 @@ module.exports.create = function(widgetData,container) {
}
widget.getValue = function() {
return widget.state?widgetData.on:widgetData.off
return widget[widget.lastChanged]?widgetData.on:widgetData.off
}
widget.setValuePrivate = function(v,send,sync) {
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
widget.addClass('active')
widget.active = 1
if (send) widget.sendValue(v)
widget.lastChanged = 'active'
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
widget.removeClass('active')
widget.active = 0
if (send) widget.sendValue(v)
widget.lastChanged = 'active'
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
}
}
widget.setValue = function(v,send,sync) {
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
widget.addClass('on')
widget.state = 1
if (send) widget.sendValue(v)
widget.lastChanged = 'state'
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
widget.removeClass('on')
widget.state = 0
if (send) widget.sendValue(v)
widget.lastChanged = 'state'
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
}
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
}
widget.sendValue = function(v) {
if (v===false) return
var args = widgetData.preArgs.concat(v)