/*made by Miguel Rodrigues @ KBZ miguel.rodrigues@knowledgebiz.pt*/
console.log("Defining rulesCtrl");
angular.module('mainApp')
.controller('rulesCtrl', function($scope, $routeParams, $http, appService) {
$scope.appId = $routeParams.appid;
$scope.description = null;
$scope.parameter = null;
$scope.conditionValue = null;
$scope.controlValue = null;
$scope.notificationType = null;
console.log(" Running rulesCtrl... ");
appService.getAppRules($routeParams.appid).then(function(response){
if(response.data.success){
console.log("getAppRules response: " + JSON.stringify(response.data));
$scope.rules = response.data.data;
}else{
console.log("Something went wrong...");
}
}).then(function(){
console.log("getAppRules timed out");
});
$scope.postdata = function (description, parameter, conditionValue, controlValue, notificationType) {
var data = {
appID: $routeParams.appid,
description: description,
parameter: parameter,
conditionValue: conditionValue,
controlValue: controlValue,
notificationType: notificationType
};
appService.postAppRules(data).then(function(res) {
if(res.data.success){
console.log("Post Data Submitted Successfully!");
window.location = '/'+$routeParams.developerid
}else{
console.log("Failed to Register");
}
}).then(function(){
console.log("postAppRules timed out");
});
};
$scope.redirect = function (rulesid) {
window.location = '/'+$routeParams.developerid+'/'+$routeParams.appid+'/'+rulesid
};
console.log("Loading rulesCtrl");
});