joosy 0.1.0.RC3 → 0.1.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -2
- data/Gemfile +2 -13
- data/Gemfile.lock +62 -80
- data/Guardfile +15 -21
- data/MIT-LICENSE +2 -2
- data/README.rdoc +3 -0
- data/app/helpers/joosy/sprockets_helper.rb +11 -23
- data/joosy.gemspec +3 -3
- data/lib/joosy/forms.rb +12 -2
- data/lib/joosy/rails/engine.rb +1 -9
- data/lib/joosy/rails/version.rb +2 -2
- data/lib/joosy-rails.rb +5 -0
- data/lib/rails/generators/joosy/application_generator.rb +3 -13
- data/lib/rails/generators/joosy/joosy_base.rb +2 -2
- data/lib/rails/generators/joosy/layout_generator.rb +1 -8
- data/lib/rails/generators/joosy/page_generator.rb +6 -21
- data/lib/rails/generators/joosy/preloader_generator.rb +7 -14
- data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +0 -1
- data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
- data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
- data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
- data/lib/rails/generators/joosy/templates/app/routes.js.coffee +1 -7
- data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
- data/lib/rails/generators/joosy/templates/app.js.coffee +0 -3
- data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +12 -9
- data/lib/rails/generators/joosy/templates/preload.html.erb +6 -5
- data/lib/rails/generators/joosy/templates/preload.html.haml +5 -3
- data/lib/rails/generators/joosy/templates/preload.html.slim +21 -0
- data/lib/rails/generators/joosy/widget_generator.rb +1 -8
- data/spec/javascripts/helpers/spec_helper.js.coffee +0 -20
- data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +27 -24
- data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +18 -42
- data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +27 -27
- data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
- data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +15 -6
- data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +7 -12
- data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +17 -31
- data/tmp/javascripts/.gitignore +1 -0
- data/tmp/spec/javascripts/helpers/.gitignore +1 -0
- data/vendor/assets/javascripts/base64.js +135 -0
- data/vendor/assets/javascripts/joosy/core/application.js.coffee +26 -0
- data/vendor/assets/javascripts/joosy/core/form.js.coffee +87 -0
- data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +62 -0
- data/vendor/assets/javascripts/joosy/core/layout.js.coffee +38 -0
- data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +51 -0
- data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +17 -0
- data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
- data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +12 -0
- data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +28 -0
- data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +23 -0
- data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +45 -0
- data/vendor/assets/javascripts/joosy/core/page.js.coffee +136 -0
- data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +69 -0
- data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +42 -0
- data/vendor/assets/javascripts/joosy/core/router.js.coffee +75 -0
- data/vendor/assets/javascripts/joosy/core/widget.js.coffee +35 -0
- data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +27 -0
- data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +84 -0
- data/{app → vendor}/assets/javascripts/joosy.js.coffee +0 -0
- data/vendor/assets/javascripts/jquery.form.js +963 -978
- data/vendor/assets/javascripts/sugar.js +1 -1
- metadata +48 -77
- data/.codoopts +0 -5
- data/README.md +0 -95
- data/app/assets/javascripts/joosy/core/application.js.coffee +0 -50
- data/app/assets/javascripts/joosy/core/form.js.coffee +0 -304
- data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +0 -30
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +0 -129
- data/app/assets/javascripts/joosy/core/layout.js.coffee +0 -162
- data/app/assets/javascripts/joosy/core/modules/container.js.coffee +0 -104
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +0 -123
- data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -67
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +0 -36
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +0 -105
- data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +0 -195
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -46
- data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -84
- data/app/assets/javascripts/joosy/core/page.js.coffee +0 -375
- data/app/assets/javascripts/joosy/core/preloader.js.coffee +0 -13
- data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +0 -174
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +0 -254
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -197
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -125
- data/app/assets/javascripts/joosy/core/router.js.coffee +0 -163
- data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +0 -36
- data/app/assets/javascripts/joosy/core/widget.js.coffee +0 -80
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +0 -169
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +0 -56
- data/lib/joosy.rb +0 -9
- data/lib/rails/generators/joosy/resource_generator.rb +0 -29
- data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +0 -4
- data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +0 -22
- data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
- data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +0 -2
- data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +0 -7
- data/spec/javascripts/joosy/core/application_spec.js.coffee +0 -40
- data/spec/javascripts/joosy/core/form_spec.js.coffee +0 -184
- data/spec/javascripts/joosy/core/joosy_spec.js.coffee +0 -72
- data/spec/javascripts/joosy/core/layout_spec.js.coffee +0 -50
- data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +0 -185
- data/spec/javascripts/joosy/core/page_spec.js.coffee +0 -178
- data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +0 -84
- data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +0 -118
- data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +0 -58
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -129
- data/spec/javascripts/joosy/core/router_spec.js.coffee +0 -123
- data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +0 -25
- data/spec/javascripts/joosy/core/widget_spec.js.coffee +0 -40
- data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +0 -36
- data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +0 -16
- data/spec/javascripts/support/assets/coolface.jpg +0 -0
- data/spec/javascripts/support/assets/okay.jpg +0 -0
- data/spec/javascripts/support/assets/test.js +0 -1
- data/spec/javascripts/support/sinon-ie-1.3.1.js +0 -82
- data/vendor/assets/javascripts/metamorph.js +0 -409
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Widgets management routines
|
|
3
|
-
#
|
|
4
|
-
# @module
|
|
5
|
-
#
|
|
6
|
-
Joosy.Modules.WidgetsManager =
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
# Registeres and runs widget inside specified container
|
|
10
|
-
#
|
|
11
|
-
# @param [DOM] container jQuery or direct dom node object
|
|
12
|
-
# @param [Joosy.Widget] widget Class or object of Joosy.Widget to register
|
|
13
|
-
#
|
|
14
|
-
registerWidget: (container, widget) ->
|
|
15
|
-
if Joosy.Module.hasAncestor widget, Joosy.Widget
|
|
16
|
-
widget = new widget()
|
|
17
|
-
|
|
18
|
-
@__activeWidgets ||= []
|
|
19
|
-
@__activeWidgets.push widget.__load(this, $(container))
|
|
20
|
-
|
|
21
|
-
widget
|
|
22
|
-
|
|
23
|
-
#
|
|
24
|
-
# Unregisteres and destroys widget
|
|
25
|
-
#
|
|
26
|
-
# @param [Joosy.Widget] widget Object of Joosy.Widget to unregister
|
|
27
|
-
#
|
|
28
|
-
unregisterWidget: (widget) ->
|
|
29
|
-
widget.__unload()
|
|
30
|
-
|
|
31
|
-
@__activeWidgets.splice @__activeWidgets.indexOf(widget), 1
|
|
32
|
-
|
|
33
|
-
#
|
|
34
|
-
# Gathers widgets definitions from current and super classes
|
|
35
|
-
#
|
|
36
|
-
__collectWidgets: ->
|
|
37
|
-
widgets = Object.extended @widgets || {}
|
|
38
|
-
|
|
39
|
-
klass = this
|
|
40
|
-
while klass = klass.constructor.__super__
|
|
41
|
-
Joosy.Module.merge widgets, klass.widgets, false
|
|
42
|
-
|
|
43
|
-
widgets
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
# Intialize all widgets for current object
|
|
47
|
-
#
|
|
48
|
-
__setupWidgets: ->
|
|
49
|
-
widgets = @__collectWidgets()
|
|
50
|
-
registered = Object.extended()
|
|
51
|
-
|
|
52
|
-
widgets.each (selector, widget) =>
|
|
53
|
-
if selector == '$container'
|
|
54
|
-
activeSelector = @container
|
|
55
|
-
else
|
|
56
|
-
if r = selector.match /\$([A-z_]+)/
|
|
57
|
-
selector = @elements[r[1]]
|
|
58
|
-
|
|
59
|
-
activeSelector = $(selector, @container)
|
|
60
|
-
|
|
61
|
-
registered[selector] = Object.extended()
|
|
62
|
-
|
|
63
|
-
activeSelector.each (index, elem) =>
|
|
64
|
-
if Joosy.Module.hasAncestor widget, Joosy.Widget
|
|
65
|
-
instance = new widget
|
|
66
|
-
else
|
|
67
|
-
instance = widget.call this, index
|
|
68
|
-
|
|
69
|
-
registered[selector][Joosy.Module.__className instance] ||= 0
|
|
70
|
-
registered[selector][Joosy.Module.__className instance] += 1
|
|
71
|
-
|
|
72
|
-
@registerWidget $(elem), instance
|
|
73
|
-
|
|
74
|
-
registered.each (selector, value) =>
|
|
75
|
-
value.each (widget, count) =>
|
|
76
|
-
Joosy.Modules.Log.debugAs @, "Widget #{widget} registered at '#{selector}'. Elements: #{count}"
|
|
77
|
-
|
|
78
|
-
#
|
|
79
|
-
# Unregister all widgets for current object
|
|
80
|
-
#
|
|
81
|
-
__unloadWidgets: ->
|
|
82
|
-
if @__activeWidgets
|
|
83
|
-
for widget in @__activeWidgets
|
|
84
|
-
widget.__unload()
|
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
#= require joosy/core/joosy
|
|
2
|
-
#= require joosy/core/modules/module
|
|
3
|
-
#= require joosy/core/modules/log
|
|
4
|
-
#= require joosy/core/modules/events
|
|
5
|
-
#= require joosy/core/modules/container
|
|
6
|
-
#= require joosy/core/modules/renderer
|
|
7
|
-
#= require joosy/core/modules/time_manager
|
|
8
|
-
#= require joosy/core/modules/widgets_manager
|
|
9
|
-
#= require joosy/core/modules/filters
|
|
10
|
-
|
|
11
|
-
#
|
|
12
|
-
# Base class for all of your Joosy Pages.
|
|
13
|
-
# @see http://guides.joosy.ws/guides/layouts-pages-and-routing.html
|
|
14
|
-
#
|
|
15
|
-
# @example Sample application page
|
|
16
|
-
# class @RumbaPage extends Joosy.Layout
|
|
17
|
-
# @view 'rumba'
|
|
18
|
-
#
|
|
19
|
-
class Joosy.Page extends Joosy.Module
|
|
20
|
-
@include Joosy.Modules.Log
|
|
21
|
-
@include Joosy.Modules.Events
|
|
22
|
-
@include Joosy.Modules.Container
|
|
23
|
-
@include Joosy.Modules.Renderer
|
|
24
|
-
@include Joosy.Modules.TimeManager
|
|
25
|
-
@include Joosy.Modules.WidgetsManager
|
|
26
|
-
@include Joosy.Modules.Filters
|
|
27
|
-
|
|
28
|
-
#
|
|
29
|
-
# Default layout is no layout.
|
|
30
|
-
#
|
|
31
|
-
layout: false
|
|
32
|
-
|
|
33
|
-
#
|
|
34
|
-
# Previous page.
|
|
35
|
-
#
|
|
36
|
-
previous: false
|
|
37
|
-
|
|
38
|
-
#
|
|
39
|
-
# Route params.
|
|
40
|
-
#
|
|
41
|
-
params: false
|
|
42
|
-
|
|
43
|
-
#
|
|
44
|
-
# Prefetched page data.
|
|
45
|
-
#
|
|
46
|
-
data: false
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
# Sets layout for current page
|
|
50
|
-
#
|
|
51
|
-
# @param [Class] layoutClass Layout to use
|
|
52
|
-
#
|
|
53
|
-
@layout: (layoutClass) ->
|
|
54
|
-
@::__layoutClass = layoutClass
|
|
55
|
-
|
|
56
|
-
#
|
|
57
|
-
# Sets the method which will controll the painting preparation proccess.
|
|
58
|
-
#
|
|
59
|
-
# This method will be called right ater previous page {Joosy.Page.erase} and in parallel with
|
|
60
|
-
# page data fetching so you can use it to initiate preloader.
|
|
61
|
-
#
|
|
62
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
63
|
-
# preparations are done you should call that function.
|
|
64
|
-
#
|
|
65
|
-
# @example Sample before painter
|
|
66
|
-
# @beforePaint (complete) ->
|
|
67
|
-
# if !@data # checks if parallel fetching finished
|
|
68
|
-
# $('preloader').slideDown -> complete()
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
@beforePaint: (callback) ->
|
|
72
|
-
@::__beforePaint = callback
|
|
73
|
-
|
|
74
|
-
#
|
|
75
|
-
# Sets the method which will controll the painting proccess.
|
|
76
|
-
#
|
|
77
|
-
# This method will be called after fetching, erasing and beforePaint is complete.
|
|
78
|
-
# It should be used to setup appearance effects of page.
|
|
79
|
-
#
|
|
80
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
81
|
-
# preparations are done you should call that function.
|
|
82
|
-
#
|
|
83
|
-
# @example Sample painter
|
|
84
|
-
# @paint (complete) ->
|
|
85
|
-
# @container.fadeIn -> complete()
|
|
86
|
-
#
|
|
87
|
-
@paint: (callback) ->
|
|
88
|
-
@::__paint = callback
|
|
89
|
-
|
|
90
|
-
#
|
|
91
|
-
# @todo Does anybody have idea why we could need this method?
|
|
92
|
-
# Looks like something should be removed from here and bootstrap proccess.
|
|
93
|
-
#
|
|
94
|
-
@afterPaint: (callback) ->
|
|
95
|
-
@::__afterPaint = callback
|
|
96
|
-
|
|
97
|
-
#
|
|
98
|
-
# Sets the method which will controll the erasing proccess.
|
|
99
|
-
#
|
|
100
|
-
# Use this method to setup hiding effect.
|
|
101
|
-
#
|
|
102
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
103
|
-
# preparations are done you should call that function.
|
|
104
|
-
#
|
|
105
|
-
# @note This method will be caled _before_ unload routines so in theory you can
|
|
106
|
-
# access page data from that. Think twice if you are doing it right though.
|
|
107
|
-
#
|
|
108
|
-
# @example Sample eraser
|
|
109
|
-
# @erase (complete) ->
|
|
110
|
-
# @container.fadeOut -> complete()
|
|
111
|
-
#
|
|
112
|
-
@erase: (callback) ->
|
|
113
|
-
@::__erase = callback
|
|
114
|
-
|
|
115
|
-
#
|
|
116
|
-
# Sets the method which will controll the data fetching proccess.
|
|
117
|
-
#
|
|
118
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
119
|
-
# preparations are done you should call that function.
|
|
120
|
-
#
|
|
121
|
-
# @example Basic usage
|
|
122
|
-
# @fetch (complete) ->
|
|
123
|
-
# $.get '/rumbas', (@data) => complete()
|
|
124
|
-
#
|
|
125
|
-
@fetch: (callback) ->
|
|
126
|
-
@::__fetch = callback
|
|
127
|
-
|
|
128
|
-
#
|
|
129
|
-
# Sets the several separate methods that will fetch data in parallel.
|
|
130
|
-
#
|
|
131
|
-
# @note This will work through {Joosy.Modules.Events#synchronize}
|
|
132
|
-
#
|
|
133
|
-
# @example Basic usage
|
|
134
|
-
# @fetchSynchronized (context) ->
|
|
135
|
-
# context.do (done) ->
|
|
136
|
-
# $.get '/rumbas', (data) =>
|
|
137
|
-
# @data.rumbas = data
|
|
138
|
-
# done()
|
|
139
|
-
#
|
|
140
|
-
# context.do (done) ->
|
|
141
|
-
# $.get '/kutuzkas', (data) =>
|
|
142
|
-
# @data.kutuzkas = data
|
|
143
|
-
# done()
|
|
144
|
-
#
|
|
145
|
-
@fetchSynchronized: (callback) ->
|
|
146
|
-
@::__fetch = (complete) ->
|
|
147
|
-
@synchronize (context) ->
|
|
148
|
-
context.after -> complete()
|
|
149
|
-
callback.call(this, context)
|
|
150
|
-
|
|
151
|
-
#
|
|
152
|
-
# Sets the position where page will be scrolled to after load.
|
|
153
|
-
#
|
|
154
|
-
# @note If you use animated scroll joosy will atempt to temporarily fix the
|
|
155
|
-
# height of your document while scrolling to prevent jump effect.
|
|
156
|
-
#
|
|
157
|
-
# @param [jQuery] element Element to scroll to
|
|
158
|
-
# @param [Hash] options
|
|
159
|
-
#
|
|
160
|
-
# @option options [Integer] speed Sets the animation duration (500 is default)
|
|
161
|
-
# @option options [Integer] margin Defines the margin from element position.
|
|
162
|
-
# Can be negative.
|
|
163
|
-
#
|
|
164
|
-
@scroll: (element, options={}) ->
|
|
165
|
-
@::__scrollElement = element
|
|
166
|
-
@::__scrollSpeed = options.speed || 500
|
|
167
|
-
@::__scrollMargin = options.margin || 0
|
|
168
|
-
|
|
169
|
-
#
|
|
170
|
-
# Sets the page HTML title.
|
|
171
|
-
#
|
|
172
|
-
# @note Title will be reverted on unload.
|
|
173
|
-
#
|
|
174
|
-
# @param [String] title Title to set.
|
|
175
|
-
#
|
|
176
|
-
@title: (title, separator=' / ') ->
|
|
177
|
-
@afterLoad ->
|
|
178
|
-
titleStr = if Object.isFunction(title) then title.apply(this) else title
|
|
179
|
-
titleStr = titleStr.join(separator) if Object.isArray(titleStr)
|
|
180
|
-
@__previousTitle = document.title
|
|
181
|
-
document.title = titleStr
|
|
182
|
-
|
|
183
|
-
@afterUnload ->
|
|
184
|
-
document.title = @__previousTitle
|
|
185
|
-
|
|
186
|
-
#
|
|
187
|
-
# Constructor is very destructive (c), it calls bootstrap directly so use with caution.
|
|
188
|
-
#
|
|
189
|
-
# @params [Hash] params Route params
|
|
190
|
-
# @params [Joosy.Page] previous Previous page to unload
|
|
191
|
-
#
|
|
192
|
-
constructor: (@params, @previous) ->
|
|
193
|
-
Joosy.Application.loading = true
|
|
194
|
-
|
|
195
|
-
@__layoutClass ||= ApplicationLayout
|
|
196
|
-
|
|
197
|
-
if @__runBeforeLoads @params, @previous
|
|
198
|
-
if !@previous?.layout?.uuid? || @previous?.__layoutClass != @__layoutClass
|
|
199
|
-
@__bootstrapLayout()
|
|
200
|
-
else
|
|
201
|
-
@__bootstrap()
|
|
202
|
-
|
|
203
|
-
#
|
|
204
|
-
# @see Joosy.Router#navigate
|
|
205
|
-
#
|
|
206
|
-
navigate: (args...) ->
|
|
207
|
-
Joosy.Router.navigate(args...)
|
|
208
|
-
|
|
209
|
-
#
|
|
210
|
-
# This is required by {Joosy.Modules.Renderer}
|
|
211
|
-
# Sets the base template dir to app_name/templates/pages
|
|
212
|
-
#
|
|
213
|
-
__renderSection: ->
|
|
214
|
-
'pages'
|
|
215
|
-
|
|
216
|
-
#
|
|
217
|
-
# Freezes the page height through $(html).
|
|
218
|
-
#
|
|
219
|
-
# Required to implement better {Joosy.Page.scroll} behavior.
|
|
220
|
-
#
|
|
221
|
-
__fixHeight: ->
|
|
222
|
-
$('html').css 'min-height', $(document).height()
|
|
223
|
-
|
|
224
|
-
#
|
|
225
|
-
# Undo {#__fixHeight}
|
|
226
|
-
#
|
|
227
|
-
__releaseHeight: ->
|
|
228
|
-
$('html').css 'min-height', ''
|
|
229
|
-
|
|
230
|
-
#
|
|
231
|
-
# Page bootstrap proccess
|
|
232
|
-
#
|
|
233
|
-
# * {Joosy.Modules.Container#refreshElements}
|
|
234
|
-
# * {Joosy.Modules.Container#__delegateEvents}
|
|
235
|
-
# * {Joosy.Modules.WidgetsManager#__setupWidgets}
|
|
236
|
-
# * {Joosy.Modules.Filters#__runAfterLoads}
|
|
237
|
-
# * Scrolling
|
|
238
|
-
#
|
|
239
|
-
__load: ->
|
|
240
|
-
@refreshElements()
|
|
241
|
-
@__delegateEvents()
|
|
242
|
-
@__setupWidgets()
|
|
243
|
-
@__runAfterLoads @params, @previous
|
|
244
|
-
if @__scrollElement
|
|
245
|
-
scroll = $(@__extractSelector @__scrollElement).offset()?.top + @__scrollMargin
|
|
246
|
-
Joosy.Modules.Log.debugAs @, "Scrolling to #{@__extractSelector @__scrollElement}"
|
|
247
|
-
$('html, body').animate {scrollTop: scroll}, @__scrollSpeed, =>
|
|
248
|
-
if @__scrollSpeed != 0
|
|
249
|
-
@__releaseHeight()
|
|
250
|
-
Joosy.Application.loading = false
|
|
251
|
-
@trigger 'loaded'
|
|
252
|
-
|
|
253
|
-
Joosy.Modules.Log.debugAs @, "Page loaded"
|
|
254
|
-
|
|
255
|
-
#
|
|
256
|
-
# Page destruction proccess.
|
|
257
|
-
#
|
|
258
|
-
# * {Joosy.Modules.TimeManager#__clearTime}
|
|
259
|
-
# * {Joosy.Modules.WidgetsManager#__unloadWidgets}
|
|
260
|
-
# * {Joosy.Modules.Renderer#__removeMetamorphs}
|
|
261
|
-
# * {Joosy.Modules.Filters#__runAfterUnloads}
|
|
262
|
-
#
|
|
263
|
-
__unload: ->
|
|
264
|
-
@__clearTime()
|
|
265
|
-
@__unloadWidgets()
|
|
266
|
-
@__removeMetamorphs()
|
|
267
|
-
@__runAfterUnloads @params, @previous
|
|
268
|
-
delete @previous
|
|
269
|
-
|
|
270
|
-
#
|
|
271
|
-
# Proxies callback through possible async wrapper.
|
|
272
|
-
#
|
|
273
|
-
# If wrapper is defined, it will be called with given callback as one of parameters.
|
|
274
|
-
# If wrapper is not defined callback will be called directly.
|
|
275
|
-
#
|
|
276
|
-
# @note Magic People Voodoo People
|
|
277
|
-
#
|
|
278
|
-
# @param [Object] entity Object possibly containing wrapper method
|
|
279
|
-
# @param [String] receiver String name of wrapper method inside entity
|
|
280
|
-
# @param [Hash] params Params to send to wrapper, callback will be
|
|
281
|
-
# attached as the last of them.
|
|
282
|
-
# @param [Function] callback Callback to run
|
|
283
|
-
#
|
|
284
|
-
__callSyncedThrough: (entity, receiver, params, callback) ->
|
|
285
|
-
if entity?[receiver]?
|
|
286
|
-
entity[receiver].apply entity, params.clone().add(callback)
|
|
287
|
-
else
|
|
288
|
-
callback()
|
|
289
|
-
|
|
290
|
-
#
|
|
291
|
-
# The single page (without layout reloading) bootstrap logic
|
|
292
|
-
#
|
|
293
|
-
# @example Hacky boot sequence description
|
|
294
|
-
# previous::erase \
|
|
295
|
-
# previous::unload \
|
|
296
|
-
# beforePaint \
|
|
297
|
-
# > paint
|
|
298
|
-
# fetch /
|
|
299
|
-
#
|
|
300
|
-
__bootstrap: ->
|
|
301
|
-
Joosy.Modules.Log.debugAs @, "Boostraping page"
|
|
302
|
-
@layout = @previous.layout
|
|
303
|
-
|
|
304
|
-
callbacksParams = [@layout.content()]
|
|
305
|
-
|
|
306
|
-
if @__scrollElement && @__scrollSpeed != 0
|
|
307
|
-
@__fixHeight()
|
|
308
|
-
|
|
309
|
-
@wait "stageClear dataReceived", =>
|
|
310
|
-
@__callSyncedThrough this, '__paint', callbacksParams, =>
|
|
311
|
-
# Page HTML
|
|
312
|
-
@swapContainer @layout.content(), @__renderer(@data || {})
|
|
313
|
-
@container = @layout.content()
|
|
314
|
-
|
|
315
|
-
# Loading
|
|
316
|
-
@__load()
|
|
317
|
-
|
|
318
|
-
@layout.content()
|
|
319
|
-
|
|
320
|
-
@__callSyncedThrough @previous, '__erase', callbacksParams, =>
|
|
321
|
-
@previous?.__unload()
|
|
322
|
-
@__callSyncedThrough this, '__beforePaint', callbacksParams, =>
|
|
323
|
-
@trigger 'stageClear'
|
|
324
|
-
|
|
325
|
-
@__callSyncedThrough this, '__fetch', [], =>
|
|
326
|
-
Joosy.Modules.Log.debugAs @, "Fetch complete"
|
|
327
|
-
@trigger 'dataReceived'
|
|
328
|
-
|
|
329
|
-
#
|
|
330
|
-
# The page+layout bootstrap logic
|
|
331
|
-
#
|
|
332
|
-
# @example Hacky boot sequence description
|
|
333
|
-
# previous::erase \
|
|
334
|
-
# previous::unload \
|
|
335
|
-
# beforePaint \
|
|
336
|
-
# > paint
|
|
337
|
-
# fetch /
|
|
338
|
-
#
|
|
339
|
-
__bootstrapLayout: ->
|
|
340
|
-
Joosy.Modules.Log.debugAs @, "Boostraping page with layout"
|
|
341
|
-
@layout = new @__layoutClass(@params)
|
|
342
|
-
|
|
343
|
-
callbacksParams = [Joosy.Application.content(), this]
|
|
344
|
-
|
|
345
|
-
if @__scrollElement && @__scrollSpeed != 0
|
|
346
|
-
@__fixHeight()
|
|
347
|
-
|
|
348
|
-
@wait "stageClear dataReceived", =>
|
|
349
|
-
@__callSyncedThrough @layout, '__paint', callbacksParams, =>
|
|
350
|
-
# Layout HTML
|
|
351
|
-
data = Joosy.Module.merge {}, @layout.data || {}
|
|
352
|
-
data = Joosy.Module.merge data, yield: => @layout.yield()
|
|
353
|
-
|
|
354
|
-
@swapContainer Joosy.Application.content(), @layout.__renderer data
|
|
355
|
-
|
|
356
|
-
# Page HTML
|
|
357
|
-
@swapContainer @layout.content(), @__renderer(@data || {})
|
|
358
|
-
@container = @layout.content()
|
|
359
|
-
|
|
360
|
-
# Loading
|
|
361
|
-
@layout.__load Joosy.Application.content()
|
|
362
|
-
@__load()
|
|
363
|
-
|
|
364
|
-
Joosy.Application.content()
|
|
365
|
-
|
|
366
|
-
@__callSyncedThrough @previous?.layout, '__erase', callbacksParams, =>
|
|
367
|
-
@previous?.layout?.__unload?()
|
|
368
|
-
@previous?.__unload()
|
|
369
|
-
@__callSyncedThrough @layout, '__beforePaint', callbacksParams, =>
|
|
370
|
-
@trigger 'stageClear'
|
|
371
|
-
|
|
372
|
-
@__callSyncedThrough @layout, '__fetch', [], =>
|
|
373
|
-
@__callSyncedThrough this, '__fetch', [], =>
|
|
374
|
-
Joosy.Modules.Log.debugAs @, "Fetch complete"
|
|
375
|
-
@trigger 'dataReceived'
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Basic collection of Resources.
|
|
3
|
-
# Turns JSON array into array of Resources and manages them.
|
|
4
|
-
#
|
|
5
|
-
# @note You should not use Collection directly. It will be
|
|
6
|
-
# automatically created by things like {Joosy.Resource.Generic.map}
|
|
7
|
-
# or {Joosy.Resource.REST.find}.
|
|
8
|
-
#
|
|
9
|
-
# @example Basic sample
|
|
10
|
-
# class R extends Joosy.Resource.Generic
|
|
11
|
-
# @entity 'r'
|
|
12
|
-
#
|
|
13
|
-
# collection = new Joosy.Resource.Collection(R)
|
|
14
|
-
#
|
|
15
|
-
# collection.reset [{foo: 'bar'}, {foo: 'baz'}]
|
|
16
|
-
# collection.each (resource) ->
|
|
17
|
-
# resource('foo')
|
|
18
|
-
#
|
|
19
|
-
class Joosy.Resource.Collection extends Joosy.Module
|
|
20
|
-
@include Joosy.Modules.Events
|
|
21
|
-
|
|
22
|
-
#
|
|
23
|
-
# Allows to modify data before it gets stored
|
|
24
|
-
#
|
|
25
|
-
# @note Supposed to be used in descendants
|
|
26
|
-
#
|
|
27
|
-
# @param [Function] action `(Object) -> Object` to call
|
|
28
|
-
#
|
|
29
|
-
@beforeLoad: (action) -> @::__beforeLoad = action
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
# Sets the default model for collection
|
|
33
|
-
#
|
|
34
|
-
# @note Supposed to be used in descendants
|
|
35
|
-
#
|
|
36
|
-
# @param [Class] model Model class
|
|
37
|
-
#
|
|
38
|
-
@model: (model) -> @::model = model
|
|
39
|
-
|
|
40
|
-
#
|
|
41
|
-
# Modelized data storage
|
|
42
|
-
#
|
|
43
|
-
data: []
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
# If model param was empty it will fallback to `@model`
|
|
47
|
-
# If both param and `@model` were empty it will throw an exception.
|
|
48
|
-
#
|
|
49
|
-
# @param [Class] model Resource class which this collection will handle
|
|
50
|
-
#
|
|
51
|
-
constructor: (model=false) ->
|
|
52
|
-
@model = model if model
|
|
53
|
-
|
|
54
|
-
if !@model
|
|
55
|
-
throw new Error "#{Joosy.Module.__className @}> model can't be empty"
|
|
56
|
-
|
|
57
|
-
#
|
|
58
|
-
# Clears the storage and attempts to import given array
|
|
59
|
-
#
|
|
60
|
-
# @param [Array, Hash] entities Array of entities to import.
|
|
61
|
-
# If hash was given will seek for moodel name camelized and pluralized.
|
|
62
|
-
# @param [Boolean] notify Indicates whether to trigger 'changed' event
|
|
63
|
-
#
|
|
64
|
-
# @return [Joosy.Resource.Collection] Returns self.
|
|
65
|
-
#
|
|
66
|
-
reset: (entities, notify=true) ->
|
|
67
|
-
if @__beforeLoad?
|
|
68
|
-
entities = @__beforeLoad entities
|
|
69
|
-
|
|
70
|
-
@data = @modelize entities
|
|
71
|
-
|
|
72
|
-
if notify
|
|
73
|
-
@trigger 'changed'
|
|
74
|
-
this
|
|
75
|
-
|
|
76
|
-
#
|
|
77
|
-
# Turns Objects array into array of Resources
|
|
78
|
-
#
|
|
79
|
-
# @param [Array] collection Array of Objects
|
|
80
|
-
#
|
|
81
|
-
modelize: (collection) ->
|
|
82
|
-
root = @model::__entityName.pluralize()
|
|
83
|
-
|
|
84
|
-
if collection not instanceof Array
|
|
85
|
-
collection = collection?[root.camelize(false)]
|
|
86
|
-
|
|
87
|
-
if collection not instanceof Array
|
|
88
|
-
throw new Error "Can not read incoming JSON"
|
|
89
|
-
|
|
90
|
-
collection.map (x) =>
|
|
91
|
-
@model.create x
|
|
92
|
-
|
|
93
|
-
#
|
|
94
|
-
# Calls callback for each Resource inside Collection
|
|
95
|
-
#
|
|
96
|
-
# @param [Function] callback `(mixed) -> mixed` to call for each Resource in collection
|
|
97
|
-
#
|
|
98
|
-
each: (callback) ->
|
|
99
|
-
@data.each callback
|
|
100
|
-
|
|
101
|
-
#
|
|
102
|
-
# Returns number of Resources inside Collection
|
|
103
|
-
#
|
|
104
|
-
size: ->
|
|
105
|
-
@data.length
|
|
106
|
-
|
|
107
|
-
#
|
|
108
|
-
# Gets first resource matching description (see Sugar.js Array#find)
|
|
109
|
-
#
|
|
110
|
-
# @param [Function] description Callback matcher
|
|
111
|
-
#
|
|
112
|
-
# @return [Joosy.Resource.Generic]
|
|
113
|
-
#
|
|
114
|
-
find: (description) ->
|
|
115
|
-
@data.find description
|
|
116
|
-
|
|
117
|
-
#
|
|
118
|
-
# Gets resource by id
|
|
119
|
-
#
|
|
120
|
-
# @param [Integer] id Id to find
|
|
121
|
-
#
|
|
122
|
-
# @return [Joosy.Resource.Generic]
|
|
123
|
-
#
|
|
124
|
-
findById: (id) ->
|
|
125
|
-
@data.find (x) -> x('id').toString() == id.toString()
|
|
126
|
-
|
|
127
|
-
#
|
|
128
|
-
# Gets resource by its index inside collection
|
|
129
|
-
#
|
|
130
|
-
# @param [Integer] i Index
|
|
131
|
-
#
|
|
132
|
-
# @return [Joosy.Resource.Generic]
|
|
133
|
-
#
|
|
134
|
-
at: (i) ->
|
|
135
|
-
@data[i]
|
|
136
|
-
|
|
137
|
-
#
|
|
138
|
-
# Removes resource from collection by its index or by === comparison
|
|
139
|
-
#
|
|
140
|
-
# @param [Integer] target Index
|
|
141
|
-
# @param [Resource] target Resource by itself
|
|
142
|
-
# @param [Boolean] notify Indicates whether to trigger 'changed' event
|
|
143
|
-
#
|
|
144
|
-
# @return [Joosy.Resource.Generic] Removed element
|
|
145
|
-
#
|
|
146
|
-
remove: (target, notify=true) ->
|
|
147
|
-
if Object.isNumber target
|
|
148
|
-
index = target
|
|
149
|
-
else
|
|
150
|
-
index = @data.indexOf target
|
|
151
|
-
if index >= 0
|
|
152
|
-
result = @data.splice(index, 1)[0]
|
|
153
|
-
if notify
|
|
154
|
-
@trigger 'changed'
|
|
155
|
-
result
|
|
156
|
-
|
|
157
|
-
#
|
|
158
|
-
# Adds resource to collection to given index or to the end
|
|
159
|
-
#
|
|
160
|
-
# @param [Resource] element Resource to add
|
|
161
|
-
# @param [Integer] index Index to add to. If omited will be pushed to the end
|
|
162
|
-
# @param [Boolean] notify Indicates whether to trigger 'changed' event
|
|
163
|
-
#
|
|
164
|
-
# @return [Joosy.Resource.Generic] Added element
|
|
165
|
-
#
|
|
166
|
-
add: (element, index=false, notify=true) ->
|
|
167
|
-
if index
|
|
168
|
-
@data.splice index, 0, element
|
|
169
|
-
else
|
|
170
|
-
@data.push element
|
|
171
|
-
|
|
172
|
-
if notify
|
|
173
|
-
@trigger 'changed'
|
|
174
|
-
element
|