zettapi_client
Version:
Client side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project
42 lines (36 loc) • 1.55 kB
JavaScript
app.directive('zlSignup', function(zapiPath) {
return {
restrict: 'E',
scope: {
item: '=',
zlClass: '@?',
onComplete: '&?'
},
replace: false,
templateUrl: zapiPath + '/directives/signup/signup.html',
controller: function($scope, blockUI, $entity, $uibModalStack) {
if (typeof $scope.zlClass === 'undefined') $scope.zlClass = "form-control input-lg";
$scope.signup = function(item) {
if ($scope.validateSignup(item)) return;
blockUI.start("A reservar conta...");
$entity.add('user', item).then(function(response) {
if (typeof $scope.onComplete() === 'function') return $scope.onComplete()();
swal("Está quase!", "Consulte o seu email para ativar a conta de utilizador", "success");
$uibModalStack.dismissAll();
}).catch(function(response) {
swal("Erro", response.data, "error");
}).finally(function() {
blockUI.stop();
});
};
$scope.validateSignup = function(item) {
if (!item) return true;
if (!item.username) return true;
var validUsername = new RegExp('^[a-zA-Z0-9.\-_$@*!]{3,30}$');
if (!validUsername.test(item.username)) return true;
if (!item.email) return true;
return false;
};
}
};
});