joosy 1.0.0.RC4 → 1.0.0.RC5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +99 -82
- data/README.md +1 -1
- data/app/assets/javascripts/joosy/core/application.js.coffee +2 -2
- data/app/assets/javascripts/joosy/core/form.js.coffee +35 -22
- data/app/assets/javascripts/joosy/core/helpers/form.js.coffee +38 -9
- data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +10 -4
- data/app/assets/javascripts/joosy/core/helpers/widgets.js.coffee +6 -1
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +5 -3
- data/app/assets/javascripts/joosy/core/layout.js.coffee +5 -5
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +28 -10
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +1 -1
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +2 -2
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +1 -1
- data/app/assets/javascripts/joosy/core/page.js.coffee +1 -1
- data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +18 -18
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +21 -19
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +26 -14
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +2 -2
- data/app/assets/javascripts/joosy/core/router.js.coffee +2 -2
- data/app/assets/javascripts/joosy/core/widget.js.coffee +3 -0
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +7 -7
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +5 -5
- data/lib/joosy/rails/version.rb +1 -1
- data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +2 -2
- data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +5 -5
- data/lib/rails/generators/joosy/templates/app/routes.js.coffee +2 -2
- data/lib/rails/generators/joosy/templates/preload.html.slim +19 -0
- data/lib/rails/resources_with_joosy.rb +2 -2
- data/spec/javascripts/helpers/spec_helper.js.coffee +19 -0
- data/spec/javascripts/joosy/core/form_spec.js.coffee +36 -16
- data/spec/javascripts/joosy/core/helpers/forms_spec.js.coffee +28 -23
- data/spec/javascripts/joosy/core/helpers/widgets_spec.js.coffee +17 -0
- data/spec/javascripts/joosy/core/joosy_spec.js.coffee +2 -0
- data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +35 -1
- data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +29 -29
- data/spec/javascripts/joosy/core/page_spec.js.coffee +2 -2
- data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +14 -9
- data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +19 -19
- data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +0 -1
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +9 -3
- data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +7 -7
- data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +5 -5
- data/spec/javascripts/support/sinon-1.3.1.js +6 -6
- data/spec/javascripts/support/sinon-ie-1.3.1.js +5 -5
- metadata +22 -20
@@ -48,11 +48,11 @@ class Joosy.Layout extends Joosy.Module
|
|
48
48
|
# @beforePaint (complete) ->
|
49
49
|
# if !@data # checks if parallel fetching finished
|
50
50
|
# $('preloader').slideDown -> complete()
|
51
|
-
#
|
51
|
+
#
|
52
52
|
#
|
53
53
|
@beforePaint: (callback) ->
|
54
54
|
@::__beforePaint = callback
|
55
|
-
|
55
|
+
|
56
56
|
#
|
57
57
|
# Sets the method which will controll the painting proccess.
|
58
58
|
#
|
@@ -86,7 +86,7 @@ class Joosy.Layout extends Joosy.Module
|
|
86
86
|
#
|
87
87
|
@erase: (callback) ->
|
88
88
|
@::__erase = callback
|
89
|
-
|
89
|
+
|
90
90
|
#
|
91
91
|
# Sets the method which will controll the data fetching proccess.
|
92
92
|
#
|
@@ -101,7 +101,7 @@ class Joosy.Layout extends Joosy.Module
|
|
101
101
|
# $.get '/rumbas', (@data) => complete()
|
102
102
|
#
|
103
103
|
@fetch: (callback) ->
|
104
|
-
@::__fetch = (complete) ->
|
104
|
+
@::__fetch = (complete) ->
|
105
105
|
@data = {}
|
106
106
|
callback.call this, =>
|
107
107
|
@dataFetched = true
|
@@ -112,7 +112,7 @@ class Joosy.Layout extends Joosy.Module
|
|
112
112
|
#
|
113
113
|
data: false
|
114
114
|
dataFetched: false
|
115
|
-
|
115
|
+
|
116
116
|
#
|
117
117
|
# @param [Hash] params List of route params
|
118
118
|
#
|
@@ -12,7 +12,8 @@ Joosy.Modules.Events =
|
|
12
12
|
# @param [Function] callback Action to run when all events were triggered at least once
|
13
13
|
#
|
14
14
|
wait: (events, callback) ->
|
15
|
-
events =
|
15
|
+
events = @__splitEvents events
|
16
|
+
@__validateEvents events
|
16
17
|
|
17
18
|
@__oneShotEvents ||= []
|
18
19
|
@__oneShotEvents.push [events, callback]
|
@@ -24,7 +25,8 @@ Joosy.Modules.Events =
|
|
24
25
|
# @param [Function] callback Action to run on trigger
|
25
26
|
#
|
26
27
|
bind: (events, callback) ->
|
27
|
-
events = events
|
28
|
+
events = @__splitEvents events
|
29
|
+
@__validateEvents events
|
28
30
|
|
29
31
|
@__boundEvents ||= []
|
30
32
|
@__boundEvents.push [events, callback]
|
@@ -61,7 +63,7 @@ Joosy.Modules.Events =
|
|
61
63
|
for [events, callback] in @__boundEvents
|
62
64
|
if events.has event
|
63
65
|
callback data...
|
64
|
-
|
66
|
+
|
65
67
|
#
|
66
68
|
# Runs set of callbacks finializing with result callback
|
67
69
|
#
|
@@ -77,13 +79,29 @@ Joosy.Modules.Events =
|
|
77
79
|
synchronize: (block) ->
|
78
80
|
context = new Joosy.Modules.Events.SynchronizationContext(this)
|
79
81
|
block.call(this, context)
|
80
|
-
|
81
|
-
@wait context.expectations, => context.after.call(this)
|
82
82
|
|
83
|
-
context.
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
if context.expectations.length == 0
|
84
|
+
context.after.call(this)
|
85
|
+
else
|
86
|
+
@wait context.expectations, => context.after.call(this)
|
87
|
+
context.actions.each (data) =>
|
88
|
+
data[0].call this, =>
|
89
|
+
@trigger data[1]
|
90
|
+
|
91
|
+
__splitEvents: (events) ->
|
92
|
+
if Object.isString events
|
93
|
+
if events.isBlank()
|
94
|
+
[]
|
95
|
+
else
|
96
|
+
events.trim().split /\s+/
|
97
|
+
else
|
98
|
+
events
|
99
|
+
|
100
|
+
__validateEvents: (events) ->
|
101
|
+
unless Object.isArray(events) && events.length > 0
|
102
|
+
throw new Error "#{Joosy.Module.__className @}> bind invalid events: #{events}"
|
103
|
+
|
104
|
+
|
87
105
|
#
|
88
106
|
# Internal representation of {Joosy.Modules.Events.synchronize} context
|
89
107
|
#
|
@@ -114,7 +132,7 @@ class Joosy.Modules.Events.SynchronizationContext
|
|
114
132
|
@actions.push [action, event]
|
115
133
|
|
116
134
|
#
|
117
|
-
# Registers finalizer: the action that will be called when all do-functions
|
135
|
+
# Registers finalizer: the action that will be called when all do-functions
|
118
136
|
# marked themselves as complete.
|
119
137
|
#
|
120
138
|
# @param [Function] after Function to call.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
moduleKeywords = ['included', 'extended']
|
2
2
|
|
3
3
|
#
|
4
|
-
# Base Joosy class extending Coffee class with module-like injections
|
4
|
+
# Base Joosy class extending Coffee class with module-like injections
|
5
5
|
# and other tiny stuff.
|
6
6
|
#
|
7
7
|
class Joosy.Module
|
@@ -65,7 +65,7 @@ class Joosy.Module
|
|
65
65
|
|
66
66
|
@[chained] = @[method]
|
67
67
|
@[method] = action
|
68
|
-
|
68
|
+
|
69
69
|
#
|
70
70
|
# Simple and fast shallow merge implementation.
|
71
71
|
#
|
@@ -3,15 +3,15 @@
|
|
3
3
|
# Turns JSON array into array of Resources and manages them.
|
4
4
|
#
|
5
5
|
# @note You should not use Collection directly. It will be
|
6
|
-
# automatically created by things like {Joosy.Resource.Generic.map}
|
6
|
+
# automatically created by things like {Joosy.Resource.Generic.map}
|
7
7
|
# or {Joosy.Resource.REST.find}.
|
8
8
|
#
|
9
9
|
# @example Basic sample
|
10
10
|
# class R extends Joosy.Resource.Generic
|
11
11
|
# @entity 'r'
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# collection = new Joosy.Resource.Collection(R)
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# collection.load [{foo: 'bar'}, {foo: 'baz'}]
|
16
16
|
# collection.each (resource) ->
|
17
17
|
# resource('foo')
|
@@ -20,7 +20,7 @@
|
|
20
20
|
#
|
21
21
|
class Joosy.Resource.Collection extends Joosy.Module
|
22
22
|
@include Joosy.Modules.Events
|
23
|
-
|
23
|
+
|
24
24
|
#
|
25
25
|
# Allows to modify data before it gets stored
|
26
26
|
#
|
@@ -29,7 +29,7 @@ class Joosy.Resource.Collection extends Joosy.Module
|
|
29
29
|
# @param [Function] action `(Object) -> Object` to call
|
30
30
|
#
|
31
31
|
@beforeLoad: (action) -> @::__beforeLoad = action
|
32
|
-
|
32
|
+
|
33
33
|
#
|
34
34
|
# Sets the default model for collection
|
35
35
|
#
|
@@ -38,24 +38,24 @@ class Joosy.Resource.Collection extends Joosy.Module
|
|
38
38
|
# @param [Class] model Model class
|
39
39
|
#
|
40
40
|
@model: (model) -> @::model = model
|
41
|
-
|
41
|
+
|
42
42
|
#
|
43
43
|
# If model param was empty it will fallback to `@model`
|
44
44
|
# If both param and `@model` were empty it will throw an exception.
|
45
45
|
#
|
46
46
|
# @param [Class] model Resource class which this collection will handle
|
47
47
|
#
|
48
|
-
constructor: (model=false) ->
|
48
|
+
constructor: (model=false, @findOptions) ->
|
49
49
|
@model = model if model
|
50
50
|
|
51
51
|
#
|
52
52
|
# Modelized data storage
|
53
53
|
#
|
54
54
|
@data = []
|
55
|
-
|
55
|
+
|
56
56
|
if !@model
|
57
57
|
throw new Error "#{Joosy.Module.__className @}> model can't be empty"
|
58
|
-
|
58
|
+
|
59
59
|
#
|
60
60
|
# Clears the storage and attempts to import given array
|
61
61
|
#
|
@@ -70,10 +70,10 @@ class Joosy.Resource.Collection extends Joosy.Module
|
|
70
70
|
entities = @__beforeLoad entities
|
71
71
|
|
72
72
|
@data = @modelize entities
|
73
|
-
|
73
|
+
|
74
74
|
@trigger 'changed' if notify
|
75
75
|
this
|
76
|
-
|
76
|
+
|
77
77
|
#
|
78
78
|
# Turns Objects array into array of Resources
|
79
79
|
#
|
@@ -86,11 +86,11 @@ class Joosy.Resource.Collection extends Joosy.Module
|
|
86
86
|
collection = collection?[root.camelize(false)]
|
87
87
|
|
88
88
|
if collection not instanceof Array
|
89
|
-
throw new Error "Can not read incoming JSON"
|
89
|
+
throw new Error "Can not read incoming JSON"
|
90
90
|
|
91
91
|
collection.map (x) =>
|
92
92
|
@model.build x
|
93
|
-
|
93
|
+
|
94
94
|
#
|
95
95
|
# Calls callback for each Resource inside Collection
|
96
96
|
#
|
@@ -117,7 +117,7 @@ class Joosy.Resource.Collection extends Joosy.Module
|
|
117
117
|
|
118
118
|
sortBy: (params...) ->
|
119
119
|
@data.sortBy params...
|
120
|
-
|
120
|
+
|
121
121
|
#
|
122
122
|
# Gets resource by id
|
123
123
|
#
|
@@ -127,7 +127,7 @@ class Joosy.Resource.Collection extends Joosy.Module
|
|
127
127
|
#
|
128
128
|
findById: (id) ->
|
129
129
|
@data.find (x) -> x.id().toString() == id.toString()
|
130
|
-
|
130
|
+
|
131
131
|
#
|
132
132
|
# Gets resource by its index inside collection
|
133
133
|
#
|
@@ -168,11 +168,11 @@ class Joosy.Resource.Collection extends Joosy.Module
|
|
168
168
|
# @return [Joosy.Resource.Generic] Added element
|
169
169
|
#
|
170
170
|
add: (element, index=false, notify=true) ->
|
171
|
-
if index
|
171
|
+
if typeof index is 'number'
|
172
172
|
@data.splice index, 0, element
|
173
173
|
else
|
174
174
|
@data.push element
|
175
|
-
|
175
|
+
|
176
176
|
if notify
|
177
177
|
@trigger 'changed'
|
178
|
-
element
|
178
|
+
element
|
@@ -4,12 +4,12 @@
|
|
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.build {r: {foo: {bar: 'baz'}}}
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# r('foo') # {baz: 'baz'}
|
14
14
|
# r('real') # true
|
15
15
|
# r('foo.bar') # baz
|
@@ -30,7 +30,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
30
30
|
__source: false
|
31
31
|
|
32
32
|
#
|
33
|
-
# Clears the identity map cache. Recomended to be called during layout switch to
|
33
|
+
# Clears the identity map cache. Recomended to be called during layout switch to
|
34
34
|
# ensure correct garbage collection.
|
35
35
|
#
|
36
36
|
@resetIdentity: ->
|
@@ -72,7 +72,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
72
72
|
class clone extends this
|
73
73
|
|
74
74
|
if entity instanceof Joosy.Resource.Generic
|
75
|
-
clone.__source = entity.memberPath()
|
75
|
+
clone.__source = entity.memberPath()
|
76
76
|
clone.__source += '/' + @::__entityName.pluralize() if @::__entityName
|
77
77
|
else
|
78
78
|
clone.__source = entity
|
@@ -86,7 +86,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
86
86
|
# @param [String] name Singular name of resource
|
87
87
|
#
|
88
88
|
@entity: (name) -> @::__entityName = name
|
89
|
-
|
89
|
+
|
90
90
|
#
|
91
91
|
# Sets the collection to use
|
92
92
|
#
|
@@ -96,7 +96,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
96
96
|
# @param [Class] klass Class to assign as collection
|
97
97
|
#
|
98
98
|
@collection: (klass) -> @::__collection = -> klass
|
99
|
-
|
99
|
+
|
100
100
|
#
|
101
101
|
# Implements {Joosy.Resource.Generic.collection} default behavior.
|
102
102
|
#
|
@@ -116,9 +116,9 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
116
116
|
# class Puppy extends Joosy.Resource.Generic
|
117
117
|
# @entity 'puppy'
|
118
118
|
# @map 'zombies'
|
119
|
-
#
|
119
|
+
#
|
120
120
|
# p = Puppy.build {zombies: [{foo: 'bar'}]}
|
121
|
-
#
|
121
|
+
#
|
122
122
|
# p('zombies') # Direct access: [{foo: 'bar'}]
|
123
123
|
# p.zombies # Wrapped Collection of Zombie instances
|
124
124
|
# p.zombies.at(0)('foo') # bar
|
@@ -129,11 +129,13 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
129
129
|
@map: (name, klass=false) ->
|
130
130
|
unless klass
|
131
131
|
klass = window[name.singularize().camelize()]
|
132
|
-
|
132
|
+
|
133
133
|
if !klass
|
134
134
|
throw new Error "#{Joosy.Module.__className @}> class can not be detected for '#{name}' mapping"
|
135
135
|
|
136
136
|
@beforeLoad (data) ->
|
137
|
+
klass = klass() unless Joosy.Module.hasAncestor(klass, Joosy.Resource.Generic)
|
138
|
+
|
137
139
|
@__map(data, name, klass)
|
138
140
|
|
139
141
|
#
|
@@ -156,14 +158,14 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
156
158
|
else
|
157
159
|
for key, value of @prototype
|
158
160
|
shim[key] = value
|
159
|
-
|
161
|
+
|
160
162
|
shim.constructor = @
|
161
163
|
|
162
164
|
if Object.isNumber(data) || Object.isString(data)
|
163
165
|
id = data
|
164
166
|
data = {}
|
165
167
|
data[shim.__primaryKey] = id
|
166
|
-
|
168
|
+
|
167
169
|
if Joosy.Application.identity
|
168
170
|
id = data[shim.__primaryKey]
|
169
171
|
|
@@ -203,7 +205,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
203
205
|
load: (data) ->
|
204
206
|
@__fillData data
|
205
207
|
return this
|
206
|
-
|
208
|
+
|
207
209
|
#
|
208
210
|
# Getter for wrapped data
|
209
211
|
#
|
@@ -231,7 +233,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
231
233
|
target[0](target[1], value)
|
232
234
|
else
|
233
235
|
target[0][target[1]] = value
|
234
|
-
|
236
|
+
|
235
237
|
@trigger 'changed'
|
236
238
|
null
|
237
239
|
|
@@ -246,7 +248,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
246
248
|
path = path.split '.'
|
247
249
|
keyword = path.pop()
|
248
250
|
target = @data
|
249
|
-
|
251
|
+
|
250
252
|
for part in path
|
251
253
|
target[part] ||= {}
|
252
254
|
if target instanceof Joosy.Resource.Generic
|
@@ -277,7 +279,7 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
277
279
|
@data = {} unless @hasOwnProperty 'data'
|
278
280
|
|
279
281
|
Joosy.Module.merge @data, @__prepareData(data)
|
280
|
-
|
282
|
+
|
281
283
|
@trigger 'changed' if notify
|
282
284
|
|
283
285
|
null
|
@@ -288,14 +290,14 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
288
290
|
# @param [Hash] data Raw data to prepare
|
289
291
|
# @return [Hash]
|
290
292
|
#
|
291
|
-
__prepareData: (data) ->
|
293
|
+
__prepareData: (data) ->
|
292
294
|
if Object.isObject(data) && Object.keys(data).length == 1 && @__entityName
|
293
295
|
name = @__entityName.camelize(false)
|
294
296
|
data = data[name] if data[name]
|
295
297
|
|
296
298
|
if @__beforeLoads?
|
297
299
|
data = bl.call(this, data) for bl in @__beforeLoads
|
298
|
-
|
300
|
+
|
299
301
|
data
|
300
302
|
|
301
303
|
__map: (data, name, klass) ->
|
@@ -305,4 +307,4 @@ class Joosy.Resource.Generic extends Joosy.Module
|
|
305
307
|
data[name] = entry
|
306
308
|
else if Object.isObject data[name]
|
307
309
|
data[name] = klass.build data[name]
|
308
|
-
data
|
310
|
+
data
|
@@ -11,6 +11,22 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
11
11
|
named = @__entityName.camelize().pluralize() + 'Collection'
|
12
12
|
if window[named] then window[named] else Joosy.Resource.RESTCollection
|
13
13
|
|
14
|
+
#
|
15
|
+
# Builds parents part of member path based on parents array
|
16
|
+
#
|
17
|
+
# @param [Array] parents Array of parents
|
18
|
+
#
|
19
|
+
# @example Basic usage
|
20
|
+
# Resource.__parentsPath([otherResource, '/bars/1']) # /other_resources/1/bars/1
|
21
|
+
#
|
22
|
+
@__parentsPath: (parents) ->
|
23
|
+
parents.reduce (path, parent) ->
|
24
|
+
path += if Joosy.Module.hasAncestor parent.constructor, Joosy.Resource.REST
|
25
|
+
parent.memberPath()
|
26
|
+
else
|
27
|
+
parent
|
28
|
+
, ''
|
29
|
+
|
14
30
|
#
|
15
31
|
# Builds member path based on the given id.
|
16
32
|
#
|
@@ -25,10 +41,8 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
25
41
|
path = @__source if @__source? && !options.parent?
|
26
42
|
path += "/#{id}"
|
27
43
|
|
28
|
-
if options.parent
|
29
|
-
path = options.parent.
|
30
|
-
else if options.parent?
|
31
|
-
path = options.parent + path
|
44
|
+
if options.parent?
|
45
|
+
path = @__parentsPath(if Object.isArray(options.parent) then options.parent else [options.parent]) + path
|
32
46
|
|
33
47
|
path += "/#{options.from}" if options.from?
|
34
48
|
path
|
@@ -56,10 +70,8 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
56
70
|
path = ("/" + @::__entityName.pluralize())
|
57
71
|
path = @__source if @__source? && !options.parent?
|
58
72
|
|
59
|
-
if options.parent
|
60
|
-
path = options.parent.
|
61
|
-
else if options.parent?
|
62
|
-
path = options.parent + path
|
73
|
+
if options.parent?
|
74
|
+
path = @__parentsPath(if Object.isArray(options.parent) then options.parent else [options.parent]) + path
|
63
75
|
|
64
76
|
path += "/#{options.from}" if options.from?
|
65
77
|
path
|
@@ -181,10 +193,10 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
181
193
|
#
|
182
194
|
# @param [String] where Possible values: 'all', id.
|
183
195
|
# 'all' will query for collection from collectionPath.
|
184
|
-
# Everything else will be considered as an id string and will make resource
|
196
|
+
# Everything else will be considered as an id string and will make resource
|
185
197
|
# query for single instance from memberPath.
|
186
198
|
# @param [Hash] options Path modification options
|
187
|
-
# @param [Function] callback Resulting callback
|
199
|
+
# @param [Function] callback Resulting callback
|
188
200
|
# (will receive retrieved Collection/Resource)
|
189
201
|
#
|
190
202
|
# @option options [Joosy.Resource.REST] parent Sets the given resource as a base path
|
@@ -205,12 +217,12 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
205
217
|
|
206
218
|
@__query @collectionPath(options), 'GET', options.params, (data) =>
|
207
219
|
result.load data
|
208
|
-
callback?(result)
|
220
|
+
callback?(result, data)
|
209
221
|
else
|
210
222
|
result = @build where
|
211
223
|
@__query @memberPath(where, options), 'GET', options.params, (data) =>
|
212
224
|
result.load data
|
213
|
-
callback?(result)
|
225
|
+
callback?(result, data)
|
214
226
|
|
215
227
|
result
|
216
228
|
|
@@ -232,7 +244,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
232
244
|
# Refetches the data from backend and triggers `changed`
|
233
245
|
#
|
234
246
|
# @param [Hash] options See {Joosy.Resource.REST.find} for possible options
|
235
|
-
# @param [Function] callback Resulting callback
|
247
|
+
# @param [Function] callback Resulting callback
|
236
248
|
#
|
237
249
|
reload: (options={}, callback=false) ->
|
238
250
|
if Object.isFunction(options)
|
@@ -241,4 +253,4 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
|
|
241
253
|
|
242
254
|
@constructor.__query @memberPath(options), 'GET', options.params, (data) =>
|
243
255
|
@load data
|
244
|
-
callback? this
|
256
|
+
callback? this
|
@@ -12,7 +12,7 @@ class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
|
12
12
|
# Refetches the data from backend and triggers `changed`
|
13
13
|
#
|
14
14
|
# @param [Hash] options See {Joosy.Resource.REST.find} for possible options
|
15
|
-
# @param [Function] callback Resulting callback
|
15
|
+
# @param [Function] callback Resulting callback
|
16
16
|
#
|
17
17
|
reload: (options={}, callback=false) ->
|
18
18
|
if Object.isFunction(options)
|
@@ -21,4 +21,4 @@ class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
|
21
21
|
|
22
22
|
@model.__query @model.collectionPath(options), 'GET', options.params, (data) =>
|
23
23
|
@load data
|
24
|
-
callback?(data)
|
24
|
+
callback?(data)
|
@@ -87,7 +87,7 @@ Joosy.Router =
|
|
87
87
|
__setupRoutes: ->
|
88
88
|
$(window).hashchange =>
|
89
89
|
unless @__ignoreRequest && location.hash.match(@__ignoreRequest)
|
90
|
-
@__respondRoute location.hash
|
90
|
+
@__respondRoute location.hash
|
91
91
|
|
92
92
|
@__prepareRoutes @rawRoutes
|
93
93
|
@__respondRoute location.hash
|
@@ -200,4 +200,4 @@ Joosy.Router =
|
|
200
200
|
|
201
201
|
params
|
202
202
|
|
203
|
-
Joosy.Module.merge Joosy.Router, Joosy.Modules.Events
|
203
|
+
Joosy.Module.merge Joosy.Router, Joosy.Modules.Events
|
@@ -29,6 +29,7 @@ class Joosy.Widget extends Joosy.Module
|
|
29
29
|
@include Joosy.Modules.Renderer
|
30
30
|
@include Joosy.Modules.Filters
|
31
31
|
@include Joosy.Modules.TimeManager
|
32
|
+
@include Joosy.Modules.WidgetsManager
|
32
33
|
|
33
34
|
#
|
34
35
|
# By default widget will not render on load
|
@@ -69,6 +70,7 @@ class Joosy.Widget extends Joosy.Module
|
|
69
70
|
@swapContainer @container, @__renderer(@data || {})
|
70
71
|
@refreshElements()
|
71
72
|
@__delegateEvents()
|
73
|
+
@__setupWidgets()
|
72
74
|
@__runAfterLoads()
|
73
75
|
|
74
76
|
this
|
@@ -81,5 +83,6 @@ class Joosy.Widget extends Joosy.Module
|
|
81
83
|
#
|
82
84
|
__unload: ->
|
83
85
|
@__clearTime()
|
86
|
+
@__unloadWidgets()
|
84
87
|
@__removeMetamorphs()
|
85
88
|
@__runAfterUnloads()
|
@@ -1,12 +1,12 @@
|
|
1
1
|
#
|
2
2
|
# Preloader for libraries with localStorage cache
|
3
3
|
#
|
4
|
-
# @note The `start` callback will only be called if loading required.
|
4
|
+
# @note The `start` callback will only be called if loading required.
|
5
5
|
# While working with cache, `complete` is the only callback that will be triggered.
|
6
6
|
#
|
7
7
|
# @example Basic usage
|
8
8
|
# libraries = [['/test1.js', 100], ['/test2.js', 500]] #100, 500 - size in bytes
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# CachingPreloader.load libraries,
|
11
11
|
# start: -> console.log 'preloading started'
|
12
12
|
# progress: (percent) -> console.log "#{percent}% loaded"
|
@@ -19,17 +19,17 @@
|
|
19
19
|
# If set to true, localStorage cache will be avoided
|
20
20
|
#
|
21
21
|
force: false
|
22
|
-
|
22
|
+
|
23
23
|
#
|
24
24
|
# Prefix for localStorage keys
|
25
25
|
#
|
26
26
|
prefix: "cache:"
|
27
|
-
|
27
|
+
|
28
28
|
#
|
29
29
|
# Number of libraries have been loaded (increases after lib was loaded)
|
30
30
|
#
|
31
31
|
counter: 0
|
32
|
-
|
32
|
+
|
33
33
|
#
|
34
34
|
# Loads (or takes from cache) set of libraries using xhr and caches them in localStorage
|
35
35
|
# See class description for example of usage
|
@@ -142,7 +142,7 @@
|
|
142
142
|
#
|
143
143
|
clean: ->
|
144
144
|
i = 0
|
145
|
-
|
145
|
+
|
146
146
|
find = (arr, obj) ->
|
147
147
|
(return i if obj == x) for x in arr
|
148
148
|
return -1
|
@@ -166,4 +166,4 @@ window.evalGlobaly = (src) ->
|
|
166
166
|
else
|
167
167
|
window.eval src
|
168
168
|
|
169
|
-
@Preloader = @CachingPreloader
|
169
|
+
@Preloader = @CachingPreloader
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @example Basic usage
|
5
5
|
# libraries = [['/test1.js'], ['/test2.js']]
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# InlinePreloader.load libraries,
|
8
8
|
# start: -> console.log 'preloading started'
|
9
9
|
# complete: -> console.log 'preloading finished'
|
@@ -12,15 +12,15 @@
|
|
12
12
|
#
|
13
13
|
@InlinePreloader =
|
14
14
|
#
|
15
|
-
# Loads set of libraries by adding `script src` to DOM head
|
15
|
+
# Loads set of libraries by adding `script src` to DOM head
|
16
16
|
# See class description for example of usage
|
17
17
|
#
|
18
18
|
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js'],['/test2.js']]
|
19
19
|
# @param [Hash] Available options:
|
20
|
-
# * start: `() -> null` to call before load starts:
|
20
|
+
# * start: `() -> null` to call before load starts:
|
21
21
|
# * complete: `() -> null` to call after load completes
|
22
22
|
#
|
23
|
-
load: (libraries, options) ->
|
23
|
+
load: (libraries, options) ->
|
24
24
|
@[key] = val for key, val of options
|
25
25
|
@start?()
|
26
26
|
|
@@ -53,4 +53,4 @@
|
|
53
53
|
head.appendChild script
|
54
54
|
return undefined
|
55
55
|
|
56
|
-
@Preloader = @InlinePreloader
|
56
|
+
@Preloader = @InlinePreloader
|
data/lib/joosy/rails/version.rb
CHANGED