From 57c5384ec19f826e31ee502552d4b2e4e094cc90 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Wed, 21 Oct 2015 15:34:07 -0700 Subject: [PATCH] Refactor editor:save-new-version from a mediator event to a normal Backbone event Part of a push to move away from global subscriptions when 'local' ones will do. --- app/schemas/subscriptions/editor.coffee | 4 ---- app/views/editor/article/ArticleEditView.coffee | 8 ++++---- app/views/editor/modal/SaveVersionModal.coffee | 2 +- app/views/editor/thang/ThangTypeEditView.coffee | 6 ++++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/schemas/subscriptions/editor.coffee b/app/schemas/subscriptions/editor.coffee index a0a416f25..46b6e0f86 100644 --- a/app/schemas/subscriptions/editor.coffee +++ b/app/schemas/subscriptions/editor.coffee @@ -4,10 +4,6 @@ module.exports = 'editor:campaign-analytics-modal-closed': c.object {title: 'Campaign editor analytics modal closed'}, targetLevelSlug: {type: 'string'} - 'editor:save-new-version': c.object {title: 'Save New Version', description: 'Published when a version gets saved', required: ['major', 'commitMessage']}, - major: {type: 'boolean'} - commitMessage: {type: 'string'} - 'editor:view-switched': c.object {title: 'Level View Switched', description: 'Published whenever the view switches'}, targetURL: {type: 'string'} diff --git a/app/views/editor/article/ArticleEditView.coffee b/app/views/editor/article/ArticleEditView.coffee index 63d7e7cc4..8c308406f 100644 --- a/app/views/editor/article/ArticleEditView.coffee +++ b/app/views/editor/article/ArticleEditView.coffee @@ -16,9 +16,6 @@ module.exports = class ArticleEditView extends RootView 'click #history-button': 'showVersionHistory' 'click #save-button': 'openSaveModal' - subscriptions: - 'editor:save-new-version': 'saveNewArticle' - constructor: (options, @articleID) -> super options @article = new Article(_id: @articleID) @@ -82,7 +79,10 @@ module.exports = class ArticleEditView extends RootView return false openSaveModal: -> - @openModalView(new SaveVersionModal({model: @article})) + modal = new SaveVersionModal({model: @article}) + @openModalView(modal) + @listenToOnce modal, 'save-new-version', @saveNewArticle + @listenToOnce modal, 'hidden', -> @stopListening(modal) saveNewArticle: (e) -> @treema.endExistingEdits() diff --git a/app/views/editor/modal/SaveVersionModal.coffee b/app/views/editor/modal/SaveVersionModal.coffee index 91cd3e997..f615c0d13 100644 --- a/app/views/editor/modal/SaveVersionModal.coffee +++ b/app/views/editor/modal/SaveVersionModal.coffee @@ -45,7 +45,7 @@ module.exports = class SaveVersionModal extends ModalView if @isPatch then @submitPatch() else @saveChanges() saveChanges: -> - Backbone.Mediator.publish 'editor:save-new-version', { + @trigger 'save-new-version', { major: @$el.find('#major-version').prop('checked') commitMessage: @$el.find('#commit-message').val() } diff --git a/app/views/editor/thang/ThangTypeEditView.coffee b/app/views/editor/thang/ThangTypeEditView.coffee index 940492f73..326896f2c 100644 --- a/app/views/editor/thang/ThangTypeEditView.coffee +++ b/app/views/editor/thang/ThangTypeEditView.coffee @@ -167,7 +167,6 @@ module.exports = class ThangTypeEditView extends RootView subscriptions: 'editor:thang-type-color-groups-changed': 'onColorGroupsChanged' - 'editor:save-new-version': 'saveNewThangType' # init / render @@ -590,7 +589,10 @@ module.exports = class ThangTypeEditView extends RootView _.delay((-> document.location.reload()), 500) openSaveModal: -> - @openModalView new SaveVersionModal model: @thangType + modal = new SaveVersionModal model: @thangType + @openModalView modal + @listenToOnce modal, 'save-new-version', @saveNewThangType + @listenToOnce modal, 'hidden', -> @stopListening(modal) startForking: (e) -> @openModalView new ForkModal model: @thangType, editorPath: 'thang'