mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-29 14:19:48 -04:00
Move redeem prepaid code UI out of modal
This commit is contained in:
parent
f9b9ac8f86
commit
5eadd926b3
2 changed files with 79 additions and 13 deletions
app
|
@ -21,7 +21,7 @@ block content
|
|||
.panel-title
|
||||
a(data-toggle="collapse" href="#purchasepanel")
|
||||
span(data-i18n="account_prepaid.purchase_code")
|
||||
.panel-collapse.collapse(class=ppc ? "": "in")#purchasepanel
|
||||
.panel-collapse.collapse(class=ppcQuery ? "": "in")#purchasepanel
|
||||
.panel-body
|
||||
p Subscription Codes can be redeemed to add premium subscription time to one or more Code Combat accounts.
|
||||
p Each Code Combat account can only redeem a particular Subscription Code once.
|
||||
|
@ -50,12 +50,19 @@ block content
|
|||
span(data-i18n="account_prepaid.redeem_codes")
|
||||
.panel-collapse.collapse.in#redeempanel
|
||||
.panel-body
|
||||
.form-horizontal
|
||||
.form-group
|
||||
label.control-label.col-md-2(for="ppc") Code:
|
||||
.col-md-10
|
||||
input#ppc.form-control(name="ppc", type="text", value="#{ppc}" required)
|
||||
button#redeem-button.btn.btn-success.pull-right View Code Details
|
||||
p
|
||||
span.spr Prepaid Code:
|
||||
input.input-ppc(name="ppc", type="text", value="#{ppc}", required)
|
||||
if ppcInfo && ppcInfo.length > 0
|
||||
p
|
||||
each info in ppcInfo
|
||||
div
|
||||
!= info
|
||||
p
|
||||
span.spr
|
||||
button.btn.btn-info.btn-check-code Lookup prepaid code
|
||||
span
|
||||
button.btn.btn-success.btn-redeem-code Apply to your account
|
||||
.row
|
||||
.col-md-12
|
||||
.panel.panel-default
|
||||
|
@ -96,4 +103,4 @@ block content
|
|||
else
|
||||
td Redeemed
|
||||
else
|
||||
p No codes yet!
|
||||
p No codes yet!
|
||||
|
|
|
@ -8,6 +8,7 @@ utils = require 'core/utils'
|
|||
RedeemModal = require 'views/account/PrepaidRedeemModal'
|
||||
forms = require 'core/forms'
|
||||
|
||||
# TODO: remove redeem code modal
|
||||
|
||||
module.exports = class PrepaidView extends RootView
|
||||
id: 'prepaid-view'
|
||||
|
@ -19,6 +20,8 @@ module.exports = class PrepaidView extends RootView
|
|||
'change #months': 'onMonthsChanged'
|
||||
'click #purchase-button': 'onPurchaseClicked'
|
||||
'click #redeem-button': 'onRedeemClicked'
|
||||
'click .btn-check-code': 'onClickCheckCode'
|
||||
'click .btn-redeem-code': 'onClickRedeemCode'
|
||||
|
||||
subscriptions:
|
||||
'stripe:received-token': 'onStripeReceivedToken'
|
||||
|
@ -38,15 +41,20 @@ module.exports = class PrepaidView extends RootView
|
|||
@render?()
|
||||
@codes.on 'sync', (code) =>
|
||||
@render?()
|
||||
|
||||
@supermodel.loadCollection(@codes, 'prepaid', {cache: false})
|
||||
|
||||
@ppc = utils.getQueryVariable('_ppc') ? ''
|
||||
unless _.isEmpty(@ppc)
|
||||
@ppcQuery = true
|
||||
@loadPrepaid(@ppc)
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
c.purchase = @purchase
|
||||
c.codes = @codes
|
||||
c.ppc = @ppc
|
||||
c.ppcInfo = @ppcInfo ? []
|
||||
c.ppcQuery = @ppcQuery ? false
|
||||
c
|
||||
|
||||
afterRender: ->
|
||||
|
@ -60,7 +68,6 @@ module.exports = class PrepaidView extends RootView
|
|||
@purchase.total = getPrepaidCodeAmount(@baseAmount, @purchase.users, @purchase.months)
|
||||
@renderSelectors("#total", "#users", "#months")
|
||||
|
||||
|
||||
# Form Input Callbacks
|
||||
onUsersChanged: (e) ->
|
||||
newAmount = $(e.target).val()
|
||||
|
@ -135,15 +142,16 @@ module.exports = class PrepaidView extends RootView
|
|||
data: { ppc: @ppc }
|
||||
|
||||
options.error = (model, res, options, foo) =>
|
||||
console.error 'FAILED redeeming prepaid code'
|
||||
# console.error 'FAILED redeeming prepaid code'
|
||||
msg = model.responseText ? ''
|
||||
@statusMessage "Error: Could not redeem prepaid code. #{msg}", "error"
|
||||
|
||||
options.success = (model, res, options) =>
|
||||
console.log 'SUCCESS redeeming prepaid code'
|
||||
# console.log 'SUCCESS redeeming prepaid code'
|
||||
@statusMessage "Prepaid Code Redeemed!", "success"
|
||||
@supermodel.loadCollection(@codes, 'prepaid', {cache: false})
|
||||
@codes.fetch()
|
||||
me.fetch cache: false
|
||||
|
||||
@supermodel.addRequestResource('subscribe_prepaid', options, 0).load()
|
||||
|
||||
|
@ -171,9 +179,60 @@ module.exports = class PrepaidView extends RootView
|
|||
# Not sure when this will happen. Stripe popup seems to give appropriate error messages.
|
||||
|
||||
options.success = (model, response, options) =>
|
||||
console.log 'SUCCESS: Prepaid purchase', model.code
|
||||
# console.log 'SUCCESS: Prepaid purchase', model.code
|
||||
@statusMessage "Successfully purchased Prepaid Code!", "success"
|
||||
@codes.add(model)
|
||||
|
||||
@statusMessage "Finalizing purchase...", "information"
|
||||
@supermodel.addRequestResource('purchase_prepaid', options, 0).load()
|
||||
|
||||
loadPrepaid: (ppc) ->
|
||||
return unless ppc
|
||||
options =
|
||||
cache: false
|
||||
method: 'GET'
|
||||
url: "/db/prepaid/-/code/#{ppc}"
|
||||
|
||||
options.success = (model, res, options) =>
|
||||
@ppcInfo = []
|
||||
if model.get('type') is 'terminal_subscription'
|
||||
months = model.get('properties')?.months ? 0
|
||||
maxRedeemers = model.get('maxRedeemers') ? 0
|
||||
redeemers = model.get('redeemers') ? []
|
||||
unlocksLeft = maxRedeemers - redeemers.length
|
||||
@ppcInfo.push "This prepaid code adds <strong>#{months} months of subscription</strong> to your account."
|
||||
@ppcInfo.push "It can be used <strong>#{unlocksLeft} more</strong> times."
|
||||
# TODO: user needs to know they can't apply it more than once to their account
|
||||
else
|
||||
@ppcInfo.push "Type: #{model.get('type')}"
|
||||
@render?()
|
||||
options.error = (model, res, options) =>
|
||||
@statusMessage "Unable to retrieve code.", "error"
|
||||
|
||||
@prepaid = new Prepaid()
|
||||
@prepaid.fetch(options)
|
||||
|
||||
onClickCheckCode: (e) ->
|
||||
@ppc = $('.input-ppc').val()
|
||||
unless @ppc
|
||||
@statusMessage "You must enter a code.", "error"
|
||||
return
|
||||
@ppcInfo = []
|
||||
@render?()
|
||||
@loadPrepaid(@ppc)
|
||||
|
||||
onClickRedeemCode: (e) ->
|
||||
@ppc = $('.input-ppc').val()
|
||||
options =
|
||||
url: '/db/subscription/-/subscribe_prepaid'
|
||||
method: 'POST'
|
||||
data: { ppc: @ppc }
|
||||
options.error = (model, res, options, foo) =>
|
||||
msg = model.responseText ? ''
|
||||
@statusMessage "Error: Could not redeem prepaid code. #{msg}", "error"
|
||||
options.success = (model, res, options) =>
|
||||
@statusMessage "Prepaid applied to your account!", "success"
|
||||
@codes.fetch cache: false
|
||||
me.fetch cache: false
|
||||
@loadPrepaid(@ppc)
|
||||
@supermodel.addRequestResource('subscribe_prepaid', options, 0).load()
|
||||
|
|
Loading…
Add table
Reference in a new issue