ffffng/app/scripts/directives/tokenForm.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-05-12 20:08:19 +02:00
'use strict';
angular.module('ffffng')
.directive('fTokenForm', function () {
var ctrl = function ($scope, Constraints) {
$scope.constraints = Constraints;
$scope.submitted = false;
2014-05-12 20:08:19 +02:00
$scope.doSubmit = function (token) {
$scope.submitted = true;
if ($scope.tokenForm.$invalid) {
return;
}
2014-05-12 20:08:19 +02:00
$scope.error = null;
$scope.onSubmit(token)
.error(function (response, code) {
switch (code) {
case 404: // not found
$scope.error = 'Zum Token wurde kein passender Eintrag gefunden.';
break;
default:
$scope.error = 'Es ist ein Fehler aufgetreten. Versuche es später noch einmal.';
}
});
};
};
return {
'controller': ctrl,
'restrict': 'E',
'templateUrl': 'views/directives/tokenForm.html',
'scope': {
'onSubmit': '=fSubmit',
'onCancel': '=fCancel'
}
};
});