-
-
Save jme900/55e746be2d9dd9f96538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular.module('eyesover') | |
.directive('rule', function () { | |
return { | |
scope: { | |
rule: '=ruleset' | |
}, | |
replace: true, | |
restrict: 'E', | |
templateUrl: 'components/rule/rule.html', | |
link: function () {}, | |
controller: function ($scope, $timeout, toastr, $http, $state) { | |
$scope.originalRule = _.clone($scope.rule); | |
$scope.originalKeywords = _.clone($scope.rule.keywords); | |
$scope.newKeyword = ''; | |
console.log($scope.$parent.$parent.rules); | |
$scope.addKeyword = function() { | |
$scope.rule.keywords.push($scope.newKeyword); | |
$scope.newKeyword = ''; | |
}; | |
$scope.toggleListener = function(l) { | |
$timeout(function() { | |
$scope.rule[l] = !$scope.rule[l]; | |
console.log($scope.rule); | |
}); | |
}; | |
$scope.useThisRule = function() { | |
$timeout(function() { | |
$scope.$parent.$parent.selectedMessage = $scope.rule.message; | |
}, 5); | |
}; | |
$scope.saveRule = function() { | |
$http.get('https://THAT URL YOU JUST SENT ME').success(function(whateverYouCallThisParameterIsTheDataFromThatEndpointYouJustSentMe) { | |
$http.put('https://localhost/rule/' + $scope.rule.id, $scope.rule) | |
.success(function () { | |
console.log('Successfully saved rule!'); | |
toastr.success('Rule saved.'); | |
}) | |
.error(function () { | |
console.error('Error saving rule!'); | |
toastr.error('Failed to save rule.'); | |
}); | |
}).error(function(data) { | |
console.error('Error saving rule!'); | |
toastr.error('Failed to save rule.'); | |
}); | |
}; | |
$scope.deleteRule = function() { | |
$http.get('https://localhost/rule/postRules?action=delete&name=' + $scope.rule.name) | |
.success(function () { | |
console.log('Successfully deleted rule!'); | |
toastr.success('Rule deleted.'); | |
$state.go($state.current, {}, {reload: true}); | |
}) | |
.error(function () { | |
console.error('Error deleting rule!'); | |
toastr.error('Failed to delete rule.'); | |
}); | |
}; | |
$scope.cancel = function() { | |
console.log('RULE BEFORE CANCEL:', $scope.rule); | |
$scope.rule = _.clone($scope.originalRule); | |
$scope.rule.keywords = _.clone($scope.originalKeywords); | |
console.log('RULE AFTER CANCEL:', $scope.rule); | |
}; | |
$scope.removeKeyword = function(keyword) { | |
$scope.rule.keywords.splice($scope.rule.keywords.indexOf(keyword), 1); | |
}; | |
} | |
}; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment