Parent: [0765ef] (diff)

Child: [bd5300] (diff)

Download this file

editRuleCtrl.js    92 lines (84 with data), 2.7 kB

 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*made by Miguel Rodrigues @ KBZ miguel.rodrigues@knowledgebiz.pt*/
console.log("Defining editRuleCtrl");
angular.module('mainApp')
.controller('editRuleCtrl', function($scope, $routeParams, $http, appService, $timeout) {
$scope.show = false;
$scope.showError = false;
$scope.data = false;
$scope.rulesid = $routeParams.rulesid;
$scope.appID = $routeParams.appid;
$scope.developerid = $routeParams.developerid;
$scope.description = null;
$scope.parameter = null;
$scope.conditionValue = null;
$scope.controlValue = null;
$scope.notificationType = null;
$scope.rule = null;
$scope.successDescription = 0;
$scope.successParameter = 0;
$scope.successControlValue = 0;
console.log(" Running editRuleCtrl... ");
appService.getAllRule($routeParams.rulesid).then(function(response){
if(response.data.success){
if(response.data.data.length > 0){
console.log("getAllRule response: " + JSON.stringify(response.data));
$scope.rule = response.data.data[0];
}else{
$scope.data = true;
$scope.noData = "There is no recorded Data";
}
}
},function(err){
console.log("Resource doesn't exist");
$scope.error = err.data.data;
});
$scope.postdata = function (description, parameter, conditionValue, controlValue, notificationType) {
$scope.successDescription = 0;
$scope.successParameter = 0;
$scope.successControlValue = 0;
if(description == null){
$scope.successDescription = 2;
}
else if (parameter == null){
$scope.successParameter = 2;
}
else if (isNaN(parseFloat(controlValue))){
$scope.successControlValue = 2;
}
else{
$scope.successDescription = 1;
$scope.successParameter = 1;
$scope.successControlValue = 1;
var data = {
description: description,
parameter: parameter,
conditionValue: conditionValue,
controlValue: controlValue,
notificationType: notificationType,
rulesid: $routeParams.rulesid
};
appService.editRule(data).then(function(res) {
if(res.data.success){
console.log("Post Data Submitted Successfully!");
$scope.show = true;
$timeout(function() {
$scope.show = false;
window.location = '/'+$routeParams.developerid+'/'+$routeParams.appid+'/listrules'
}, 2000)
}
},function(err){
$scope.showError = true;
$timeout(function() {
$scope.showError = false;
}, 2000)
});
}
};
$scope.redirectAppManager = function () {
window.location = '/'+$routeParams.developerid
};
$scope.redirectRuleManager = function () {
window.location = '/'+$routeParams.developerid+"/"+$routeParams.appid+"/listrules"
};
console.log("Loading editRuleCtrl");
});