mirror of
https://github.com/bitwarden/web
synced 2025-12-13 23:03:18 +00:00
reorganize project folder structure and remove asp.net dependency
This commit is contained in:
35
src/app/directives/apiFormDirective.js
Normal file
35
src/app/directives/apiFormDirective.js
Normal file
@@ -0,0 +1,35 @@
|
||||
angular
|
||||
.module('bit.directives')
|
||||
|
||||
.directive('apiForm', function ($rootScope, validationService) {
|
||||
return {
|
||||
require: 'form',
|
||||
restrict: 'A',
|
||||
link: function (scope, element, attrs, formCtrl) {
|
||||
var watchPromise = attrs.apiForm || null;
|
||||
if (watchPromise !== void 0) {
|
||||
scope.$watch(watchPromise, formSubmitted.bind(null, formCtrl, scope));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function formSubmitted(form, scope, promise) {
|
||||
if (!promise || !promise.then) {
|
||||
return;
|
||||
}
|
||||
|
||||
// reset errors
|
||||
form.$errors = null;
|
||||
|
||||
// start loading
|
||||
form.$loading = true;
|
||||
|
||||
promise.then(function success(response) {
|
||||
form.$loading = false;
|
||||
}, function failure(reason) {
|
||||
form.$loading = false;
|
||||
validationService.addErrors(form, reason);
|
||||
scope.$broadcast('show-errors-check-validity');
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user