joosy 1.2.0.beta.4 → 1.2.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codoopts +1 -1
- data/Gruntfile.coffee +3 -3
- data/README.md +4 -0
- data/bower.json +1 -1
- data/build/joosy.js +2 -2
- data/build/joosy/form.js +1 -1
- data/build/joosy/resources.js +1 -1
- data/package.json +2 -2
- data/source/joosy/application.coffee +2 -2
- data/source/joosy/form.coffee +4 -4
- data/source/joosy/helpers/form.coffee +12 -3
- data/source/joosy/helpers/index.coffee +0 -1
- data/source/joosy/helpers/view.coffee +16 -3
- data/source/joosy/layout.coffee +0 -4
- data/source/joosy/module.coffee +16 -1
- data/source/joosy/modules/dom.coffee +106 -101
- data/source/joosy/modules/events.coffee +44 -10
- data/source/joosy/modules/filters.coffee +64 -60
- data/source/joosy/modules/page.coffee +3 -0
- data/source/joosy/modules/page/scrolling.coffee +46 -29
- data/source/joosy/modules/page/title.coffee +14 -0
- data/source/joosy/modules/renderer.coffee +219 -190
- data/source/joosy/modules/resources.coffee +3 -0
- data/source/joosy/modules/resources/cacher.coffee +81 -10
- data/source/joosy/modules/resources/function.coffee +26 -29
- data/source/joosy/modules/resources/identity_map.coffee +64 -42
- data/source/joosy/modules/resources/model.coffee +127 -73
- data/source/joosy/modules/time_manager.coffee +2 -0
- data/source/joosy/page.coffee +3 -6
- data/source/joosy/resources/array.coffee +87 -2
- data/source/joosy/resources/hash.coffee +53 -1
- data/source/joosy/resources/rest.coffee +59 -3
- data/source/joosy/resources/scalar.coffee +47 -1
- data/source/joosy/router.coffee +63 -21
- data/source/joosy/templaters/jst.coffee +3 -0
- data/source/joosy/widget.coffee +17 -11
- data/spec/joosy/core/helpers/view_spec.coffee +14 -0
- data/spec/joosy/core/modules/dom_spec.coffee +1 -1
- data/spec/joosy/core/modules/filters_spec.coffee +2 -2
- data/spec/joosy/core/modules/module_spec.coffee +1 -1
- data/spec/joosy/core/modules/renderer_spec.coffee +19 -1
- data/spec/joosy/core/router_spec.coffee +80 -45
- data/spec/joosy/core/widget_spec.coffee +9 -0
- data/spec/joosy/resources/modules/cacher_spec.coffee +3 -3
- data/spec/joosy/resources/modules/function_spec.coffee +2 -2
- data/spec/joosy/resources/modules/identity_map_spec.coffee +2 -2
- data/spec/joosy/resources/modules/model_spec.coffee +1 -1
- metadata +2 -5
- data/source/joosy/helpers/routes.coffee +0 -17
- data/source/joosy/modules/widgets_manager.coffee +0 -90
- data/spec/joosy/core/helpers/routes_spec.coffee +0 -15
data/source/joosy/page.coffee
CHANGED
@@ -23,7 +23,7 @@ class Joosy.Page extends Joosy.Widget
|
|
23
23
|
@layout: (layoutClass) ->
|
24
24
|
@::__layoutClass = layoutClass
|
25
25
|
|
26
|
-
@
|
26
|
+
@concern Joosy.Modules.Page.Scrolling
|
27
27
|
@extend Joosy.Modules.Page.Title
|
28
28
|
|
29
29
|
#
|
@@ -44,12 +44,9 @@ class Joosy.Page extends Joosy.Widget
|
|
44
44
|
# we should declare ourselves as a relpacement to the layout, not the page
|
45
45
|
@previous = @previous.layout if @layoutShouldChange && !@layout
|
46
46
|
|
47
|
-
######
|
48
|
-
###### Widget extensions
|
49
|
-
######
|
50
|
-
|
51
47
|
#
|
52
|
-
# This is required by {Joosy.Modules.Renderer}
|
48
|
+
# This is required by {Joosy.Modules.Renderer}.
|
49
|
+
#
|
53
50
|
# Sets the base template dir to app_name/templates/pages
|
54
51
|
#
|
55
52
|
__renderSection: ->
|
@@ -1,54 +1,139 @@
|
|
1
|
+
#
|
2
|
+
# The array structure with the support of dynamic rendering
|
3
|
+
#
|
4
|
+
# @include Joosy.Modules.Events
|
5
|
+
# @extend Joosy.Modules.Filters
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
9
|
+
# data.get(0) # 1
|
10
|
+
# data.set(0, 5) # triggers 'changed'
|
11
|
+
# data.push(4) # triggers 'changed'
|
12
|
+
# data.load(7, 8, 9) # triggers 'changed'
|
13
|
+
#
|
1
14
|
class Joosy.Resources.Array extends Array
|
2
|
-
|
3
15
|
Joosy.Module.merge @, Joosy.Module
|
4
16
|
|
5
17
|
@include Joosy.Modules.Events
|
6
|
-
@
|
18
|
+
@extend Joosy.Modules.Filters
|
7
19
|
|
8
20
|
@registerPlainFilters 'beforeLoad'
|
9
21
|
|
22
|
+
#
|
23
|
+
# Instantiates a new array
|
24
|
+
#
|
10
25
|
@build: ->
|
11
26
|
new @ arguments...
|
12
27
|
|
28
|
+
#
|
29
|
+
# Accepts numerous parameters (corresponding to array members)
|
30
|
+
#
|
13
31
|
constructor: ->
|
14
32
|
@__fillData arguments, false
|
15
33
|
|
34
|
+
#
|
35
|
+
# Replaces all the values with given
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
39
|
+
# data.load 1, 2, 3
|
40
|
+
#
|
16
41
|
load: ->
|
17
42
|
@__fillData arguments
|
18
43
|
|
44
|
+
#
|
45
|
+
# Gets element by its index
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
49
|
+
# data.get(0) # 1
|
50
|
+
#
|
19
51
|
get: (index) ->
|
20
52
|
@[index]
|
21
53
|
|
54
|
+
#
|
55
|
+
# Sets element by its index
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
59
|
+
# data.set(0, 2) # 2
|
60
|
+
# data # [2, 2, 3]
|
61
|
+
#
|
22
62
|
set: (index, value) ->
|
23
63
|
@[index] = value
|
24
64
|
@trigger 'changed'
|
25
65
|
value
|
26
66
|
|
67
|
+
#
|
68
|
+
# Pushes element to the end of array
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
72
|
+
# data.push(4) # 4
|
73
|
+
# data # [1, 2, 3, 4]
|
74
|
+
#
|
27
75
|
push: ->
|
28
76
|
result = super
|
29
77
|
@trigger 'changed'
|
30
78
|
result
|
31
79
|
|
80
|
+
#
|
81
|
+
# Pops element of the end of array
|
82
|
+
#
|
83
|
+
# @example
|
84
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
85
|
+
# data.pop() # 3
|
86
|
+
# data # [1, 2]
|
87
|
+
#
|
32
88
|
pop: ->
|
33
89
|
result = super
|
34
90
|
@trigger 'changed'
|
35
91
|
result
|
36
92
|
|
93
|
+
#
|
94
|
+
# Shits element of the beginning of array
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
98
|
+
# data.shift() # 1
|
99
|
+
# data # [2, 3]
|
100
|
+
#
|
37
101
|
shift: ->
|
38
102
|
result = super
|
39
103
|
@trigger 'changed'
|
40
104
|
result
|
41
105
|
|
106
|
+
#
|
107
|
+
# Adds element of the beginning of array
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
111
|
+
# data.unshift(0) # 4
|
112
|
+
# data # [0, 1, 2, 3]
|
113
|
+
#
|
42
114
|
unshift: ->
|
43
115
|
result = super
|
44
116
|
@trigger 'changed'
|
45
117
|
result
|
46
118
|
|
119
|
+
#
|
120
|
+
# Changes the content of an array, adding new elements while removing old elements.
|
121
|
+
#
|
122
|
+
# @example
|
123
|
+
# data = Joosy.Resources.Array.build 1, 2, 3
|
124
|
+
# data.splice(0, 2, 6) # 2
|
125
|
+
# data # [6, 3]
|
126
|
+
#
|
47
127
|
splice: ->
|
48
128
|
result = super
|
49
129
|
@trigger 'changed'
|
50
130
|
result
|
51
131
|
|
132
|
+
#
|
133
|
+
# Prepares data for internal storage
|
134
|
+
#
|
135
|
+
# @private
|
136
|
+
#
|
52
137
|
__fillData: (data, notify=true) ->
|
53
138
|
data = @slice.call(data, 0)
|
54
139
|
|
@@ -1,26 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# The hash structure with the support of dynamic rendering
|
3
|
+
#
|
4
|
+
# @include Joosy.Modules.Events
|
5
|
+
# @extend Joosy.Modules.Filters
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# data = Joosy.Resources.Hash.build field1: 'test', field2: 'test'
|
9
|
+
# data.get('field1') # 'test'
|
10
|
+
# data.set('field2', 'test2') # triggers 'changed'
|
11
|
+
#
|
1
12
|
class Joosy.Resources.Hash extends Joosy.Module
|
2
13
|
|
3
14
|
@include Joosy.Modules.Events
|
4
|
-
@
|
15
|
+
@extend Joosy.Modules.Filters
|
5
16
|
|
6
17
|
@registerPlainFilters 'beforeLoad'
|
7
18
|
|
19
|
+
#
|
20
|
+
# Instantiates a new hash
|
21
|
+
#
|
8
22
|
@build: ->
|
9
23
|
new @ arguments...
|
10
24
|
|
25
|
+
#
|
26
|
+
# Internal helper for {Joosy.Modules.Resources.Function}
|
27
|
+
#
|
11
28
|
__call: (path, value) ->
|
12
29
|
if arguments.length > 1
|
13
30
|
@set path, value
|
14
31
|
else
|
15
32
|
@get path
|
16
33
|
|
34
|
+
#
|
35
|
+
# Accepts hash of fields that have to be defined
|
36
|
+
#
|
17
37
|
constructor: (data={}) ->
|
18
38
|
@__fillData data, false
|
19
39
|
|
40
|
+
#
|
41
|
+
# Replaces all the values with given
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# data = Joosy.Resources.Hash.build foo: 'bar'
|
45
|
+
# data.load bar: 'baz'
|
46
|
+
# data # { bar: 'baz' }
|
47
|
+
#
|
20
48
|
load: (data) ->
|
21
49
|
@__fillData data
|
22
50
|
@
|
23
51
|
|
52
|
+
#
|
53
|
+
# Gets value by field name.
|
54
|
+
#
|
55
|
+
# @param [String] path The path to the field that should be resolved
|
56
|
+
# @note Can resolve nested fields
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# data.get('field') # { subfield: 'value' }
|
60
|
+
# data.get('field.subfield') # 'value'
|
61
|
+
#
|
24
62
|
get: (path) ->
|
25
63
|
[instance, property] = @__callTarget path, true
|
26
64
|
|
@@ -31,6 +69,17 @@ class Joosy.Resources.Hash extends Joosy.Module
|
|
31
69
|
else
|
32
70
|
instance[property]
|
33
71
|
|
72
|
+
#
|
73
|
+
# Sets value by field name.
|
74
|
+
#
|
75
|
+
# @param [String] path The path to the field that should be resolved
|
76
|
+
# @param [Mixed] value The value to set
|
77
|
+
# @note Can resolve nested fields
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# data.set('field', {subfield: 'value'})
|
81
|
+
# data.set('field.subfield', 'value2')
|
82
|
+
#
|
34
83
|
set: (path, value) ->
|
35
84
|
[instance, property] = @__callTarget path
|
36
85
|
|
@@ -79,6 +128,9 @@ class Joosy.Resources.Hash extends Joosy.Module
|
|
79
128
|
@trigger 'changed' if notify
|
80
129
|
null
|
81
130
|
|
131
|
+
#
|
132
|
+
# @nodoc
|
133
|
+
#
|
82
134
|
toString: ->
|
83
135
|
"Hash: #{JSON.stringify(@data)}"
|
84
136
|
|
@@ -4,9 +4,11 @@
|
|
4
4
|
#
|
5
5
|
# Resource with REST/JSON backend
|
6
6
|
#
|
7
|
+
# @concern Joosy.Modules.Resources.Model
|
8
|
+
#
|
7
9
|
class Joosy.Resources.REST extends Joosy.Resources.Hash
|
8
10
|
|
9
|
-
@
|
11
|
+
@concern Joosy.Modules.Resources.Model
|
10
12
|
|
11
13
|
@registerPlainFilters 'beforeSave'
|
12
14
|
|
@@ -17,7 +19,24 @@ class Joosy.Resources.REST extends Joosy.Resources.Hash
|
|
17
19
|
|
18
20
|
data
|
19
21
|
|
20
|
-
|
22
|
+
#
|
23
|
+
# Registeres default options for all HTTP queries
|
24
|
+
#
|
25
|
+
# @param [Hash] options Options as a hash
|
26
|
+
# @param [Function<Hash>] options Function that overrides options in given hash
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# class Test extends Joosy.Resources.REST
|
30
|
+
# @requestOptions
|
31
|
+
# headers:
|
32
|
+
# 'access-token': 'test'
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# class Test extends Joosy.Resources.REST
|
36
|
+
# @requestOptions (options) ->
|
37
|
+
# options.url = Config.baseUrl + options.url
|
38
|
+
#
|
39
|
+
#
|
21
40
|
@requestOptions: (options) ->
|
22
41
|
@::__requestOptions = options
|
23
42
|
|
@@ -60,6 +79,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Hash
|
|
60
79
|
#
|
61
80
|
@at: ->
|
62
81
|
@__atWrapper (callback) =>
|
82
|
+
# @nodoc
|
63
83
|
class Clone extends @
|
64
84
|
callback(@)
|
65
85
|
, arguments...
|
@@ -289,16 +309,48 @@ class Joosy.Resources.REST extends Joosy.Resources.Hash
|
|
289
309
|
|
290
310
|
result
|
291
311
|
|
312
|
+
#
|
313
|
+
# Updates the instance on the server with PUT query
|
314
|
+
#
|
315
|
+
# @param [Function<Mixed, REST>] callback
|
316
|
+
#
|
317
|
+
# @example
|
318
|
+
# class Test extends Joosy.Resources.REST
|
319
|
+
# test = Test.build id: 1, field1: 'test'
|
320
|
+
#
|
321
|
+
# test.update (error, test) ->
|
322
|
+
# unless error
|
323
|
+
# # ...
|
324
|
+
#
|
292
325
|
update: (callback) ->
|
293
326
|
@send 'put', {params: @__applyBeforeSaves(@data)}, (error, data) =>
|
294
327
|
@load data unless error
|
295
328
|
callback? error, @
|
296
329
|
|
330
|
+
#
|
331
|
+
# Updates new entry on the server with local state with POST query
|
332
|
+
#
|
333
|
+
# @param [Function<Mixed, REST>] callback
|
334
|
+
#
|
335
|
+
# @example
|
336
|
+
# class Test extends Joosy.Resources.REST
|
337
|
+
# test = Test.build field1: 'test'
|
338
|
+
#
|
339
|
+
# test.create (error, test) ->
|
340
|
+
# unless error
|
341
|
+
# # ...
|
342
|
+
#
|
297
343
|
create: (callback) ->
|
298
344
|
@constructor.send 'post', {params: @__applyBeforeSaves(@data)}, (error, data) =>
|
299
345
|
@load data unless error
|
300
346
|
callback? error, @
|
301
347
|
|
348
|
+
#
|
349
|
+
# Saves current state of instance (automatically choosing between updation and creation)
|
350
|
+
#
|
351
|
+
# @see Joosy.Resources.REST.create
|
352
|
+
# @see Joosy.Resources.REST.update
|
353
|
+
#
|
302
354
|
save: (callback) ->
|
303
355
|
if @id()
|
304
356
|
@update callback
|
@@ -308,6 +360,8 @@ class Joosy.Resources.REST extends Joosy.Resources.Hash
|
|
308
360
|
#
|
309
361
|
# Wrapper for AJAX request
|
310
362
|
#
|
363
|
+
# @private
|
364
|
+
#
|
311
365
|
@__query: (path, method, params, callback) ->
|
312
366
|
options =
|
313
367
|
url: path
|
@@ -330,7 +384,9 @@ class Joosy.Resources.REST extends Joosy.Resources.Hash
|
|
330
384
|
$.ajax options
|
331
385
|
|
332
386
|
#
|
333
|
-
#
|
387
|
+
# Utility function for better API support for unrequired first options parameter
|
388
|
+
#
|
389
|
+
# @private
|
334
390
|
#
|
335
391
|
__extractOptionsAndCallback: (options, callback) ->
|
336
392
|
if typeof(options) == 'function'
|
@@ -1,36 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# The scalar value with the support of dynamic rendering
|
3
|
+
#
|
4
|
+
# @include Joosy.Modules.Events
|
5
|
+
# @extend Joosy.Modules.Filters
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# data = Joosy.Resources.Scalar.build 1
|
9
|
+
# data.get() # 1
|
10
|
+
# data.set(2) # triggers 'changed'
|
11
|
+
#
|
1
12
|
class Joosy.Resources.Scalar extends Joosy.Module
|
2
13
|
|
3
14
|
@include Joosy.Modules.Events
|
4
|
-
@
|
15
|
+
@extend Joosy.Modules.Filters
|
5
16
|
|
6
17
|
@registerPlainFilters 'beforeLoad'
|
7
18
|
|
19
|
+
#
|
20
|
+
# Instantiates a new instance
|
21
|
+
#
|
8
22
|
@build: ->
|
9
23
|
new @ arguments...
|
10
24
|
|
25
|
+
#
|
26
|
+
# Internal helper for {Joosy.Modules.Resources.Function}
|
27
|
+
#
|
11
28
|
__call: ->
|
12
29
|
if arguments.length > 0
|
13
30
|
@set arguments[0]
|
14
31
|
else
|
15
32
|
@get()
|
16
33
|
|
34
|
+
#
|
35
|
+
# Accepts a value to encapsulate
|
36
|
+
#
|
17
37
|
constructor: (value) ->
|
18
38
|
@load value
|
19
39
|
|
40
|
+
#
|
41
|
+
# Replaces the value with given
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# data = Joosy.Resources.Scalar.build 1
|
45
|
+
# data.load 2
|
46
|
+
# data # 2
|
47
|
+
#
|
20
48
|
load: (value) ->
|
21
49
|
@value = @__applyBeforeLoads(value)
|
22
50
|
@trigger 'changed'
|
23
51
|
@value
|
24
52
|
|
53
|
+
#
|
54
|
+
# Gets current value
|
55
|
+
#
|
25
56
|
get: ->
|
26
57
|
@value
|
27
58
|
|
59
|
+
#
|
60
|
+
# Replaces the value with given
|
61
|
+
#
|
62
|
+
# @see Joosy.Resources.Scalar.load
|
63
|
+
#
|
28
64
|
set: (@value) ->
|
29
65
|
@trigger 'changed'
|
30
66
|
|
67
|
+
#
|
68
|
+
# JS helper converting object to its internal value during basic operations
|
69
|
+
#
|
70
|
+
# @nodoc
|
71
|
+
#
|
31
72
|
valueOf: ->
|
32
73
|
@value.valueOf()
|
33
74
|
|
75
|
+
#
|
76
|
+
# String representation
|
77
|
+
#
|
78
|
+
# @nodoc
|
79
|
+
#
|
34
80
|
toString: ->
|
35
81
|
@value.toString()
|
36
82
|
|