-
Notifications
You must be signed in to change notification settings - Fork 61
/
RulesController.js
45 lines (36 loc) · 903 Bytes
/
RulesController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
angular.module('switcheroo')
.controller('RulesController', ['$scope', 'RulesService', function($scope, rulesService) {
$scope.rules = chrome.extension.getBackgroundPage().rules;
$scope.isEditing = false;
$scope.add = function() {
$scope.rules.push({
from: $scope.from,
to: $scope.to,
isActive: true
});
$scope.from = '';
$scope.to = '';
};
$scope.remove = function(index) {
$scope.rules.splice(index,1);
};
$scope.clear = function() {
$scope.rules = [];
};
$scope.enableEditing = function() {
$scope.isEditing = true;
};
$scope.disableEditing = function() {
$scope.isEditing = false;
};
$scope.shortenText = function (text){
var maxLength = 25;
if(text && text.length > maxLength){
text = text.substring(0,maxLength) + "...";
}
return text;
};
$scope.$watch('rules', function(oldValue, newValue){
rulesService.set(newValue);
}, true);
}]);