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:
committed by
Kyle Spearrin
parent
b297c4279a
commit
f5ccc22076
31
src/popup/app/directives/form.directive.ts
Normal file
31
src/popup/app/directives/form.directive.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user