forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.coffee
More file actions
84 lines (73 loc) · 2.47 KB
/
Copy pathModel.coffee
File metadata and controls
84 lines (73 loc) · 2.47 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
define [
'compiled/util/mixin'
'underscore'
'node_modules-version-of-backbone'
'compiled/backbone-ext/Model/computedAttributes'
'compiled/backbone-ext/Model/dateAttributes'
'compiled/backbone-ext/Model/errors'
], (mixin, _, Backbone) ->
class Backbone.Model extends Backbone.Model
##
# Mixes in objects to a model's definition, being mindful of certain
# properties (like defaults) that need to be merged also.
#
# @param {Object} mixins...
# @api public
@mixin: (mixins...) ->
mixin this, mixins...
initialize: (attributes, options) ->
super
@options = _.extend {}, @defaults, options
fn.call this for fn in @__initialize__ if @__initialize__
this
# Method Summary
# Trigger an event indicating an item has started to save. This
# can be used to add a loading icon or trigger another event
# when an model tries to save itself.
#
# For example, inside of the initializer of the model you want
# to show a loading icon you could do something like this
#
# @model.on 'saving', -> console.log "Do something awesome"
#
# @api backbone override
save: ->
@trigger "saving"
super
# Method Summary
# Trigger an event indicating an item has started to delete. This
# can be used to add a loading icon or trigger an event while the
# model is being deleted.
#
# For example, inside of the initializer of the model you want to
# show a loading icon, you could do something like this.
#
# @model.on 'destroying', -> console.log 'Do something awesome'
#
# @api backbone override
destroy: ->
@trigger "destroying"
super
##
# Increment an attribute by 1 (or the specified amount)
increment: (key, delta = 1) ->
@set key, @get(key) + delta
##
# Decrement an attribute by 1 (or the specified amount)
decrement: (key, delta = 1) ->
@increment key, -delta
# Add support for nested attributes on a backbone model. Nested
# attributes are indicated by a . to seperate each level. You get
# get nested attributes by doing the following.
# ie:
# // given {foo: {bar: 'catz'}}
# @get 'foo.bar' // returns catz
#
# @api backbone override
deepGet: (property) ->
split = property.split "."
value = @get split.shift()
# Move through objects until found
while next = split.shift()
value = value[next]
value