Refactor ConfirmModal for and

This commit is contained in:
Scott Erickson 2016-03-14 15:35:33 -07:00
parent 1c629a3181
commit 93c7072d8d
5 changed files with 30 additions and 37 deletions

View file

@ -1,11 +1,11 @@
extends /templates/core/modal-base extends /templates/core/modal-base
block modal-header-content block modal-header-content
h3 #{confirmTitle} h3= view.title
block modal-body-content block modal-body-content
p #{confirmBody} p= view.body
block modal-footer-content block modal-footer-content
button.btn.btn-secondary#decline-button(type="button", data-dismiss="modal") #{confirmDecline} button.btn.btn-secondary#decline-button(type="button", data-dismiss="modal")= view.decline
button.btn.btn-primary#confirm-button(type="button", data-dismiss=closeOnConfirm === true ? "modal" : undefined) #{confirmConfirm} button.btn.btn-primary#confirm-button(type="button", data-dismiss=closeOnConfirm === true ? "modal" : undefined)= view.confirm

View file

@ -64,10 +64,10 @@ module.exports = class AccountSettingsView extends CocoView
onClickDeleteAccountButton: (e) -> onClickDeleteAccountButton: (e) ->
@validateCredentialsForDestruction @$el.find('#delete-account-form'), => @validateCredentialsForDestruction @$el.find('#delete-account-form'), =>
renderData = renderData =
confirmTitle: 'Are you really sure?' title: 'Are you really sure?'
confirmBody: 'This will completely delete your account. This action CANNOT be undone. Are you entirely sure?' body: 'This will completely delete your account. This action CANNOT be undone. Are you entirely sure?'
confirmDecline: 'Cancel' decline: 'Cancel'
confirmConfirm: 'DELETE Your Account' confirm: 'DELETE Your Account'
confirmModal = new ConfirmModal renderData confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', @deleteAccount confirmModal.on 'confirm', @deleteAccount
@openModalView confirmModal @openModalView confirmModal
@ -75,10 +75,10 @@ module.exports = class AccountSettingsView extends CocoView
onClickResetProgressButton: -> onClickResetProgressButton: ->
@validateCredentialsForDestruction @$el.find('#reset-progress-form'), => @validateCredentialsForDestruction @$el.find('#reset-progress-form'), =>
renderData = renderData =
confirmTitle: 'Are you really sure?' title: 'Are you really sure?'
confirmBody: 'This will completely erase your progress: code, levels, achievements, earned gems, and course work. This action CANNOT be undone. Are you entirely sure?' body: 'This will completely erase your progress: code, levels, achievements, earned gems, and course work. This action CANNOT be undone. Are you entirely sure?'
confirmDecline: 'Cancel' decline: 'Cancel'
confirmConfirm: 'Erase ALL Progress' confirm: 'Erase ALL Progress'
confirmModal = new ConfirmModal renderData confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', @resetProgress confirmModal.on 'confirm', @resetProgress
@openModalView confirmModal @openModalView confirmModal

View file

@ -85,10 +85,10 @@ module.exports = class AchievementEditView extends RootView
confirmRecalculation: (e, all=false) -> confirmRecalculation: (e, all=false) ->
renderData = renderData =
'confirmTitle': 'Are you really sure?' title: 'Are you really sure?'
'confirmBody': "This will trigger recalculation of #{if all then 'all achievements' else 'the achievement'} for all users. Are you really sure you want to go down this path?" body: "This will trigger recalculation of #{if all then 'all achievements' else 'the achievement'} for all users. Are you really sure you want to go down this path?"
'confirmDecline': 'Not really' decline: 'Not really'
'confirmConfirm': 'Definitely' confirm: 'Definitely'
confirmModal = new ConfirmModal renderData confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', @recalculateAchievement confirmModal.on 'confirm', @recalculateAchievement
@ -100,10 +100,10 @@ module.exports = class AchievementEditView extends RootView
confirmDeletion: -> confirmDeletion: ->
renderData = renderData =
'confirmTitle': 'Are you really sure?' title: 'Are you really sure?'
'confirmBody': 'This will completely delete the achievement, potentially breaking a lot of stuff you don\'t want breaking. Are you entirely sure?' body: 'This will completely delete the achievement, potentially breaking a lot of stuff you don\'t want breaking. Are you entirely sure?'
'confirmDecline': 'Not really' decline: 'Not really'
'confirmConfirm': 'Definitely' confirm: 'Definitely'
confirmModal = new ConfirmModal renderData confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', @deleteAchievement confirmModal.on 'confirm', @deleteAchievement

View file

@ -8,19 +8,12 @@ module.exports = class ConfirmModal extends ModalView
closeOnConfirm: true closeOnConfirm: true
events: events:
'click #decline-button': 'onDecline' 'click #decline-button': 'onClickDecline'
'click #confirm-button': 'onConfirm' 'click #confirm-button': 'onClickConfirm'
constructor: (@renderData={}, options={}) -> initialize: (options) ->
super(options) _.assign @, _.pick(options, 'title', 'body', 'decline', 'confirm', 'closeOnConfirm', 'closeButton')
getRenderData: -> onClickDecline: -> @trigger 'decline'
context = super()
context.closeOnConfirm = @closeOnConfirm
_.extend context, @renderData
setRenderData: (@renderData) -> onClickConfirm: -> @trigger 'confirm'
onDecline: -> @trigger 'decline'
onConfirm: -> @trigger 'confirm'

View file

@ -98,10 +98,10 @@ module.exports = class PollEditView extends RootView
confirmDeletion: -> confirmDeletion: ->
renderData = renderData =
'confirmTitle': 'Are you really sure?' title: 'Are you really sure?'
'confirmBody': 'This will completely delete the poll, potentially breaking a lot of stuff you don\'t want breaking. Are you entirely sure?' body: 'This will completely delete the poll, potentially breaking a lot of stuff you don\'t want breaking. Are you entirely sure?'
'confirmDecline': 'Not really' decline: 'Not really'
'confirmConfirm': 'Definitely' confirm: 'Definitely'
confirmModal = new ConfirmModal renderData confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', @deletePoll confirmModal.on 'confirm', @deletePoll