-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.js.coffee
52 lines (35 loc) · 1.17 KB
/
post.js.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
String::dasherize = ->
this.replace /_/g, "-"
String::senitize = ->
this.replace /_/g, "-"
#alert "one_two".dasherize()
class RailsBackboneRelational.Models.Post extends Backbone.RelationalModel
paramRoot: 'post'
defaults:
title: 'title?'
relations: [
type: Backbone.HasMany
key: 'comments'
relatedModel: 'RailsBackboneRelational.Models.Comment'
collectionType: 'RailsBackboneRelational.Collections.CommentsCollection'
includeInJSON: false
reverseRelation:
key: 'post_id',
includeInJSON: 'id'
]
validate: (attrs) ->
if (attrs.hasOwnProperty('title') && _.isNull(attrs.title))
return 'attr.direction must be a non null value.'
sanitize1: (str) ->
str.senitize()
initialize: () ->
console.log('init post')
class RailsBackboneRelational.Collections.PostsCollection extends Backbone.Collection
model: RailsBackboneRelational.Models.Post
url: '/posts'
initialize: () ->
#console.log('init post')
#alert('new collection posts')
#localStorage: new Backbone.LocalStorage("PostsCollection")
comparator: (post) ->
return post.get('id');