delete attachments

This commit is contained in:
Kyle Spearrin 2017-07-07 10:58:51 -04:00
parent b380d723b7
commit ff729608e1
4 changed files with 38 additions and 9 deletions

View File

@ -46,7 +46,8 @@
method: 'POST', method: 'POST',
headers: { 'Content-Type': undefined }, headers: { 'Content-Type': undefined },
params: { id: '@id' } params: { id: '@id' }
} },
delAttachment: { url: _apiUri + '/ciphers/:id/attachment/:attachmentId/delete', method: 'POST', params: { id: '@id', attachmentId: '@attachmentId' } }
}); });
_service.organizations = $resource(_apiUri + '/organizations/:id', {}, { _service.organizations = $resource(_apiUri + '/organizations/:id', {}, {

View File

@ -70,7 +70,7 @@ angular
name: _service.decryptProperty(encryptedCipher.Data.Name, key, false), name: _service.decryptProperty(encryptedCipher.Data.Name, key, false),
username: _service.decryptProperty(encryptedCipher.Data.Username, key, true), username: _service.decryptProperty(encryptedCipher.Data.Username, key, true),
password: _service.decryptProperty(encryptedCipher.Data.Password, key, true), password: _service.decryptProperty(encryptedCipher.Data.Password, key, true),
hasAttachments: !!encryptedCipher.Attachments hasAttachments: !!encryptedCipher.Attachments && encryptedCipher.Attachments.length > 0
}; };
return login; return login;

View File

@ -7,6 +7,7 @@
$scope.login = {}; $scope.login = {};
$scope.readOnly = false; $scope.readOnly = false;
$scope.loading = true; $scope.loading = true;
var closing = false;
apiService.logins.get({ id: loginId }, function (login) { apiService.logins.get({ id: loginId }, function (login) {
$scope.login = cipherService.decryptLogin(login); $scope.login = cipherService.decryptLogin(login);
@ -46,10 +47,8 @@
}).then(function (response) { }).then(function (response) {
$analytics.eventTrack('Added Attachment'); $analytics.eventTrack('Added Attachment');
toastr.success('The attachment has been added.'); toastr.success('The attachment has been added.');
$uibModalInstance.close({ closing = true;
action: 'attach', $uibModalInstance.close(true);
data: $scope.login
});
}); });
}; };
reader.onerror = function (evt) { reader.onerror = function (evt) {
@ -104,7 +103,36 @@
return null; return null;
} }
$scope.remove = function (attachment) {
if (!confirm('Are you sure you want to delete this attachment (' + attachment.fileName + ')?')) {
return;
}
attachment.loading = true;
apiService.ciphers.delAttachment({ id: loginId, attachmentId: attachment.id }).$promise.then(function () {
attachment.loading = false;
$analytics.eventTrack('Deleted Attachment');
var index = $scope.login.attachments.indexOf(attachment);
if (index > -1) {
$scope.login.attachments.splice(index, 1);
}
}, function () {
toastr.error('Cannot delete attachment.');
attachment.loading = false;
});
};
$scope.close = function () { $scope.close = function () {
$uibModalInstance.dismiss('cancel'); $uibModalInstance.dismiss('cancel');
}; };
$scope.$on('modal.closing', function (e, reason, closed) {
if (closing) {
return;
}
e.preventDefault();
closing = true;
$uibModalInstance.close(!!$scope.login.attachments && $scope.login.attachments.length > 0);
});
}); });

View File

@ -217,7 +217,7 @@
return; return;
} }
var addModel = $uibModal.open({ var attachmentModel = $uibModal.open({
animation: true, animation: true,
templateUrl: 'app/vault/views/vaultAttachments.html', templateUrl: 'app/vault/views/vaultAttachments.html',
controller: 'vaultAttachmentsController', controller: 'vaultAttachmentsController',
@ -226,8 +226,8 @@
} }
}); });
addModel.result.then(function (data) { attachmentModel.result.then(function (hasAttachments) {
login.hasAttachments = hasAttachments;
}); });
}); });
}; };