From 5243404c726e10f3c0616a896fcd5898a2675f66 Mon Sep 17 00:00:00 2001 From: fazo96 Date: Wed, 28 May 2014 12:50:30 +0200 Subject: [PATCH] separate notifications and errors. Fixes #8 --- client/client.coffee | 37 ++++++++++++++++++++++--------------- client/index.html | 13 +++++++++++-- client/style.css | 5 ++--- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/client/client.coffee b/client/client.coffee index d486b7f..36c4c82 100644 --- a/client/client.coffee +++ b/client/client.coffee @@ -6,29 +6,28 @@ user = -> Meteor.user() UI.registerHelper "loggingIn", -> Meteor.loggingIn() # User Interface -Template.userInfo.events { +Template.userInfo.events 'click #logout': (e,template) -> Meteor.logout() -} + Template.userInfo.in = -> Meteor.user().emails[0].address # Notes template -Template.notes.truncateNoteDesc = (s) -> - if s.length > 52 then s.slice(0,48)+"..." else s +Template.notes.truncateNoteDesc = (s) -> s + #if s.length > 52 then s.slice(0,48)+"..." else s Template.notes.notes = -> d = notes.find().fetch() Template.notes.events '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 notes.remove @_id 'click .edit-note': -> Session.set 'note', this 'keypress #newNote': (e,template) -> if e.keyCode is 13 and template.find('#newNote').value isnt "" - notes.insert { + notes.insert title: template.find('#newNote').value content: "" userId: Meteor.userId() - } template.find('#newNote').value = "" # Note Editor @@ -47,15 +46,14 @@ Template.editor.events # Notifications alerts = [] alertDep = new Deps.Dependency -errCallback = (err) -> notify { msg: err.reason } +errCallback = (err) -> showError msg: err.reason # Show a notification notify = (data) -> - alerts.push { + alerts.push title: data.title msg: data.msg - id: data.id or alerts.length type: data.type or "danger" - }; alertDep.changed() + alertDep.changed() # Clear all notifications clearNotifications = -> alerts.clear(); alertDep.changed() # Get all the notifications @@ -65,6 +63,15 @@ Template.notifications.events alerts.splice alerts.indexOf(this), 1 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 Template.loading.status = -> Meteor.status() @@ -80,11 +87,11 @@ Template.auth.events 'click #register': (e,template) -> mail = template.find('#mail').value; pass = template.find('#pass').value if not mail - notify { msg: "Please enter an Email" } + showError msg: "Please enter an Email" else if not pass - notify { msg: "Please enter a password" } + showError msg: "Please enter a password" else if pass.length < 8 - notify { msg: "Password too short" } + showError msg: "Password too short" else # Sending actual registration request try Accounts.createUser { @@ -92,4 +99,4 @@ Template.auth.events password: pass }, (e) -> errCallback e catch err - notify { msg: err } + showError msg: err diff --git a/client/index.html b/client/index.html index ec84d76..b5a4ccf 100644 --- a/client/index.html +++ b/client/index.html @@ -39,7 +39,7 @@ + +