diff --git a/ui/admin/app/components/form/target/details/index.hbs b/ui/admin/app/components/form/target/details/index.hbs index 56cf42ff7..2fa1f77bd 100644 --- a/ui/admin/app/components/form/target/details/index.hbs +++ b/ui/admin/app/components/form/target/details/index.hbs @@ -1,5 +1,5 @@ message) - async submit() { - const target = this.args.model; - const numHostSources = target.host_sources?.length; - const address = target.address; - if (address && numHostSources) { - try { - await this.confirm.confirm( - this.intl.t( - 'resources.target.questions.delete-host-sources.message', - { numHostSources } - ), - { - title: 'resources.target.questions.delete-host-sources.title', - confirm: 'actions.remove-resources', - } - ); - } catch (e) { - // if the user denies, do nothing and return - return; - } - - await target.removeHostSources( - target.host_sources.map((hs) => hs.host_source_id) - ); - // After saving the host sources, the model gets reset to an empty address, - // so we need to update the address with the previous value before saving - target.address = address; - } - - await this.args.submit(); - } } diff --git a/ui/admin/app/routes/scopes/scope/targets.js b/ui/admin/app/routes/scopes/scope/targets.js index da6a73893..1adab4283 100644 --- a/ui/admin/app/routes/scopes/scope/targets.js +++ b/ui/admin/app/routes/scopes/scope/targets.js @@ -13,6 +13,7 @@ export default class ScopesScopeTargetsRoute extends Route { @service session; @service can; @service router; + @service confirm; // =methods @@ -69,6 +70,40 @@ export default class ScopesScopeTargetsRoute extends Route { this.refresh(); } + @action + @loading + @notifyError(({ message }) => message) + async saveWithAddress(target) { + const numHostSources = target.host_sources?.length; + const address = target.address; + if (address && numHostSources) { + try { + await this.confirm.confirm( + this.intl.t( + 'resources.target.questions.delete-host-sources.message', + { numHostSources } + ), + { + title: 'resources.target.questions.delete-host-sources.title', + confirm: 'actions.remove-resources', + } + ); + } catch (e) { + // if the user denies, do nothing and return + return; + } + + await target.removeHostSources( + target.host_sources.map((hs) => hs.host_source_id) + ); + // After saving the host sources, the model gets reset to an empty address, + // so we need to update the address with the previous value before saving + target.address = address; + } + + await this.save(target); + } + /** * Deletes a target and redirects to targets index. * @param {TargetModel} target diff --git a/ui/admin/app/templates/scopes/scope/targets/target/index.hbs b/ui/admin/app/templates/scopes/scope/targets/target/index.hbs index 164acd745..626c46a18 100644 --- a/ui/admin/app/templates/scopes/scope/targets/target/index.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/target/index.hbs @@ -19,7 +19,7 @@