Permalink
Browse files

home registration

  • Loading branch information...
1 parent e1f8b8a commit e031b6c25c7e4f0f6328a7ffb8b744f0daeb47a6 @banacorn committed Feb 16, 2013

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,61 @@
+define [
+ 'underscore',
+ 'backbone'
+], (_, Backbone) ->
+
+ class Model extends Backbone.Model
+
+ url: '/api/users'
+
+ initialize: ->
+
+ @on 'error', (model, error) =>
+
+ if error.status is 403
+ errorMessage = (JSON.parse error.responseText).errors
+
+ if _.contains errorMessage, 'Username has already been taken'
+ @trigger 'error', @, 'username taken'
+ if _.contains errorMessage, 'Email has already been taken'
+ @trigger 'error', @, 'email taken'
+ if _.contains errorMessage, 'Username is too long (maximum is 20 characters)'
+ @trigger 'error', @, 'username too lone'
+
+
+ defaults:
+ username: undefined
+ email: undefined
+ password: undefined
+ passwordConfirmation: 'fuck you'
+
+ validate: (user) ->
+ if not user.username?
+ return "username undefined"
+ if not user.email?
+ return "email undefined"
+ if not user.password?
+ return "password undefined"
+ if user.username.length < 3
+ return "username too short"
+ if user.username.length > 20
+ return "username too long"
+ if user.password isnt user.passwordConfirmation
+ return "password confirmation mismatched"
+ if user.password.length < 6
+ return "password too short"
+
+
+
+
+ parse: (result) ->
+
+ # console.log 'success'
+ # console.log result
+ @trigger 'success', @
+ # console.log result
+ # if result.success
+ # else
+ # if _.contains result.errors, 'Username has already been taken'
+ # @trigger 'error', @, 'username taken'
+ # if _.contains result.errors, 'Email has already been taken'
+ # @trigger 'error', @, 'email taken'
View
@@ -20,6 +20,18 @@ $blueLight = lighten($blue, 10%)
border: none
#home
+
+ #home-hero
+ text-align: center
+
+ #home-iconset
+ font-size: 600%
+ color: $grayLighter
+ padding: 20px
+
+ #home-registration h3
+ text-align: center
+
section
padding: 40px 0
View
@@ -1,14 +1,49 @@
define [
+ 'models/registration',
'jquery',
'backbone',
'template'
-], ($, Backbone, $$) ->
+], (ModelRegistration, $, Backbone, $$) ->
class Home extends Backbone.View
tagName: 'article'
id: 'home'
template: $$.home
- initialize: -> @render()
+ initialize: ->
+ @render()
render: ->
@$el.html @template.render()
return @
+
+ events:
+ 'submit #registration': 'submit'
+
+ submit: ->
+
+
+ # @resetError()
+
+ registrationModel = new ModelRegistration
+ username: $('#inputUsername').val()
+ email: $('#inputEmail').val()
+ password: $('#inputPassword').val()
+ passwordConfirmation: $('#inputPasswordConfirmation').val()
+
+ registrationModel.on 'error', (model, error) =>
+ console.log error
+ # switch error
+ # when 'password confirmation mismatched' then @errorPasswordMismatched()
+ # when 'password too short' then @errorPasswordTooShort()
+ # when 'username too short' then @errorUsernameTooShort()
+ # when 'username too long' then @errorUsernameTooLong()
+ # when 'username taken' then @errorUsernameTaken()
+ # when 'email taken' then @errorEmailTaken()
+
+ registrationModel.on 'success', =>
+ console.log 'success'
+
+
+
+ registrationModel.save()
+
+ return false
View
@@ -10,6 +10,17 @@
background: #345;
border: none;
}
+#home #home-hero {
+ text-align: center;
+}
+#home #home-iconset {
+ font-size: 600%;
+ color: #eee;
+ padding: 20px;
+}
+#home #home-registration h3 {
+ text-align: center;
+}
#home section {
padding: 40px 0;
}
View
@@ -1,13 +1,47 @@
<section >
<div class="container">
- <h1 class="blue">Tryneeds 是什麼?</h1>
<div class="row">
- <div class="span6">
- <h2 class="lead">自由軟體中文化的翻譯平台<br>快加入自由軟體中文化的行列吧!</h2>
+ <div id="home-hero" class="span6">
+ <h1 class="blue">Tryneeds 是什麼?</h1>
+ <div id="home-iconset">
+ <i class="icon-file-alt"></i> <i class="icon-exchange"></i> <i class="icon-file-alt"></i>
+ </div>
+ <h2 class="lead">自由軟體中文化的翻譯平台<br>快加入志工們的行列吧!</h2>
</div>
- <div class="span6">
- <a href="/registration" class="btn btn-extra-large btn-primary">註冊 <i class="icon-chevron-right"></i></a>
+ <div id="home-registration" class="span6">
+ <h3 class="blue">馬上註冊</h3>
+ <form id="registration" class="form-horizontal">
+ <div class="control-group">
+ <label class="control-label" for="inputUsername">帳號</label>
+ <div class="controls">
+ <input type="text" id="inputUsername" placeholder="帳號">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="inputEmail">信箱</label>
+ <div class="controls">
+ <input type="email" id="inputEmail" placeholder="信箱">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="inputPassword">密碼</label>
+ <div class="controls">
+ <input type="password" id="inputPassword" placeholder="密碼" pattern=".{6,}">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="inputPasswordConfirmation">密碼確認</label>
+ <div class="controls">
+ <input type="password" id="inputPasswordConfirmation" placeholder="密碼確認" pattern=".{6,}">
+ </div>
+ </div>
+ <div class="control-group">
+ <div class="controls">
+ <button type="submit" class="btn btn-primary">註冊 <i class="icon-chevron-right"></i></button>
+ </div>
+ </div>
+ </form>
</div>
</div>
</div>
@@ -1 +1,23 @@
-<h1>註冊</h1>
+<h1>註冊</h1>
+<form class="form-horizontal">
+ <div class="control-group">
+ <label class="control-label" for="inputEmail">Email</label>
+ <div class="controls">
+ <input type="text" id="inputEmail" placeholder="Email">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="inputPassword">Password</label>
+ <div class="controls">
+ <input type="password" id="inputPassword" placeholder="Password">
+ </div>
+ </div>
+ <div class="control-group">
+ <div class="controls">
+ <label class="checkbox">
+ <input type="checkbox"> Remember me
+ </label>
+ <button type="submit" class="btn">Sign in</button>
+ </div>
+ </div>
+</form>

0 comments on commit e031b6c

Please sign in to comment.