mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
Merge branch 'JordanLittell-email-validation'
This commit is contained in:
commit
7752757888
3 changed files with 43 additions and 2 deletions
|
@ -1,5 +1,12 @@
|
|||
#subscription-view
|
||||
|
||||
.invalid-email-message
|
||||
color: red
|
||||
font-size: 12px
|
||||
|
||||
.recipient-emails.invalid
|
||||
border: 1px solid red
|
||||
|
||||
.logged-out-blurb
|
||||
font-size: 18px
|
||||
|
||||
|
|
|
@ -150,7 +150,9 @@ block content
|
|||
if view.recipientSubs.state === 'subscribing'
|
||||
.alert.alert-info(data-i18n="subscribe.subscribing")
|
||||
else
|
||||
textarea.recipient-emails(rows=3, data-i18n="[placeholder]subscribe.recipient_emails_placeholder")
|
||||
if emailValidator.state === 'invalid'
|
||||
div.invalid-email-message(aria-hidden="true") please make sure all entries are valid emails
|
||||
textarea.recipient-emails(rows=3, data-i18n="[placeholder]subscribe.recipient_emails_placeholder")=emailValidator.lastEmails
|
||||
div
|
||||
button.recipients-subscribe-button.btn.btn-lg.btn-success(data-i18n="subscribe.subscribe_users")
|
||||
if view.recipientSubs.state === 'declined'
|
||||
|
|
|
@ -49,9 +49,15 @@ module.exports = class SubscriptionView extends RootView
|
|||
prepaidCode = utils.getQueryVariable '_ppc'
|
||||
@personalSub = new PersonalSub(@supermodel, prepaidCode)
|
||||
@recipientSubs = new RecipientSubs(@supermodel)
|
||||
@emailValidator = new EmailValidator(@superModel)
|
||||
@personalSub.update => @render?()
|
||||
@recipientSubs.update => @render?()
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
c.emailValidator = @emailValidator
|
||||
c
|
||||
|
||||
# Personal Subscriptions
|
||||
|
||||
onClickStartSubscription: (e) ->
|
||||
|
@ -82,7 +88,8 @@ module.exports = class SubscriptionView extends RootView
|
|||
|
||||
onClickRecipientsSubscribe: (e) ->
|
||||
emails = @$el.find('.recipient-emails').val().split('\n')
|
||||
@recipientSubs.startSubscribe(emails)
|
||||
valid = @emailValidator.validateEmails(emails, =>@render?())
|
||||
@recipientSubs.startSubscribe(emails) if valid
|
||||
|
||||
onClickRecipientUnsubscribe: (e) ->
|
||||
$(e.target).addClass('hide')
|
||||
|
@ -97,6 +104,31 @@ module.exports = class SubscriptionView extends RootView
|
|||
|
||||
# Helper classes for managing subscription actions and updating UI state
|
||||
|
||||
class EmailValidator
|
||||
|
||||
validateEmails: (emails, render) ->
|
||||
@lastEmails = emails.join('\n')
|
||||
#taken from http://www.regular-expressions.info/email.html
|
||||
emailRegex = /[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}/
|
||||
@validEmails = (email for email in emails when emailRegex.test(email.trim().toLowerCase()))
|
||||
return @emailsInvalid(render) if @validEmails.length < emails.length
|
||||
return @emailsValid(render)
|
||||
|
||||
emailString: ->
|
||||
return unless @validEmails
|
||||
return @validEmails.join('\n')
|
||||
|
||||
emailsInvalid: (render) ->
|
||||
@state = "invalid"
|
||||
render()
|
||||
return false
|
||||
|
||||
emailsValid: (render) ->
|
||||
@state = "valid"
|
||||
render()
|
||||
return true
|
||||
|
||||
|
||||
class PersonalSub
|
||||
constructor: (@supermodel, @prepaidCode) ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue