manage 1.3.20 → 1.3.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -20
- data/README.rdoc +96 -96
- data/Rakefile +31 -31
- data/app/assets/javascripts/manage/application.js +0 -2
- data/app/assets/javascripts/manage/collection_actions.js.coffee +30 -30
- data/app/assets/javascripts/manage/handlers.js.coffee +46 -46
- data/app/assets/javascripts/manage/init.js.coffee +1 -4
- data/app/assets/javascripts/manage/table_checkboxes.js.coffee +11 -11
- data/app/assets/stylesheets/manage/application.css.scss +1 -2
- data/app/assets/stylesheets/manage/layout.css.scss +44 -44
- data/app/controllers/manage/application_controller.rb +13 -13
- data/app/controllers/manage/dashboards_controller.rb +4 -4
- data/app/controllers/manage/resource_controller.rb +125 -125
- data/app/controllers/manage/responder.rb +11 -11
- data/app/controllers/manage/sessions_controller.rb +11 -11
- data/app/helpers/manage/application_helper.rb +42 -42
- data/app/helpers/manage/form_helper.rb +21 -21
- data/app/helpers/manage/resource_helper.rb +77 -77
- data/app/models/admin_user.rb +4 -4
- data/app/views/layouts/manage/_main_menu.html.slim +52 -52
- data/app/views/layouts/manage/application.html.slim +39 -39
- data/app/views/layouts/manage/sign_in.html.slim +30 -30
- data/app/views/manage/resource/_form.html.slim +4 -4
- data/app/views/manage/resource/index.html.slim +18 -18
- data/app/views/manage/resource/index/_collection_actions.html.slim +2 -2
- data/app/views/manage/resource/index/_count.html.slim +6 -6
- data/app/views/manage/resource/index/_filters.html.slim +22 -22
- data/app/views/manage/resource/index/_table.html.slim +25 -25
- data/app/views/manage/resource/show.html.slim +10 -10
- data/app/views/manage/sessions/new.html.slim +10 -10
- data/config/initializers/devise.rb +247 -247
- data/config/initializers/session_store.rb +3 -3
- data/config/initializers/simple_form.rb +145 -145
- data/config/initializers/simple_form_foundation.rb +26 -26
- data/config/locales/devise.en.yml +59 -59
- data/config/locales/en.yml +20 -20
- data/config/routes.rb +10 -10
- data/db/migrate/20131204142720_create_admin_users.rb +24 -24
- data/lib/manage.rb +5 -5
- data/lib/manage/engine.rb +21 -21
- data/lib/manage/fields.rb +6 -6
- data/lib/manage/fields/reader.rb +57 -57
- data/lib/manage/fields/searcher.rb +51 -51
- data/lib/manage/version.rb +1 -1
- data/lib/tasks/manage_tasks.rake +15 -15
- data/lib/templates/erb/scaffold/_form.html.erb +13 -13
- data/spec/controllers/manage/resource_controller_spec.rb +29 -29
- data/spec/dummy/README.rdoc +28 -28
- data/spec/dummy/Rakefile +6 -6
- data/spec/dummy/app/assets/javascripts/application.js +13 -13
- data/spec/dummy/app/assets/stylesheets/application.css +13 -13
- data/spec/dummy/app/controllers/application_controller.rb +5 -5
- data/spec/dummy/app/controllers/manage/posts_controller.rb +4 -4
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/models/post.rb +3 -3
- data/spec/dummy/app/models/user.rb +5 -5
- data/spec/dummy/app/views/layouts/application.html.erb +14 -14
- data/spec/dummy/bin/bundle +3 -3
- data/spec/dummy/bin/rails +4 -4
- data/spec/dummy/bin/rake +4 -4
- data/spec/dummy/config.ru +4 -4
- data/spec/dummy/config/application.rb +24 -24
- data/spec/dummy/config/boot.rb +5 -5
- data/spec/dummy/config/database.yml +25 -25
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +29 -29
- data/spec/dummy/config/environments/production.rb +80 -80
- data/spec/dummy/config/environments/test.rb +36 -36
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
- data/spec/dummy/config/initializers/inflections.rb +16 -16
- data/spec/dummy/config/initializers/mime_types.rb +5 -5
- data/spec/dummy/config/initializers/secret_token.rb +12 -12
- data/spec/dummy/config/initializers/session_store.rb +3 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +23 -23
- data/spec/dummy/config/routes.rb +10 -10
- data/spec/dummy/db/migrate/20130716083410_init_migration.rb +21 -21
- data/spec/dummy/db/schema.rb +53 -53
- data/spec/dummy/public/404.html +58 -58
- data/spec/dummy/public/422.html +58 -58
- data/spec/dummy/public/500.html +57 -57
- data/spec/fields/reader_spec.rb +79 -79
- data/spec/spec_helper.rb +24 -24
- metadata +88 -110
- data/app/assets/javascripts/manage/tinymce/plugins/code/plugin.min.js +0 -1
- data/app/assets/javascripts/manage/tinymce/theme.min.js +0 -1
- data/app/assets/javascripts/manage/tinymce/tinymce.min.js +0 -9
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/content.inline.min.css +0 -1
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/content.min.css +0 -1
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/readme.md +0 -1
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce-small.eot +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce-small.svg +0 -175
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce-small.ttf +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce-small.woff +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce.eot +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce.svg +0 -153
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce.ttf +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/fonts/tinymce.woff +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/img/anchor.gif +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/img/loader.gif +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/img/object.gif +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/img/trans.gif +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/img/wline.gif +0 -0
- data/app/assets/stylesheets/manage/tinymce/skins/lightgray/skin.min.css +0 -1
- data/spec/dummy/log/test.log +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5652d11db7e96887d8a3762a8364c7470eb647be
|
4
|
+
data.tar.gz: 16753aaa3e98ccb07b40905b0fe3456b84ba266b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6c1c273d41c21e41848ec11917d65be0f85ba9cd8ca3f5a5a79145668232ad6b5886a84a829a2d3391558ad454100a621ab0b453682b6d7897deeb5c13a2bc1
|
7
|
+
data.tar.gz: 3387051f8227f686f6fba0a723979d8154939cfd05faee683fdb8d3543a67addaa5a40aa5b77611bd963a3111df9631f49f6316abfc702df92b74790fe758d5d
|
data/MIT-LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright 2013 YOURNAME
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,97 +1,97 @@
|
|
1
|
-
= Manage
|
2
|
-
|
3
|
-
Admin backend started from http://iain.nl/backends-in-rails-3-1
|
4
|
-
|
5
|
-
Based on inherit_resources, slim, kaminari
|
6
|
-
|
7
|
-
== Installing
|
8
|
-
|
9
|
-
Add the engine
|
10
|
-
|
11
|
-
to Gemfile
|
12
|
-
|
13
|
-
gem 'manage'
|
14
|
-
|
15
|
-
|
16
|
-
to routes.rb yourapp/config/routes.rb:
|
17
|
-
|
18
|
-
mount Manage::Engine, at: "/manage"
|
19
|
-
|
20
|
-
|
21
|
-
if you want to have custom design in your app for the manage engine add in application.rb:
|
22
|
-
|
23
|
-
config.assets.precompile += [
|
24
|
-
'manage/custom.css'
|
25
|
-
]
|
26
|
-
|
27
|
-
== Defining resource for administration
|
28
|
-
|
29
|
-
|
30
|
-
Add the resource to your app routes.rb yourapp/config/routes.rb:
|
31
|
-
|
32
|
-
Manage::Engine.routes.draw do
|
33
|
-
resources :cities
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
Create controller in your application yourapp/app/controllers/manage/cities_controller.rb
|
38
|
-
|
39
|
-
class Manage::CitiesController < Manage::ResourceController
|
40
|
-
@@per_page = 10 # optional
|
41
|
-
|
42
|
-
# optional
|
43
|
-
def collection_actions collection
|
44
|
-
[
|
45
|
-
view_context.button_to(t('manage.views.winners.export_as_bank_file'), [:export_as_bank_file, resource_class], method: :post, data: {handler: 'CollectionActions'}, class: 'button')
|
46
|
-
].join('').html_safe
|
47
|
-
end
|
48
|
-
|
49
|
-
# optional
|
50
|
-
def resource_actions resource
|
51
|
-
[
|
52
|
-
'',
|
53
|
-
view_context.link_to('Login as', login_as_user_path(resource.id)),
|
54
|
-
].join(' '.html_safe).html_safe
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
=== View overriding
|
61
|
-
You can overrede the views in
|
62
|
-
|
63
|
-
app/views/manage/countries
|
64
|
-
|
65
|
-
* _index.html.slim
|
66
|
-
* _form.html_slim
|
67
|
-
* edit.html.slim
|
68
|
-
* new.html.slim
|
69
|
-
* show.html.slim
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
== Authorization
|
75
|
-
In your app do
|
76
|
-
|
77
|
-
rails generate devise AdminUser
|
78
|
-
|
79
|
-
delete "devise_for :admin_users" from routes.rb
|
80
|
-
|
81
|
-
|
82
|
-
Create an admin user. The users benefit from the devise password validation/generation but doesn't use the devise controllers.
|
83
|
-
|
84
|
-
|
85
|
-
AdminUser.create(email: 'admin@example.com', password: '11223344', password_confirmation: '11223344')
|
86
|
-
|
87
|
-
|
88
|
-
= TODO
|
89
|
-
|
90
|
-
* Make it work with devise session controllers
|
91
|
-
* add filters
|
92
|
-
* add search
|
93
|
-
* make nice layout
|
94
|
-
|
95
|
-
== License
|
96
|
-
|
1
|
+
= Manage
|
2
|
+
|
3
|
+
Admin backend started from http://iain.nl/backends-in-rails-3-1
|
4
|
+
|
5
|
+
Based on inherit_resources, slim, kaminari
|
6
|
+
|
7
|
+
== Installing
|
8
|
+
|
9
|
+
Add the engine
|
10
|
+
|
11
|
+
to Gemfile
|
12
|
+
|
13
|
+
gem 'manage'
|
14
|
+
|
15
|
+
|
16
|
+
to routes.rb yourapp/config/routes.rb:
|
17
|
+
|
18
|
+
mount Manage::Engine, at: "/manage"
|
19
|
+
|
20
|
+
|
21
|
+
if you want to have custom design in your app for the manage engine add in application.rb:
|
22
|
+
|
23
|
+
config.assets.precompile += [
|
24
|
+
'manage/custom.css'
|
25
|
+
]
|
26
|
+
|
27
|
+
== Defining resource for administration
|
28
|
+
|
29
|
+
|
30
|
+
Add the resource to your app routes.rb yourapp/config/routes.rb:
|
31
|
+
|
32
|
+
Manage::Engine.routes.draw do
|
33
|
+
resources :cities
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
Create controller in your application yourapp/app/controllers/manage/cities_controller.rb
|
38
|
+
|
39
|
+
class Manage::CitiesController < Manage::ResourceController
|
40
|
+
@@per_page = 10 # optional
|
41
|
+
|
42
|
+
# optional
|
43
|
+
def collection_actions collection
|
44
|
+
[
|
45
|
+
view_context.button_to(t('manage.views.winners.export_as_bank_file'), [:export_as_bank_file, resource_class], method: :post, data: {handler: 'CollectionActions'}, class: 'button')
|
46
|
+
].join('').html_safe
|
47
|
+
end
|
48
|
+
|
49
|
+
# optional
|
50
|
+
def resource_actions resource
|
51
|
+
[
|
52
|
+
'',
|
53
|
+
view_context.link_to('Login as', login_as_user_path(resource.id)),
|
54
|
+
].join(' '.html_safe).html_safe
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
=== View overriding
|
61
|
+
You can overrede the views in
|
62
|
+
|
63
|
+
app/views/manage/countries
|
64
|
+
|
65
|
+
* _index.html.slim
|
66
|
+
* _form.html_slim
|
67
|
+
* edit.html.slim
|
68
|
+
* new.html.slim
|
69
|
+
* show.html.slim
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
== Authorization
|
75
|
+
In your app do
|
76
|
+
|
77
|
+
rails generate devise AdminUser
|
78
|
+
|
79
|
+
delete "devise_for :admin_users" from routes.rb
|
80
|
+
|
81
|
+
|
82
|
+
Create an admin user. The users benefit from the devise password validation/generation but doesn't use the devise controllers.
|
83
|
+
|
84
|
+
|
85
|
+
AdminUser.create(email: 'admin@example.com', password: '11223344', password_confirmation: '11223344')
|
86
|
+
|
87
|
+
|
88
|
+
= TODO
|
89
|
+
|
90
|
+
* Make it work with devise session controllers
|
91
|
+
* add filters
|
92
|
+
* add search
|
93
|
+
* make nice layout
|
94
|
+
|
95
|
+
== License
|
96
|
+
|
97
97
|
This project rocks and uses MIT license
|
data/Rakefile
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
begin
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'Manage'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
|
-
|
17
|
-
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
-
load 'rails/tasks/engine.rake'
|
19
|
-
|
20
|
-
|
21
|
-
Bundler::GemHelper.install_tasks
|
22
|
-
|
23
|
-
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
24
|
-
|
25
|
-
require 'rspec/core'
|
26
|
-
require 'rspec/core/rake_task'
|
27
|
-
|
28
|
-
desc "Run all specs in spec directory (excluding plugin specs)"
|
29
|
-
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
30
|
-
|
31
|
-
task default: :spec
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Manage'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
Bundler::GemHelper.install_tasks
|
22
|
+
|
23
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
24
|
+
|
25
|
+
require 'rspec/core'
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
|
28
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
29
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
30
|
+
|
31
|
+
task default: :spec
|
@@ -1,30 +1,30 @@
|
|
1
|
-
class CollectionActions
|
2
|
-
constructor: (el) ->
|
3
|
-
$el = $(el)
|
4
|
-
|
5
|
-
$form = $el.closest('form')
|
6
|
-
|
7
|
-
$el.on 'click', (e) ->
|
8
|
-
e.stopPropagation()
|
9
|
-
e.preventDefault()
|
10
|
-
|
11
|
-
checkedCheckboxes = $('.rs:checked')
|
12
|
-
unless checkedCheckboxes.length
|
13
|
-
alert 'Select Items'
|
14
|
-
return false
|
15
|
-
|
16
|
-
# clear all hidden fields with class .hidden_selected_ids
|
17
|
-
$form.find('input[type="hidden"]').remove()
|
18
|
-
|
19
|
-
checkedCheckboxes.each ->
|
20
|
-
# create a new hidden
|
21
|
-
hidden_input = $('<input>').attr({
|
22
|
-
type: 'hidden',
|
23
|
-
name: 'selected_ids[]',
|
24
|
-
value: $(@).val()
|
25
|
-
}).appendTo($form)
|
26
|
-
|
27
|
-
$form.submit()
|
28
|
-
|
29
|
-
|
30
|
-
Handlers.register 'CollectionActions', CollectionActions
|
1
|
+
class CollectionActions
|
2
|
+
constructor: (el) ->
|
3
|
+
$el = $(el)
|
4
|
+
|
5
|
+
$form = $el.closest('form')
|
6
|
+
|
7
|
+
$el.on 'click', (e) ->
|
8
|
+
e.stopPropagation()
|
9
|
+
e.preventDefault()
|
10
|
+
|
11
|
+
checkedCheckboxes = $('.rs:checked')
|
12
|
+
unless checkedCheckboxes.length
|
13
|
+
alert 'Select Items'
|
14
|
+
return false
|
15
|
+
|
16
|
+
# clear all hidden fields with class .hidden_selected_ids
|
17
|
+
$form.find('input[type="hidden"]').remove()
|
18
|
+
|
19
|
+
checkedCheckboxes.each ->
|
20
|
+
# create a new hidden
|
21
|
+
hidden_input = $('<input>').attr({
|
22
|
+
type: 'hidden',
|
23
|
+
name: 'selected_ids[]',
|
24
|
+
value: $(@).val()
|
25
|
+
}).appendTo($form)
|
26
|
+
|
27
|
+
$form.submit()
|
28
|
+
|
29
|
+
|
30
|
+
Handlers.register 'CollectionActions', CollectionActions
|
@@ -1,46 +1,46 @@
|
|
1
|
-
class @Handlers
|
2
|
-
@handlers = {}
|
3
|
-
|
4
|
-
@register: (handler, registeredClass) ->
|
5
|
-
throw "No constructor on " + handler unless registeredClass.constructor
|
6
|
-
@handlers[handler] = registeredClass
|
7
|
-
|
8
|
-
@instantiate: (handlers, element) ->
|
9
|
-
handlers = handlers.replace(/\s/g, '').split(',')
|
10
|
-
element.handlers = []
|
11
|
-
$.each handlers, (index, handler) =>
|
12
|
-
if @handlers[handler]
|
13
|
-
instance = new @handlers[handler](element)
|
14
|
-
element.handlers.push instance
|
15
|
-
else
|
16
|
-
throw "Unknown handler " + handler
|
17
|
-
|
18
|
-
@destroy: (instances) ->
|
19
|
-
$.each instances, (index, instance) ->
|
20
|
-
instance.destroy() if instance.destroy
|
21
|
-
|
22
|
-
@unregisterAll: ->
|
23
|
-
@handlers = {}
|
24
|
-
|
25
|
-
$(document).on 'handlers:pageChanged', ->
|
26
|
-
$('[data-handler]').each ->
|
27
|
-
Handlers.instantiate $(this).attr('data-handler'), this
|
28
|
-
|
29
|
-
$(document).on 'handlers:pageUpdated', (event, scope) ->
|
30
|
-
$(scope).find('[data-handler]').each ->
|
31
|
-
Handlers.instantiate $(this).attr('data-handler'), this
|
32
|
-
|
33
|
-
$(document).on 'handlers:pageUpdating', (event, scope) ->
|
34
|
-
$(scope).find('[data-handler]').each ->
|
35
|
-
Handlers.destroy @handlers if @handlers
|
36
|
-
delete @handlers if @handlers
|
37
|
-
|
38
|
-
if typeof(Turbolinks) != undefined
|
39
|
-
$(document).on 'page:fetch', ->
|
40
|
-
$(document).trigger 'handlers:pageUpdating', 'body'
|
41
|
-
|
42
|
-
$(document).on 'page:change', ->
|
43
|
-
$(document).trigger 'handlers:pageUpdated', 'body'
|
44
|
-
|
45
|
-
$ ->
|
46
|
-
$(document).trigger 'handlers:pageChanged'
|
1
|
+
class @Handlers
|
2
|
+
@handlers = {}
|
3
|
+
|
4
|
+
@register: (handler, registeredClass) ->
|
5
|
+
throw "No constructor on " + handler unless registeredClass.constructor
|
6
|
+
@handlers[handler] = registeredClass
|
7
|
+
|
8
|
+
@instantiate: (handlers, element) ->
|
9
|
+
handlers = handlers.replace(/\s/g, '').split(',')
|
10
|
+
element.handlers = []
|
11
|
+
$.each handlers, (index, handler) =>
|
12
|
+
if @handlers[handler]
|
13
|
+
instance = new @handlers[handler](element)
|
14
|
+
element.handlers.push instance
|
15
|
+
else
|
16
|
+
throw "Unknown handler " + handler
|
17
|
+
|
18
|
+
@destroy: (instances) ->
|
19
|
+
$.each instances, (index, instance) ->
|
20
|
+
instance.destroy() if instance.destroy
|
21
|
+
|
22
|
+
@unregisterAll: ->
|
23
|
+
@handlers = {}
|
24
|
+
|
25
|
+
$(document).on 'handlers:pageChanged', ->
|
26
|
+
$('[data-handler]').each ->
|
27
|
+
Handlers.instantiate $(this).attr('data-handler'), this
|
28
|
+
|
29
|
+
$(document).on 'handlers:pageUpdated', (event, scope) ->
|
30
|
+
$(scope).find('[data-handler]').each ->
|
31
|
+
Handlers.instantiate $(this).attr('data-handler'), this
|
32
|
+
|
33
|
+
$(document).on 'handlers:pageUpdating', (event, scope) ->
|
34
|
+
$(scope).find('[data-handler]').each ->
|
35
|
+
Handlers.destroy @handlers if @handlers
|
36
|
+
delete @handlers if @handlers
|
37
|
+
|
38
|
+
if typeof(Turbolinks) != undefined
|
39
|
+
$(document).on 'page:fetch', ->
|
40
|
+
$(document).trigger 'handlers:pageUpdating', 'body'
|
41
|
+
|
42
|
+
$(document).on 'page:change', ->
|
43
|
+
$(document).trigger 'handlers:pageUpdated', 'body'
|
44
|
+
|
45
|
+
$ ->
|
46
|
+
$(document).trigger 'handlers:pageChanged'
|