joosy 0.1.0.RC1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +159 -0
- data/Guardfile +30 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +3 -0
- data/Rakefile +14 -0
- data/app/assets/javascripts/joosy.js.coffee +7 -0
- data/app/assets/javascripts/joosy/core/application.js.coffee +28 -0
- data/app/assets/javascripts/joosy/core/form.js.coffee +87 -0
- data/app/assets/javascripts/joosy/core/helpers.js.coffee +6 -0
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +65 -0
- data/app/assets/javascripts/joosy/core/layout.js.coffee +47 -0
- data/app/assets/javascripts/joosy/core/modules/container.js.coffee +59 -0
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +35 -0
- data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +15 -0
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +43 -0
- data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +116 -0
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +25 -0
- data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +58 -0
- data/app/assets/javascripts/joosy/core/page.js.coffee +156 -0
- data/app/assets/javascripts/joosy/core/preloader.js.coffee +5 -0
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +61 -0
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +76 -0
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +48 -0
- data/app/assets/javascripts/joosy/core/router.js.coffee +89 -0
- data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +20 -0
- data/app/assets/javascripts/joosy/core/widget.js.coffee +41 -0
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +94 -0
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +55 -0
- data/app/helpers/joosy/sprockets_helper.rb +23 -0
- data/app/views/layouts/json_wrapper.json.erb +1 -0
- data/joosy.gemspec +25 -0
- data/lib/joosy.rb +9 -0
- data/lib/joosy/forms.rb +47 -0
- data/lib/joosy/rails/engine.rb +17 -0
- data/lib/joosy/rails/version.rb +5 -0
- data/lib/rails/generators/joosy/application_generator.rb +41 -0
- data/lib/rails/generators/joosy/joosy_base.rb +30 -0
- data/lib/rails/generators/joosy/layout_generator.rb +32 -0
- data/lib/rails/generators/joosy/page_generator.rb +44 -0
- data/lib/rails/generators/joosy/preloader_generator.rb +32 -0
- data/lib/rails/generators/joosy/resource_generator.rb +29 -0
- data/lib/rails/generators/joosy/templates/app.js.coffee +10 -0
- data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +4 -0
- data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +2 -0
- data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +2 -0
- data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -0
- data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +5 -0
- data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +22 -0
- data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +2 -0
- data/lib/rails/generators/joosy/templates/app/routes.js.coffee +8 -0
- data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +2 -0
- data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +7 -0
- data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -0
- data/lib/rails/generators/joosy/templates/app_controller.rb +9 -0
- data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +13 -0
- data/lib/rails/generators/joosy/templates/preload.html.erb +26 -0
- data/lib/rails/generators/joosy/templates/preload.html.haml +19 -0
- data/lib/rails/generators/joosy/widget_generator.rb +32 -0
- data/spec/javascripts/helpers/spec_helper.js.coffee +44 -0
- data/spec/javascripts/joosy/core/application_spec.js.coffee +40 -0
- data/spec/javascripts/joosy/core/form_spec.js.coffee +141 -0
- data/spec/javascripts/joosy/core/joosy_spec.js.coffee +72 -0
- data/spec/javascripts/joosy/core/layout_spec.js.coffee +50 -0
- data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +92 -0
- data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +53 -0
- data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +71 -0
- data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +15 -0
- data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +47 -0
- data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +149 -0
- data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +25 -0
- data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +75 -0
- data/spec/javascripts/joosy/core/page_spec.js.coffee +175 -0
- data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +35 -0
- data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +65 -0
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +108 -0
- data/spec/javascripts/joosy/core/router_spec.js.coffee +123 -0
- data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +25 -0
- data/spec/javascripts/joosy/core/widget_spec.js.coffee +51 -0
- data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +36 -0
- data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +16 -0
- 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 +1 -0
- data/spec/javascripts/support/jasmine.yml +74 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/javascripts/support/sinon-1.3.1.js +3469 -0
- data/spec/javascripts/support/sinon-ie-1.3.1.js +82 -0
- data/vendor/assets/javascripts/base64.js +135 -0
- data/vendor/assets/javascripts/inflection.js +656 -0
- data/vendor/assets/javascripts/jquery.form.js +980 -0
- data/vendor/assets/javascripts/jquery.hashchange.js +390 -0
- data/vendor/assets/javascripts/metamorph.js +409 -0
- data/vendor/assets/javascripts/sugar.js +6040 -0
- metadata +232 -0
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in joosy.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'jasmine', :git => 'git://github.com/pivotal/jasmine-gem.git'
|
7
|
+
gem 'guard-sprockets', :git => 'git://github.com/roundlake/guard-sprockets.git'
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
if RUBY_PLATFORM =~ /linux/
|
11
|
+
gem 'rb-inotify'
|
12
|
+
gem 'libnotify'
|
13
|
+
end
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/pivotal/jasmine-gem.git
|
3
|
+
revision: 953d17dff4b4adba79b2a808b55cf33f4ff93af7
|
4
|
+
specs:
|
5
|
+
jasmine (1.2.0.rc2)
|
6
|
+
jasmine-core (>= 1.2.0.rc1)
|
7
|
+
rack (>= 1.1)
|
8
|
+
rspec (>= 1.3.1)
|
9
|
+
selenium-webdriver (>= 0.1.3)
|
10
|
+
|
11
|
+
GIT
|
12
|
+
remote: git://github.com/roundlake/guard-sprockets.git
|
13
|
+
revision: ba7574363f41b2c2c950f095b3b5cfc08762a6cc
|
14
|
+
specs:
|
15
|
+
guard-sprockets (0.2.0)
|
16
|
+
guard (>= 0.2.2)
|
17
|
+
sprockets (~> 2)
|
18
|
+
|
19
|
+
PATH
|
20
|
+
remote: .
|
21
|
+
specs:
|
22
|
+
joosy (0.1.0.alpha)
|
23
|
+
coffee-rails
|
24
|
+
haml_coffee_assets
|
25
|
+
jquery-rails
|
26
|
+
rails (>= 3.1.0)
|
27
|
+
|
28
|
+
GEM
|
29
|
+
remote: http://rubygems.org/
|
30
|
+
specs:
|
31
|
+
actionmailer (3.2.1)
|
32
|
+
actionpack (= 3.2.1)
|
33
|
+
mail (~> 2.4.0)
|
34
|
+
actionpack (3.2.1)
|
35
|
+
activemodel (= 3.2.1)
|
36
|
+
activesupport (= 3.2.1)
|
37
|
+
builder (~> 3.0.0)
|
38
|
+
erubis (~> 2.7.0)
|
39
|
+
journey (~> 1.0.1)
|
40
|
+
rack (~> 1.4.0)
|
41
|
+
rack-cache (~> 1.1)
|
42
|
+
rack-test (~> 0.6.1)
|
43
|
+
sprockets (~> 2.1.2)
|
44
|
+
activemodel (3.2.1)
|
45
|
+
activesupport (= 3.2.1)
|
46
|
+
builder (~> 3.0.0)
|
47
|
+
activerecord (3.2.1)
|
48
|
+
activemodel (= 3.2.1)
|
49
|
+
activesupport (= 3.2.1)
|
50
|
+
arel (~> 3.0.0)
|
51
|
+
tzinfo (~> 0.3.29)
|
52
|
+
activeresource (3.2.1)
|
53
|
+
activemodel (= 3.2.1)
|
54
|
+
activesupport (= 3.2.1)
|
55
|
+
activesupport (3.2.1)
|
56
|
+
i18n (~> 0.6)
|
57
|
+
multi_json (~> 1.0)
|
58
|
+
arel (3.0.0)
|
59
|
+
builder (3.0.0)
|
60
|
+
childprocess (0.3.0)
|
61
|
+
ffi (~> 1.0.6)
|
62
|
+
coffee-rails (3.2.2)
|
63
|
+
coffee-script (>= 2.2.0)
|
64
|
+
railties (~> 3.2.0)
|
65
|
+
coffee-script (2.2.0)
|
66
|
+
coffee-script-source
|
67
|
+
execjs
|
68
|
+
coffee-script-source (1.2.0)
|
69
|
+
diff-lcs (1.1.3)
|
70
|
+
erubis (2.7.0)
|
71
|
+
execjs (1.3.0)
|
72
|
+
multi_json (~> 1.0)
|
73
|
+
ffi (1.0.11)
|
74
|
+
ffi (1.0.11-java)
|
75
|
+
guard (1.0.0)
|
76
|
+
ffi (>= 0.5.0)
|
77
|
+
thor (~> 0.14.6)
|
78
|
+
guard-coffeescript (0.5.4)
|
79
|
+
coffee-script (>= 2.2.0)
|
80
|
+
guard (>= 0.8.3)
|
81
|
+
haml_coffee_assets (0.7.1)
|
82
|
+
execjs (>= 1.2.9)
|
83
|
+
sprockets (>= 2.0.3)
|
84
|
+
tilt (>= 1.3.3)
|
85
|
+
hike (1.2.1)
|
86
|
+
i18n (0.6.0)
|
87
|
+
jasmine-core (1.2.0.rc1)
|
88
|
+
journey (1.0.1)
|
89
|
+
jquery-rails (2.0.0)
|
90
|
+
railties (>= 3.2.0.beta, < 5.0)
|
91
|
+
thor (~> 0.14)
|
92
|
+
json (1.6.5)
|
93
|
+
mail (2.4.1)
|
94
|
+
i18n (>= 0.4.0)
|
95
|
+
mime-types (~> 1.16)
|
96
|
+
treetop (~> 1.4.8)
|
97
|
+
mime-types (1.17.2)
|
98
|
+
multi_json (1.0.4)
|
99
|
+
polyglot (0.3.3)
|
100
|
+
rack (1.4.1)
|
101
|
+
rack-cache (1.1)
|
102
|
+
rack (>= 0.4)
|
103
|
+
rack-ssl (1.3.2)
|
104
|
+
rack
|
105
|
+
rack-test (0.6.1)
|
106
|
+
rack (>= 1.0)
|
107
|
+
rails (3.2.1)
|
108
|
+
actionmailer (= 3.2.1)
|
109
|
+
actionpack (= 3.2.1)
|
110
|
+
activerecord (= 3.2.1)
|
111
|
+
activeresource (= 3.2.1)
|
112
|
+
activesupport (= 3.2.1)
|
113
|
+
bundler (~> 1.0)
|
114
|
+
railties (= 3.2.1)
|
115
|
+
railties (3.2.1)
|
116
|
+
actionpack (= 3.2.1)
|
117
|
+
activesupport (= 3.2.1)
|
118
|
+
rack-ssl (~> 1.3.2)
|
119
|
+
rake (>= 0.8.7)
|
120
|
+
rdoc (~> 3.4)
|
121
|
+
thor (~> 0.14.6)
|
122
|
+
rake (0.9.2.2)
|
123
|
+
rdoc (3.12)
|
124
|
+
json (~> 1.4)
|
125
|
+
rspec (2.8.0)
|
126
|
+
rspec-core (~> 2.8.0)
|
127
|
+
rspec-expectations (~> 2.8.0)
|
128
|
+
rspec-mocks (~> 2.8.0)
|
129
|
+
rspec-core (2.8.0)
|
130
|
+
rspec-expectations (2.8.0)
|
131
|
+
diff-lcs (~> 1.1.2)
|
132
|
+
rspec-mocks (2.8.0)
|
133
|
+
rubyzip (0.9.5)
|
134
|
+
selenium-webdriver (2.17.0)
|
135
|
+
childprocess (>= 0.2.5)
|
136
|
+
ffi (~> 1.0.9)
|
137
|
+
multi_json (~> 1.0.4)
|
138
|
+
rubyzip
|
139
|
+
sprockets (2.1.2)
|
140
|
+
hike (~> 1.2)
|
141
|
+
rack (~> 1.0)
|
142
|
+
tilt (~> 1.1, != 1.3.0)
|
143
|
+
thor (0.14.6)
|
144
|
+
tilt (1.3.3)
|
145
|
+
treetop (1.4.10)
|
146
|
+
polyglot
|
147
|
+
polyglot (>= 0.3.1)
|
148
|
+
tzinfo (0.3.31)
|
149
|
+
|
150
|
+
PLATFORMS
|
151
|
+
java
|
152
|
+
ruby
|
153
|
+
|
154
|
+
DEPENDENCIES
|
155
|
+
guard
|
156
|
+
guard-coffeescript
|
157
|
+
guard-sprockets!
|
158
|
+
jasmine!
|
159
|
+
joosy!
|
data/Guardfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
guard 'coffeescript', :output => 'tmp/spec/javascripts' do
|
2
|
+
watch(%r{^spec/javascripts/(.+)[sS]pec\.js\.coffee$})
|
3
|
+
end
|
4
|
+
|
5
|
+
guard 'coffeescript', :output => 'tmp/spec/javascripts/helpers' do
|
6
|
+
watch(%r{^spec/javascripts/helpers/(.+)\.js\.coffee$})
|
7
|
+
end
|
8
|
+
|
9
|
+
jquery_path = File.join(Gem.loaded_specs['jquery-rails'].full_gem_path, 'vendor/assets/javascripts')
|
10
|
+
|
11
|
+
guard 'sprockets', :destination => 'tmp/javascripts',
|
12
|
+
:asset_paths => ['app/assets/javascripts', 'vendor/assets/javascripts', jquery_path],
|
13
|
+
:root_file => 'app/assets/javascripts/joosy.js.coffee' do
|
14
|
+
watch %r{^app/assets/javascripts/joosy/core.+\.js}
|
15
|
+
watch 'app/assets/javascripts/joosy.js.coffee'
|
16
|
+
end
|
17
|
+
|
18
|
+
guard 'sprockets', :destination => 'tmp/javascripts',
|
19
|
+
:asset_paths => ['app/assets/javascripts', 'vendor/assets/javascripts', jquery_path],
|
20
|
+
:root_file => 'app/assets/javascripts/joosy/preloaders/caching.js.coffee' do
|
21
|
+
watch 'app/assets/javascripts/joosy/preloaders/caching.js.coffee'
|
22
|
+
end
|
23
|
+
|
24
|
+
guard 'sprockets', :destination => 'tmp/javascripts',
|
25
|
+
:asset_paths => ['app/assets/javascripts', 'vendor/assets/javascripts', jquery_path],
|
26
|
+
:root_file => 'app/assets/javascripts/joosy/preloaders/inline.js.coffee' do
|
27
|
+
watch 'app/assets/javascripts/joosy/preloaders/inline.js.coffee'
|
28
|
+
end
|
29
|
+
|
30
|
+
puts 'HI! Hit <Enter> to generate all stuff.'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (C) 2011 by Boris Staal <boris@roundlake.ru>,
|
2
|
+
Peter Zotov <p.zotov@roundlake.ru>.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jasmine'
|
5
|
+
load 'jasmine/tasks/jasmine.rake'
|
6
|
+
rescue LoadError
|
7
|
+
task :jasmine do
|
8
|
+
abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
task :guard do
|
13
|
+
`bundle exec guard`
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#= require joosy/core/joosy
|
2
|
+
|
3
|
+
Joosy.Application =
|
4
|
+
Pages: {}
|
5
|
+
Layouts: {}
|
6
|
+
Controls: {}
|
7
|
+
|
8
|
+
selector: false
|
9
|
+
|
10
|
+
initialize: (@name, @selector, options={}) ->
|
11
|
+
@[key] = value for key, value of options
|
12
|
+
@templater = new Joosy.Templaters.RailsJST(@name)
|
13
|
+
|
14
|
+
Joosy.Router.setupRoutes()
|
15
|
+
|
16
|
+
@sandboxSelector = Joosy.uuid()
|
17
|
+
@content().after("<div id='#{@sandboxSelector}' style='display:none'></div>")
|
18
|
+
@sandboxSelector = '#' + @sandboxSelector
|
19
|
+
|
20
|
+
content: ->
|
21
|
+
$(@selector)
|
22
|
+
|
23
|
+
sandbox: ->
|
24
|
+
$(@sandboxSelector)
|
25
|
+
|
26
|
+
setCurrentPage: (page, params) ->
|
27
|
+
#if @page not instanceof page
|
28
|
+
@page = new page(params, @page)
|
@@ -0,0 +1,87 @@
|
|
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
|
+
|
7
|
+
class Joosy.Form extends Joosy.Module
|
8
|
+
@include Joosy.Modules.Log
|
9
|
+
@include Joosy.Modules.Events
|
10
|
+
@include Joosy.Modules.Container
|
11
|
+
|
12
|
+
invalidationClass: 'field_with_errors'
|
13
|
+
substitutions: {}
|
14
|
+
|
15
|
+
elements:
|
16
|
+
'fields': 'input,select,textarea'
|
17
|
+
|
18
|
+
constructor: (form, opts={}) ->
|
19
|
+
if Object.isFunction opts
|
20
|
+
@success = opts
|
21
|
+
else
|
22
|
+
Object.extended(opts).each (key, value) =>
|
23
|
+
@[key] = value
|
24
|
+
|
25
|
+
@container = $(form)
|
26
|
+
@refreshElements()
|
27
|
+
@__delegateEvents()
|
28
|
+
|
29
|
+
if (method = @container.get(0).getAttribute('method')?.toLowerCase()) && !['get', 'post'].has(method)
|
30
|
+
@__markMethod method
|
31
|
+
@container.attr 'method', 'POST'
|
32
|
+
|
33
|
+
@container.ajaxForm
|
34
|
+
dataType: 'json'
|
35
|
+
beforeSend: => @__before(arguments...)
|
36
|
+
success: => @__success(arguments...)
|
37
|
+
error: => @__error(arguments...)
|
38
|
+
xhr: =>
|
39
|
+
xhr = $.ajaxSettings.xhr()
|
40
|
+
if xhr.upload? && @progress
|
41
|
+
xhr.upload.onprogress = (event) =>
|
42
|
+
@progress (event.position/event.total*100).round(2) if event.lengthComputable
|
43
|
+
xhr
|
44
|
+
|
45
|
+
fill: (resource, decorator) ->
|
46
|
+
e = if decorator? then decorator(resource.e) else resource.e
|
47
|
+
Object.each e, (key, val) =>
|
48
|
+
key = resource.constructor.entityName()+"[#{key}]"
|
49
|
+
@fields.filter("[name='#{key.underscore()}']:not(:file),[name='#{key.camelize(false)}']:not(:file)").val(val)
|
50
|
+
|
51
|
+
@container.attr 'action', resource.constructor.__buildSource(extension: resource.id)
|
52
|
+
@__markMethod() if resource.id
|
53
|
+
@container.attr 'method', 'POST'
|
54
|
+
|
55
|
+
__success: (response, status, xhr) ->
|
56
|
+
if xhr
|
57
|
+
@success(response)
|
58
|
+
else if response.status == 200
|
59
|
+
@success(response.json)
|
60
|
+
else
|
61
|
+
@__error(response.json)
|
62
|
+
|
63
|
+
__before: (xhr, settings) ->
|
64
|
+
if !@before? || @before(arguments...) is true
|
65
|
+
@fields.removeClass(@invalidationClass)
|
66
|
+
|
67
|
+
__error: (data) ->
|
68
|
+
errors = if data.responseText
|
69
|
+
try
|
70
|
+
Object.extended(jQuery.parseJSON(data.responseText))
|
71
|
+
catch error
|
72
|
+
Object.extended()
|
73
|
+
else
|
74
|
+
Object.extended(data)
|
75
|
+
|
76
|
+
if !@error? || @error(errors) is true
|
77
|
+
errors.each (field, notifications) =>
|
78
|
+
field = @substitutions[field] if @substitutions[field]?
|
79
|
+
input = @fields.filter("[name='#{field}']").addClass(@invalidationClass)
|
80
|
+
@notification?(input, notifications)
|
81
|
+
|
82
|
+
__markMethod: (method='PUT') ->
|
83
|
+
method = $ '<input/>',
|
84
|
+
type: 'hidden'
|
85
|
+
name: '_method'
|
86
|
+
value: method
|
87
|
+
@container.append(method)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
@Joosy = Object.extended(if @Joosy? then @Joosy else {})
|
2
|
+
|
3
|
+
@Joosy.merge
|
4
|
+
debug: false
|
5
|
+
Modules: {}
|
6
|
+
Resource: {}
|
7
|
+
Templaters: {}
|
8
|
+
|
9
|
+
Joosy.namespace = (name, generator=false) ->
|
10
|
+
name = name.split('.')
|
11
|
+
space = window
|
12
|
+
space = space[part] ?= {} for part in name
|
13
|
+
|
14
|
+
generator = generator.apply(space) if generator
|
15
|
+
for key, klass of space
|
16
|
+
if space.hasOwnProperty(key) &&
|
17
|
+
Joosy.Module.hasAncestor(klass, Joosy.Module)
|
18
|
+
klass.__namespace__ = name
|
19
|
+
|
20
|
+
Joosy.helpers = (name, generator) ->
|
21
|
+
Joosy.namespace("Joosy.Helpers.#{name}", generator)
|
22
|
+
|
23
|
+
Joosy.test = ->
|
24
|
+
text = "Hi :). I'm Joosy. And everything is just fine!"
|
25
|
+
|
26
|
+
if console
|
27
|
+
console.log text
|
28
|
+
else
|
29
|
+
alert text
|
30
|
+
|
31
|
+
Joosy.uuid = ->
|
32
|
+
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
|
33
|
+
r = Math.random() * 16 | 0
|
34
|
+
v = if c is 'x' then r else r & 3 | 8
|
35
|
+
v.toString 16
|
36
|
+
.toUpperCase()
|
37
|
+
|
38
|
+
Joosy.preloadImages = (images, callback) ->
|
39
|
+
images = [images] if !Object.isArray(images)
|
40
|
+
callback() if images.length == 0
|
41
|
+
|
42
|
+
ticks = images.length
|
43
|
+
result = []
|
44
|
+
checker = ->
|
45
|
+
callback?() if (ticks -= 1) == 0
|
46
|
+
|
47
|
+
for p in images
|
48
|
+
result.push $('<img/>').load(checker).attr('src', p)
|
49
|
+
|
50
|
+
result
|
51
|
+
|
52
|
+
Joosy.buildUrl = (url, params) ->
|
53
|
+
paramsString = []
|
54
|
+
|
55
|
+
Object.each params, (key, value) ->
|
56
|
+
paramsString.push("#{key}=#{value}")
|
57
|
+
|
58
|
+
hash = url.match(/(\#.*)?$/)[0]
|
59
|
+
url = url.replace(/\#.*$/, '')
|
60
|
+
url = url + "?" if !paramsString.isEmpty() && !url.has(/\?/)
|
61
|
+
|
62
|
+
paramsString = paramsString.join('&')
|
63
|
+
paramsString = '&' + paramsString if paramsString != '' && url.last() != '?'
|
64
|
+
|
65
|
+
url + paramsString + hash
|