joosy 0.1.0.RC1 → 0.1.0.RC2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +8 -1
- data/MIT-LICENSE +2 -2
- data/README.md +89 -0
- data/app/assets/javascripts/joosy/core/application.js.coffee +25 -5
- data/app/assets/javascripts/joosy/core/form.js.coffee +212 -22
- data/app/assets/javascripts/joosy/core/helpers.js.coffee +11 -1
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +22 -17
- data/app/assets/javascripts/joosy/core/layout.js.coffee +17 -7
- data/app/assets/javascripts/joosy/core/modules/container.js.coffee +19 -15
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +10 -9
- data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +16 -12
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +8 -5
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +31 -21
- data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +114 -51
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +2 -2
- data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +10 -10
- data/app/assets/javascripts/joosy/core/page.js.coffee +31 -21
- data/app/assets/javascripts/joosy/core/preloader.js.coffee +3 -3
- data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +137 -0
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +178 -13
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +167 -44
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +100 -32
- data/app/assets/javascripts/joosy/core/router.js.coffee +23 -25
- data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +19 -3
- data/app/assets/javascripts/joosy/core/widget.js.coffee +7 -9
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +117 -57
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +23 -24
- data/app/helpers/joosy/sprockets_helper.rb +1 -1
- data/lib/joosy/forms.rb +2 -12
- data/lib/joosy/rails/version.rb +1 -1
- data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +1 -1
- data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +1 -1
- data/spec/javascripts/joosy/core/form_spec.js.coffee +55 -12
- data/spec/javascripts/joosy/core/layout_spec.js.coffee +1 -1
- data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +0 -1
- data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +1 -1
- data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +39 -3
- data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +1 -1
- data/spec/javascripts/joosy/core/page_spec.js.coffee +4 -1
- data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +84 -0
- data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +86 -3
- data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +15 -22
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +27 -4
- data/spec/javascripts/joosy/core/widget_spec.js.coffee +3 -14
- metadata +21 -19
- data/README.rdoc +0 -3
@@ -1,48 +1,116 @@
|
|
1
|
-
|
1
|
+
#
|
2
|
+
# Collection of Resources with REST-fetching capabilities
|
3
|
+
#
|
4
|
+
# Generally you should not use RESTCollection directly. It will be
|
5
|
+
# automatically created by Joosy.Resource.REST#find.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# class R extends Joosy.Resource.REST
|
9
|
+
# @entity 'r'
|
10
|
+
#
|
11
|
+
# collection = new Joosy.Resource.RESTCollection(R, {color: 'green'})
|
12
|
+
#
|
13
|
+
# collection.fetch()
|
14
|
+
# collection.page 2
|
15
|
+
#
|
16
|
+
# collection.params = {color: 'red', sort: 'date'}
|
17
|
+
# collection.fetch()
|
18
|
+
#
|
19
|
+
class Joosy.Resource.RESTCollection extends Joosy.Resource.Collection
|
2
20
|
@include Joosy.Modules.Log
|
3
21
|
@include Joosy.Modules.Events
|
4
22
|
|
5
|
-
|
23
|
+
#
|
24
|
+
# Hash containing the cache for pages of raw data
|
25
|
+
# Keys are pages numbers, values are stored AJAX response
|
26
|
+
#
|
6
27
|
pages: Object.extended()
|
7
28
|
|
29
|
+
#
|
30
|
+
# @param [Class] model Resource class this collection will handle
|
31
|
+
# @param [Object] params Additional GET-parameters to supply when fetching
|
32
|
+
#
|
8
33
|
constructor: (@model, params={}) ->
|
9
|
-
@params = Object.extended
|
34
|
+
@params = Object.extended params
|
10
35
|
|
36
|
+
#
|
11
37
|
# Clears the storage and attempts to import given JSON
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
38
|
+
#
|
39
|
+
# @param [Object] entities Entities to import
|
40
|
+
#
|
41
|
+
reset: (entities, notify=true) ->
|
42
|
+
super entities, false
|
43
|
+
if notify
|
44
|
+
@trigger 'changed'
|
16
45
|
this
|
17
46
|
|
47
|
+
#
|
18
48
|
# Clears the storage and gets new data from server
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
49
|
+
#
|
50
|
+
# @param [Function|Object] options AJAX options.
|
51
|
+
# Will be considered as a success callback if function given
|
52
|
+
#
|
53
|
+
fetch: (options) ->
|
54
|
+
if Object.isFunction options
|
55
|
+
callback = options
|
56
|
+
else
|
57
|
+
callback = options?.success
|
58
|
+
delete options?.success
|
59
|
+
|
60
|
+
@__fetch @params, options, (data) =>
|
61
|
+
@reset data, false
|
62
|
+
callback? this
|
63
|
+
@trigger 'changed'
|
24
64
|
this
|
25
65
|
|
66
|
+
#
|
26
67
|
# Returns the subset for requested page. Requests with &page=x if not found localy.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
68
|
+
#
|
69
|
+
# @param [Integer] number Index of page
|
70
|
+
# @param [Function|Object] options AJAX options.
|
71
|
+
# Will be considered as a success callback if function given
|
72
|
+
#
|
73
|
+
page: (number, options) ->
|
74
|
+
if Object.isFunction options
|
75
|
+
callback = options
|
76
|
+
else
|
77
|
+
callback = options?.success
|
78
|
+
delete options?.success
|
79
|
+
|
80
|
+
@__fetch Joosy.Module.merge({page: number}, @params), options, (data) =>
|
81
|
+
@reset data, false
|
82
|
+
callback? @data
|
83
|
+
@trigger 'changed'
|
41
84
|
this
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
85
|
+
|
86
|
+
#
|
87
|
+
# Requests the REST collection URL with POST or any method given in options.type
|
88
|
+
#
|
89
|
+
# @param [String] ending Collection url (like 'foo' or 'foo/bar')
|
90
|
+
# @param [Function|Object] options AJAX options.
|
91
|
+
# Will be considered as a success callback if function given
|
92
|
+
#
|
93
|
+
request: (ending, options) ->
|
94
|
+
if Object.isFunction options
|
95
|
+
callback = options
|
96
|
+
else
|
97
|
+
callback = options?.success
|
98
|
+
delete options?.success
|
99
|
+
|
100
|
+
if options.method || options.type
|
101
|
+
type = options.method || options.type
|
47
102
|
else
|
48
|
-
|
103
|
+
type = 'post'
|
104
|
+
|
105
|
+
@model.__ajax type, @model.__buildSource(extension: ending), options, callback
|
106
|
+
|
107
|
+
#
|
108
|
+
# Does AJAX request
|
109
|
+
#
|
110
|
+
# @param [Object] urlOptions GET-params for request
|
111
|
+
# @param [Object] ajaxOptions AJAX options to pass with request
|
112
|
+
# @param [Function] callback
|
113
|
+
#
|
114
|
+
__fetch: (urlOptions, ajaxOptions, callback) ->
|
115
|
+
@model.__ajax 'get', @model.__buildSource(params: @params.merge(urlOptions)), ajaxOptions, (data) ->
|
116
|
+
callback(data)
|
@@ -9,61 +9,59 @@ Joosy.Router =
|
|
9
9
|
@routes = Object.extended()
|
10
10
|
|
11
11
|
map: (routes) ->
|
12
|
-
|
12
|
+
Joosy.Module.merge @rawRoutes, routes
|
13
13
|
|
14
14
|
setupRoutes: ->
|
15
15
|
@prepareRoutes @rawRoutes
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
@respondRoute location.hash
|
17
|
+
$(window).hashchange =>
|
18
|
+
@respondRoute location.hash
|
19
19
|
|
20
20
|
prepareRoutes: (routes, namespace='') ->
|
21
21
|
if !namespace && routes[404]
|
22
22
|
@wildcardAction = routes[404]
|
23
23
|
delete routes[404]
|
24
24
|
|
25
|
-
|
26
|
-
path = (namespace + path).replace
|
27
|
-
if response && (
|
28
|
-
|
25
|
+
Object.each routes, (path, response) =>
|
26
|
+
path = (namespace + path).replace /\/{2,}/, '/'
|
27
|
+
if response && (Object.isFunction(response) || response.prototype?)
|
28
|
+
Joosy.Module.merge @routes, @prepareRoute(path, response)
|
29
29
|
else
|
30
|
-
@prepareRoutes
|
30
|
+
@prepareRoutes response, path
|
31
31
|
|
32
32
|
prepareRoute: (path, response) ->
|
33
33
|
matchPath = path.replace(/\/:([^\/]+)/g, '/([^/]+)').replace(/^\/?/, '^/?').replace(/\/?$/, '/?$')
|
34
34
|
result = Object.extended()
|
35
35
|
|
36
36
|
result[matchPath] =
|
37
|
-
capture: (path.match(/\/:[^\/]+/g) || []).map(
|
37
|
+
capture: (path.match(/\/:[^\/]+/g) || []).map (str) ->
|
38
|
+
str.substr 2
|
38
39
|
action: response
|
39
40
|
result
|
40
41
|
|
41
42
|
respondRoute: (hash) ->
|
42
43
|
Joosy.Modules.Log.debug "Router> Answering '#{hash}'"
|
43
|
-
|
44
|
-
fullPath = hash.replace(/^#!?/, '')
|
45
|
-
|
44
|
+
fullPath = hash.replace /^#!?/, ''
|
46
45
|
@currentPath = fullPath
|
47
46
|
found = false
|
48
|
-
|
49
|
-
queryArray = fullPath.split('&')
|
47
|
+
queryArray = fullPath.split '&'
|
50
48
|
path = queryArray.shift()
|
51
|
-
urlParams = @paramsFromQueryArray
|
49
|
+
urlParams = @paramsFromQueryArray queryArray
|
52
50
|
|
53
|
-
for regex, route of @routes when @routes.hasOwnProperty
|
54
|
-
if vals = path.match
|
51
|
+
for regex, route of @routes when @routes.hasOwnProperty regex
|
52
|
+
if vals = path.match new RegExp(regex)
|
55
53
|
params = @paramsFromRouteMatch(vals, route).merge urlParams
|
56
54
|
|
57
|
-
if
|
58
|
-
route.action
|
55
|
+
if Joosy.Module.hasAncestor route.action, Joosy.Page
|
56
|
+
Joosy.Application.setCurrentPage route.action, params
|
59
57
|
else
|
60
|
-
|
58
|
+
route.action.call this, params
|
61
59
|
|
62
60
|
found = true
|
63
61
|
break
|
64
62
|
|
65
|
-
if !found && @wildcardAction
|
66
|
-
@wildcardAction
|
63
|
+
if !found && @wildcardAction?
|
64
|
+
@wildcardAction path, urlParams
|
67
65
|
|
68
66
|
paramsFromRouteMatch: (vals, route) ->
|
69
67
|
params = Object.extended()
|
@@ -78,8 +76,8 @@ Joosy.Router =
|
|
78
76
|
params = Object.extended()
|
79
77
|
|
80
78
|
if queryArray
|
81
|
-
$.each queryArray,
|
82
|
-
|
79
|
+
$.each queryArray, ->
|
80
|
+
unless @isBlank()
|
83
81
|
pair = @split '='
|
84
82
|
params[pair[0]] = pair[1]
|
85
83
|
|
@@ -1,8 +1,16 @@
|
|
1
1
|
#= require joosy/core/joosy
|
2
2
|
|
3
|
+
#
|
4
|
+
# Rails JST template precompilation binding
|
5
|
+
#
|
3
6
|
class Joosy.Templaters.RailsJST
|
4
7
|
constructor: (@applicationName) ->
|
5
8
|
|
9
|
+
#
|
10
|
+
# Gets template lambda by its full name
|
11
|
+
#
|
12
|
+
# @param [String] name Template name 'foo/bar'
|
13
|
+
#
|
6
14
|
buildView: (name) ->
|
7
15
|
template = JST[location = "#{@applicationName}/templates/#{name}"]
|
8
16
|
|
@@ -11,10 +19,18 @@ class Joosy.Templaters.RailsJST
|
|
11
19
|
|
12
20
|
template
|
13
21
|
|
22
|
+
#
|
23
|
+
# Gets full name of template by several params
|
24
|
+
#
|
25
|
+
# @param [String] section Section of templates like pages/layouts/...
|
26
|
+
# @param [String] template Internal template path
|
27
|
+
# @param [String] entity Entity to lookup template path by its namespace
|
28
|
+
#
|
14
29
|
resolveTemplate: (section, template, entity) ->
|
15
|
-
|
30
|
+
if template.startsWith '/'
|
31
|
+
return template.substr 1
|
16
32
|
|
17
33
|
path = entity.constructor?.__namespace__?.map('underscore') || []
|
18
|
-
path.unshift
|
34
|
+
path.unshift section
|
19
35
|
|
20
|
-
"#{path.join
|
36
|
+
"#{path.join '/'}/#{template}"
|
@@ -12,24 +12,21 @@ class Joosy.Widget extends Joosy.Module
|
|
12
12
|
@include Joosy.Modules.Container
|
13
13
|
@include Joosy.Modules.Renderer
|
14
14
|
@include Joosy.Modules.Filters
|
15
|
+
@include Joosy.Modules.TimeManager
|
15
16
|
|
16
17
|
__renderer: false
|
17
|
-
|
18
|
-
|
19
|
-
@parent.setInterval(args...)
|
20
|
-
|
21
|
-
setTimeout: (args...) ->
|
22
|
-
@parent.setTimeout(args...)
|
18
|
+
|
19
|
+
data: false
|
23
20
|
|
24
21
|
navigate: (args...) ->
|
25
|
-
Joosy.Router.navigate
|
22
|
+
Joosy.Router.navigate args...
|
26
23
|
|
27
24
|
__renderSection: ->
|
28
25
|
'widgets'
|
29
26
|
|
30
27
|
__load: (@parent, @container) ->
|
31
28
|
if @__renderer
|
32
|
-
@container.html @__renderer()
|
29
|
+
@container.html @__renderer(@data || {})
|
33
30
|
@refreshElements()
|
34
31
|
@__delegateEvents()
|
35
32
|
@__runAfterLoads()
|
@@ -37,5 +34,6 @@ class Joosy.Widget extends Joosy.Module
|
|
37
34
|
this
|
38
35
|
|
39
36
|
__unload: ->
|
37
|
+
@__clearTime()
|
40
38
|
@__removeMetamorphs()
|
41
|
-
@__runAfterUnloads()
|
39
|
+
@__runAfterUnloads()
|
@@ -1,52 +1,83 @@
|
|
1
1
|
#= require base64
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
#
|
4
|
+
# Preloader for libraries with localStorage cache
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# libraries = [['/test1.js', 100], ['/test2.js', 500]] #100, 500 - size in bytes
|
8
|
+
# CachingPreloader.load libraries,
|
9
|
+
# start: -> console.log 'preloading started'
|
10
|
+
# progress: (percent) -> console.log "#{percent}% loaded"
|
11
|
+
# complete: -> console.log 'preloading finished'
|
12
|
+
#
|
13
|
+
# @class CachingPreloader
|
14
|
+
#
|
11
15
|
@Preloader = @CachingPreloader =
|
16
|
+
#
|
17
|
+
# If set to true, localStorage cache will be avoided
|
18
|
+
#
|
12
19
|
force: false
|
20
|
+
|
21
|
+
#
|
22
|
+
# Prefix for localStorage keys
|
23
|
+
#
|
13
24
|
prefix: "cache:"
|
14
|
-
|
15
|
-
|
25
|
+
|
26
|
+
#
|
27
|
+
# Number of libraries have been loaded (increases after lib was loaded)
|
28
|
+
#
|
16
29
|
counter: 0
|
30
|
+
|
31
|
+
#
|
32
|
+
# Loads (or takes from cache) set of libraries using xhr and caches them in localStorage
|
33
|
+
# See class description for example of usage
|
34
|
+
#
|
35
|
+
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js', 10],['/test2.js', 20]]
|
36
|
+
# Second param of inner level is a size of script in bytes. Can be undefined.
|
37
|
+
# @param [Hash] Available options:
|
38
|
+
# * start: `() -> null` to call before load starts
|
39
|
+
# * progress: `(int percents) -> null` to call each 100ms of load in progress
|
40
|
+
# * complete: `() -> null` to call after load completes
|
41
|
+
#
|
42
|
+
load: (libraries, options={}) ->
|
43
|
+
@[key] = val for key, val of options
|
44
|
+
@libraries = libraries.slice()
|
17
45
|
|
18
|
-
|
46
|
+
for lib, i in @libraries
|
47
|
+
@libraries[i] = @prefix+lib[0]
|
19
48
|
|
20
|
-
|
21
|
-
|
22
|
-
x = new XMLHttpRequest
|
49
|
+
if !@force && @check()
|
50
|
+
@restore()
|
23
51
|
else
|
24
|
-
|
25
|
-
|
26
|
-
x.open 'GET', url, 1
|
27
|
-
|
28
|
-
x.onreadystatechange = () =>
|
29
|
-
if x.readyState > 3
|
30
|
-
clearInterval(@interval)
|
31
|
-
callback?(x)
|
32
|
-
|
33
|
-
if @progress
|
34
|
-
poller = =>
|
35
|
-
try
|
36
|
-
@progress.call window, Math.round((x.responseText.length / size) * (@counter / @libraries.length) * 100)
|
37
|
-
catch e
|
38
|
-
# ... IE?
|
39
|
-
|
40
|
-
@interval = setInterval poller, 100
|
41
|
-
|
42
|
-
x.send()
|
52
|
+
@start?.call window
|
53
|
+
@download libraries
|
43
54
|
|
55
|
+
#
|
56
|
+
# Checks if we can load libraries or have to download them over
|
57
|
+
#
|
58
|
+
check: ->
|
59
|
+
flag = true
|
60
|
+
for name, i in @libraries
|
61
|
+
flag &&= window.localStorage.getItem(name)?
|
62
|
+
flag
|
63
|
+
|
64
|
+
#
|
65
|
+
# Gets sources of scripts from localStorage and evals them
|
66
|
+
#
|
44
67
|
restore: ->
|
45
68
|
for name, i in @libraries
|
46
|
-
code = window.localStorage.getItem
|
47
|
-
|
69
|
+
code = window.localStorage.getItem name
|
70
|
+
if window.navigator.appName == "Microsoft Internet Explorer"
|
71
|
+
code = Base64.decode code
|
72
|
+
@evalGlobaly code
|
48
73
|
@complete?.call window, true
|
49
74
|
|
75
|
+
#
|
76
|
+
# Loads set of libraries using xhr and caches them in localStorage
|
77
|
+
#
|
78
|
+
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js', 100],['/test2.js', 500]]
|
79
|
+
# Second param of inner level is a size of script in bytes. Can be undefined.
|
80
|
+
#
|
50
81
|
download: (libraries) ->
|
51
82
|
if libraries.length > 0
|
52
83
|
@counter += 1
|
@@ -57,38 +88,67 @@ window.globalEval = (src) ->
|
|
57
88
|
|
58
89
|
@ajax url, size, (xhr) =>
|
59
90
|
code = xhr.responseText
|
60
|
-
|
61
|
-
|
91
|
+
if window.navigator.appName == "Microsoft Internet Explorer"
|
92
|
+
code = Base64.encode code
|
93
|
+
window.localStorage.setItem @prefix+url, code
|
94
|
+
@evalGlobaly xhr.responseText
|
62
95
|
@download libraries
|
63
96
|
else
|
64
97
|
@clean()
|
65
98
|
@complete?.call window
|
66
99
|
|
67
|
-
|
68
|
-
|
69
|
-
|
100
|
+
#
|
101
|
+
# Runs XHR request to get single script body
|
102
|
+
# Binds poller to call @progress each 100ms if possible (not IE *doh*)
|
103
|
+
#
|
104
|
+
# @param [String] URL to download from
|
105
|
+
# @param [Float] Expected size of download (to calculate percents)
|
106
|
+
# Size can not be taken from headers since we are supposed to get gziped content
|
107
|
+
# @param [Function] `(xhr) -> null` to call after script was loaded
|
108
|
+
#
|
109
|
+
ajax: (url, size, callback) ->
|
110
|
+
if window.XMLHttpRequest
|
111
|
+
x = new XMLHttpRequest
|
112
|
+
else
|
113
|
+
x = new ActiveXObject 'Microsoft.XMLHTTP'
|
70
114
|
|
71
|
-
|
72
|
-
@libraries[i] = @prefix+lib[0]
|
115
|
+
x.open 'GET', url, 1
|
73
116
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@download libraries
|
117
|
+
x.onreadystatechange = () =>
|
118
|
+
if x.readyState > 3
|
119
|
+
clearInterval @interval
|
120
|
+
callback? x
|
79
121
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
122
|
+
if @progress
|
123
|
+
poller = =>
|
124
|
+
try
|
125
|
+
@progress.call window, Math.round((x.responseText.length / size) * (@counter / @libraries.length) * 100)
|
126
|
+
catch e
|
127
|
+
# ... IE?
|
85
128
|
|
86
|
-
|
87
|
-
removed = 0
|
129
|
+
@interval = setInterval poller, 100
|
88
130
|
|
89
|
-
|
90
|
-
|
131
|
+
x.send()
|
132
|
+
|
133
|
+
#
|
134
|
+
# Searches through localStorage for outdated entries with our prefix and removes them
|
135
|
+
#
|
136
|
+
clean: ->
|
137
|
+
i = 0
|
91
138
|
|
139
|
+
while i < window.localStorage.length && key = window.localStorage.key(i)
|
92
140
|
if key.indexOf(@prefix) == 0 && @libraries.indexOf(key) < 0
|
93
141
|
window.localStorage.removeItem key
|
94
|
-
|
142
|
+
else
|
143
|
+
i += 1
|
144
|
+
|
145
|
+
#
|
146
|
+
# Evals source at a global scope
|
147
|
+
#
|
148
|
+
# @param [String] JS source to execute
|
149
|
+
#
|
150
|
+
evalGlobaly: (src) ->
|
151
|
+
if window.execScript
|
152
|
+
window.execScript src
|
153
|
+
else
|
154
|
+
window.eval src
|
@@ -11,6 +11,24 @@
|
|
11
11
|
#
|
12
12
|
@Preloader = @InlinePreloader =
|
13
13
|
|
14
|
+
#
|
15
|
+
# Loads set of libraries by adding <script src> to DOM head
|
16
|
+
# See class description for example of usage
|
17
|
+
#
|
18
|
+
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js'],['/test2.js']]
|
19
|
+
# @param [Hash] Available options:
|
20
|
+
# * start: `() -> null` to call before load starts:
|
21
|
+
# * complete: `() -> null` to call after load completes
|
22
|
+
#
|
23
|
+
load: (libraries, options) ->
|
24
|
+
@[key] = val for key, val of options
|
25
|
+
@start?()
|
26
|
+
|
27
|
+
if libraries.length > 0
|
28
|
+
@receive libraries.shift()[0], => @load(libraries)
|
29
|
+
else
|
30
|
+
@complete?()
|
31
|
+
|
14
32
|
#
|
15
33
|
# Loads one script by adding <script src> to DOM head
|
16
34
|
#
|
@@ -19,37 +37,18 @@
|
|
19
37
|
#
|
20
38
|
receive: (url, callback) ->
|
21
39
|
head = document.getElementsByTagName("head")[0]
|
22
|
-
script = document.createElement
|
40
|
+
script = document.createElement "script"
|
23
41
|
script.src = url
|
24
42
|
|
25
43
|
done = false
|
26
44
|
|
27
45
|
proceed = ->
|
28
|
-
if
|
29
|
-
|
30
|
-
|
31
|
-
done = true and callback() if callback
|
46
|
+
if !done && (!@readyState? || @readyState == "loaded" || @readyState == "complete")
|
47
|
+
done = true
|
48
|
+
callback?()
|
32
49
|
script.onload = script.onreadystatechange = null
|
33
50
|
|
34
51
|
script.onload = script.onreadystatechange = proceed
|
35
52
|
|
36
|
-
head.appendChild
|
53
|
+
head.appendChild script
|
37
54
|
return undefined
|
38
|
-
|
39
|
-
#
|
40
|
-
# Loads set of libraries by adding <script src> to DOM head
|
41
|
-
# See class description for example of usage
|
42
|
-
#
|
43
|
-
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js'],['/test2.js']]
|
44
|
-
# @param [Hash] Available options:
|
45
|
-
# * start: `() -> null` to call before load starts:
|
46
|
-
# * complete: `() -> null` to call after load completes
|
47
|
-
#
|
48
|
-
load: (libraries, options) ->
|
49
|
-
@[key] = val for key, val of options
|
50
|
-
@start?.call window
|
51
|
-
|
52
|
-
if libraries.length > 0
|
53
|
-
@receive libraries.shift()[0], => @load(libraries)
|
54
|
-
else
|
55
|
-
@complete?.call window
|
@@ -17,7 +17,7 @@ module Joosy::SprocketsHelper
|
|
17
17
|
if force_preloader
|
18
18
|
require_asset preloader_asset
|
19
19
|
else
|
20
|
-
require_asset Rails.env == '
|
20
|
+
require_asset Rails.env == 'development' ? app_asset : preloader_asset
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/joosy/forms.rb
CHANGED
@@ -9,23 +9,13 @@ module Joosy
|
|
9
9
|
if entity.save
|
10
10
|
joosy_succeed(data, entity, &block)
|
11
11
|
else
|
12
|
-
joosy_fail(entity.errors
|
12
|
+
joosy_fail(entity.errors, entity.class.name)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def joosy_fail(errors, entity=false)
|
17
17
|
errors = Hash[*errors.map {|x| [x, nil]}.flatten] if errors.is_a?(Array)
|
18
|
-
|
19
|
-
if !entity
|
20
|
-
notifications = errors
|
21
|
-
else
|
22
|
-
notifications = {}
|
23
|
-
errors.each do |k, v|
|
24
|
-
notifications["#{entity.underscore}[#{k}]"] = v
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
joosy_respond notifications, :unprocessable_entity
|
18
|
+
joosy_respond errors, :unprocessable_entity
|
29
19
|
end
|
30
20
|
|
31
21
|
def joosy_succeed(data, entity=nil, &block)
|
data/lib/joosy/rails/version.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
class @<%= file_name.camelize %>
|
1
|
+
class @<%= file_name.camelize %> extends Joosy.Resource.REST
|
2
2
|
@entity '<%= file_name %>'
|