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.
This commit is contained in:
Scott Erickson 2015-10-21 15:34:07 -07:00
parent 6636051765
commit 57c5384ec1
4 changed files with 9 additions and 11 deletions

View file

@ -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'}

View file

@ -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()

View file

@ -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()
}

View file

@ -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'