2014-10-04 08:48:44 +02:00
|
|
|
docs = new Meteor.Collection 'docs'
|
|
|
|
|
|
|
|
Router.configure
|
|
|
|
layoutTemplate: 'layout'
|
|
|
|
|
|
|
|
Router.map ->
|
2014-10-04 10:11:08 +02:00
|
|
|
@route 'home',
|
|
|
|
path: '/'
|
|
|
|
waitOn: -> Meteor.subscribe 'docs'
|
2014-10-04 10:34:13 +02:00
|
|
|
action: ->
|
|
|
|
if !@ready()
|
|
|
|
@render(); @render 'spinner', to: 'outside'
|
|
|
|
else @render()
|
2014-10-04 08:48:44 +02:00
|
|
|
@route 'doc',
|
|
|
|
path: '/d/:_id'
|
2014-10-04 08:56:18 +02:00
|
|
|
layoutTemplate: 'docLayout'
|
2014-10-04 08:48:44 +02:00
|
|
|
waitOn: -> @docHandle = Meteor.subscribe 'doc', @params._id
|
|
|
|
data: -> docs.findOne @params._id
|
2014-10-04 10:11:08 +02:00
|
|
|
action: ->
|
|
|
|
if @ready()
|
|
|
|
@render()
|
|
|
|
else @render 'loading'
|
2014-10-04 08:48:44 +02:00
|
|
|
@route 'new'
|
|
|
|
|
2014-10-04 10:34:13 +02:00
|
|
|
Template.layout.showSpinner = ->
|
|
|
|
Meteor.status().connected is no or Router.current().ready() is no
|
2014-10-04 10:11:08 +02:00
|
|
|
Template.home.ndocs = -> docs.find().count()
|
2014-10-04 08:48:44 +02:00
|
|
|
Template.new.events
|
|
|
|
'click #new-btn': (e,t) ->
|
|
|
|
id = docs.insert
|
|
|
|
text: t.find('#editor').value
|
|
|
|
if id?
|
|
|
|
Router.go 'doc', _id: id
|