From 1c285f8299b119cdcc1bf66978ecf36f8670d27f Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Thu, 31 May 2018 20:36:55 -0300 Subject: [PATCH] do not require confirm action on destroyRecord from a modal for new non persisted records --- addon/mixins/modal-base.coffee | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/addon/mixins/modal-base.coffee b/addon/mixins/modal-base.coffee index 700047a..f65fc58 100644 --- a/addon/mixins/modal-base.coffee +++ b/addon/mixins/modal-base.coffee @@ -118,14 +118,20 @@ export default Ember.Component.extend if my_scope.get('router.globals.current_route.path')?.match("^#{flat_model_name}.show") my_scope.get('router').transitionTo flat_model_name - @modal 'confirm', - title_path: @get('modal_options.destroy_text_path') || 'general.destroy.are_you_sure' - model: @get('model') - ok: -> - model = @get("model") - model = model.get("_content") if model.__changeset__ - model.destroyRecord().then -> destroy_callback.call(my_scope, model) - @send 'closeModal' unless @preventClose + if @get('model.isNew') + model = @get('model') + model = model.get("_content") if model.__changeset__ + model.destroyRecord().then -> destroy_callback.call(my_scope, model) + @send 'closeModal' unless @preventClose + else + @modal 'confirm', + title_path: @get('modal_options.destroy_text_path') || 'general.destroy.are_you_sure' + model: @get('model') + ok: -> + model = @get("model") + model = model.get("_content") if model.__changeset__ + model.destroyRecord().then -> destroy_callback.call(my_scope, model) + @send 'closeModal' unless @preventClose closeModal: -> container = Ember.getOwner(@)