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
block modal-header-content
h3 #{confirmTitle}
h3= view.title
block modal-body-content
p #{confirmBody}
p= view.body
block modal-footer-content
button.btn.btn-secondary#decline-button(type="button", data-dismiss="modal") #{confirmDecline}
button.btn.btn-primary#confirm-button(type="button", data-dismiss=closeOnConfirm === true ? "modal" : undefined) #{confirmConfirm}
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)= view.confirm

View file

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

View file

@ -85,10 +85,10 @@ module.exports = class AchievementEditView extends RootView
confirmRecalculation: (e, all=false) ->
renderData =
'confirmTitle': '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?"
'confirmDecline': 'Not really'
'confirmConfirm': 'Definitely'
title: 'Are you really sure?'
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?"
decline: 'Not really'
confirm: 'Definitely'
confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', @recalculateAchievement
@ -100,10 +100,10 @@ module.exports = class AchievementEditView extends RootView
confirmDeletion: ->
renderData =
'confirmTitle': '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?'
'confirmDecline': 'Not really'
'confirmConfirm': 'Definitely'
title: 'Are you really sure?'
body: 'This will completely delete the achievement, potentially breaking a lot of stuff you don\'t want breaking. Are you entirely sure?'
decline: 'Not really'
confirm: 'Definitely'
confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', @deleteAchievement

View file

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

View file

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