1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

[TypeScript] Convert directives (#396)

* Convert directives to TypeScript.

* FormDirective uses ValidationService type.
This commit is contained in:
Oscar Hinton
2017-11-25 14:02:22 +01:00
committed by Kyle Spearrin
parent b297c4279a
commit f5ccc22076
13 changed files with 73 additions and 74 deletions

View File

@@ -0,0 +1,31 @@
import { ValidationService } from '../services/validation.service';
export function FormDirective($rootScope: ng.IRootScopeService, validationService: ValidationService) {
return {
require: 'form',
restrict: 'A',
link: (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes,
formCtrl: ng.IFormController) => {
const watchPromise = attrs.bitForm || null;
if (watchPromise) {
scope.$watch(watchPromise, formSubmitted.bind(null, formCtrl, scope));
}
},
};
function formSubmitted(form: any, scope: ng.IScope, promise: any) {
if (!promise || !promise.then) {
return;
}
// start loading
form.$loading = true;
promise.then((response: any) => {
form.$loading = false;
}, (reason: any) => {
form.$loading = false;
validationService.showError(reason);
});
}
}