-
Notifications
You must be signed in to change notification settings - Fork 1
/
spomet.coffee
55 lines (46 loc) · 1.58 KB
/
spomet.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
if Meteor.isClient
Template.addable.posts = () ->
Posts.find {indexed: false}, {limit: 3}
Template.search.results = () ->
Spomet.defaultSearch.results()
Template.result.score = () ->
@score.toFixed 4
Template.result.title = () ->
if @type isnt 'custom'
p = Posts.findOne {_id: @base}
if p? then p.title else 'deleted'
else
c = CustomContent.findOne {_id: @base}
if c? then c.text.substring(0,10) + '...' else 'deleted'
Template.result.text = () ->
if @type isnt 'custom'
p = Posts.findOne {_id: @base}
if p? then p.text else 'deleted'
else
c = CustomContent.findOne {_id: @base}
if c? then c.text else 'deleted'
Template.addable.events
'click input' : () ->
Spomet.add
text: @title
path: '/title'
base: @_id
type: 'post'
Spomet.add
text: @text
path: '/text'
base: @_id
type: 'post'
Posts.update {_id: @_id},{$set: {indexed: true}}
Template.ownText.events
'submit form': (e) ->
e.preventDefault()
tarea = $(e.target).find('textarea').first()
text = tarea.val()
id = CustomContent.insert {text: text}
Spomet.add
text: text
path: 'custom'
base: id
type: 'custom'
tarea.val ''