diff --git a/app/class/AutomationManager.php b/app/class/AutomationManager.php index e57f359..a06581b 100644 --- a/app/class/AutomationManager.php +++ b/app/class/AutomationManager.php @@ -13,6 +13,10 @@ class AutomationManager{ return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId)); } + public function restart($automationId) { + return Db::command ('UPDATE automation SET executed = 0 WHERE automation_id=?', array ($automationId)); + } + public function create ($name, $onDays, $doCode, $ifCode, $automationId = "") { $scene = array ( 'name' => $name, diff --git a/app/templates/automation.phtml b/app/templates/automation.phtml index 0b3cbc9..f58ac4b 100644 --- a/app/templates/automation.phtml +++ b/app/templates/automation.phtml @@ -52,7 +52,9 @@ $partial->prepare('langMng',$LANGMNG); $partial->prepare('subDevices',$SUBDEVICES); $partial->render(); - } + }?> + + render(); ?> diff --git a/app/templates/js/automation.js b/app/templates/js/automation.js new file mode 100644 index 0000000..660f9d9 --- /dev/null +++ b/app/templates/js/automation.js @@ -0,0 +1,35 @@ +function restartAutomation(automationId){ + console.log("restartingAutomation" + automationId); + $.ajax({ + url: 'ajax', + type: 'POST', + data: { + "automation_id" : automationId, + "action": 'restart' + }, + success: function(data){ + console.log(data); + }, + error: function (request, status, error) { + console.log("ERROR ", request, error); + } + }); +} + +function toggleAutomation(automationId){ + console.log("togglingAutomation" + automationId); + $.ajax({ + url: 'ajax', + type: 'POST', + data: { + "automation_id" : automationId, + "action": 'deactive' + }, + success: function(data){ + console.log(data); + }, + error: function (request, status, error) { + console.log("ERROR ", request, error); + } + }); +} \ No newline at end of file diff --git a/app/views/Ajax.php b/app/views/Ajax.php index d00c6f2..7e925ab 100644 --- a/app/views/Ajax.php +++ b/app/views/Ajax.php @@ -40,6 +40,11 @@ class Ajax extends Template die(); break; + case 'restart': + AutomationManager::restart($automationId); + die(); + break; + default: echo 'no action detected'; break;