Skip to content

Instantly share code, notes, and snippets.

@scottbaggett
Last active December 21, 2015 20:29
Show Gist options
  • Select an option

  • Save scottbaggett/6361433 to your computer and use it in GitHub Desktop.

Select an option

Save scottbaggett/6361433 to your computer and use it in GitHub Desktop.
Template.articlesForm.events
'submit #formNewArticle': (e, tmpl) ->
e.preventDefault()
# article properties
article =
created_at: new Date()
published_on: new Date(tmpl.find(".datepicker").value)
title: tmpl.find('#inputTitle').value
content: $("#editor").html()
# update if there's an id,
# create if not
if @_id
_id = Articles.update this._id, $set:
created_at: article.createdAt
title: article.title
published_on: article.published_on
content: article.content
else
_id = Articles.insert article
# redirect back to articles
Router.go "/articles"
Template.articlesForm.rendered = ->
# article content editor
$("#editor").wysiwyg
hotKeys:
"ctrl+b meta+b": "bold"
"ctrl+i meta+i": "italic"
"ctrl+u meta+u": "underline"
"ctrl+z meta+z": "undo"
"ctrl+y meta+y meta+shift+z": "redo"
# published_on date picker
$('.datepicker').datepicker()
Template.articlesForm.published_on = ->
moment(@published_on).format('MM/DD/YY hh:mma')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment