1
0
mirror of https://github.com/fazo96/homework.git synced 2025-01-10 12:14:22 +01:00

separate notifications and errors. Fixes #8

This commit is contained in:
fazo96 2014-05-28 12:50:30 +02:00
parent 7ebd34163c
commit 5243404c72
3 changed files with 35 additions and 20 deletions

View File

@ -6,29 +6,28 @@ user = -> Meteor.user()
UI.registerHelper "loggingIn", -> Meteor.loggingIn() UI.registerHelper "loggingIn", -> Meteor.loggingIn()
# User Interface # User Interface
Template.userInfo.events { Template.userInfo.events
'click #logout': (e,template) -> Meteor.logout() 'click #logout': (e,template) -> Meteor.logout()
}
Template.userInfo.in = -> Meteor.user().emails[0].address Template.userInfo.in = -> Meteor.user().emails[0].address
# Notes template # Notes template
Template.notes.truncateNoteDesc = (s) -> Template.notes.truncateNoteDesc = (s) -> s
if s.length > 52 then s.slice(0,48)+"..." else s #if s.length > 52 then s.slice(0,48)+"..." else s
Template.notes.notes = -> Template.notes.notes = ->
d = notes.find().fetch() d = notes.find().fetch()
Template.notes.events Template.notes.events
'click .close-note': -> 'click .close-note': ->
if Session.get('note')._id is @_id if Session.get('note') and Session.get('note')._id is @_id
Session.set 'note', undefined Session.set 'note', undefined
notes.remove @_id notes.remove @_id
'click .edit-note': -> Session.set 'note', this 'click .edit-note': -> Session.set 'note', this
'keypress #newNote': (e,template) -> 'keypress #newNote': (e,template) ->
if e.keyCode is 13 and template.find('#newNote').value isnt "" if e.keyCode is 13 and template.find('#newNote').value isnt ""
notes.insert { notes.insert
title: template.find('#newNote').value title: template.find('#newNote').value
content: "" content: ""
userId: Meteor.userId() userId: Meteor.userId()
}
template.find('#newNote').value = "" template.find('#newNote').value = ""
# Note Editor # Note Editor
@ -47,15 +46,14 @@ Template.editor.events
# Notifications # Notifications
alerts = [] alerts = []
alertDep = new Deps.Dependency alertDep = new Deps.Dependency
errCallback = (err) -> notify { msg: err.reason } errCallback = (err) -> showError msg: err.reason
# Show a notification # Show a notification
notify = (data) -> notify = (data) ->
alerts.push { alerts.push
title: data.title title: data.title
msg: data.msg msg: data.msg
id: data.id or alerts.length
type: data.type or "danger" type: data.type or "danger"
}; alertDep.changed() alertDep.changed()
# Clear all notifications # Clear all notifications
clearNotifications = -> alerts.clear(); alertDep.changed() clearNotifications = -> alerts.clear(); alertDep.changed()
# Get all the notifications # Get all the notifications
@ -65,6 +63,15 @@ Template.notifications.events
alerts.splice alerts.indexOf(this), 1 alerts.splice alerts.indexOf(this), 1
alertDep.changed() alertDep.changed()
# "Error" visualization template
errorDep = new Deps.Dependency; shownError = undefined
showError = (err) ->
shownError = err; shownError.type = err.type or "danger"
errorDep.changed()
clearError = -> shownError = undefined; errorDep.changed()
Template.error.error = -> errorDep.depend(); shownError
Template.error.events 'click .close': -> clearError()
# "Loading" template # "Loading" template
Template.loading.status = -> Meteor.status() Template.loading.status = -> Meteor.status()
@ -80,11 +87,11 @@ Template.auth.events
'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
if not mail if not mail
notify { msg: "Please enter an Email" } showError msg: "Please enter an Email"
else if not pass else if not pass
notify { msg: "Please enter a password" } showError msg: "Please enter a password"
else if pass.length < 8 else if pass.length < 8
notify { msg: "Password too short" } showError msg: "Password too short"
else # Sending actual registration request else # Sending actual registration request
try try
Accounts.createUser { Accounts.createUser {
@ -92,4 +99,4 @@ Template.auth.events
password: pass password: pass
}, (e) -> errCallback e }, (e) -> errCallback e
catch err catch err
notify { msg: err } showError msg: err

View File

@ -39,7 +39,7 @@
<template name="auth"> <template name="auth">
<div align="center"> <div align="center">
<p>Register a new Account or login</p> <p>Register a new Account or login</p>
{{> notifications }} {{> error}}
{{#if loggingIn}} {{#if loggingIn}}
{{> loading}} {{> loading}}
{{else}} {{else}}
@ -64,7 +64,7 @@
</template> </template>
<template name="editor"> <template name="editor">
<div align="center">{{> notifications }}</div> <div align="center">{{> error }}</div>
{{#if note}} {{#if note}}
<div class="panel panel-info"> <div class="panel panel-info">
<div class="panel-heading"> <div class="panel-heading">
@ -91,6 +91,15 @@
{{/each}} {{/each}}
</template> </template>
<template name="error">
{{#if error}}
<div class="alert alert-{{error.type}} error">
<p align="center">{{error.msg}}</p>
<button type="button" class="close close-error">&times;</button>
</div>
{{/if}}
</template>
<template name="ribbon"> <template name="ribbon">
<div class="github-fork-ribbon-wrapper right"> <div class="github-fork-ribbon-wrapper right">
<div class="github-fork-ribbon"> <div class="github-fork-ribbon">

View File

@ -21,8 +21,7 @@ input {
.subtitle { color: #999; } .subtitle { color: #999; }
/* Custom Classes */ /* Custom Classes */
.notification, .error {
.notification {
max-width: 80%; max-width: 80%;
} }
@ -56,7 +55,7 @@ input {
margin-top: -24px; margin-top: -24px;
} }
.close-notification{ .close-notification, .close-error {
float: right; float: right;
margin-top: -22px; margin-top: -22px;
} }