This commit is contained in:
James Cole 2016-02-10 15:04:06 +01:00
parent 94b6c7975a
commit 076ff7c7ba
4 changed files with 94 additions and 5 deletions

View File

@ -11,8 +11,7 @@ var actionCount = 0;
$(function () {
"use strict";
console.log("create-edit");
console.log('edit-create');
});
@ -21,11 +20,18 @@ function addNewTrigger() {
triggerCount++;
$.getJSON('json/trigger', {count: triggerCount}).done(function (data) {
//console.log(data.html);
$('tbody.rule-trigger-tbody').append(data.html);
$('.remove-trigger').unbind('click').click(function (e) {
removeTrigger(e);
return false;
});
}).fail(function () {
alert('Cannot get a new trigger.');
});
}
function addNewAction() {
@ -35,7 +41,45 @@ function addNewAction() {
$.getJSON('json/action', {count: actionCount}).done(function (data) {
//console.log(data.html);
$('tbody.rule-action-tbody').append(data.html);
// add action things.
$('.remove-action').unbind('click').click(function (e) {
removeAction(e);
return false;
});
}).fail(function () {
alert('Cannot get a new action.');
});
}
function removeTrigger(e) {
"use strict";
var target = $(e.target);
if(target.prop("tagName") == "I") {
target = target.parent();
}
// remove grand parent:
target.parent().parent().remove();
// if now at zero, immediatly add one again:
if($('.rule-trigger-tbody tr').length == 0) {
addNewTrigger();
}
}
function removeAction(e) {
"use strict";
var target = $(e.target);
if(target.prop("tagName") == "I") {
target = target.parent();
}
// remove grand parent:
target.parent().parent().remove();
// if now at zero, immediatly add one again:
if($('.rule-action-tbody tr').length == 0) {
addNewAction();
}
}

View File

@ -11,7 +11,7 @@
$(function () {
"use strict";
console.log("edit");
console.log("create");
if (triggerCount === 0) {
addNewTrigger();
}

45
public/js/rules/edit.js Normal file
View File

@ -0,0 +1,45 @@
/*
* edit.js
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
$(function () {
"use strict";
console.log("edit");
if (triggerCount === 0) {
addNewTrigger();
}
if (actionCount === 0) {
addNewAction();
}
$('.add_rule_trigger').click(function () {
addNewTrigger();
return false;
});
$('.add_rule_action').click(function () {
addNewAction();
return false;
});
$('.remove-trigger').unbind('click').click(function (e) {
removeTrigger(e);
return false;
});
// add action things.
$('.remove-action').unbind('click').click(function (e) {
removeAction(e);
return false;
});
});

View File

@ -128,5 +128,5 @@
var triggerCount = {{ triggerCount }};
var actionCount = {{ actionCount }};
</script>
<script type="text/javascript" src="js/rules/create.js"></script>
<script type="text/javascript" src="js/rules/edit.js"></script>
{% endblock %}