/*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");
});