backbone-nested-attributes 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/backbone-nested-attributes/model.js +7 -0
- data/backbone-nested-attributes.js +8 -1
- data/bower.json +1 -1
- data/lib/backbone-nested-attributes/version.rb +1 -1
- data/spec/javascripts/backbone-nested-attributes/ModelSpec.js +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDEyYjJmMDFiN2I5ZDJhM2MwN2E2YjBjOGNkNjk2MTBlNjU3ZGYyNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
YWU2ZDI4ZTBmODNkNDg3OGMxMDUzMmExYWFlZmQ2Zjc2N2QzNzkzYQ==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTJlYmY0N2YyNzk3YjQ1MDcwMWQ1MTUwNjBiYjFiZGI1MzRjZjAzM2ZiYWZk
|
10
|
+
MTNmZTU5YzU1MjAwMDI5ZjhhZTE5ZWU2ODk2MjZlMzkyYTg2MmU0MzM3YzNh
|
11
|
+
NDljMTRiYmQ4YTZjZTJjMmNjZGI5MGI4MzFiN2EwZmE4MzUzNTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzRmNjQ0YmZkNGM2MzUxNjUyYzgwOThjNmNiMDMyMzhjZjdlZWJmYThmMTI5
|
14
|
+
ZjZhNDQzNDhkMmU0ZDE5MDBlZjBlMzYzM2VlMmViNGUzZTQwYTQ1YmNiMjkw
|
15
|
+
MzdmNTBmOTg2ZDI3YWRkOGUxZDkzMWRlOWQ5Yzc2ODM0MjNiNGI=
|
data/Gemfile.lock
CHANGED
@@ -153,11 +153,18 @@
|
|
153
153
|
|
154
154
|
collection.deletedModels = new Backbone.Collection
|
155
155
|
collection.deletedModels.model = collection.model
|
156
|
+
collection.on('add', nestedModelAdded)
|
156
157
|
collection.on('remove', nestedModelRemoved)
|
157
158
|
|
158
159
|
return collection
|
159
160
|
}
|
160
161
|
|
162
|
+
function nestedModelAdded(model, collection) {
|
163
|
+
if (model.get('_destroy')) {
|
164
|
+
collection.remove(model)
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
161
168
|
function nestedModelRemoved(model, collection) {
|
162
169
|
if (!model.isNew()) {
|
163
170
|
model.set({ _destroy: true })
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright (c) 2013-2014 Vicente Mundim
|
3
3
|
*
|
4
|
-
* Version: 0.
|
4
|
+
* Version: 0.5.0
|
5
5
|
*
|
6
6
|
* MIT License
|
7
7
|
*
|
@@ -186,11 +186,18 @@
|
|
186
186
|
|
187
187
|
collection.deletedModels = new Backbone.Collection
|
188
188
|
collection.deletedModels.model = collection.model
|
189
|
+
collection.on('add', nestedModelAdded)
|
189
190
|
collection.on('remove', nestedModelRemoved)
|
190
191
|
|
191
192
|
return collection
|
192
193
|
}
|
193
194
|
|
195
|
+
function nestedModelAdded(model, collection) {
|
196
|
+
if (model.get('_destroy')) {
|
197
|
+
collection.remove(model)
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
194
201
|
function nestedModelRemoved(model, collection) {
|
195
202
|
if (!model.isNew()) {
|
196
203
|
model.set({ _destroy: true })
|
data/bower.json
CHANGED
@@ -312,6 +312,22 @@ describe("Backbone.NestedAttributesModel", function() {
|
|
312
312
|
})
|
313
313
|
})
|
314
314
|
|
315
|
+
describe('passing a model in a collection with { _destroy: true }', function () {
|
316
|
+
beforeEach(function() {
|
317
|
+
model = new Post({ title: 'Some Title', comments: [{ body: 'some content' }, { id: '123', body: 'other content', _destroy: true }] })
|
318
|
+
})
|
319
|
+
|
320
|
+
it('do not add the model with { _destroy: true } to the relation collection', function () {
|
321
|
+
expect(model.get('comments').length).toBe(1)
|
322
|
+
expect(model.get('comments').at(0).get('body')).toBe('some content')
|
323
|
+
})
|
324
|
+
|
325
|
+
it('adds them to the deletedModels collection inside the relation collection', function () {
|
326
|
+
expect(model.get('comments').deletedModels.length).toBe(1)
|
327
|
+
expect(model.get('comments').deletedModels.at(0).get('body')).toBe('other content')
|
328
|
+
})
|
329
|
+
})
|
330
|
+
|
315
331
|
describe("passing a deleted_<collection> attribute", function() {
|
316
332
|
var comments
|
317
333
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backbone-nested-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vicente Mundim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.1.11
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Add nested attributes to your Backbone models
|