diff options
Diffstat (limited to 'app/common/directives/certificate.js')
-rw-r--r-- | app/common/directives/certificate.js | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/app/common/directives/certificate.js b/app/common/directives/certificate.js index 45b8c99..48fa851 100644 --- a/app/common/directives/certificate.js +++ b/app/common/directives/certificate.js @@ -9,8 +9,8 @@ window.angular && (function(angular) { 'template': require('./certificate.html'), 'scope': {'cert': '=', 'reload': '&'}, 'controller': [ - '$scope', 'APIUtils', 'toastService', 'Constants', - function($scope, APIUtils, toastService, Constants) { + '$scope', 'APIUtils', 'toastService', 'Constants', '$uibModal', + function($scope, APIUtils, toastService, Constants, $uibModal) { var certificateType = 'PEM'; var availableCertificateTypes = Constants.CERTIFICATE_TYPES; @@ -35,6 +35,65 @@ window.angular && (function(angular) { } }; + $scope.isDeletable = function(certificate) { + return certificate.Description == 'TrustStore Certificate'; + }; + + $scope.confirmDeleteCert = function(certificate) { + initRemoveModal(certificate); + }; + + /** + * Intiate remove certificate modal + * @param {*} certificate + */ + function initRemoveModal(certificate) { + const template = require('./certificate-modal-remove.html'); + $uibModal + .open({ + template, + windowTopClass: 'uib-modal', + ariaLabelledBy: 'dialog_label', + controllerAs: 'modalCtrl', + controller: function() { + this.certificate = certificate; + } + }) + .result + .then(() => { + deleteCert(certificate); + }) + .catch( + () => { + // do nothing + }) + }; + + /** + * Removes certificate + * @param {*} certificate + */ + function deleteCert(certificate) { + $scope.confirm_delete = false; + APIUtils.deleteRedfishObject(certificate['@odata.id']) + .then( + function(data) { + $scope.loading = false; + toastService.success( + $scope.getCertificateName(certificate.Description) + + ' was deleted.'); + $scope.reload(); + }, + function(error) { + console.log(error); + $scope.loading = false; + toastService.error( + 'Unable to delete ' + + $scope.getCertificateName(certificate.Description)); + }); + return; + }; + $scope.replaceCertificate = function(certificate) { $scope.loading = true; if (certificate.file.name.split('.').pop() !== |