joosy 0.1.0.RC2 → 0.1.0.RC3
Sign up to get free protection for your applications and to get access to all the features.
- data/.codoopts +5 -0
- data/.gitignore +2 -0
- data/Gemfile.lock +4 -2
- data/README.md +10 -4
- data/app/assets/javascripts/joosy/core/application.js.coffee +3 -1
- data/app/assets/javascripts/joosy/core/form.js.coffee +69 -42
- data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +30 -0
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +125 -66
- data/app/assets/javascripts/joosy/core/layout.js.coffee +106 -1
- data/app/assets/javascripts/joosy/core/modules/container.js.coffee +41 -0
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +88 -1
- data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +24 -0
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +18 -0
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +53 -1
- data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +22 -6
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +21 -0
- data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +26 -0
- data/app/assets/javascripts/joosy/core/page.js.coffee +225 -16
- data/app/assets/javascripts/joosy/core/preloader.js.coffee +8 -0
- data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +52 -15
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +78 -50
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +39 -41
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +36 -27
- data/app/assets/javascripts/joosy/core/router.js.coffee +95 -19
- data/app/assets/javascripts/joosy/core/widget.js.coffee +42 -1
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +39 -24
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +9 -7
- data/app/helpers/joosy/sprockets_helper.rb +4 -1
- data/lib/joosy/rails/version.rb +1 -1
- data/spec/javascripts/joosy/core/application_spec.js.coffee +3 -3
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -2
- data/spec/javascripts/joosy/core/router_spec.js.coffee +24 -24
- data/vendor/assets/javascripts/jquery.form.js +978 -963
- data/vendor/assets/javascripts/sugar.js +1 -1
- metadata +20 -20
- data/app/assets/javascripts/joosy/core/helpers.js.coffee +0 -16
- data/vendor/assets/javascripts/base64.js +0 -135
@@ -1,15 +1,15 @@
|
|
1
1
|
#
|
2
|
-
# Basic data wrapper with triggering
|
2
|
+
# Basic data wrapper with triggering and entity name binding
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# @example Basic usage
|
5
5
|
# class R extends Joosy.Resource.Generic
|
6
6
|
# @entity 'r'
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# @beforeLoad (data) ->
|
9
9
|
# data.real = true
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# r = R.create {r: {foo: {bar: 'baz'}}}
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# r('foo') # {baz: 'baz'}
|
14
14
|
# r('real') # true
|
15
15
|
# r('foo.bar') # baz
|
@@ -21,68 +21,96 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
21
21
|
|
22
22
|
#
|
23
23
|
# Sets the data source description (which is NOT required)
|
24
|
-
# This has no use in Generic but is required in any descendant
|
24
|
+
# @note This has no use in Generic but is required in any descendant
|
25
25
|
#
|
26
|
-
# @param [mixed] Source can be any type including lambda
|
27
|
-
# If lambda is given resource will not expect direct .create
|
28
|
-
# You'll have to prepare descendant with .at
|
26
|
+
# @param [mixed] Source can be any type including lambda.
|
27
|
+
# If lambda is given resource will not expect direct {Joosy.Resource.Generic.create} calls
|
28
|
+
# You'll have to prepare descendant with {Joosy.Resource.Generic.at} first.
|
29
29
|
#
|
30
|
-
#
|
30
|
+
# @example Simple case
|
31
31
|
# Class Y extends Joosy.Resource.Generic
|
32
32
|
# @source 'fluffies'
|
33
|
+
#
|
34
|
+
# r = Y.create {}
|
35
|
+
#
|
36
|
+
# @example Case with lambda
|
33
37
|
# class R extends Joosy.Resource.Generic
|
34
38
|
# @source -> (path) "/"+path
|
35
|
-
#
|
36
|
-
# r = Y.create{} # will work as expected
|
39
|
+
#
|
37
40
|
# r = R.create {} # will raise exception
|
38
41
|
# r = R.at('foo/bar').create {} # will work as expected
|
39
42
|
#
|
40
43
|
@source: (source) -> @__source = source
|
44
|
+
|
45
|
+
#
|
46
|
+
# Creates the proxy of current resource with proper {Joosy.Resource.Generic.source} value
|
47
|
+
#
|
48
|
+
# @note Should be used together with lambda source (see {Joosy.Resource.Generic.source} for example)
|
49
|
+
#
|
50
|
+
@at: ->
|
51
|
+
if !Object.isFunction @__source
|
52
|
+
throw new Error "#{Joosy.Module.__className @}> should be created directly (without `at')"
|
53
|
+
|
54
|
+
#
|
55
|
+
# Class inheritance used to create proxy
|
56
|
+
#
|
57
|
+
# @private
|
58
|
+
#
|
59
|
+
class clone extends this
|
60
|
+
clone.__source = @__source arguments...
|
61
|
+
clone
|
41
62
|
|
42
63
|
#
|
43
|
-
#
|
64
|
+
# Sets the entity text name:
|
65
|
+
# required to do some magic like skipping the root node.
|
44
66
|
#
|
45
67
|
# @param [String] name Singular name of resource
|
46
68
|
#
|
47
69
|
@entity: (name) -> @::__entityName = name
|
48
70
|
|
49
71
|
#
|
50
|
-
# Sets the collection
|
72
|
+
# Sets the collection to use
|
51
73
|
#
|
52
|
-
# @
|
74
|
+
# @note By default will try to seek for `EntityNamesCollection`.
|
75
|
+
# Will fallback to {Joosy.Resource.Collection}
|
76
|
+
#
|
77
|
+
# @param [Class] klass Class to assign as collection
|
53
78
|
#
|
54
79
|
@collection: (klass) -> @::__collection = -> klass
|
55
80
|
|
56
81
|
#
|
57
|
-
#
|
58
|
-
# Will try to seek for EntityNamesCollection
|
59
|
-
# Will fallback to Joosy.Resource.Collection
|
82
|
+
# Implements {Joosy.Resource.Generic.collection} default behavior.
|
60
83
|
#
|
61
84
|
__collection: ->
|
62
85
|
named = @__entityName.camelize().pluralize() + 'Collection'
|
63
86
|
if window[named] then window[named] else Joosy.Resource.Collection
|
64
87
|
|
65
88
|
#
|
66
|
-
# Allows to modify data before it gets stored
|
89
|
+
# Allows to modify data before it gets stored.
|
90
|
+
# You can define several beforeLoad filters that will be chained.
|
67
91
|
#
|
68
92
|
# @param [Function] action `(Object) -> Object` to call
|
69
93
|
#
|
70
|
-
@beforeLoad: (action) ->
|
94
|
+
@beforeLoad: (action) ->
|
95
|
+
unless @::hasOwnProperty '__beforeLoads'
|
96
|
+
@::__beforeLoads = [].concat @.__super__.__beforeLoads || []
|
97
|
+
@::__beforeLoads.push action
|
71
98
|
|
72
99
|
#
|
73
|
-
# Dynamically creates collection of inline resources
|
74
|
-
#
|
75
|
-
#
|
100
|
+
# Dynamically creates collection of inline resources.
|
101
|
+
#
|
102
|
+
# Inline resources share the instance with direct data and therefore can be used
|
103
|
+
# to handle inline changes with triggers and all that resources stuff
|
76
104
|
#
|
77
|
-
#
|
105
|
+
# @example Basic usage
|
78
106
|
# class Zombie extends Joosy.Resource.Generic
|
79
|
-
# @entity '
|
107
|
+
# @entity 'zombie'
|
80
108
|
# class Puppy extends Joosy.Resource.Generic
|
81
|
-
# @entity '
|
82
|
-
# @
|
83
|
-
#
|
109
|
+
# @entity 'puppy'
|
110
|
+
# @map 'zombies'
|
111
|
+
#
|
84
112
|
# p = Puppy.create {zombies: [{foo: 'bar'}]}
|
85
|
-
#
|
113
|
+
#
|
86
114
|
# p('zombies') # Direct access: [{foo: 'bar'}]
|
87
115
|
# p.zombies # Wrapped Collection of Zombie instances
|
88
116
|
# p.zombies.at(0)('foo') # bar
|
@@ -103,18 +131,6 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
103
131
|
@[name].reset data[name]
|
104
132
|
data
|
105
133
|
|
106
|
-
#
|
107
|
-
# Creates the descnendant of current resource with proper source
|
108
|
-
# Should be used together with lambda source (see @source for example)
|
109
|
-
#
|
110
|
-
@at: ->
|
111
|
-
if !Object.isFunction @__source
|
112
|
-
throw new Error "#{Joosy.Module.__className @}> should be created directly (without `at')"
|
113
|
-
|
114
|
-
class clone extends this
|
115
|
-
clone.__source = @__source arguments...
|
116
|
-
clone
|
117
|
-
|
118
134
|
#
|
119
135
|
# Wraps instance of resource inside shim-function allowing to track
|
120
136
|
# data changes. See class example
|
@@ -138,12 +154,24 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
138
154
|
shim
|
139
155
|
|
140
156
|
#
|
141
|
-
# Should NOT be called directly, use
|
157
|
+
# Should NOT be called directly, use {::create} instead
|
142
158
|
#
|
159
|
+
# @private
|
143
160
|
# @param [Object] data Data to store
|
144
161
|
#
|
145
162
|
constructor: (data) ->
|
163
|
+
@__fillData data, false
|
164
|
+
|
165
|
+
#
|
166
|
+
# Set the resource data manually
|
167
|
+
#
|
168
|
+
# @param [Object] data Data to store
|
169
|
+
#
|
170
|
+
# @return [Joosy.Resource.Generic] Returns self
|
171
|
+
#
|
172
|
+
reset: (data) ->
|
146
173
|
@__fillData data
|
174
|
+
return this
|
147
175
|
|
148
176
|
#
|
149
177
|
# Getter for wrapped data
|
@@ -156,7 +184,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
156
184
|
target[0][target[1]]
|
157
185
|
|
158
186
|
#
|
159
|
-
# Setter for wrapped data, triggers
|
187
|
+
# Setter for wrapped data, triggers `changed` event.
|
160
188
|
#
|
161
189
|
# @param [String] path Attribute name to set. Can contain dots to get inline Objects values
|
162
190
|
# @param [mixed] value Value to set
|
@@ -168,9 +196,9 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
168
196
|
null
|
169
197
|
|
170
198
|
#
|
171
|
-
# Locates the actual instance of
|
199
|
+
# Locates the actual instance of attribute path `foo.bar` from get/set
|
172
200
|
#
|
173
|
-
# @param [String] path Path to the attribute (
|
201
|
+
# @param [String] path Path to the attribute (`foo.bar`)
|
174
202
|
# @return [Array] Instance of object containing last step of path and keyword for required field
|
175
203
|
#
|
176
204
|
__callTarget: (path) ->
|
@@ -188,7 +216,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
188
216
|
[@e, path]
|
189
217
|
|
190
218
|
#
|
191
|
-
# Wrapper for .create
|
219
|
+
# Wrapper for {Joosy.Resource.Generic.create} magic
|
192
220
|
#
|
193
221
|
__call: (path, value) ->
|
194
222
|
if arguments.length > 1
|
@@ -212,15 +240,15 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
212
240
|
#
|
213
241
|
# Prepares raw data: cuts the root node if it exists, runs before filters
|
214
242
|
#
|
215
|
-
# @param [
|
216
|
-
# @return [
|
243
|
+
# @param [Hash] data Raw data to prepare
|
244
|
+
# @return [Hash]
|
217
245
|
#
|
218
246
|
__prepareData: (data) ->
|
219
247
|
if Object.isObject(data) && Object.keys(data).length == 1 && @__entityName
|
220
248
|
name = @__entityName.camelize(false)
|
221
249
|
data = data[name] if data[name]
|
222
250
|
|
223
|
-
if @
|
224
|
-
data =
|
251
|
+
if @__beforeLoads?
|
252
|
+
data = bl.call(this, data) for bl in @__beforeLoads
|
225
253
|
|
226
254
|
data
|
@@ -1,20 +1,20 @@
|
|
1
1
|
#= require ./rest_collection
|
2
2
|
|
3
3
|
#
|
4
|
-
# Resource with the HTTP REST as the backend
|
4
|
+
# Resource with the HTTP REST as the backend.
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# @example Basic usage
|
7
7
|
# class Rocket extends Joosy.Resource.REST
|
8
8
|
# @entity 'rocket'
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# r = Rocket.find {speed: 'fast'} # queries /rockets/?speed=fast to get RESTCollection
|
11
11
|
# r = Rocket.find 1 # queries /rockets/1 to get Rocket instance
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# class Engine extends Joosy.Resource.REST
|
14
14
|
# @entity 'engine'
|
15
15
|
# @source ->
|
16
16
|
# (rocket) "/rockets/#{rocket 'id'}/engines"
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# e = Engine.at(r).find {oil: true} # queries /rockets/1/engies?oil=true
|
19
19
|
#
|
20
20
|
class Joosy.Resource.REST extends Joosy.Resource.Generic
|
@@ -24,31 +24,28 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
24
24
|
#
|
25
25
|
__primaryKey: 'id'
|
26
26
|
|
27
|
-
|
28
27
|
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# Will fallback to Joosy.Resource.RESTCollection
|
28
|
+
# Implements `@collection` default behavior.
|
29
|
+
# Changes the default fallback to Joosy.Resource.RESTCollection.
|
32
30
|
#
|
33
31
|
__collection: ->
|
34
32
|
named = @__entityName.camelize().pluralize() + 'Collection'
|
35
33
|
if window[named] then window[named] else Joosy.Resource.RESTCollection
|
36
34
|
|
37
35
|
#
|
38
|
-
# Sets the field containing primary key
|
36
|
+
# Sets the field containing primary key.
|
39
37
|
#
|
40
|
-
# It has no direct use inside the REST resource itself and can be omited
|
41
|
-
#
|
42
|
-
# just to improve end-users experience for cases when primary exists.
|
38
|
+
# @note It has no direct use inside the REST resource itself and can be omited.
|
39
|
+
# But it usually should not since we have plans on adding some kind of Identity Map to Joosy.
|
43
40
|
#
|
44
41
|
# @param [String] primary Name of the field
|
45
42
|
#
|
46
43
|
@primary: (primary) -> @::__primaryKey = primary
|
47
44
|
|
48
45
|
#
|
49
|
-
# Should NOT be called directly, use .create
|
46
|
+
# Should NOT be called directly, use {Joosy.Resource.Generic.create} instead
|
50
47
|
#
|
51
|
-
# @param [Integer
|
48
|
+
# @param [Integer, String, Object] description ID of entity or full data to store
|
52
49
|
#
|
53
50
|
constructor: (description={}) ->
|
54
51
|
if @constructor.__isId description
|
@@ -58,18 +55,18 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
58
55
|
@id = @e[@__primaryKey]
|
59
56
|
|
60
57
|
#
|
61
|
-
# Queries for REST data and creates resources instances
|
58
|
+
# Queries for REST data and creates resources instances.
|
62
59
|
#
|
63
|
-
# Returns single entity if integer or string given
|
64
|
-
# Returns collection if no value or Object (with parameters) given
|
60
|
+
# Returns single entity if integer or string given.
|
61
|
+
# Returns collection if no value or Object (with parameters) given.
|
65
62
|
#
|
66
|
-
# If first parameter is a Function it's considered as a result callback
|
67
|
-
#
|
63
|
+
# If first parameter is a Function it's considered as a result callback,
|
64
|
+
# in this case parameters will be considered equal to `{ }`
|
68
65
|
#
|
69
|
-
#
|
66
|
+
# @example Different find
|
70
67
|
# class Rocket extends Joosy.Resource.REST
|
71
68
|
# @entity 'rocket'
|
72
|
-
#
|
69
|
+
#
|
73
70
|
# Rocket.find 1
|
74
71
|
# Rocket.find {type: 'nuclear'}, (data) -> data
|
75
72
|
# Rocket.find (data) -> data
|
@@ -77,11 +74,11 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
77
74
|
# success: (data) -> data)
|
78
75
|
# cache: true
|
79
76
|
#
|
80
|
-
# @param [Integer
|
81
|
-
# @param [Function
|
82
|
-
# Will be considered as a success callback if function given
|
77
|
+
# @param [Integer, String, Object] description ID of entity or full data to store
|
78
|
+
# @param [Hash, Function] options AJAX options.
|
79
|
+
# Will be considered as a success callback if function is given.
|
83
80
|
#
|
84
|
-
# @return [Joosy.Resource.REST
|
81
|
+
# @return [Joosy.Resource.REST, Joosy.Resource.RESTCollection]
|
85
82
|
#
|
86
83
|
@find: (description, options) ->
|
87
84
|
if Object.isFunction options
|
@@ -102,8 +99,8 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
102
99
|
#
|
103
100
|
# Queries the resource url and reloads the data from server
|
104
101
|
#
|
105
|
-
# @param [Function
|
106
|
-
# Will be considered as a success callback if function given
|
102
|
+
# @param [Hash, Function] options AJAX options.
|
103
|
+
# Will be considered as a success callback if function is given.
|
107
104
|
# @return [Joosy.Resource.REST]
|
108
105
|
#
|
109
106
|
fetch: (options) ->
|
@@ -124,8 +121,8 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
124
121
|
#
|
125
122
|
# Destroys the resource by DELETE query
|
126
123
|
#
|
127
|
-
# @param [Function
|
128
|
-
# Will be considered as a success callback if function given
|
124
|
+
# @param [Hash, Function] options AJAX options.
|
125
|
+
# Will be considered as a success callback if function is given.
|
129
126
|
# @return [Joosy.Resource.REST]
|
130
127
|
#
|
131
128
|
destroy: (options) ->
|
@@ -140,11 +137,11 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
140
137
|
this
|
141
138
|
|
142
139
|
#
|
143
|
-
# Requests the REST member URL with POST or any method given in options.type
|
140
|
+
# Requests the REST member URL with POST or any method given in options.type.
|
144
141
|
#
|
145
|
-
# @param [String] ending
|
146
|
-
# @param [Function
|
147
|
-
# Will be considered as a success callback if function given
|
142
|
+
# @param [String] ending Member url (like 'foo' or 'foo/bar')
|
143
|
+
# @param [Hash, Function] options AJAX options.
|
144
|
+
# Will be considered as a success callback if function is given.
|
148
145
|
#
|
149
146
|
request: (ending, options) ->
|
150
147
|
if Object.isFunction options
|
@@ -163,18 +160,18 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
163
160
|
#
|
164
161
|
# Checks if given description can be considered as ID
|
165
162
|
#
|
166
|
-
# @param [Integer
|
163
|
+
# @param [Integer, String, Object] something Value to test
|
167
164
|
# @return [Boolean]
|
168
165
|
#
|
169
166
|
@__isId: (something) ->
|
170
167
|
Object.isNumber(something) || Object.isString(something)
|
171
168
|
|
172
169
|
#
|
173
|
-
# jQuery AJAX wrapper
|
170
|
+
# jQuery AJAX wrapper.
|
174
171
|
#
|
175
172
|
# @param [String] method HTTP Method (GET/POST/PUT/DELETE)
|
176
173
|
# @param [String] url URL to query
|
177
|
-
# @param [
|
174
|
+
# @param [Hash] options AJAX options to pass with request
|
178
175
|
# @param [Function] callback XHR callback
|
179
176
|
#
|
180
177
|
@__ajax: (method, url, options={}, callback) ->
|
@@ -185,11 +182,12 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
185
182
|
dataType: 'json'
|
186
183
|
|
187
184
|
#
|
188
|
-
# Builds URL for current resource location
|
185
|
+
# Builds URL for current resource location.
|
186
|
+
#
|
187
|
+
# @param [Hash] options Handling options
|
189
188
|
#
|
190
|
-
# @
|
191
|
-
#
|
192
|
-
# params: GET-params to add to resulting url
|
189
|
+
# @option options [String] extension String to add to resource base url
|
190
|
+
# @option options [Hash] params GET-params to add to resulting url
|
193
191
|
#
|
194
192
|
@__buildSource: (options={}) ->
|
195
193
|
unless @hasOwnProperty '__source'
|
@@ -1,18 +1,18 @@
|
|
1
1
|
#
|
2
|
-
# Collection of Resources with REST-fetching capabilities
|
2
|
+
# Collection of Resources with REST-fetching capabilities.
|
3
3
|
#
|
4
|
-
# Generally you should not use RESTCollection directly. It will be
|
5
|
-
#
|
4
|
+
# @note Generally you should not use RESTCollection directly. It will be
|
5
|
+
# automatically created by Joosy.Resource.REST#find.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# @example Basic samples
|
8
8
|
# class R extends Joosy.Resource.REST
|
9
9
|
# @entity 'r'
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# collection = new Joosy.Resource.RESTCollection(R, {color: 'green'})
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# collection.fetch()
|
14
14
|
# collection.page 2
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# collection.params = {color: 'red', sort: 'date'}
|
17
17
|
# collection.fetch()
|
18
18
|
#
|
@@ -21,22 +21,27 @@ class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
|
21
21
|
@include Joosy.Modules.Events
|
22
22
|
|
23
23
|
#
|
24
|
-
# Hash containing the cache for pages of raw data
|
25
|
-
# Keys are pages numbers, values are stored AJAX response
|
24
|
+
# Hash containing the cache for pages of raw data.
|
25
|
+
# Keys are pages numbers, values are stored AJAX response.
|
26
26
|
#
|
27
27
|
pages: Object.extended()
|
28
28
|
|
29
29
|
#
|
30
30
|
# @param [Class] model Resource class this collection will handle
|
31
|
-
# @param [
|
31
|
+
# @param [Hash] params Additional parameters that will be added to all REST requests.
|
32
32
|
#
|
33
|
-
constructor: (
|
33
|
+
constructor: (model, params={}) ->
|
34
|
+
super model
|
34
35
|
@params = Object.extended params
|
35
36
|
|
36
37
|
#
|
37
|
-
# Clears the storage and attempts to import given
|
38
|
+
# Clears the storage and attempts to import given array
|
38
39
|
#
|
39
|
-
# @param [
|
40
|
+
# @param [Array, Hash] entities Array of entities to import.
|
41
|
+
# If hash was given will seek for moodel name camelized and pluralized.
|
42
|
+
# @param [Boolean] notify Indicates whether to trigger 'changed' event
|
43
|
+
#
|
44
|
+
# @return [Joosy.Resource.RESTCollection] Returns self.
|
40
45
|
#
|
41
46
|
reset: (entities, notify=true) ->
|
42
47
|
super entities, false
|
@@ -45,10 +50,12 @@ class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
|
45
50
|
this
|
46
51
|
|
47
52
|
#
|
48
|
-
# Clears the storage and gets new data from server
|
53
|
+
# Clears the storage and gets new data from server.
|
54
|
+
#
|
55
|
+
# @param [Hash, Function] options AJAX options.
|
56
|
+
# Will be considered as a success callback if function is given.
|
49
57
|
#
|
50
|
-
# @
|
51
|
-
# Will be considered as a success callback if function given
|
58
|
+
# @return [Joosy.Resource.RESTCollection] Returns self.
|
52
59
|
#
|
53
60
|
fetch: (options) ->
|
54
61
|
if Object.isFunction options
|
@@ -64,11 +71,13 @@ class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
|
64
71
|
this
|
65
72
|
|
66
73
|
#
|
67
|
-
# Returns the subset for requested page
|
74
|
+
# Returns the subset for requested page: requests with &page=x.
|
75
|
+
#
|
76
|
+
# @param [Integer] number Index of page
|
77
|
+
# @param [Hash, Function] options AJAX options.
|
78
|
+
# Will be considered as a success callback if function is given.
|
68
79
|
#
|
69
|
-
# @
|
70
|
-
# @param [Function|Object] options AJAX options.
|
71
|
-
# Will be considered as a success callback if function given
|
80
|
+
# @return [Joosy.Resource.RESTCollection] Returns self.
|
72
81
|
#
|
73
82
|
page: (number, options) ->
|
74
83
|
if Object.isFunction options
|
@@ -84,11 +93,11 @@ class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
|
84
93
|
this
|
85
94
|
|
86
95
|
#
|
87
|
-
# Requests the REST collection URL with POST or any method given in options.type
|
96
|
+
# Requests the REST collection URL with POST or any method given in options.type.
|
88
97
|
#
|
89
|
-
# @param [String] ending
|
90
|
-
# @param [Function
|
91
|
-
# Will be considered as a success callback if function given
|
98
|
+
# @param [String] ending Collection url (like 'foo' or 'foo/bar')
|
99
|
+
# @param [Hash, Function] options AJAX options.
|
100
|
+
# Will be considered as a success callback if function is given.
|
92
101
|
#
|
93
102
|
request: (ending, options) ->
|
94
103
|
if Object.isFunction options
|
@@ -105,10 +114,10 @@ class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
|
105
114
|
@model.__ajax type, @model.__buildSource(extension: ending), options, callback
|
106
115
|
|
107
116
|
#
|
108
|
-
#
|
117
|
+
# Internal AJAX request implementation.
|
109
118
|
#
|
110
|
-
# @param [
|
111
|
-
# @param [
|
119
|
+
# @param [Hash] urlOptions GET-params for request
|
120
|
+
# @param [Hash] ajaxOptions AJAX options to pass with request
|
112
121
|
# @param [Function] callback
|
113
122
|
#
|
114
123
|
__fetch: (urlOptions, ajaxOptions, callback) ->
|