mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
1. email validation when subscribing other users
This commit is contained in:
parent
b9f0aa1622
commit
e0be8e94ea
3 changed files with 33 additions and 1 deletions
|
@ -1,4 +1,11 @@
|
|||
#subscription-view
|
||||
|
||||
.invalid-email-message
|
||||
color: red
|
||||
font-size: 12px
|
||||
|
||||
.recipient-emails.invalid
|
||||
border: 1px solid red
|
||||
|
||||
.logged-out-blurb
|
||||
font-size: 18px
|
||||
|
|
|
@ -150,6 +150,8 @@ block content
|
|||
if recipientSubs.state === 'subscribing'
|
||||
.alert.alert-info(data-i18n="subscribe.subscribing")
|
||||
else
|
||||
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")
|
||||
div
|
||||
button.recipients-subscribe-button.btn.btn-lg.btn-success(data-i18n="subscribe.subscribe_users")
|
||||
|
|
|
@ -49,6 +49,7 @@ 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?()
|
||||
|
||||
|
@ -56,6 +57,7 @@ module.exports = class SubscriptionView extends RootView
|
|||
c = super()
|
||||
c.personalSub = @personalSub
|
||||
c.recipientSubs = @recipientSubs
|
||||
c.emailValidator = @emailValidator
|
||||
c
|
||||
|
||||
# Personal Subscriptions
|
||||
|
@ -88,7 +90,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')
|
||||
|
@ -102,6 +105,26 @@ module.exports = class SubscriptionView extends RootView
|
|||
@recipientSubs.finishSubscribe(e.token.id, => @render?())
|
||||
|
||||
# Helper classes for managing subscription actions and updating UI state
|
||||
|
||||
|
||||
class EmailValidator
|
||||
|
||||
validateEmails: (emails, render) ->
|
||||
emailRegex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
|
||||
@validEmails = (emailRegex.test(email.trim().toLowerCase()) for email in emails)
|
||||
return @emailsInvalid(render) if _.contains(@validEmails, false)
|
||||
return @emailsValid(render)
|
||||
|
||||
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