typus 3.0.6 → 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +15 -0
- data/Gemfile +9 -5
- data/Rakefile +34 -21
- data/app/controllers/admin/base_controller.rb +0 -4
- data/app/controllers/admin/resources_controller.rb +77 -213
- data/app/controllers/admin/session_controller.rb +1 -1
- data/app/helpers/admin/base_helper.rb +4 -4
- data/app/helpers/admin/dashboard_helper.rb +1 -3
- data/app/helpers/admin/display_helper.rb +49 -0
- data/app/helpers/admin/file_preview_helper.rb +10 -12
- data/app/helpers/admin/filters_helper.rb +1 -1
- data/app/helpers/admin/form_helper.rb +2 -13
- data/app/helpers/admin/list_helper.rb +14 -3
- data/app/helpers/admin/relationships_helper.rb +79 -62
- data/app/helpers/admin/resources_helper.rb +17 -16
- data/app/helpers/admin/search_helper.rb +1 -1
- data/app/helpers/admin/sidebar_helper.rb +1 -2
- data/app/helpers/admin/table_helper.rb +9 -4
- data/app/views/admin/helpers/_file_preview.html.erb +1 -1
- data/app/views/admin/helpers/base/_apps.html.erb +23 -0
- data/app/views/admin/helpers/{_flash_message.html.erb → base/_flash_message.html.erb} +0 -0
- data/app/views/admin/helpers/{_header.html.erb → base/_header.html.erb} +0 -0
- data/app/views/admin/helpers/{_login_info.html.erb → base/_login_info.html.erb} +0 -0
- data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +1 -1
- data/app/views/admin/resources/show.html.erb +4 -27
- data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +11 -0
- data/app/views/admin/templates/_has_n.html.erb +1 -1
- data/app/views/admin/templates/_has_one.html.erb +3 -3
- data/app/views/admin/templates/_relate_form.html.erb +1 -1
- data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +24 -0
- data/app/views/layouts/admin/base.html.erb +15 -9
- data/app/views/layouts/admin/headless.html.erb +44 -0
- data/app/views/layouts/admin/session.html.erb +3 -2
- data/doc/hudson_setup.md +19 -0
- data/lib/generators/typus/assets_generator.rb +0 -4
- data/lib/generators/typus/config_generator.rb +107 -0
- data/lib/generators/typus/controller_generator.rb +0 -4
- data/lib/generators/typus/initializers_generator.rb +22 -0
- data/lib/generators/typus/migration_generator.rb +0 -4
- data/lib/generators/typus/typus_generator.rb +8 -101
- data/lib/generators/typus/views_generator.rb +0 -4
- data/lib/support/active_record.rb +8 -2
- data/lib/support/fake_user.rb +2 -0
- data/lib/support/hash.rb +1 -1
- data/lib/support/string.rb +3 -3
- data/lib/tasks/typus.rake +1 -1
- data/lib/typus.rb +15 -6
- data/lib/typus/controller/actions.rb +69 -0
- data/lib/typus/controller/associations.rb +82 -0
- data/lib/typus/controller/autocomplete.rb +16 -0
- data/lib/typus/controller/filters.rb +24 -0
- data/lib/typus/controller/format.rb +70 -0
- data/lib/typus/orm/active_record.rb +9 -240
- data/lib/typus/orm/active_record/class_methods.rb +227 -0
- data/lib/typus/orm/active_record/instance_methods.rb +13 -0
- data/lib/typus/orm/active_record/search.rb +17 -5
- data/lib/typus/orm/active_record/user.rb +157 -0
- data/lib/typus/regex.rb +11 -0
- data/lib/typus/version.rb +1 -1
- data/test/app/controllers/admin/account_controller_test.rb +104 -0
- data/test/app/controllers/admin/assets_controller_test.rb +153 -0
- data/test/app/controllers/admin/base_controller_test.rb +41 -0
- data/test/app/controllers/admin/birds_controller_test.rb +42 -0
- data/test/app/controllers/admin/cases_controller_test.rb +21 -0
- data/test/app/controllers/admin/categories_controller_test.rb +141 -0
- data/test/app/controllers/admin/comments_controller_test.rb +79 -0
- data/test/app/controllers/admin/dashboard_controller_test.rb +162 -0
- data/test/app/controllers/admin/image_holders_controller_test.rb +75 -0
- data/test/app/controllers/admin/invoices_controller_test.rb +78 -0
- data/test/app/controllers/admin/orders_controller_test.rb +18 -0
- data/test/app/controllers/admin/pages_controller_test.rb +37 -0
- data/test/app/controllers/admin/posts_controller_test.rb +745 -0
- data/test/app/controllers/admin/projects_controller_test.rb +52 -0
- data/test/app/controllers/admin/session_controller_test.rb +92 -0
- data/test/app/controllers/admin/status_controller_test.rb +54 -0
- data/test/app/controllers/admin/typus_users_controller_test.rb +160 -0
- data/test/app/controllers/admin/users_controller_test.rb +106 -0
- data/test/app/helpers/admin/base_helper_test.rb +83 -0
- data/test/app/helpers/admin/dashboard_helper_test.rb +32 -0
- data/test/app/helpers/admin/file_preview_helper_test.rb +82 -0
- data/test/app/helpers/admin/filters_helper_test.rb +161 -0
- data/test/app/helpers/admin/form_helper_test.rb +126 -0
- data/test/app/helpers/admin/list_helper_test.rb +59 -0
- data/test/app/helpers/admin/relationships_helper_test.rb +19 -0
- data/test/app/helpers/admin/resources_helper_test.rb +46 -0
- data/test/app/helpers/admin/search_helper_test.rb +60 -0
- data/test/app/helpers/admin/sidebar_helper_test.rb +34 -0
- data/test/app/helpers/admin/table_helper_test.rb +215 -0
- data/test/app/mailers/admin/mailer_test.rb +32 -0
- data/test/app/models/typus_user_roles_test.rb +124 -0
- data/test/app/models/typus_user_test.rb +194 -0
- data/test/config/routes_test.rb +29 -0
- data/test/factories.rb +111 -0
- data/test/fixtures/config/broken/application.yml +68 -0
- data/test/fixtures/config/broken/application_roles.yml +20 -0
- data/test/fixtures/config/broken/empty.yml +0 -0
- data/test/fixtures/config/broken/empty_roles.yml +0 -0
- data/test/fixtures/config/broken/undefined.yml +3 -0
- data/test/fixtures/config/broken/undefined_roles.yml +6 -0
- data/test/fixtures/config/default/typus.yml +13 -0
- data/test/fixtures/config/default/typus_roles.yml +2 -0
- data/test/fixtures/config/empty/empty_01.yml +0 -0
- data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
- data/test/fixtures/config/empty/empty_02.yml +0 -0
- data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
- data/test/fixtures/config/locales/es.yml +10 -0
- data/test/fixtures/config/namespaced/application.yml +5 -0
- data/test/fixtures/config/namespaced/application_roles.yml +2 -0
- data/test/fixtures/config/ordered/001_roles.yml +2 -0
- data/test/fixtures/config/ordered/002_roles.yml +2 -0
- data/test/fixtures/config/unordered/app_one_roles.yml +2 -0
- data/test/fixtures/config/unordered/app_two_roles.yml +2 -0
- data/test/fixtures/rails_app/.gitignore +4 -0
- data/test/fixtures/rails_app/Capfile +6 -0
- data/test/fixtures/rails_app/README +256 -0
- data/test/fixtures/rails_app/Rakefile +7 -0
- data/test/fixtures/rails_app/app/controllers/admin/animals_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/articles_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +51 -0
- data/test/fixtures/rails_app/app/controllers/admin/birds_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/cases_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/dogs_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/entries_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/image_holders_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/invoices_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/orders_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +7 -0
- data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/project_collaborators_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/projects_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/users_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/views_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/fixtures/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/fixtures/rails_app/app/helpers/form_helper.rb +3 -0
- data/test/fixtures/rails_app/app/models/animal.rb +21 -0
- data/test/fixtures/rails_app/app/models/article.rb +10 -0
- data/test/fixtures/rails_app/app/models/asset.rb +39 -0
- data/test/fixtures/rails_app/app/models/bird.rb +2 -0
- data/test/fixtures/rails_app/app/models/case.rb +2 -0
- data/test/fixtures/rails_app/app/models/category.rb +31 -0
- data/test/fixtures/rails_app/app/models/comment.rb +17 -0
- data/test/fixtures/rails_app/app/models/delayed/task.rb +5 -0
- data/test/fixtures/rails_app/app/models/dog.rb +2 -0
- data/test/fixtures/rails_app/app/models/entry.rb +23 -0
- data/test/fixtures/rails_app/app/models/image_holder.rb +21 -0
- data/test/fixtures/rails_app/app/models/invoice.rb +10 -0
- data/test/fixtures/rails_app/app/models/order.rb +9 -0
- data/test/fixtures/rails_app/app/models/page.rb +24 -0
- data/test/fixtures/rails_app/app/models/post.rb +32 -0
- data/test/fixtures/rails_app/app/models/project.rb +17 -0
- data/test/fixtures/rails_app/app/models/project_collaborator.rb +16 -0
- data/test/fixtures/rails_app/app/models/typus_user.rb +22 -0
- data/test/fixtures/rails_app/app/models/user.rb +10 -0
- data/test/fixtures/rails_app/app/models/view.rb +17 -0
- data/test/fixtures/rails_app/app/views/admin/assets/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/cases/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/categories/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +11 -0
- data/test/fixtures/rails_app/app/views/admin/entries/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/pages/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +5 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +9 -0
- data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/watch_dog/index.html.erb +9 -0
- data/test/fixtures/rails_app/app/views/layouts/admin/headless.html.erb +38 -0
- data/test/fixtures/rails_app/config.ru +4 -0
- data/test/fixtures/rails_app/config/application.rb +44 -0
- data/test/fixtures/rails_app/config/boot.rb +13 -0
- data/test/fixtures/rails_app/config/database.yml +34 -0
- data/test/fixtures/rails_app/config/deploy.rb +32 -0
- data/test/fixtures/rails_app/config/environment.rb +5 -0
- data/test/fixtures/rails_app/config/environments/development.rb +32 -0
- data/test/fixtures/rails_app/config/environments/production.rb +54 -0
- data/test/fixtures/rails_app/config/environments/test.rb +40 -0
- data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/dragonfly.rb +1 -0
- data/test/fixtures/rails_app/config/initializers/inflections.rb +12 -0
- data/test/fixtures/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/fixtures/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/session_store.rb +8 -0
- data/test/fixtures/rails_app/config/initializers/typus.rb +5 -0
- data/test/fixtures/rails_app/config/initializers/typus_resources.rb +27 -0
- data/test/fixtures/rails_app/config/locales/en.yml +5 -0
- data/test/fixtures/rails_app/config/routes.rb +61 -0
- data/test/fixtures/rails_app/config/typus/README +68 -0
- data/test/fixtures/rails_app/config/typus/crud_basic.yml +10 -0
- data/test/fixtures/rails_app/config/typus/crud_basic_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/crud_extended.yml +64 -0
- data/test/fixtures/rails_app/config/typus/crud_extended_roles.yml +18 -0
- data/test/fixtures/rails_app/config/typus/has_many.yml +0 -0
- data/test/fixtures/rails_app/config/typus/has_many_roles.yml +0 -0
- data/test/fixtures/rails_app/config/typus/has_many_through.yml +23 -0
- data/test/fixtures/rails_app/config/typus/has_many_through_roles.yml +4 -0
- data/test/fixtures/rails_app/config/typus/has_one.yml +12 -0
- data/test/fixtures/rails_app/config/typus/has_one_roles.yml +3 -0
- data/test/fixtures/rails_app/config/typus/polymorphic.yml +17 -0
- data/test/fixtures/rails_app/config/typus/polymorphic_roles.yml +5 -0
- data/test/fixtures/rails_app/config/typus/resource_roles.yml +7 -0
- data/test/fixtures/rails_app/config/typus/sti.yml +5 -0
- data/test/fixtures/rails_app/config/typus/sti_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/typus.yml +13 -0
- data/test/fixtures/rails_app/config/typus/typus_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/unknown.yml +3 -0
- data/test/fixtures/rails_app/config/typus/unknown_roles.yml +5 -0
- data/test/fixtures/rails_app/db/.gitkeep +0 -0
- data/test/fixtures/rails_app/db/schema.rb +174 -0
- data/test/fixtures/rails_app/db/seeds.rb +54 -0
- data/test/fixtures/rails_app/db/seeds/assets/000.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/001.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/002.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/003.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/004.jpg +0 -0
- data/test/fixtures/rails_app/public/404.html +26 -0
- data/test/fixtures/rails_app/public/422.html +26 -0
- data/test/fixtures/rails_app/public/500.html +26 -0
- data/test/fixtures/rails_app/public/favicon.ico +0 -0
- data/test/fixtures/rails_app/public/images/rails.png +0 -0
- data/test/fixtures/rails_app/public/javascripts/application.js +2 -0
- data/test/fixtures/rails_app/public/javascripts/controls.js +965 -0
- data/test/fixtures/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/fixtures/rails_app/public/javascripts/effects.js +1123 -0
- data/test/fixtures/rails_app/public/javascripts/prototype.js +6001 -0
- data/test/fixtures/rails_app/public/javascripts/rails.js +175 -0
- data/test/fixtures/rails_app/public/robots.txt +5 -0
- data/test/fixtures/rails_app/public/stylesheets/.gitkeep +0 -0
- data/test/fixtures/rails_app/script/rails +6 -0
- data/test/lib/support/active_record_test.rb +150 -0
- data/test/lib/support/fake_user_test.rb +59 -0
- data/test/lib/support/hash_test.rb +29 -0
- data/test/lib/support/object_test.rb +17 -0
- data/test/lib/support/string_test.rb +116 -0
- data/test/lib/typus/configuration_test.rb +46 -0
- data/test/lib/typus/controller/actions_test.rb +141 -0
- data/test/lib/typus/controller/associations_test.rb +7 -0
- data/test/lib/typus/controller/autocomplete_test.rb +7 -0
- data/test/lib/typus/controller/filters_test.rb +73 -0
- data/test/lib/typus/controller/format_test.rb +7 -0
- data/test/lib/typus/i18n_test.rb +9 -0
- data/test/lib/typus/orm/active_record/class_methods_test.rb +378 -0
- data/test/lib/typus/orm/active_record/search_test.rb +330 -0
- data/test/lib/typus/regex_test.rb +53 -0
- data/test/lib/typus/resources_test.rb +41 -0
- data/test/lib/typus_test.rb +141 -0
- data/test/test_helper.rb +15 -0
- data/typus.gemspec +25 -0
- metadata +586 -64
- data/Gemfile.lock +0 -149
- data/app/views/admin/helpers/_apps.html.erb +0 -9
- data/lib/generators/templates/public/admin/javascripts/application.js +0 -2
- data/lib/generators/templates/public/admin/javascripts/jquery-1.4.4.min.js +0 -167
- data/lib/generators/templates/public/admin/javascripts/jquery.application.js +0 -16
- data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +0 -160
- data/lib/generators/templates/public/admin/javascripts/jquery.searchField.js +0 -91
- data/lib/generators/templates/public/admin/stylesheets/application.css +0 -11
- data/lib/generators/templates/public/admin/stylesheets/screen.css +0 -367
- data/lib/generators/templates/public/admin/vendor/fancybox/blank.gif +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_close.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_e.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_n.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_ne.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_nw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_s.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_se.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_sw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_w.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_main.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_over.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-x.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-y.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +0 -72
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.css +0 -359
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.js +0 -1156
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.pack.js +0 -46
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -14
- data/lib/typus/actions.rb +0 -41
- data/lib/typus/filters.rb +0 -12
- data/lib/typus/format.rb +0 -70
- data/lib/typus/user.rb +0 -157
@@ -7,7 +7,7 @@ module Admin
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def header
|
10
|
-
render "admin/helpers/header"
|
10
|
+
render "admin/helpers/base/header"
|
11
11
|
end
|
12
12
|
|
13
13
|
def has_root_path?
|
@@ -15,18 +15,18 @@ module Admin
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def apps
|
18
|
-
render "admin/helpers/apps"
|
18
|
+
render "admin/helpers/base/apps"
|
19
19
|
end
|
20
20
|
|
21
21
|
def login_info
|
22
22
|
unless admin_user.is_a?(FakeUser)
|
23
|
-
render "admin/helpers/login_info"
|
23
|
+
render "admin/helpers/base/login_info"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def display_flash_message(message = flash)
|
28
28
|
if message.compact.any?
|
29
|
-
render "admin/helpers/flash_message",
|
29
|
+
render "admin/helpers/base/flash_message",
|
30
30
|
:flash_type => message.keys.first,
|
31
31
|
:message => message
|
32
32
|
end
|
@@ -7,9 +7,7 @@ module Admin
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def resources(admin_user)
|
10
|
-
available = Typus.resources.
|
11
|
-
resource if admin_user.resources.include?(resource)
|
12
|
-
end.compact
|
10
|
+
available = Typus.resources.delete_if { |r| !(admin_user.is_a?(FakeUser) || admin_user.resources.include?(r)) }
|
13
11
|
render "admin/helpers/dashboard/resources", :resources => available
|
14
12
|
end
|
15
13
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Admin
|
2
|
+
module DisplayHelper
|
3
|
+
|
4
|
+
def build_display(item, fields)
|
5
|
+
fields.map do |attribute, type|
|
6
|
+
value = if (type == :boolean) || (data = item.send(attribute))
|
7
|
+
send("display_#{type}", item, attribute)
|
8
|
+
else
|
9
|
+
"—".html_safe
|
10
|
+
end
|
11
|
+
|
12
|
+
[@resource.human_attribute_name(attribute), value]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def display_boolean(item, attribute)
|
17
|
+
data = item.send(attribute)
|
18
|
+
boolean_assoc = item.class.typus_boolean(attribute)
|
19
|
+
(data ? boolean_assoc.rassoc("true") : boolean_assoc.rassoc("false")).first
|
20
|
+
end
|
21
|
+
|
22
|
+
def display_belongs_to(item, attribute)
|
23
|
+
data = item.send(attribute)
|
24
|
+
link_to data.to_label, { :controller => data.class.to_resource,
|
25
|
+
:action => data.class.typus_options_for(:default_action_on_item),
|
26
|
+
:id => data.id }
|
27
|
+
end
|
28
|
+
|
29
|
+
def display_file(item, attribute)
|
30
|
+
typus_file_preview(item, attribute)
|
31
|
+
end
|
32
|
+
|
33
|
+
def display_selector(item, attribute)
|
34
|
+
item.mapping(attribute)
|
35
|
+
end
|
36
|
+
|
37
|
+
def display_datetime(item, attribute)
|
38
|
+
I18n.l(item.send(attribute), :format => @resource.typus_date_format(attribute))
|
39
|
+
end
|
40
|
+
|
41
|
+
def display_string(item, attribute)
|
42
|
+
item.send(attribute)
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :display_text, :display_string
|
46
|
+
alias_method :display_position, :display_string
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -25,40 +25,38 @@ module Admin
|
|
25
25
|
message = Typus::I18n.t("Remove")
|
26
26
|
label_text = <<-HTML
|
27
27
|
#{attribute_i18n}
|
28
|
-
<small>#{link_to message, { :action => '
|
28
|
+
<small>#{link_to message, { :action => 'update', :id => @item.id, :attribute => attribute }, :confirm => Typus::I18n.t("Are you sure?")}</small>
|
29
29
|
HTML
|
30
30
|
label_text.html_safe
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def typus_file_preview(item, attribute)
|
34
|
+
def typus_file_preview(item, attribute, options = {})
|
35
35
|
if (attachment = item.send(attribute))
|
36
|
-
|
37
|
-
|
38
|
-
typus_file_preview_for_dragonfly(attachment)
|
39
|
-
when :paperclip
|
40
|
-
typus_file_preview_for_paperclip(attachment)
|
41
|
-
end
|
36
|
+
adapter = get_type_of_attachment(attachment)
|
37
|
+
send("typus_file_preview_for_#{adapter}", attachment, options)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
45
|
-
def typus_file_preview_for_dragonfly(attachment)
|
41
|
+
def typus_file_preview_for_dragonfly(attachment, options = {})
|
46
42
|
if attachment.mime_type =~ /^image\/.+/
|
47
43
|
render "admin/helpers/file_preview",
|
48
44
|
:preview => attachment.process(:thumb, Typus.image_preview_size).url,
|
49
|
-
:thumb => attachment.process(:thumb, Typus.image_thumb_size).url
|
45
|
+
:thumb => attachment.process(:thumb, Typus.image_thumb_size).url,
|
46
|
+
:options => options
|
50
47
|
else
|
51
48
|
link_to attachment.name, attachment.url
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
55
|
-
def typus_file_preview_for_paperclip(attachment)
|
52
|
+
def typus_file_preview_for_paperclip(attachment, options = {})
|
56
53
|
if attachment.exists?
|
57
54
|
styles = attachment.styles.keys
|
58
55
|
if styles.include?(Typus.file_preview) && styles.include?(Typus.file_thumbnail)
|
59
56
|
render "admin/helpers/file_preview",
|
60
57
|
:preview => attachment.url(Typus.file_preview, false),
|
61
|
-
:thumb => attachment.url(Typus.file_thumbnail, false)
|
58
|
+
:thumb => attachment.url(Typus.file_thumbnail, false),
|
59
|
+
:options => options
|
62
60
|
else
|
63
61
|
link_to attachment.original_filename, attachment.url(:original, false)
|
64
62
|
end
|
@@ -30,24 +30,13 @@ module Admin
|
|
30
30
|
:values => expand_tree_into_select_field(@resource.roots, "parent_id")
|
31
31
|
end
|
32
32
|
|
33
|
-
# OPTIMIZE: Cleanup the case statement, using some meta-code.
|
34
33
|
def typus_relationships
|
35
|
-
@back_to = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id])
|
36
|
-
|
37
34
|
String.new.tap do |html|
|
38
35
|
@resource.typus_defaults_for(:relationships).each do |relationship|
|
39
36
|
association = @resource.reflect_on_association(relationship.to_sym)
|
37
|
+
next if association.macro == :belongs_to
|
40
38
|
next if admin_user.cannot?('read', association.class_name.typus_constantize)
|
41
|
-
html <<
|
42
|
-
when :has_and_belongs_to_many
|
43
|
-
typus_form_has_and_belongs_to_many(relationship)
|
44
|
-
when :has_many
|
45
|
-
typus_form_has_many(relationship)
|
46
|
-
when :has_one
|
47
|
-
typus_form_has_one(relationship)
|
48
|
-
when :belongs_to
|
49
|
-
""
|
50
|
-
end
|
39
|
+
html << send("typus_form_#{association.macro}", relationship)
|
51
40
|
end
|
52
41
|
end
|
53
42
|
end
|
@@ -9,10 +9,21 @@ module Admin
|
|
9
9
|
def list_actions
|
10
10
|
resources_actions.map do |body, url, options|
|
11
11
|
if admin_user.can?(url[:action], @resource.name)
|
12
|
-
path = params.dup.merge!(url)
|
13
|
-
link_to Typus::I18n.t(body), path
|
12
|
+
path = params.dup.merge!(url).compact.cleanup
|
13
|
+
link_to Typus::I18n.t(body), path, options
|
14
14
|
end
|
15
|
-
end.
|
15
|
+
end.join(" / ").html_safe
|
16
|
+
end
|
17
|
+
|
18
|
+
#--
|
19
|
+
# If partial `list` exists we will use it. This partial will have available
|
20
|
+
# the `@items` so we can do whatever we want there. Notice that pagination
|
21
|
+
# is still available.
|
22
|
+
#++
|
23
|
+
def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil, association_name = nil)
|
24
|
+
render "admin/#{resource}/list", :items => items
|
25
|
+
rescue ActionView::MissingTemplate
|
26
|
+
build_table(model, fields, items, link_options, association, association_name)
|
16
27
|
end
|
17
28
|
|
18
29
|
end
|
@@ -7,34 +7,38 @@ module Admin
|
|
7
7
|
@model_to_relate = @resource.reflect_on_association(field.to_sym).class_name.typus_constantize
|
8
8
|
@model_to_relate_as_resource = @model_to_relate.to_resource
|
9
9
|
@reflection = @resource.reflect_on_association(field.to_sym)
|
10
|
-
@association_name = @reflection.through_reflection ? @reflection.name.to_s : @model_to_relate.model_name
|
10
|
+
@association_name = @reflection.through_reflection ? @reflection.name.to_s : @model_to_relate.model_name
|
11
11
|
end
|
12
12
|
|
13
13
|
def typus_form_has_many(field)
|
14
14
|
setup_relationship(field)
|
15
|
-
if @reflection.through_reflection
|
16
|
-
@items_to_relate = @model_to_relate.all - @item.send(field)
|
17
|
-
else
|
18
|
-
@items_to_relate = @model_to_relate.where(@reflection.primary_key_name => nil) - @item.send(field)
|
19
|
-
end
|
20
15
|
|
21
|
-
|
22
|
-
form = build_relate_form
|
23
|
-
end
|
16
|
+
options = @reflection.through_reflection ? {} : { @reflection.primary_key_name => @item.id }
|
24
17
|
|
25
|
-
|
26
|
-
foreign_key = @reflection.primary_key_name
|
27
|
-
end
|
18
|
+
count_items_to_relate = @model_to_relate.order(@model_to_relate.typus_order_by).count - @item.send(field).count
|
28
19
|
|
29
|
-
|
20
|
+
if set_condition && !count_items_to_relate.zero?
|
21
|
+
form = if count_items_to_relate > Typus.autocomplete
|
22
|
+
build_relate_form('admin/templates/relate_form_with_autocomplete')
|
23
|
+
else
|
24
|
+
@items_to_relate = @model_to_relate.order(@model_to_relate.typus_order_by) - @item.send(field)
|
25
|
+
build_relate_form
|
26
|
+
end
|
27
|
+
end
|
30
28
|
|
31
29
|
build_pagination
|
32
30
|
|
31
|
+
# If we are on a through_reflection set the association name!
|
32
|
+
@resource_actions = if @reflection.through_reflection
|
33
|
+
[["Edit", {:action=>"edit"}, {}],
|
34
|
+
["Unrelate", {:resource_id=> @item.id, :resource=> @resource.model_name, :action=>"unrelate", :association_name => @association_name}, {:confirm=>"Unrelate?"}]]
|
35
|
+
else
|
36
|
+
[["Edit", {:action=>"edit"}, {}],
|
37
|
+
["Trash", {:resource_id=>@item.id, :resource=>@resource.model_name, :action=>"destroy"}, {:confirm=>"Trash?"}]]
|
38
|
+
end
|
39
|
+
|
33
40
|
render "admin/templates/has_n",
|
34
|
-
:model_to_relate => @model_to_relate,
|
35
|
-
:model_to_relate_as_resource => @model_to_relate_as_resource,
|
36
41
|
:association_name => @association_name,
|
37
|
-
:foreign_key => foreign_key,
|
38
42
|
:add_new => build_add_new(options),
|
39
43
|
:form => form,
|
40
44
|
:table => build_relationship_table
|
@@ -43,17 +47,24 @@ module Admin
|
|
43
47
|
def typus_form_has_and_belongs_to_many(field)
|
44
48
|
setup_relationship(field)
|
45
49
|
|
46
|
-
|
50
|
+
count_items_to_relate = @model_to_relate.order(@model_to_relate.typus_order_by).count - @item.send(field).count
|
47
51
|
|
48
|
-
if set_condition &&
|
49
|
-
form =
|
52
|
+
if set_condition && !count_items_to_relate.zero?
|
53
|
+
form = if count_items_to_relate > Typus.autocomplete
|
54
|
+
build_relate_form('admin/templates/relate_form_with_autocomplete')
|
55
|
+
else
|
56
|
+
@items_to_relate = @model_to_relate.order(@model_to_relate.typus_order_by) - @item.send(field)
|
57
|
+
build_relate_form
|
58
|
+
end
|
50
59
|
end
|
51
60
|
|
52
61
|
build_pagination
|
53
62
|
|
63
|
+
# TODO: Find a cleaner way to add these actions ...
|
64
|
+
@resource_actions = [["Edit", {:action=>"edit"}, {}],
|
65
|
+
["Unrelate", {:resource_id=> @item.id, :resource=> @resource.model_name, :action=>"unrelate"}, {:confirm=>"Unrelate?"}]]
|
66
|
+
|
54
67
|
render "admin/templates/has_n",
|
55
|
-
:model_to_relate => @model_to_relate,
|
56
|
-
:model_to_relate_as_resource => @model_to_relate_as_resource,
|
57
68
|
:association_name => @association_name,
|
58
69
|
:add_new => build_add_new,
|
59
70
|
:form => form,
|
@@ -61,17 +72,16 @@ module Admin
|
|
61
72
|
end
|
62
73
|
|
63
74
|
def build_pagination
|
64
|
-
options = { :order => @model_to_relate.typus_order_by, :conditions => set_conditions }
|
65
75
|
items_per_page = @model_to_relate.typus_options_for(:per_page)
|
66
|
-
data = @
|
76
|
+
data = @item.send(@field).order(@model_to_relate.typus_order_by).where(set_conditions)
|
67
77
|
@items = data.paginate(:per_page => items_per_page, :page => params[:page])
|
68
78
|
end
|
69
79
|
|
70
|
-
def build_relate_form
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
80
|
+
def build_relate_form(template = "admin/templates/relate_form")
|
81
|
+
options = { :association_name => @association_name,
|
82
|
+
:items_to_relate => @items_to_relate,
|
83
|
+
:model_to_relate => @model_to_relate }
|
84
|
+
render template, options
|
75
85
|
end
|
76
86
|
|
77
87
|
def build_relationship_table
|
@@ -85,9 +95,10 @@ module Admin
|
|
85
95
|
end
|
86
96
|
|
87
97
|
def build_add_new(options = {})
|
88
|
-
default_options = { :controller => "/admin/#{@model_to_relate.to_resource}",
|
89
|
-
:
|
90
|
-
:
|
98
|
+
default_options = { :controller => "/admin/#{@model_to_relate.to_resource}",
|
99
|
+
:action => "new",
|
100
|
+
:resource => @resource.model_name,
|
101
|
+
:resource_id => @item.id }
|
91
102
|
|
92
103
|
if set_condition && admin_user.can?("create", @model_to_relate)
|
93
104
|
link_to Typus::I18n.t("Add new"), default_options.merge(options)
|
@@ -112,56 +123,62 @@ module Admin
|
|
112
123
|
setup_relationship(field)
|
113
124
|
|
114
125
|
@items = Array.new
|
115
|
-
if item = @
|
126
|
+
if item = @item.send(field)
|
116
127
|
@items << item
|
117
128
|
end
|
118
129
|
|
130
|
+
# TODO: Find a cleaner way to add these actions ...
|
131
|
+
@resource_actions = [["Edit", {:action=>"edit"}, {}],
|
132
|
+
["Trash", {:resource_id=>@item.id, :resource=>@resource.model_name, :action=>"destroy"}, {:confirm=>"Trash?"}]]
|
133
|
+
|
134
|
+
options = { :resource_id => nil, @reflection.primary_key_name => @item.id }
|
135
|
+
|
119
136
|
render "admin/templates/has_one",
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:add_new => @items.empty? ? build_add_new : nil,
|
137
|
+
:association_name => @association_name,
|
138
|
+
:add_new => @items.empty? ? build_add_new(options) : nil,
|
123
139
|
:table => build_relationship_table
|
124
140
|
end
|
125
141
|
|
126
142
|
def typus_belongs_to_field(attribute, form)
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
#
|
131
|
-
params[:action] = (params[:action] == 'create') ? 'new' : params[:action]
|
132
|
-
|
133
|
-
back_to = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id])
|
134
|
-
|
135
|
-
related = @resource.reflect_on_association(attribute.to_sym).class_name.typus_constantize
|
136
|
-
related_fk = @resource.reflect_on_association(attribute.to_sym).primary_key_name
|
137
|
-
|
138
|
-
if params[:action] == 'edit'
|
139
|
-
options = { :resource => @resource.model_name,
|
140
|
-
:resource_id => @item.id }
|
141
|
-
else
|
142
|
-
options = { :resource => @resource.model_name }
|
143
|
-
end
|
144
|
-
|
145
|
-
default = { :controller => "/admin/#{related.to_resource}", :action => 'new', :back_to => back_to }
|
143
|
+
association = @resource.reflect_on_association(attribute.to_sym)
|
144
|
+
related = association.class_name.typus_constantize
|
145
|
+
related_fk = association.primary_key_name
|
146
146
|
|
147
|
+
# TODO: Use the build_add_new method.
|
147
148
|
if admin_user.can?('create', related)
|
148
|
-
|
149
|
+
options = { :controller => "/admin/#{related.to_resource}",
|
150
|
+
:action => 'new',
|
151
|
+
:resource => @resource.model_name }
|
152
|
+
# Pass the resource_id only to edit/update because only there is where
|
153
|
+
# the record actually exists.
|
154
|
+
options.merge!(:resource_id => @item.id) if %w(edit update).include?(params[:action])
|
155
|
+
message = link_to Typus::I18n.t("Add"), options
|
149
156
|
end
|
150
157
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
158
|
+
# Set the template.
|
159
|
+
template = if related.respond_to?(:roots) || !(related.count > Typus.autocomplete)
|
160
|
+
"admin/templates/belongs_to"
|
161
|
+
else
|
162
|
+
"admin/templates/belongs_to_with_autocomplete"
|
163
|
+
end
|
164
|
+
|
165
|
+
# Set the values.
|
166
|
+
values = if related.respond_to?(:roots)
|
167
|
+
expand_tree_into_select_field(related.roots, related_fk)
|
168
|
+
elsif !(related.count > Typus.autocomplete)
|
169
|
+
related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
|
170
|
+
end
|
171
|
+
|
172
|
+
render template,
|
156
173
|
:resource => @resource,
|
157
174
|
:attribute => attribute,
|
158
175
|
:form => form,
|
159
176
|
:related_fk => related_fk,
|
177
|
+
:related => related,
|
160
178
|
:message => message,
|
161
179
|
:label_text => @resource.human_attribute_name(attribute),
|
162
180
|
:values => values,
|
163
|
-
|
164
|
-
:html_options => {},
|
181
|
+
:html_options => { :disabled => attribute_disabled?(attribute) },
|
165
182
|
:options => { :include_blank => true }
|
166
183
|
end
|
167
184
|
|
@@ -2,6 +2,7 @@ module Admin
|
|
2
2
|
|
3
3
|
module ResourcesHelper
|
4
4
|
|
5
|
+
include Admin::DisplayHelper
|
5
6
|
include Admin::ListHelper
|
6
7
|
include Admin::FiltersHelper
|
7
8
|
include Admin::FormHelper
|
@@ -11,25 +12,25 @@ module Admin
|
|
11
12
|
include Admin::SidebarHelper
|
12
13
|
include Admin::TableHelper
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
# the `@items` so we can do whatever we want there. Notice that pagination
|
17
|
-
# is still available.
|
18
|
-
#++
|
19
|
-
def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil, association_name = nil)
|
20
|
-
render "admin/#{resource}/list", :items => items
|
21
|
-
rescue ActionView::MissingTemplate
|
22
|
-
build_table(model, fields, items, link_options, association, association_name)
|
23
|
-
end
|
15
|
+
def display_link_to_previous(params = params)
|
16
|
+
if params[:resource]
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
item_class = params[:resource].typus_constantize
|
19
|
+
url = { :controller => item_class.to_resource }
|
20
|
+
|
21
|
+
if params[:resource_id]
|
22
|
+
item = item_class.find(params[:resource_id])
|
23
|
+
url.merge!(:action => 'edit', :id => item.id)
|
24
|
+
else
|
25
|
+
url.merge!(:action => 'new')
|
26
|
+
end
|
28
27
|
|
29
|
-
|
28
|
+
body = Typus::I18n.t("Cancel adding a new %{resource}?", :resource => @resource.model_name.human.downcase)
|
30
29
|
|
31
|
-
|
32
|
-
|
30
|
+
render "admin/helpers/resources/display_link_to_previous",
|
31
|
+
:body => body,
|
32
|
+
:url => url
|
33
|
+
end
|
33
34
|
end
|
34
35
|
|
35
36
|
end
|