From 1f957770f7e58b48b325dd7db730735ec0f4114a Mon Sep 17 00:00:00 2001 From: fazo96 Date: Mon, 26 May 2014 19:36:59 +0200 Subject: [PATCH] notes are now editable --- app.coffee | 50 +++++++++++++++++++++++++++++--------------------- index.html | 10 ++++++---- style.css | 13 +++++++++++++ 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/app.coffee b/app.coffee index f3227a9..027717d 100644 --- a/app.coffee +++ b/app.coffee @@ -13,19 +13,39 @@ if Meteor.isClient Meteor.subscribe "my-notes" + # User Interface + Template.userInfo.events { + 'click #logout': (e,template) -> + Meteor.logout() + 'keypress #newNote': (e,template) -> + if e.keyCode is 13 + notes.insert { + title: template.find('#newNote').value + content: "..." + userId: Meteor.userId() + } + template.find('#newNote').value = "" + } + Template.userInfo.in = -> Meteor.user().emails[0].address + # Notes template - Template.notes.notes = -> notes.find().fetch() + Template.notes.notes = -> + d = notes.find().fetch(); + #d.splice d.indexOf(Session.get('note')), 1 ; d Template.notes.events { 'click .close-note': -> notes.remove @_id - 'click .edit': -> Session.set 'note', this + 'click .edit-note': -> Session.set 'note', this } # Note Editor - Template.editor.show = -> Session.get 'note' - Template.editor.events { - 'click .close': -> Session.set 'note', undefined - 'click .save': -> null - } + Template.editor.note = -> Session.get 'note' + Template.editor.events + 'click .close-editor': -> Session.set 'note', undefined + 'click .save-editor': (e,t) -> + notes.update Session.get('note')._id, + $set: + title: t.find('.title').value + content: t.find('.area').value # Notifications alerts = [] @@ -48,11 +68,12 @@ if Meteor.isClient alerts.splice alerts.indexOf(this), 1 alertDep.changed() } + + # Login and Register pressLogin = (template) -> mail = template.find('#mail').value; pass = template.find('#pass').value Meteor.loginWithPassword mail, pass, (err) -> errCallback err; if Meteor.userId() then clearNotifications() - # Login and Register Template.auth.events { 'keypress .login': (e,template) -> if e.keyCode is 13 then pressLogin template @@ -72,16 +93,3 @@ if Meteor.isClient catch err notify { msg: err } } - # User Logged In - Template.userInfo.events { - 'click #logout': (e,template) -> - 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 diff --git a/index.html b/index.html index 3795c2b..2c7509c 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@ {{#each notes}}
  • - {{content}} + {{title}} {{content}}
  • {{/each}} @@ -58,12 +58,14 @@

    - +
    +

    -
    - +
    + +
    {{/if}} diff --git a/style.css b/style.css index d492c35..66d8097 100644 --- a/style.css +++ b/style.css @@ -15,6 +15,8 @@ input { clear:both; } +.subtitle { color: #999; } + /* Custom Classes */ .edit-note { @@ -22,6 +24,17 @@ input { margin-right: 10px; } +.title { width: 85%; } + +.close-editor { + margin-top: -28px; + margin-right: 5px; +} + +.save-editor { + margin-top: 10px; +} + .btn-auth { width: 100px; }