typus 3.0.2 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +20 -9
- data/Gemfile.lock +93 -65
- data/MIT-LICENSE +1 -1
- data/README.md +61 -0
- data/Rakefile +5 -0
- data/app/controllers/admin/account_controller.rb +7 -10
- data/app/controllers/admin/base_controller.rb +16 -1
- data/app/controllers/admin/resources_controller.rb +270 -159
- data/app/controllers/admin/session_controller.rb +8 -9
- data/app/helpers/admin/base_helper.rb +13 -28
- data/app/helpers/admin/dashboard_helper.rb +4 -10
- data/app/helpers/admin/file_preview_helper.rb +70 -0
- data/app/helpers/admin/filters_helper.rb +64 -45
- data/app/helpers/admin/form_helper.rb +37 -62
- data/app/helpers/admin/relationships_helper.rb +63 -78
- data/app/helpers/admin/resources_helper.rb +10 -31
- data/app/helpers/admin/search_helper.rb +6 -9
- data/app/helpers/admin/sidebar_helper.rb +15 -20
- data/app/helpers/admin/table_helper.rb +79 -170
- data/app/mailers/admin/mailer.rb +1 -1
- data/app/views/admin/account/forgot_password.html.erb +2 -2
- data/app/views/admin/account/new.html.erb +8 -4
- data/app/views/admin/base/user_guide.html.erb +85 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +3 -1
- data/app/views/admin/dashboard/show.html.erb +2 -2
- data/app/views/admin/dashboard/styles.html.erb +2 -2
- data/app/views/admin/helpers/_apps.html.erb +5 -4
- data/app/views/admin/helpers/_file_preview.html.erb +3 -0
- data/app/views/admin/helpers/_header.html.erb +3 -3
- data/app/views/admin/helpers/_login_info.html.erb +2 -2
- data/app/views/admin/helpers/dashboard/_applications.html.erb +6 -9
- data/app/views/admin/helpers/dashboard/_resources.html.erb +2 -3
- data/app/views/admin/helpers/filters/_filters.html.erb +1 -1
- data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +1 -1
- data/app/views/admin/helpers/resources/_errors.html.erb +10 -0
- data/app/views/admin/helpers/search/_search.html.erb +1 -1
- data/app/views/admin/helpers/sidebar/_sidebar.html.erb +6 -3
- data/app/views/admin/helpers/table/_table.html.erb +17 -5
- data/app/views/admin/mailer/reset_password_link.text.erb +2 -2
- data/app/views/admin/resources/_form.html.erb +3 -12
- data/app/views/admin/resources/edit.html.erb +7 -5
- data/app/views/admin/resources/index.html.erb +13 -18
- data/app/views/admin/resources/new.html.erb +4 -4
- data/app/views/admin/resources/show.html.erb +9 -13
- data/app/views/admin/session/new.html.erb +8 -4
- data/app/views/admin/templates/_belongs_to.html.erb +1 -1
- data/app/views/admin/templates/_boolean.html.erb +2 -2
- data/app/views/admin/templates/_date.html.erb +2 -2
- data/app/views/admin/templates/_datetime.html.erb +2 -2
- data/app/views/admin/templates/_file.html.erb +3 -19
- data/app/views/admin/templates/_has_n.html.erb +4 -4
- data/app/views/admin/templates/_has_one.html.erb +14 -0
- data/app/views/admin/templates/_password.html.erb +2 -2
- data/app/views/admin/templates/_profile_sidebar.html.erb +3 -0
- data/app/views/admin/templates/_relate_form.html.erb +2 -1
- data/app/views/admin/templates/_selector.html.erb +1 -1
- data/app/views/admin/templates/_string.html.erb +6 -6
- data/app/views/admin/templates/_text.html.erb +11 -4
- data/app/views/admin/templates/_time.html.erb +2 -2
- data/app/views/admin/templates/_tree.html.erb +1 -1
- data/app/views/layouts/admin/base.html.erb +7 -6
- data/app/views/layouts/admin/session.html.erb +4 -14
- data/config/{available_locales/ca_models.yml → locales/typus.ca.models.yml} +5 -4
- data/config/locales/typus.ca.yml +81 -0
- data/config/{available_locales/de_models.yml → locales/typus.de.models.yml} +6 -2
- data/config/locales/typus.de.yml +80 -0
- data/config/locales/typus.el.models.yml +17 -0
- data/config/locales/typus.el.yml +82 -0
- data/config/{available_locales/es_models.yml → locales/typus.es.models.yml} +9 -4
- data/config/locales/typus.es.yml +82 -0
- data/config/{available_locales/fr_models.yml → locales/typus.fr.models.yml} +8 -3
- data/config/locales/typus.fr.yml +87 -0
- data/config/{available_locales/hu_models.yml → locales/typus.hu.models.yml} +6 -2
- data/config/locales/typus.hu.yml +80 -0
- data/config/{available_locales/it_models.yml → locales/typus.it.models.yml} +7 -4
- data/config/locales/typus.it.yml +89 -0
- data/config/{available_locales/language_models.yml.template → locales/typus.locale.models.yml.template} +8 -4
- data/config/locales/typus.locale.yml.template +81 -0
- data/config/{available_locales/pt-BR_models.yml → locales/typus.pt-BR.models.yml} +6 -2
- data/config/locales/typus.pt-BR.yml +80 -0
- data/config/{available_locales/ru_models.yml → locales/typus.ru.models.yml} +6 -2
- data/config/locales/typus.ru.yml +80 -0
- data/config/locales/typus.zh-CN.models.yml +17 -0
- data/config/locales/typus.zh-CN.yml +79 -0
- data/config/routes.rb +11 -7
- data/lib/generators/templates/config/initializers/typus.rb +8 -5
- data/lib/generators/templates/config/initializers/typus_resources.rb +0 -3
- data/lib/generators/templates/config/typus/README +6 -6
- data/lib/generators/templates/config/typus/typus.yml +5 -5
- data/lib/generators/templates/controller.rb +1 -1
- data/lib/generators/templates/migration.rb +1 -0
- data/lib/generators/templates/public/admin/javascripts/application.js +0 -4
- data/lib/generators/templates/public/admin/javascripts/jquery-1.4.4.min.js +167 -0
- data/lib/generators/templates/public/admin/javascripts/jquery.application.js +16 -0
- data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +50 -22
- data/lib/generators/templates/public/admin/stylesheets/screen.css +43 -34
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +32 -32
- data/lib/generators/templates/public/admin/vendor/fancybox/{jquery.fancybox-1.3.1.css → jquery.fancybox-1.3.4.css} +359 -363
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.js +1156 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
- data/lib/generators/typus/assets_generator.rb +23 -0
- data/lib/generators/typus/controller_generator.rb +29 -0
- data/lib/generators/typus/migration_generator.rb +39 -20
- data/lib/generators/typus/typus_generator.rb +17 -57
- data/lib/generators/typus/views_generator.rb +2 -6
- data/lib/support/active_record.rb +8 -20
- data/lib/support/fake_user.rb +6 -1
- data/lib/support/hash.rb +1 -2
- data/lib/support/object.rb +4 -17
- data/lib/support/string.rb +34 -3
- data/lib/tasks/typus.rake +1 -1
- data/lib/typus.rb +60 -48
- data/lib/typus/actions.rb +27 -0
- data/lib/typus/authentication/base.rb +3 -4
- data/lib/typus/authentication/http_basic.rb +1 -1
- data/lib/typus/authentication/none.rb +1 -1
- data/lib/typus/authentication/session.rb +53 -108
- data/lib/typus/configuration.rb +13 -11
- data/lib/typus/filters.rb +12 -0
- data/lib/typus/format.rb +9 -13
- data/lib/typus/i18n.rb +30 -0
- data/lib/typus/orm/active_record.rb +97 -194
- data/lib/typus/orm/active_record/search.rb +91 -0
- data/lib/typus/resources.rb +6 -10
- data/lib/typus/user.rb +20 -40
- data/lib/typus/version.rb +1 -1
- metadata +77 -231
- data/CHANGELOG +0 -102
- data/README.rdoc +0 -48
- data/app/helpers/admin/preview_helper.rb +0 -46
- data/app/views/admin/helpers/_preview.html.erb +0 -13
- data/app/views/admin/templates/_has_many.html.erb +0 -22
- data/config/available_locales/ca.yml +0 -122
- data/config/available_locales/de.yml +0 -122
- data/config/available_locales/es.yml +0 -122
- data/config/available_locales/fr.yml +0 -127
- data/config/available_locales/hu.yml +0 -122
- data/config/available_locales/it.yml +0 -132
- data/config/available_locales/language.yml.template +0 -120
- data/config/available_locales/pt-BR.yml +0 -122
- data/config/available_locales/ru.yml +0 -122
- data/lib/generators/templates/functional_test.rb +0 -10
- data/lib/generators/templates/model.rb +0 -8
- data/lib/generators/templates/public/admin/images/ui-icons.png +0 -0
- data/lib/generators/templates/public/admin/javascripts/jquery-1.4.2.min.js +0 -154
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.js +0 -1077
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.2.pack.js +0 -13
- data/lib/typus/pagination.rb +0 -18
- data/test/factories.rb +0 -43
- data/test/fixtures/config/broken/application.yml +0 -68
- data/test/fixtures/config/broken/application_roles.yml +0 -20
- 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 +0 -3
- data/test/fixtures/config/broken/undefined_roles.yml +0 -6
- data/test/fixtures/config/default/typus.yml +0 -13
- data/test/fixtures/config/default/typus_roles.yml +0 -2
- 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 +0 -10
- data/test/fixtures/config/namespaced/application.yml +0 -5
- data/test/fixtures/config/namespaced/application_roles.yml +0 -2
- data/test/fixtures/config/ordered/001_roles.yml +0 -2
- data/test/fixtures/config/ordered/002_roles.yml +0 -2
- data/test/fixtures/config/unordered/app_one_roles.yml +0 -2
- data/test/fixtures/config/unordered/app_two_roles.yml +0 -2
- data/test/fixtures/config/working/application.yml +0 -73
- data/test/fixtures/config/working/application_roles.yml +0 -24
- data/test/fixtures/config/working/typus.yml +0 -13
- data/test/fixtures/config/working/typus_roles.yml +0 -2
- data/test/fixtures/rails_app/Rakefile +0 -7
- data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/pictures_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +0 -2
- data/test/fixtures/rails_app/app/controllers/application_controller.rb +0 -3
- data/test/fixtures/rails_app/app/models/asset.rb +0 -5
- data/test/fixtures/rails_app/app/models/category.rb +0 -11
- data/test/fixtures/rails_app/app/models/comment.rb +0 -6
- data/test/fixtures/rails_app/app/models/custom_user.rb +0 -2
- data/test/fixtures/rails_app/app/models/delayed/task.rb +0 -5
- data/test/fixtures/rails_app/app/models/page.rb +0 -5
- data/test/fixtures/rails_app/app/models/picture.rb +0 -6
- data/test/fixtures/rails_app/app/models/post.rb +0 -21
- data/test/fixtures/rails_app/app/models/typus_user.rb +0 -8
- data/test/fixtures/rails_app/app/models/view.rb +0 -5
- data/test/fixtures/rails_app/app/views/admin/categories/_form.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/mailer/reset_password_link.text.erb +0 -6
- data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/posts/_sidebar.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +0 -1
- data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +0 -1
- data/test/fixtures/rails_app/config.ru +0 -4
- data/test/fixtures/rails_app/config/application.rb +0 -53
- data/test/fixtures/rails_app/config/boot.rb +0 -13
- data/test/fixtures/rails_app/config/database.yml +0 -14
- data/test/fixtures/rails_app/config/environment.rb +0 -5
- data/test/fixtures/rails_app/config/environments/test.rb +0 -34
- data/test/fixtures/rails_app/config/initializers/secret_token.rb +0 -7
- data/test/fixtures/rails_app/config/initializers/session_store.rb +0 -8
- data/test/fixtures/rails_app/config/initializers/typus.rb +0 -6
- data/test/fixtures/rails_app/config/routes.rb +0 -5
- data/test/fixtures/rails_app/config/typus/application.yml +0 -79
- data/test/fixtures/rails_app/config/typus/application_roles.yml +0 -25
- data/test/fixtures/rails_app/config/typus/typus.yml +0 -12
- data/test/fixtures/rails_app/config/typus/typus_roles.yml +0 -2
- data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
- data/test/fixtures/rails_app/tmp/export-posts-20101012213057.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012213132.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012213234.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012213506.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215057.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215217.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215415.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215443.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215509.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215528.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215551.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215615.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215640.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215714.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215744.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215814.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215836.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012215906.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012220659.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012221043.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012221258.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012222558.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012222752.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012222848.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012223433.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012223535.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012224003.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012224052.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012224109.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012224139.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012224205.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012224243.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101012225119.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063215.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063300.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063352.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063427.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063448.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063530.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063559.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063646.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063737.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063822.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063837.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063919.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063939.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013063952.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064220.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064253.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064318.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064404.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064452.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064536.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064652.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013064845.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013065023.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013065137.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013065713.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013065954.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070057.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070116.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070156.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070349.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070429.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070448.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070514.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070709.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070745.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070809.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070905.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013070955.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013071116.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013071209.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013071335.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013071632.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013071643.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013071735.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013071749.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013072030.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013072050.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013072108.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013072713.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013072751.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013072912.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101013074546.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101018180512.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101018183359.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101018183608.csv +0 -2
- data/test/fixtures/rails_app/tmp/export-posts-20101018183759.csv +0 -2
- data/test/functional/admin/account_controller_test.rb +0 -90
- data/test/functional/admin/assets_controller_test.rb +0 -55
- data/test/functional/admin/categories_controller_test.rb +0 -62
- data/test/functional/admin/comments_controller_test.rb +0 -21
- data/test/functional/admin/dashboard_controller_test.rb +0 -138
- data/test/functional/admin/posts_controller_test.rb +0 -548
- data/test/functional/admin/session_controller_test.rb +0 -85
- data/test/functional/admin/status_controller_test.rb +0 -46
- data/test/functional/admin/typus_users_controller_test.rb +0 -159
- data/test/helpers/admin/base_helper_test.rb +0 -67
- data/test/helpers/admin/dashboard_helper_test.rb +0 -19
- data/test/helpers/admin/form_helper_test.rb +0 -117
- data/test/helpers/admin/resources_helper_test.rb +0 -64
- data/test/helpers/admin/sidebar_helper_test.rb +0 -274
- data/test/helpers/admin/table_helper_test.rb +0 -219
- data/test/integration/login_test.rb +0 -13
- data/test/integration_test_helper.rb +0 -21
- data/test/lib/support/active_record_test.rb +0 -86
- data/test/lib/support/array_test.rb +0 -11
- data/test/lib/support/hash_test.rb +0 -11
- data/test/lib/support/string_test.rb +0 -39
- data/test/lib/typus/active_record_test.rb +0 -451
- data/test/lib/typus/configuration_test.rb +0 -52
- data/test/lib/typus/resource_test.rb +0 -17
- data/test/lib/typus/routes_test.rb +0 -29
- data/test/lib/typus_test.rb +0 -107
- data/test/schema.rb +0 -100
- data/test/test_helper.rb +0 -16
- data/test/unit/admin/mailer_test.rb +0 -32
- data/test/unit/typus_user_roles_test.rb +0 -105
- data/test/unit/typus_user_test.rb +0 -142
- data/typus.gemspec +0 -25
@@ -4,23 +4,28 @@ module Admin
|
|
4
4
|
|
5
5
|
def setup_relationship(field)
|
6
6
|
@field = field
|
7
|
-
@model_to_relate = @resource.reflect_on_association(field.to_sym).class_name.
|
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
|
-
@
|
10
|
+
@association_name = @reflection.through_reflection ? @reflection.name.to_s : @model_to_relate.model_name.tableize
|
11
11
|
end
|
12
12
|
|
13
13
|
def typus_form_has_many(field)
|
14
|
-
|
15
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
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
@items_to_relate = @model_to_relate.send("find_all_by_#{foreign_key}", nil)
|
20
|
-
if set_condition && !@items_to_relate.empty?
|
21
|
+
if set_condition && @items_to_relate.any?
|
21
22
|
form = build_relate_form
|
22
23
|
end
|
23
24
|
|
25
|
+
unless @reflection.through_reflection
|
26
|
+
foreign_key = @reflection.primary_key_name
|
27
|
+
end
|
28
|
+
|
24
29
|
options = { foreign_key => @item.id }
|
25
30
|
|
26
31
|
build_pagination
|
@@ -28,19 +33,19 @@ module Admin
|
|
28
33
|
render "admin/templates/has_n",
|
29
34
|
:model_to_relate => @model_to_relate,
|
30
35
|
:model_to_relate_as_resource => @model_to_relate_as_resource,
|
36
|
+
:association_name => @association_name,
|
31
37
|
:foreign_key => foreign_key,
|
32
|
-
:add_new =>
|
38
|
+
:add_new => build_add_new(options),
|
33
39
|
:form => form,
|
34
40
|
:table => build_relationship_table
|
35
|
-
|
36
41
|
end
|
37
42
|
|
38
43
|
def typus_form_has_and_belongs_to_many(field)
|
39
|
-
|
40
44
|
setup_relationship(field)
|
41
45
|
|
42
|
-
@items_to_relate =
|
43
|
-
|
46
|
+
@items_to_relate = @model_to_relate.all - @item.send(field)
|
47
|
+
|
48
|
+
if set_condition && @items_to_relate.any?
|
44
49
|
form = build_relate_form
|
45
50
|
end
|
46
51
|
|
@@ -49,23 +54,24 @@ module Admin
|
|
49
54
|
render "admin/templates/has_n",
|
50
55
|
:model_to_relate => @model_to_relate,
|
51
56
|
:model_to_relate_as_resource => @model_to_relate_as_resource,
|
52
|
-
:
|
57
|
+
:association_name => @association_name,
|
58
|
+
:add_new => build_add_new,
|
53
59
|
:form => form,
|
54
60
|
:table => build_relationship_table
|
55
|
-
|
56
61
|
end
|
57
62
|
|
58
63
|
def build_pagination
|
59
64
|
options = { :order => @model_to_relate.typus_order_by, :conditions => set_conditions }
|
60
65
|
items_per_page = @model_to_relate.typus_options_for(:per_page)
|
61
|
-
data = @resource.find(params[:id]).send(@field).all(options)
|
66
|
+
data = @resource.unscoped.find(params[:id]).send(@field).all(options)
|
62
67
|
@items = data.paginate(:per_page => items_per_page, :page => params[:page])
|
63
68
|
end
|
64
69
|
|
65
70
|
def build_relate_form
|
66
71
|
render "admin/templates/relate_form",
|
67
72
|
:model_to_relate => @model_to_relate,
|
68
|
-
:items_to_relate => @items_to_relate
|
73
|
+
:items_to_relate => @items_to_relate,
|
74
|
+
:association_name => @association_name
|
69
75
|
end
|
70
76
|
|
71
77
|
def build_relationship_table
|
@@ -74,110 +80,89 @@ module Admin
|
|
74
80
|
@items,
|
75
81
|
@model_to_relate_as_resource,
|
76
82
|
{},
|
77
|
-
@
|
83
|
+
@reflection.macro,
|
84
|
+
@association_name)
|
78
85
|
end
|
79
86
|
|
80
87
|
def build_add_new(options = {})
|
81
|
-
default_options = { :controller => @
|
82
|
-
:resource => @resource.
|
88
|
+
default_options = { :controller => "/admin/#{@model_to_relate.to_resource}", :action => "new",
|
89
|
+
:resource => @resource.model_name, :resource_id => @item.id,
|
83
90
|
:back_to => @back_to }
|
84
91
|
|
85
|
-
|
86
|
-
|
87
|
-
|
92
|
+
if set_condition && admin_user.can?("create", @model_to_relate)
|
93
|
+
link_to Typus::I18n.t("Add new"), default_options.merge(options)
|
94
|
+
end
|
88
95
|
end
|
89
96
|
|
90
97
|
def set_condition
|
91
|
-
if @resource.typus_user_id? &&
|
92
|
-
@item.owned_by?(
|
98
|
+
if @resource.typus_user_id? && admin_user.is_not_root?
|
99
|
+
@item.owned_by?(admin_user)
|
93
100
|
else
|
94
101
|
true
|
95
102
|
end
|
96
103
|
end
|
97
104
|
|
98
105
|
def set_conditions
|
99
|
-
if @model_to_relate.typus_options_for(:only_user_items) &&
|
100
|
-
{ Typus.user_fk =>
|
106
|
+
if @model_to_relate.typus_options_for(:only_user_items) && admin_user.is_not_root?
|
107
|
+
{ Typus.user_fk => admin_user }
|
101
108
|
end
|
102
109
|
end
|
103
110
|
|
104
|
-
#--
|
105
|
-
# TODO: Move html code to partial.
|
106
|
-
#++
|
107
111
|
def typus_form_has_one(field)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
reflection = @resource.reflect_on_association(field.to_sym)
|
114
|
-
association = reflection.macro
|
115
|
-
|
116
|
-
html << <<-HTML
|
117
|
-
<a name="#{field}"></a>
|
118
|
-
<div class="box_relationships" id="#{model_to_relate_as_resource}">
|
119
|
-
<h2>
|
120
|
-
#{link_to model_to_relate.model_name.human, :controller => "admin/#{model_to_relate_as_resource}"}
|
121
|
-
</h2>
|
122
|
-
HTML
|
123
|
-
items = Array.new
|
124
|
-
items << @resource.find(params[:id]).send(field) unless @resource.find(params[:id]).send(field).nil?
|
125
|
-
unless items.empty?
|
126
|
-
options = { :back_to => @back_to, :resource => @resource.to_resource, :resource_id => @item.id }
|
127
|
-
html << build_list(model_to_relate,
|
128
|
-
model_to_relate.typus_fields_for(:relationship),
|
129
|
-
items,
|
130
|
-
model_to_relate_as_resource,
|
131
|
-
options,
|
132
|
-
association)
|
133
|
-
else
|
134
|
-
message = _t("There are no %{records}.",
|
135
|
-
:records => model_to_relate.model_name.human.downcase)
|
136
|
-
html << <<-HTML
|
137
|
-
<div id="flash" class="notice"><p>#{message}</p></div>
|
138
|
-
HTML
|
112
|
+
setup_relationship(field)
|
113
|
+
|
114
|
+
@items = Array.new
|
115
|
+
if item = @resource.find(params[:id]).send(field)
|
116
|
+
@items << item
|
139
117
|
end
|
140
|
-
html << <<-HTML
|
141
|
-
</div>
|
142
|
-
HTML
|
143
118
|
|
144
|
-
|
119
|
+
render "admin/templates/has_one",
|
120
|
+
:model_to_relate => @model_to_relate,
|
121
|
+
:model_to_relate_as_resource => @model_to_relate_as_resource,
|
122
|
+
:add_new => @items.empty? ? build_add_new : nil,
|
123
|
+
:table => build_relationship_table
|
145
124
|
end
|
146
125
|
|
147
126
|
def typus_belongs_to_field(attribute, form)
|
148
|
-
|
149
127
|
##
|
150
|
-
# We only
|
151
|
-
# the
|
128
|
+
# We can only pass parameters to 'new' and 'edit'. This hack replaces
|
129
|
+
# the current action.
|
152
130
|
#
|
153
131
|
params[:action] = (params[:action] == 'create') ? 'new' : params[:action]
|
154
132
|
|
155
133
|
back_to = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id])
|
156
134
|
|
157
|
-
related = @resource.reflect_on_association(attribute.to_sym).class_name.
|
135
|
+
related = @resource.reflect_on_association(attribute.to_sym).class_name.typus_constantize
|
158
136
|
related_fk = @resource.reflect_on_association(attribute.to_sym).primary_key_name
|
159
137
|
|
160
|
-
|
161
|
-
|
162
|
-
|
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 }
|
163
146
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
147
|
+
if admin_user.can?('create', related)
|
148
|
+
message = link_to Typus::I18n.t("Add"), default.merge(options)
|
149
|
+
end
|
150
|
+
|
151
|
+
values = related.respond_to?(:roots) ?
|
152
|
+
expand_tree_into_select_field(related.roots, related_fk) :
|
153
|
+
related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
|
169
154
|
|
170
155
|
render "admin/templates/belongs_to",
|
171
156
|
:resource => @resource,
|
157
|
+
:attribute => attribute,
|
172
158
|
:form => form,
|
173
159
|
:related_fk => related_fk,
|
174
160
|
:message => message,
|
175
161
|
:label_text => @resource.human_attribute_name(attribute),
|
176
|
-
:values =>
|
162
|
+
:values => values,
|
177
163
|
# :html_options => { :disabled => attribute_disabled?(attribute) },
|
178
164
|
:html_options => {},
|
179
165
|
:options => { :include_blank => true }
|
180
|
-
|
181
166
|
end
|
182
167
|
|
183
168
|
end
|
@@ -2,48 +2,27 @@ module Admin
|
|
2
2
|
|
3
3
|
module ResourcesHelper
|
4
4
|
|
5
|
-
include FiltersHelper
|
6
|
-
include FormHelper
|
7
|
-
include RelationshipsHelper
|
8
|
-
include
|
9
|
-
include SearchHelper
|
10
|
-
include SidebarHelper
|
11
|
-
include TableHelper
|
5
|
+
include Admin::FiltersHelper
|
6
|
+
include Admin::FormHelper
|
7
|
+
include Admin::RelationshipsHelper
|
8
|
+
include Admin::FilePreviewHelper
|
9
|
+
include Admin::SearchHelper
|
10
|
+
include Admin::SidebarHelper
|
11
|
+
include Admin::TableHelper
|
12
12
|
|
13
13
|
#--
|
14
14
|
# If partial `list` exists we will use it. This partial will have available
|
15
15
|
# the `@items` so we can do whatever we want there. Notice that pagination
|
16
16
|
# is still available.
|
17
17
|
#++
|
18
|
-
def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil)
|
18
|
+
def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil, association_name = nil)
|
19
19
|
render "admin/#{resource}/list", :items => items
|
20
20
|
rescue ActionView::MissingTemplate
|
21
|
-
build_table(model, fields, items, link_options, association)
|
21
|
+
build_table(model, fields, items, link_options, association, association_name)
|
22
22
|
end
|
23
23
|
|
24
24
|
def display_link_to_previous
|
25
|
-
|
26
|
-
|
27
|
-
options = {}
|
28
|
-
options[:resource_from] = @resource.model_name.human
|
29
|
-
options[:resource_to] = params[:resource].classify.constantize.model_name.human if params[:resource]
|
30
|
-
|
31
|
-
editing = %w( edit update ).include?(params[:action])
|
32
|
-
message = case
|
33
|
-
when params[:resource] && editing
|
34
|
-
"You're updating a %{resource_from} for %{resource_to}."
|
35
|
-
when editing
|
36
|
-
"You're updating a %{resource_from}."
|
37
|
-
when params[:resource]
|
38
|
-
"You're adding a new %{resource_from} to %{resource_to}."
|
39
|
-
else
|
40
|
-
"You're adding a new %{resource_from}."
|
41
|
-
end
|
42
|
-
message = _t(message,
|
43
|
-
:resource_from => options[:resource_from],
|
44
|
-
:resource_to => options[:resource_to])
|
45
|
-
|
46
|
-
render File.join(path, "display_link_to_previous"), :message => message
|
25
|
+
render File.join(path, "display_link_to_previous") if params[:back_to]
|
47
26
|
end
|
48
27
|
|
49
28
|
private
|
@@ -3,15 +3,12 @@ module Admin
|
|
3
3
|
module SearchHelper
|
4
4
|
|
5
5
|
def search(resource = @resource)
|
6
|
-
typus_search = resource.typus_defaults_for(:search)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
hidden_params = search_params.map { |k, v| hidden_field_tag(k, v) }
|
13
|
-
|
14
|
-
render "admin/helpers/search/search", :hidden_params => hidden_params, :search_by => search_by
|
6
|
+
if (typus_search = resource.typus_defaults_for(:search)) && typus_search.any?
|
7
|
+
search_params = params.dup
|
8
|
+
%w(action controller id search page utf8).each { |p| search_params.delete(p) }
|
9
|
+
options = { :hidden_params => search_params.map { |k, v| hidden_field_tag(k, v) } }
|
10
|
+
render "admin/helpers/search/search", options
|
11
|
+
end
|
15
12
|
end
|
16
13
|
|
17
14
|
end
|
@@ -6,13 +6,13 @@ module Admin
|
|
6
6
|
resources = ActiveSupport::OrderedHash.new
|
7
7
|
app_name = @resource.typus_application
|
8
8
|
|
9
|
-
Typus.application(app_name).sort {|a,b| a.
|
10
|
-
next unless
|
11
|
-
klass = resource.
|
9
|
+
Typus.application(app_name).sort {|a,b| a.typus_constantize.model_name.human <=> b.typus_constantize.model_name.human}.each do |resource|
|
10
|
+
next unless admin_user.resources.include?(resource)
|
11
|
+
klass = resource.typus_constantize
|
12
12
|
|
13
13
|
resources[resource] = default_actions(klass)
|
14
|
-
resources[resource] += export(klass) if params[:action] == 'index'
|
15
14
|
resources[resource] += custom_actions(klass)
|
15
|
+
resources[resource] += export(klass) if params[:action] == 'index'
|
16
16
|
|
17
17
|
resources[resource].compact!
|
18
18
|
end
|
@@ -21,31 +21,26 @@ module Admin
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def default_actions(klass)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
actions << link_to_unless_current(_t("Add new"), :action => "new")
|
28
|
-
end
|
29
|
-
|
30
|
-
actions << link_to_unless_current(_t("List"), :action => "index")
|
31
|
-
|
32
|
-
return actions
|
33
|
-
end
|
34
|
-
|
35
|
-
def export(klass)
|
36
|
-
klass.typus_export_formats.map do |format|
|
37
|
-
link_to _t("Export as %{format}", :format => format.upcase), params.merge(:format => format)
|
24
|
+
Array.new.tap do |tap|
|
25
|
+
tap << link_to_unless_current(Typus::I18n.t("Add new"), :action => "new") if admin_user.can?("create", klass)
|
26
|
+
tap << link_to_unless_current(Typus::I18n.t("List"), :action => "index")
|
38
27
|
end
|
39
28
|
end
|
40
29
|
|
41
30
|
def custom_actions(klass)
|
42
31
|
klass.typus_actions_on(params[:action]).map do |action|
|
43
|
-
if
|
44
|
-
link_to_unless_current(
|
32
|
+
if admin_user.can?(action, klass)
|
33
|
+
link_to_unless_current(Typus::I18n.t(action.humanize), params.merge(:action => action))
|
45
34
|
end
|
46
35
|
end
|
47
36
|
end
|
48
37
|
|
38
|
+
def export(klass, params = params)
|
39
|
+
klass.typus_export_formats.map do |format|
|
40
|
+
link_to Typus::I18n.t("Export as %{mime}", :mime => format.upcase), params.merge(:format => format)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
49
44
|
end
|
50
45
|
|
51
46
|
end
|
@@ -2,26 +2,27 @@ module Admin
|
|
2
2
|
|
3
3
|
module TableHelper
|
4
4
|
|
5
|
-
def build_table(model, fields, items, link_options = {}, association = nil)
|
5
|
+
def build_table(model, fields, items, link_options = {}, association = nil, association_name = nil)
|
6
6
|
render "admin/helpers/table/table",
|
7
7
|
:model => model,
|
8
8
|
:fields => fields,
|
9
9
|
:items => items,
|
10
10
|
:link_options => link_options,
|
11
|
-
:headers => table_header(model, fields)
|
11
|
+
:headers => table_header(model, fields),
|
12
|
+
:association_name => association_name
|
12
13
|
end
|
13
14
|
|
14
|
-
def table_header(model, fields)
|
15
|
+
def table_header(model, fields, params = params)
|
15
16
|
fields.map do |key, value|
|
16
17
|
|
17
18
|
key = key.gsub(".", " ") if key.match(/\./)
|
18
19
|
content = model.human_attribute_name(key)
|
19
20
|
|
20
|
-
if params[:action]
|
21
|
+
if params[:action].eql?('index') && model.typus_options_for(:sortable)
|
21
22
|
association = model.reflect_on_association(key.to_sym)
|
22
23
|
order_by = association ? association.primary_key_name : key
|
23
24
|
|
24
|
-
if (model.model_fields.map(&:first).
|
25
|
+
if (model.model_fields.map(&:first).map { |i| i.to_s }.include?(key) || model.reflect_on_all_associations(:belongs_to).map(&:name).include?(key.to_sym))
|
25
26
|
sort_order = case params[:sort_order]
|
26
27
|
when 'asc' then ['desc', '↓']
|
27
28
|
when 'desc' then ['asc', '↑']
|
@@ -29,8 +30,8 @@ module Admin
|
|
29
30
|
end
|
30
31
|
switch = sort_order.last if params[:order_by].eql?(order_by)
|
31
32
|
options = { :order_by => order_by, :sort_order => sort_order.first }
|
32
|
-
message = [
|
33
|
-
link_to
|
33
|
+
message = [content, switch].compact.join(" ").html_safe
|
34
|
+
link_to message, params.merge(options)
|
34
35
|
else
|
35
36
|
content
|
36
37
|
end
|
@@ -42,206 +43,114 @@ module Admin
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
def table_fields_for_item(item, fields
|
46
|
-
fields.map
|
47
|
-
case value
|
48
|
-
when :boolean then table_boolean_field(key, item)
|
49
|
-
when :datetime then table_datetime_field(key, item, link_options)
|
50
|
-
when :date then table_datetime_field(key, item, link_options)
|
51
|
-
when :file then table_file_field(key, item, link_options)
|
52
|
-
when :time then table_datetime_field(key, item, link_options)
|
53
|
-
when :belongs_to then table_belongs_to_field(key, item)
|
54
|
-
when :tree then table_tree_field(key, item)
|
55
|
-
when :position then table_position_field(key, item)
|
56
|
-
when :selector then table_selector(key, item)
|
57
|
-
when :transversal then table_transversal(key, item)
|
58
|
-
when :has_and_belongs_to_many then table_has_and_belongs_to_many_field(key, item)
|
59
|
-
else
|
60
|
-
table_string_field(key, item, link_options)
|
61
|
-
end
|
62
|
-
end
|
46
|
+
def table_fields_for_item(item, fields)
|
47
|
+
fields.map { |k, v| send("table_#{v}_field", k, item) }
|
63
48
|
end
|
64
49
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
item.owned_by?(current_user) ? item.class.typus_options_for(:default_action_on_item) : "show"
|
69
|
-
elsif current_user.cannot?("edit", model)
|
70
|
-
'show'
|
71
|
-
else
|
72
|
-
item.class.typus_options_for(:default_action_on_item)
|
73
|
-
end
|
74
|
-
|
75
|
-
options = { :controller => "admin/#{item.class.to_resource}",
|
76
|
-
:action => action,
|
77
|
-
:id => item.id }
|
78
|
-
|
79
|
-
link_to _t(action.capitalize), options
|
80
|
-
end
|
81
|
-
|
82
|
-
#--
|
83
|
-
# This controls the action to perform. If we are on a model list we
|
84
|
-
# will remove the entry, but if we inside a model we will remove the
|
85
|
-
# relationship between the models.
|
86
|
-
#
|
87
|
-
# Only shown is the user can destroy/unrelate items.
|
88
|
-
#++
|
89
|
-
def table_action(model, item)
|
90
|
-
|
91
|
-
condition = true
|
92
|
-
|
93
|
-
case params[:action]
|
94
|
-
when "index"
|
95
|
-
action = "trash"
|
96
|
-
options = { :action => 'destroy', :id => item.id }
|
97
|
-
method = :delete
|
98
|
-
when "edit", "show"
|
99
|
-
action = "unrelate"
|
100
|
-
options = { :action => 'unrelate', :id => params[:id], :resource => model, :resource_id => item.id }
|
101
|
-
end
|
102
|
-
|
103
|
-
title = _t(action.titleize)
|
104
|
-
|
105
|
-
case params[:action]
|
106
|
-
when 'index'
|
107
|
-
condition = if model.typus_user_id? && current_user.is_not_root?
|
108
|
-
item.owned_by?(current_user)
|
109
|
-
elsif (current_user.id.eql?(item.id) && model.eql?(Typus.user_class))
|
110
|
-
false
|
111
|
-
else
|
112
|
-
current_user.can?('destroy', model)
|
113
|
-
end
|
114
|
-
confirm = _t("Remove %{resource}?", :resource => item.class.model_name.human)
|
115
|
-
when 'edit'
|
116
|
-
# If we are editing content, we can relate and unrelate always!
|
117
|
-
confirm = _t("Unrelate %{unrelate_model} from %{unrelate_model_from}?",
|
118
|
-
:unrelate_model => model.model_name.human,
|
119
|
-
:unrelate_model_from => @resource.model_name.human)
|
120
|
-
when 'show'
|
121
|
-
# If we are showing content, we only can relate and unrelate if we are
|
122
|
-
# the owners of the owner record.
|
123
|
-
# If the owner record doesn't have a foreign key (Typus.user_fk) we look
|
124
|
-
# each item to verify the ownership.
|
125
|
-
condition = if @resource.typus_user_id? && current_user.is_not_root?
|
126
|
-
@item.owned_by?(current_user)
|
127
|
-
end
|
128
|
-
confirm = _t("Unrelate %{unrelate_model} from %{unrelate_model_from}?",
|
129
|
-
:unrelate_model => model.model_name.human,
|
130
|
-
:unrelate_model_from => @resource.model_name.human)
|
131
|
-
end
|
132
|
-
|
133
|
-
message = %(<div class="sprite #{action}">#{_t(action.titleize)}</div>)
|
134
|
-
|
135
|
-
if condition
|
136
|
-
link_to raw(message), options, :title => title, :confirm => confirm, :method => method
|
137
|
-
end
|
50
|
+
def actions
|
51
|
+
@actions ||= []
|
52
|
+
end
|
138
53
|
|
54
|
+
def table_actions(model, item, association_name = nil)
|
55
|
+
actions.map do |action|
|
56
|
+
if admin_user.can?(action[:action], model.name)
|
57
|
+
link_to Typus::I18n.t(action[:action_name]),
|
58
|
+
{ :controller => model.to_resource, :action => action[:action], :id => item.id, :resource => action[:resource], :resource_id => action[:resource_id], :association_name => association_name },
|
59
|
+
{ :confirm => action[:confirm], :method => action[:method], :target => "_parent" }
|
60
|
+
end
|
61
|
+
end.compact.join(" / ").html_safe
|
139
62
|
end
|
140
63
|
|
141
64
|
def table_belongs_to_field(attribute, item)
|
142
|
-
att_value = item.send(attribute)
|
143
|
-
content = "—".html_safe
|
144
|
-
|
145
|
-
unless att_value.nil?
|
146
|
-
content = att_value.to_label
|
65
|
+
if att_value = item.send(attribute)
|
147
66
|
action = item.send(attribute).class.typus_options_for(:default_action_on_item)
|
148
|
-
if
|
149
|
-
|
67
|
+
if admin_user.can?(action, att_value.class.name)
|
68
|
+
link_to att_value.to_label, :controller => "/admin/#{att_value.class.to_resource}", :action => action, :id => att_value.id
|
69
|
+
else
|
70
|
+
att_value.to_label
|
150
71
|
end
|
72
|
+
else
|
73
|
+
"—".html_safe
|
151
74
|
end
|
152
|
-
|
153
|
-
return content_tag(:td, content)
|
154
75
|
end
|
155
76
|
|
156
77
|
def table_has_and_belongs_to_many_field(attribute, item)
|
157
|
-
|
158
|
-
return content_tag(:td, content)
|
78
|
+
item.send(attribute).map { |i| i.to_label }.join(", ")
|
159
79
|
end
|
160
80
|
|
161
|
-
|
162
|
-
raw_content = item.send(attribute)
|
163
|
-
content = raw_content.blank? ? "—".html_safe : raw_content
|
164
|
-
return content_tag(:td, content, :class => attribute)
|
165
|
-
end
|
81
|
+
alias :table_has_many_field :table_has_and_belongs_to_many_field
|
166
82
|
|
167
|
-
def
|
168
|
-
raw_content = item.
|
169
|
-
return content_tag(:td, raw_content, :class => attribute)
|
83
|
+
def table_string_field(attribute, item)
|
84
|
+
(raw_content = item.send(attribute)).present? ? truncate(raw_content) : "—".html_safe
|
170
85
|
end
|
171
86
|
|
172
|
-
|
173
|
-
file_preview = Typus.file_preview
|
174
|
-
file_thumbnail = Typus.file_thumbnail
|
87
|
+
alias :table_text_field :table_string_field
|
175
88
|
|
176
|
-
|
177
|
-
|
89
|
+
def table_generic_field(attribute, item)
|
90
|
+
(raw_content = item.send(attribute)).present? ? raw_content : "—".html_safe
|
91
|
+
end
|
178
92
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
:content => item.to_label,
|
184
|
-
:file_preview_is_image => file_preview_is_image,
|
185
|
-
:has_file_preview => has_file_preview,
|
186
|
-
:href => item.send(attribute).url(file_preview),
|
187
|
-
:item => item
|
188
|
-
else
|
189
|
-
link_to item.send(attribute), item.send(attribute).url
|
190
|
-
end
|
93
|
+
alias :table_float_field :table_generic_field
|
94
|
+
alias :table_integer_field :table_generic_field
|
95
|
+
alias :table_decimal_field :table_generic_field
|
96
|
+
alias :table_virtual_field :table_generic_field
|
191
97
|
|
192
|
-
|
98
|
+
def table_selector_field(attribute, item)
|
99
|
+
item.mapping(attribute)
|
100
|
+
end
|
101
|
+
|
102
|
+
def table_file_field(attribute, item)
|
103
|
+
typus_file_preview(item, attribute)
|
193
104
|
end
|
194
105
|
|
195
106
|
def table_tree_field(attribute, item)
|
196
|
-
|
197
|
-
return content_tag(:td, content)
|
107
|
+
item.parent ? item.parent.to_label : "—".html_safe
|
198
108
|
end
|
199
109
|
|
200
|
-
def table_position_field(attribute, item)
|
110
|
+
def table_position_field(attribute, item, connector = " / ")
|
201
111
|
html_position = []
|
202
112
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
113
|
+
[ [:move_to_top, "Top"],
|
114
|
+
[:move_higher, "Up"],
|
115
|
+
[:move_lower, "Down"],
|
116
|
+
[:move_to_bottom, "Bottom"] ].each do |key, value|
|
117
|
+
|
118
|
+
options = { :controller => "/admin/#{item.class.to_resource}", :action => "position", :id => item.id, :go => key }
|
119
|
+
should_be_inactive = (item.respond_to?(:first?) && ([:move_higher, :move_to_top].include?(key) && item.first?)) ||
|
120
|
+
(item.respond_to?(:last?) && ([:move_lower, :move_to_bottom].include?(key) && item.last?))
|
121
|
+
html_position << link_to_unless(should_be_inactive, Typus::I18n.t(value), params.merge(options)) do |name|
|
122
|
+
%w(<span class="inactive">#{name}</span>)
|
208
123
|
end
|
209
124
|
end
|
210
125
|
|
211
|
-
|
212
|
-
return content_tag(:td, content)
|
126
|
+
"#{item.position}<br/><br/>#{html_position.compact.join(connector)}".html_safe
|
213
127
|
end
|
214
128
|
|
215
|
-
def table_datetime_field(attribute, item
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
return content_tag(:td, content)
|
129
|
+
def table_datetime_field(attribute, item)
|
130
|
+
if field = item.send(attribute)
|
131
|
+
I18n.localize(field, :format => item.class.typus_date_format(attribute))
|
132
|
+
end
|
220
133
|
end
|
221
134
|
|
135
|
+
alias :table_date_field :table_datetime_field
|
136
|
+
alias :table_time_field :table_datetime_field
|
137
|
+
|
222
138
|
def table_boolean_field(attribute, item)
|
223
|
-
boolean_hash = item.class.typus_boolean(attribute).invert
|
224
139
|
status = item.send(attribute)
|
140
|
+
boolean_hash = item.class.typus_boolean(attribute).invert
|
141
|
+
human_boolean = status ? boolean_hash["true"] : boolean_hash["false"]
|
142
|
+
|
143
|
+
options = { :controller => "/admin/#{item.class.to_resource}",
|
144
|
+
:action => "toggle",
|
145
|
+
:id => item.id,
|
146
|
+
:field => attribute.gsub(/\?$/, '') }
|
147
|
+
confirm = Typus::I18n.t("Change %{attribute}?", :attribute => item.class.human_attribute_name(attribute).downcase)
|
148
|
+
link_to Typus::I18n.t(human_boolean), options, :confirm => confirm
|
149
|
+
end
|
225
150
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
message = _t(boolean_hash[status.to_s])
|
230
|
-
options = { :controller => "admin/#{item.class.to_resource}",
|
231
|
-
:action => "toggle",
|
232
|
-
:id => item.id,
|
233
|
-
:field => attribute.gsub(/\?$/,'') }
|
234
|
-
confirm = _t("Change %{attribute}?",
|
235
|
-
:attribute => item.class.human_attribute_name(attribute).downcase)
|
236
|
-
link_to message, options, :confirm => confirm
|
237
|
-
end
|
238
|
-
|
239
|
-
return content_tag(:td, content)
|
240
|
-
end
|
241
|
-
|
242
|
-
def table_transversal(attribute, item)
|
243
|
-
_attribute, virtual = attribute.split(".")
|
244
|
-
return content_tag(:td, item.send(_attribute).send(virtual))
|
151
|
+
def table_transversal_field(attribute, item)
|
152
|
+
field_1, field_2 = attribute.split(".")
|
153
|
+
item.send(field_1).send(field_2)
|
245
154
|
end
|
246
155
|
|
247
156
|
end
|