unserver-unify
Version:
60 lines (59 loc) • 2.13 kB
JavaScript
;
angular.module('bamboo.help').controller('RequestCtrl', function($scope, ApiService, CommonService, $state, $timeout, $translate) {
this.info = {};
var self = this;
ApiService.getDocCategory('requestCategoryDoc',function(result){
self.Categorys = result;
});
this.createRequest = function() {
$scope.submitted = true;
if ($scope.form.$invalid) {
console.log($scope.form);
$scope.shaking = true;
$timeout(function() {
$scope.shaking = false;
}, 500);
return;
}
var string1 = removeSpaces(self.captchaCode);
var string2 = removeSpaces(self.userCaptcha);
console.log(string1);
console.log(string2);
if (string1 != string2) {
CommonService.showError($translate.instant('Captcha Code is not matched'));
self.generateCaptcha();
self.userCaptcha = '';
return;
}
//self.info.action = "addRequestRecord";
var info = {
action: "addRequestRecord",
object: self.info,
}
console.log(info);
ApiService.post('/logs', info).then(function(result) {
console.log(result);
if (result.data.success) {
CommonService.showInfo($translate.instant('Submit Successful!'),function(res){
$state.go('index.home');
});
} else {
CommonService.showError(result.data.error || result.data.info);
}
});
};
//.......... Captcha .............
this.generateCaptcha = function() {
var alpha = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
var i;
var code = "";
for (i = 0; i < 6; i++) {
code = code + alpha[Math.floor(Math.random() * alpha.length)] + " ";
}
self.captchaCode = code;
}
self.generateCaptcha();
var removeSpaces = function (string) {
return string.split(' ').join('');
}
});