1
0
mirror of https://github.com/fazo96/homework.git synced 2025-03-29 23:48:38 +01:00

trying to fix alerts...

This commit is contained in:
fazo96 2014-05-25 19:49:32 +02:00
parent 5c6307bdfd
commit fa326ac809
3 changed files with 67 additions and 42 deletions

View File

@ -1,7 +1,7 @@
todos = new Meteor.Collection "todos" notes = new Meteor.Collection "notes"
if Meteor.isServer if Meteor.isServer
#todos.insert { content: "Example" } unless todos.find().fetch().length > 0 #notes.insert { content: "Example" } unless notes.find().fetch().length > 0
# Accounts # Accounts
### ###
Accounts.registerLoginHandler (req) -> Accounts.registerLoginHandler (req) ->
@ -18,48 +18,55 @@ if Meteor.isServer
loginExpirationInDays: 1 loginExpirationInDays: 1
} }
Meteor.publish "todos", -> Meteor.publish "my-notes", ->
todos.find( { userId: @userId } ) notes.find( { userId: @userId } ) unless not @userId
if Meteor.isClient if Meteor.isClient
Meteor.subscribe "todos" Meteor.subscribe "my-notes"
# Notes template # Notes template
Template.notes.notes = -> Template.notes.notes = ->
todos.find().fetch() notes.find().fetch()
Template.notes.events { Template.notes.events {
'click .delete': -> 'click .delete': ->
todos.remove @_id notes.remove @_id
} }
# Template for new notes
Template.adder.events { # Auth
'keypress #newNote': (e,template) -> Template.auth.alerts = []
if e.keyCode is 13 Template.auth.errCallback = (err) ->
console.log Meteor.userId() Template.auth.alert { msg: err.reason }
todos.insert {
content: template.find('#newNote').value Template.auth.alert = (add,remove) ->
userId: Meteor.userId() if add then Template.auth.alerts.push add;
} if remove
template.find('#newNote').value = "" Template.auth.alerts.splice Template.auth.alerts.indexOf(remove), 1
} Template.auth.alerts
# Auth template
Template.auth.events { Template.auth.events {
'click .delete': (e,template) -> Template.auth.alert null, this
'keypress .login': (e,template) -> 'keypress .login': (e,template) ->
if e.keyCode is 13 mail = template.find('#mail').value; pass = template.find('#pass').value
# Login if e.keyCode is 13 # Login
mail = template.find('#mail').value; pass = template.find('#pass').value Meteor.loginWithPassword mail, pass, Template.auth.errCallback
Accounts.loginWithPassword mail, pass, (err) -> # Login
if err then console.log err else console.log "OK"
'click #login': (e,template) -> 'click #login': (e,template) ->
mail = template.find('#mail').value; pass = template.find('#pass').value mail = template.find('#mail').value; pass = template.find('#pass').value
Meteor.loginWithPassword mail, pass, (err) -> Meteor.loginWithPassword mail, pass, Template.auth.errCallback
if err then console.log err else console.log "OK" # Register
'click #register': (e,template) -> 'click #register': (e,template) ->
mail = template.find('#mail').value; pass = template.find('#pass').value mail = template.find('#mail').value; pass = template.find('#pass').value
Accounts.createUser { email: mail, password: pass }, (err) -> Accounts.createUser { email: mail, password: pass }, Template.auth.errCallback
if err then console.log err else console.log "OK"
} }
# User Logged In # User Logged In
Template.userInfo.events { Template.userInfo.events {
'click #logout': (e,template) -> 'click #logout': (e,template) ->
Meteor.logout() Meteor.logout()
'keypress #newNote': (e,template) ->
if e.keyCode is 13
notes.insert {
content: template.find('#newNote').value
userId: Meteor.userId()
}
template.find('#newNote').value = ""
} }
Template.userInfo.in = -> Meteor.user().emails[0].address

View File

@ -11,10 +11,9 @@
</div> </div>
<div class="center-block" id="quicknotes"> <div class="center-block" id="quicknotes">
{{> notes}} {{#if currentUser}} {{> notes}} {{#if currentUser}}
<div align="center"> <div align="center"> {{> userInfo}} </div>
{{> adder}} {{> userInfo}} {{/if}}
</div> {{#unless currentUser}} <div align="center">{{> auth}}</div>{{/unless}}
{{/if}} {{#unless currentUser}} {{> auth}} {{/unless}}
</div> </div>
</div> </div>
</body> </body>
@ -22,31 +21,37 @@
<template name="notes"> <template name="notes">
<ul class="list-group"> <ul class="list-group">
{{#each notes}} {{#each notes}}
<li class="list-group-item"> <li class="note list-group-item">
{{content}} {{content}}
<button type="button" class="btn btn-danger pull-right delete"> <!--<button type="button" class="btn btn-danger pull-right delete">
<i class="fa fa-trash-o"></i> <i class="fa fa-trash-o"></i>
</button> </button>-->
<button type="button" class="delete close">&times;</button>
</li> </li>
{{/each}} {{/each}}
</ul> </ul>
</template> </template>
<template name="adder">
<input type="text" id="newNote" class="form-control" placeholder="Add new note">
</template>
<template name="auth"> <template name="auth">
<p align="center"> <p align="center">
Register a new Account or login Register a new Account or login
</p> </p>
{{#each alerts}}
<div class="alert alert-warning">
{{msg}}
<button type="button" class="delete close">&times;</button>
</div>
{{/each}}
<input type="text" id="mail" class="form-control login" placeholder="Email"> <input type="text" id="mail" class="form-control login" placeholder="Email">
<input type="text" id="pass" class="form-control login" placeholder="Password"> <input type="password" id="pass" class="form-control login" placeholder="Password">
<br> <br>
<button type="button" id="register" class="btn btn-info">Register</button> <p>Password must be at least 8 characters. Email must be a valid email</p>
<button type="button" id="login" class="btn btn-info">Login</button> <button type="button" id="register" class="btn-login btn btn-info">Register</button>
<button type="button" id="login" class="btn-login btn btn-info">Login</button>
</template> </template>
<template name="userInfo"> <template name="userInfo">
<input type="text" id="newNote" class="form-control" placeholder="Add new note">
<p>Logged in as {{in}}</p>
<button type="button" id="logout" class="btn btn-danger">Logout</button> <button type="button" id="logout" class="btn btn-danger">Logout</button>
</template> </template>

View File

@ -15,6 +15,19 @@ input {
max-width: 500px; max-width: 500px;
} }
.delete {
margin-top: -2px;
}
#newNote { #newNote {
max-width: 250px; max-width: 250px;
margin-bottom: 10px;
}
#mail {
margin-bottom: 10px;
}
.btn-login {
width: 100px;
} }