ende 0.2.8 → 0.2.9
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e5baed74e4549285499cb1cb26ec883f3b195eb
|
4
|
+
data.tar.gz: a39621527f298f1a3a961d407bcf238c9dd13824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d2ebd1d32231ba1e4f76cd2d08f2136a4fc45aa0ba25c8605f971903b61f355b3ae17ad0ffd28f2e19553e49ded0b895255268a6d3004ab21870dcb9dd9c1d0
|
7
|
+
data.tar.gz: ba358650d4d19bcad4fc0cd3267ebfb8f7e72d5f76e6e999c6a02c46ee6b306d08595acb40e913a8aa750f8dc8cd9faa67990e18c769c213a07954bb41072753
|
@@ -211,9 +211,7 @@ define 'aura/extensions/rivets', ->
|
|
211
211
|
else if value?.toString() isnt el.value?.toString()
|
212
212
|
el.value = if value? then value else ''
|
213
213
|
|
214
|
-
|
215
|
-
|
216
|
-
rivets.formatters.float = (value) ->
|
214
|
+
rivets.formatters.float ||= (value) ->
|
217
215
|
throw new TypeError "Invalid value passed to float formatter: #{value}" unless value?
|
218
216
|
|
219
217
|
# Blank value and impossible to convert to string
|
@@ -228,10 +226,11 @@ define 'aura/extensions/rivets', ->
|
|
228
226
|
# Format value
|
229
227
|
value.toFixed(2).toString().replace '.', ','
|
230
228
|
|
231
|
-
rivets.formatters.currency
|
229
|
+
rivets.formatters.currency ||= (value) ->
|
232
230
|
'R$ ' + rivets.formatters.float value
|
233
231
|
|
234
232
|
|
233
|
+
|
235
234
|
(application) ->
|
236
235
|
|
237
236
|
initialize: (application) ->
|
@@ -1,53 +1,87 @@
|
|
1
1
|
define ->
|
2
2
|
|
3
3
|
defaults =
|
4
|
-
context: null
|
5
4
|
beforeSend: (xhr) ->
|
6
5
|
xhr.setRequestHeader 'X-XHR-Referer', document.location.href
|
7
6
|
|
8
7
|
type: 'Base'
|
9
|
-
version: '0.0
|
8
|
+
version: '0.1.0'
|
10
9
|
options:
|
11
10
|
autoload: true
|
12
11
|
|
13
12
|
initialize: (options) ->
|
14
13
|
@sandbox.logger.log "initialized!"
|
15
14
|
|
16
|
-
|
17
|
-
throw new TypeError "content.initialize: Multiple before sends are not supported yet" if options.beforeSend
|
18
|
-
|
19
|
-
defaults.context = @
|
20
|
-
|
21
|
-
options.url = options.uri
|
22
|
-
delete options.uri
|
15
|
+
@sandbox.on "content.#{@identifier}.load", @load, @
|
23
16
|
|
24
17
|
if options.autoload
|
25
18
|
delete options.autoload
|
26
|
-
@load
|
27
|
-
else
|
28
|
-
@sandbox.once "content.#{@identifier}.load", @, @load
|
19
|
+
@sandbox.emit "content.#{@identifier}.load"
|
29
20
|
|
30
|
-
@$el.addClass "content"
|
21
|
+
@$el.addClass "content idle"
|
31
22
|
@$el.attr 'id', @identifier unless @$el.attr 'id'
|
32
|
-
|
23
|
+
|
24
|
+
normalize_options: (extra) ->
|
25
|
+
throw new TypeError "content.initialize: Multiple before sends are not supported yet" if extra?.beforeSend
|
26
|
+
|
33
27
|
options = @sandbox.util._.omit @options, 'el', 'ref', '_ref', 'name', 'require', 'baseUrl'
|
34
|
-
|
28
|
+
normalized_options = @sandbox.util.extend context: @, defaults, options, extra
|
29
|
+
|
30
|
+
throw new TypeError "content.initialize: No uri provided to load content" unless normalized_options.uri?
|
31
|
+
|
32
|
+
normalized_options.url = normalized_options.uri
|
33
|
+
delete normalized_options.uri
|
34
|
+
|
35
|
+
normalized_options
|
36
|
+
|
37
|
+
# Total number of completed loads (loaded or failed)
|
38
|
+
loads: 0
|
39
|
+
|
40
|
+
load: (options) ->
|
41
|
+
# TODO move to anoter method
|
42
|
+
if @loads > 0
|
43
|
+
@html ''
|
44
|
+
|
45
|
+
@loading?.abort()
|
46
|
+
@spinner?.stop()
|
47
|
+
|
48
|
+
# Give user some feedback
|
49
|
+
# TODO move spinner outside this component? And use only css
|
50
|
+
# classes instead
|
51
|
+
@spinner = @sandbox.ui.loader @$el
|
52
|
+
@$el.addClass "loading"
|
53
|
+
@$el.removeClass "idle"
|
35
54
|
|
36
55
|
# TODO remove jQuery dependency
|
37
|
-
$.ajax(options).done(@loaded).fail(@failed)
|
56
|
+
@loading = $.ajax(@normalize_options options).done(@loaded).fail(@failed).always(@ended)
|
38
57
|
|
39
|
-
|
58
|
+
@sandbox.emit "content.#{@identifier}.loading", @loading
|
40
59
|
|
60
|
+
# Executed upon successfully loaded
|
61
|
+
loaded: (response) ->
|
41
62
|
# Will also initialize sandbox!
|
42
63
|
@html response
|
43
64
|
|
44
65
|
failed: (xhr) ->
|
66
|
+
# TODO better debugging code location
|
45
67
|
if @sandbox.debug.enabled
|
46
68
|
html = "<h2>Content Widget: Failed to load Content</h2>"
|
47
69
|
html += xhr.responseText
|
48
70
|
html = html.replace /\n/g, '<br/>'
|
49
|
-
@html html
|
50
71
|
|
51
72
|
else
|
52
73
|
# TODO prettier message
|
53
74
|
html = "Failed to load content."
|
75
|
+
|
76
|
+
@html html
|
77
|
+
|
78
|
+
ended: ->
|
79
|
+
@$el.removeClass "loading"
|
80
|
+
@$el.addClass "idle"
|
81
|
+
@loads++
|
82
|
+
|
83
|
+
# TODO move to anoter method
|
84
|
+
@spinner.stop()
|
85
|
+
@spinner = null
|
86
|
+
@loading = null
|
87
|
+
|
@@ -1,9 +1,72 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
define [
|
3
|
+
define [
|
4
|
+
'./states/index',
|
5
|
+
'./presenters/default',
|
6
|
+
'/assets/jquery/inview',
|
7
|
+
'stampit/stampit'], (templates, presenter, inview, stampit) ->
|
4
8
|
|
5
9
|
observable = require('indefinido-observable').mixin
|
6
10
|
|
11
|
+
paginable = stampit
|
12
|
+
flip_to: (page) ->
|
13
|
+
@widget.scope.page (page - 1)
|
14
|
+
@flip()
|
15
|
+
|
16
|
+
flip: ->
|
17
|
+
{scope} = @widget
|
18
|
+
{page_number, total_pages} = scope
|
19
|
+
|
20
|
+
return unless total_pages?
|
21
|
+
|
22
|
+
scope.page ++page_number
|
23
|
+
|
24
|
+
if page_number <= total_pages
|
25
|
+
@widget.scope_to scope
|
26
|
+
else
|
27
|
+
@widget.sandbox.emit "#{@widget.name}.#{@widget.identifier}.last_page"
|
28
|
+
,
|
29
|
+
{}
|
30
|
+
, ->
|
31
|
+
|
32
|
+
{sandbox, scope} = @widget
|
33
|
+
{page_number} = scope
|
34
|
+
scope.total_pages ?= Infinity
|
35
|
+
|
36
|
+
unless scope.page? page_number
|
37
|
+
throw new TypeError "Pagination could not be initialized required method scope#page not found!"
|
38
|
+
|
39
|
+
# TODO scope.subscribe 'page_number', total_pages
|
40
|
+
|
41
|
+
sandbox.on "#{@widget.name}.#{@widget.identifier}.flip" , @flip , @
|
42
|
+
sandbox.on "#{@widget.name}.#{@widget.identifier}.flip_to" , @flip_to , @
|
43
|
+
|
44
|
+
stampit.mixIn @, @widget.options.pagination
|
45
|
+
|
46
|
+
scrollable = stampit
|
47
|
+
bottoned: ->
|
48
|
+
scrollBottom = @scroll_container.scrollTop() + @scroll_container.height()
|
49
|
+
scrollableBottom = @widget.$el.height() + @widget.$el.offset().top
|
50
|
+
|
51
|
+
scrollBottom + @buffer > scrollableBottom
|
52
|
+
|
53
|
+
scrolled: ->
|
54
|
+
@widget.sandbox.emit "#{@widget.name}.#{@widget.identifier}.flip" if @bottoned()
|
55
|
+
,
|
56
|
+
buffer: 400
|
57
|
+
, ->
|
58
|
+
@scroll_container = $ window
|
59
|
+
|
60
|
+
@scroll_container.scroll _.throttle (params...) =>
|
61
|
+
@scrolled params...
|
62
|
+
, 500
|
63
|
+
|
64
|
+
# Trigger more items loading if page starts in bottom state
|
65
|
+
# TODO Account for autofetchable viewer
|
66
|
+
@widget.sandbox.on "viewer.#{@widget.identifier}.populated", @scrolled, @
|
67
|
+
|
68
|
+
stampit.mixIn @, @widget.options.scroll
|
69
|
+
|
7
70
|
boo =
|
8
71
|
cache: {}
|
9
72
|
initialize: (container) ->
|
@@ -46,27 +109,30 @@ define ['./states/index', './presenters/default', '/assets/jquery/inview'], (tem
|
|
46
109
|
ghost.shamed = false
|
47
110
|
# In order to remove staticaly set width and height we pass
|
48
111
|
# empty strings to css jquery method
|
49
|
-
element.css
|
112
|
+
element.css width: '', height: '', visibility: ''
|
50
113
|
|
51
114
|
|
52
115
|
viewed: (event, in_view, horizontal, vertical) ->
|
53
116
|
boo[if in_view then 'pride' else 'shame'] event.target
|
54
117
|
|
55
|
-
version: '0.
|
118
|
+
version: '0.2.0'
|
56
119
|
|
57
120
|
# TODO better separation of concerns
|
58
121
|
# TODO Current remote page that is beign displayed
|
59
122
|
options:
|
60
123
|
resource: 'default'
|
61
124
|
|
62
|
-
# TODO rename records to
|
125
|
+
# TODO rename records to resources
|
63
126
|
records: null
|
64
127
|
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
128
|
+
# Automatically fetch records on initialization
|
129
|
+
autofetch: false
|
130
|
+
|
131
|
+
# If page attribute is set, viewer will assume that there is a
|
132
|
+
# page method on the scope
|
133
|
+
page: null
|
134
|
+
|
135
|
+
scroll: null
|
70
136
|
|
71
137
|
type: 'Base'
|
72
138
|
|
@@ -83,39 +149,45 @@ define ['./states/index', './presenters/default', '/assets/jquery/inview'], (tem
|
|
83
149
|
@sandbox.emit "viewer.#{@identifier}.selected", item.model
|
84
150
|
|
85
151
|
scope_to: (scope, child_scope) ->
|
86
|
-
throw new TypeError "Invalid scope sent to viewer@#{@identifier} sent: #{scope.resource}, expected: #{@scope.resource}" if scope.resource.toString() != @scope.resource.toString()
|
152
|
+
throw new TypeError "Invalid scope sent to viewer@#{@identifier} sent: #{scope.resource.toString()}, expected: #{@scope.resource.toString()}" if scope.resource.toString() != @scope.resource.toString()
|
87
153
|
@scope = scope
|
88
154
|
|
89
155
|
# TODO better hierachical event distribution
|
90
156
|
for { _widget: widget } in @sandbox._children?
|
91
157
|
widget.scope_to? child_scope
|
92
158
|
|
93
|
-
@repopulate()
|
94
159
|
@sandbox.emit "viewer.#{@identifier}.scope_changed", @scope
|
95
160
|
|
161
|
+
@repopulate()
|
162
|
+
|
96
163
|
repopulate: ->
|
97
164
|
if @load?
|
98
165
|
@load.stop()
|
99
166
|
@load = null
|
100
167
|
|
101
168
|
# TODO store spinner instance, instead of creating a new one every time
|
102
|
-
|
169
|
+
unless @load?
|
170
|
+
@load = @sandbox.ui.loader @$el.find '.results .items'
|
171
|
+
|
172
|
+
# TODO implement status for viewer widget
|
173
|
+
@$el.addClass 'idle'
|
174
|
+
@$el.removeClass 'loading'
|
103
175
|
|
104
176
|
viewer = @presentation.viewer
|
105
|
-
viewer.items = []
|
106
177
|
|
107
178
|
# ✔ Generalize this filtering option
|
108
179
|
# TODO make scope.all method use scope too, and replace @scope.fetch by it
|
109
180
|
options = @options # TODO better options accessing
|
110
|
-
presented = @scope.fetch null, (
|
111
|
-
|
112
|
-
|
181
|
+
presented = @scope.fetch null, (records) =>
|
182
|
+
|
183
|
+
# TODO instantiate records before calling this callback
|
184
|
+
records = _.map records, @resource, @resource unless records[0]?.resource
|
113
185
|
|
114
186
|
# TODO implement Array.concat ou Array.merge in observer, and
|
115
187
|
# use it here instead of pushing each record
|
116
|
-
viewer.items
|
188
|
+
viewer.items = records
|
117
189
|
|
118
|
-
presented.then =>
|
190
|
+
presented.then (records) =>
|
119
191
|
if viewer.items.length
|
120
192
|
# boo.initialize @$el.find '.results .items'
|
121
193
|
@$el.addClass 'filled'
|
@@ -125,15 +197,26 @@ define ['./states/index', './presenters/default', '/assets/jquery/inview'], (tem
|
|
125
197
|
@$el.addClass 'empty'
|
126
198
|
@$el.removeClass 'filled'
|
127
199
|
|
200
|
+
@sandbox.emit "viewer.#{@identifier}.populated", records
|
201
|
+
|
202
|
+
presented.always =>
|
203
|
+
# TODO implement status for viewer widget
|
204
|
+
@$el.addClass 'idle'
|
205
|
+
@$el.removeClass 'loading'
|
206
|
+
|
128
207
|
if @load?
|
129
208
|
@load.stop()
|
130
209
|
@load = null
|
131
210
|
|
211
|
+
|
132
212
|
populate: (handlers) ->
|
133
213
|
sandbox = @sandbox
|
134
214
|
|
135
|
-
@load = @sandbox.ui.loader
|
215
|
+
@load = @sandbox.ui.loader @$results
|
136
216
|
|
217
|
+
# TODO implement status for viewer widget
|
218
|
+
@$el.removeClass 'idle'
|
219
|
+
@$el.addClass 'loading'
|
137
220
|
|
138
221
|
# TODO replace with strategy pattern, please!
|
139
222
|
if @options.records?.length
|
@@ -141,24 +224,18 @@ define ['./states/index', './presenters/default', '/assets/jquery/inview'], (tem
|
|
141
224
|
deferred = jQuery.Deferred()
|
142
225
|
deferred.resolveWith @scope, [@options.records]
|
143
226
|
|
144
|
-
else if @options.
|
145
|
-
|
146
|
-
deferred = @scope.reload?()
|
227
|
+
else if @options.autofetch
|
147
228
|
|
148
|
-
|
149
|
-
unless deferred
|
150
|
-
deferred = jQuery.Deferred()
|
151
|
-
empty = {}
|
152
|
-
empty[@options.attribute] = []
|
153
|
-
deferred.resolveWith @scope, [empty]
|
229
|
+
deferred = @scope.all()
|
154
230
|
|
155
231
|
else
|
156
|
-
|
232
|
+
|
233
|
+
deferred = jQuery.Deferred()
|
234
|
+
deferred.resolveWith @scope, [[]]
|
157
235
|
|
158
236
|
# Initialize dependencies
|
159
237
|
# TODO replace with strategy pattern, please!
|
160
|
-
deferred.done (
|
161
|
-
records = if @options.attribute? then result[@options.attribute] else result
|
238
|
+
deferred.done (records) =>
|
162
239
|
|
163
240
|
@load.stop()
|
164
241
|
|
@@ -166,6 +243,7 @@ define ['./states/index', './presenters/default', '/assets/jquery/inview'], (tem
|
|
166
243
|
|
167
244
|
@html templates[@options.resource]
|
168
245
|
|
246
|
+
|
169
247
|
if records.length
|
170
248
|
# boo.initialize @$el.find '.results .items'
|
171
249
|
@$el.addClass 'filled'
|
@@ -173,22 +251,35 @@ define ['./states/index', './presenters/default', '/assets/jquery/inview'], (tem
|
|
173
251
|
@$el.addClass 'empty'
|
174
252
|
|
175
253
|
# TODO move binders to application
|
176
|
-
@bind @presentation, presenter.presentation
|
254
|
+
@bind @presentation, @presenter.presentation
|
177
255
|
|
178
256
|
@handles 'click', 'back', '.back'
|
179
257
|
|
258
|
+
@sandbox.emit "viewer.#{@identifier}.populated", records
|
259
|
+
|
260
|
+
|
180
261
|
deferred.fail =>
|
181
262
|
# TODO better error message and viewer status
|
182
263
|
@html 'Failed to fetch data from server.'
|
183
264
|
|
265
|
+
|
266
|
+
plugins: (options) ->
|
267
|
+
|
268
|
+
paginable widget: @ if options.page
|
269
|
+
scrollable widget: @ if options.scroll
|
270
|
+
|
271
|
+
|
184
272
|
initialize: (options) ->
|
185
273
|
# TODO import core extensions in another place
|
186
|
-
@
|
274
|
+
@resource = @sandbox.resource options.resource
|
275
|
+
@scope = model = @resource
|
187
276
|
cssify = @sandbox.util.inflector.cssify
|
188
277
|
@sandbox.on "viewer.#{@identifier}.scope", @scope_to, @
|
189
278
|
|
190
|
-
#
|
191
|
-
|
279
|
+
# Iniitalize plugins
|
280
|
+
@plugins options
|
281
|
+
|
282
|
+
@$el.addClass "viewer widget #{cssify(options.resource)} idle clearfix"
|
192
283
|
|
193
284
|
# Fetch custom templates
|
194
285
|
# TODO better custom templates structure and custom presenter
|
@@ -209,8 +300,6 @@ define ['./states/index', './presenters/default', '/assets/jquery/inview'], (tem
|
|
209
300
|
custom_default_template and templates[options.resource] = custom_default_template
|
210
301
|
@presenter = @sandbox.util.extend custom_presenter, presenter if custom_presenter
|
211
302
|
|
212
|
-
# Will also initialize sandbox!
|
213
|
-
@$el.addClass "viewer widget #{cssify(options.resource)}"
|
214
303
|
@$results = @$el.find '.results .items'
|
215
304
|
|
216
305
|
# Fetch default data
|
data/lib/ende/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ende
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heitor Salazar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|