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
data/Gemfile
CHANGED
@@ -1,20 +1,31 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
+
gemspec
|
4
|
+
|
3
5
|
gem "acts_as_list"
|
4
6
|
gem "acts_as_tree"
|
5
|
-
gem "
|
6
|
-
gem "
|
7
|
-
gem "paginator", "1.1.1"
|
7
|
+
gem "dragonfly", "~>0.8.1"
|
8
|
+
gem "factory_girl"
|
8
9
|
|
9
10
|
group :test do
|
10
|
-
gem "capybara"
|
11
|
-
gem "factory_girl"
|
12
11
|
gem "mysql"
|
13
|
-
gem "paperclip"
|
14
12
|
gem "pg"
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
gem "paperclip"
|
18
16
|
|
17
|
+
gem "rack-cache", :require => "rack/cache"
|
18
|
+
gem "rails", "~> 3.0"
|
19
|
+
|
20
|
+
gem 'sqlite3-ruby', '1.2.1'
|
21
|
+
|
22
|
+
# Keep this here because I use it as reference for development.
|
23
|
+
gem "fastercsv", "1.5.3" if RUBY_VERSION < '1.9'
|
24
|
+
gem "render_inheritable"
|
25
|
+
gem "will_paginate", "~> 3.0.pre2"
|
26
|
+
|
27
|
+
group :test do
|
28
|
+
gem "shoulda"
|
29
|
+
gem "tartare", :git => "https://github.com/fesplugas/rails-tartare.git", :require => false
|
19
30
|
gem "mocha"
|
20
31
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,105 +1,129 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/fesplugas/rails-tartare.git
|
3
|
+
revision: 3d74044310943023ec7d218d4c3c8b29c5b8ebed
|
4
|
+
specs:
|
5
|
+
tartare (1.0.0)
|
6
|
+
capybara (>= 0.4.0)
|
7
|
+
rails (>= 3.0.0)
|
8
|
+
|
9
|
+
PATH
|
10
|
+
remote: .
|
11
|
+
specs:
|
12
|
+
typus (3.0.3)
|
13
|
+
fastercsv (= 1.5.3)
|
14
|
+
render_inheritable
|
15
|
+
will_paginate (~> 3.0.pre2)
|
16
|
+
|
1
17
|
GEM
|
2
18
|
remote: http://rubygems.org/
|
3
19
|
specs:
|
4
20
|
abstract (1.0.0)
|
5
|
-
actionmailer (3.0.
|
6
|
-
actionpack (= 3.0.
|
7
|
-
mail (~> 2.2.
|
8
|
-
actionpack (3.0.
|
9
|
-
activemodel (= 3.0.
|
10
|
-
activesupport (= 3.0.
|
21
|
+
actionmailer (3.0.3)
|
22
|
+
actionpack (= 3.0.3)
|
23
|
+
mail (~> 2.2.9)
|
24
|
+
actionpack (3.0.3)
|
25
|
+
activemodel (= 3.0.3)
|
26
|
+
activesupport (= 3.0.3)
|
11
27
|
builder (~> 2.1.2)
|
12
28
|
erubis (~> 2.6.6)
|
13
|
-
i18n (~> 0.4
|
29
|
+
i18n (~> 0.4)
|
14
30
|
rack (~> 1.2.1)
|
15
|
-
rack-mount (~> 0.6.
|
16
|
-
rack-test (~> 0.5.
|
31
|
+
rack-mount (~> 0.6.13)
|
32
|
+
rack-test (~> 0.5.6)
|
17
33
|
tzinfo (~> 0.3.23)
|
18
|
-
activemodel (3.0.
|
19
|
-
activesupport (= 3.0.
|
34
|
+
activemodel (3.0.3)
|
35
|
+
activesupport (= 3.0.3)
|
20
36
|
builder (~> 2.1.2)
|
21
|
-
i18n (~> 0.4
|
22
|
-
activerecord (3.0.
|
23
|
-
activemodel (= 3.0.
|
24
|
-
activesupport (= 3.0.
|
25
|
-
arel (~>
|
37
|
+
i18n (~> 0.4)
|
38
|
+
activerecord (3.0.3)
|
39
|
+
activemodel (= 3.0.3)
|
40
|
+
activesupport (= 3.0.3)
|
41
|
+
arel (~> 2.0.2)
|
26
42
|
tzinfo (~> 0.3.23)
|
27
|
-
activeresource (3.0.
|
28
|
-
activemodel (= 3.0.
|
29
|
-
activesupport (= 3.0.
|
30
|
-
activesupport (3.0.
|
43
|
+
activeresource (3.0.3)
|
44
|
+
activemodel (= 3.0.3)
|
45
|
+
activesupport (= 3.0.3)
|
46
|
+
activesupport (3.0.3)
|
31
47
|
acts_as_list (0.1.2)
|
32
48
|
acts_as_tree (0.1.1)
|
33
|
-
arel (
|
34
|
-
activesupport (~> 3.0.0)
|
49
|
+
arel (2.0.7)
|
35
50
|
builder (2.1.2)
|
36
|
-
capybara (0.
|
51
|
+
capybara (0.4.0)
|
52
|
+
celerity (>= 0.7.9)
|
37
53
|
culerity (>= 0.2.4)
|
38
54
|
mime-types (>= 1.16)
|
39
55
|
nokogiri (>= 1.3.3)
|
40
56
|
rack (>= 1.0.0)
|
41
57
|
rack-test (>= 0.5.4)
|
42
|
-
selenium-webdriver (>= 0.0.
|
43
|
-
|
58
|
+
selenium-webdriver (>= 0.0.27)
|
59
|
+
xpath (~> 0.1.2)
|
60
|
+
celerity (0.8.7)
|
61
|
+
childprocess (0.1.6)
|
62
|
+
ffi (~> 0.6.3)
|
63
|
+
culerity (0.2.14)
|
64
|
+
dragonfly (0.8.2)
|
65
|
+
rack
|
44
66
|
erubis (2.6.6)
|
45
67
|
abstract (>= 1.0.0)
|
46
|
-
factory_girl (1.3.
|
68
|
+
factory_girl (1.3.3)
|
47
69
|
fastercsv (1.5.3)
|
48
70
|
ffi (0.6.3)
|
49
71
|
rake (>= 0.8.7)
|
50
|
-
|
51
|
-
rake (>= 0.8.7)
|
52
|
-
rubyforge (>= 2.0.4)
|
53
|
-
i18n (0.4.1)
|
72
|
+
i18n (0.5.0)
|
54
73
|
json_pure (1.4.6)
|
55
|
-
mail (2.2.
|
74
|
+
mail (2.2.14)
|
56
75
|
activesupport (>= 2.3.6)
|
57
|
-
|
58
|
-
|
76
|
+
i18n (>= 0.4.0)
|
77
|
+
mime-types (~> 1.16)
|
78
|
+
treetop (~> 1.4.8)
|
59
79
|
mime-types (1.16)
|
60
|
-
mocha (0.9.
|
80
|
+
mocha (0.9.10)
|
61
81
|
rake
|
62
82
|
mysql (2.8.1)
|
63
|
-
nokogiri (1.4.
|
64
|
-
|
65
|
-
hoe (>= 1.6.0)
|
66
|
-
paperclip (2.3.3)
|
83
|
+
nokogiri (1.4.4)
|
84
|
+
paperclip (2.3.8)
|
67
85
|
activerecord
|
68
86
|
activesupport
|
69
|
-
pg (0.
|
87
|
+
pg (0.10.0)
|
70
88
|
polyglot (0.3.1)
|
71
89
|
rack (1.2.1)
|
90
|
+
rack-cache (1.0)
|
91
|
+
rack (>= 0.4)
|
72
92
|
rack-mount (0.6.13)
|
73
93
|
rack (>= 1.0.0)
|
74
|
-
rack-test (0.5.
|
94
|
+
rack-test (0.5.7)
|
75
95
|
rack (>= 1.0)
|
76
|
-
rails (3.0.
|
77
|
-
actionmailer (= 3.0.
|
78
|
-
actionpack (= 3.0.
|
79
|
-
activerecord (= 3.0.
|
80
|
-
activeresource (= 3.0.
|
81
|
-
activesupport (= 3.0.
|
82
|
-
bundler (~> 1.0
|
83
|
-
railties (= 3.0.
|
84
|
-
railties (3.0.
|
85
|
-
actionpack (= 3.0.
|
86
|
-
activesupport (= 3.0.
|
87
|
-
rake (>= 0.8.
|
88
|
-
thor (~> 0.14.
|
96
|
+
rails (3.0.3)
|
97
|
+
actionmailer (= 3.0.3)
|
98
|
+
actionpack (= 3.0.3)
|
99
|
+
activerecord (= 3.0.3)
|
100
|
+
activeresource (= 3.0.3)
|
101
|
+
activesupport (= 3.0.3)
|
102
|
+
bundler (~> 1.0)
|
103
|
+
railties (= 3.0.3)
|
104
|
+
railties (3.0.3)
|
105
|
+
actionpack (= 3.0.3)
|
106
|
+
activesupport (= 3.0.3)
|
107
|
+
rake (>= 0.8.7)
|
108
|
+
thor (~> 0.14.4)
|
89
109
|
rake (0.8.7)
|
90
|
-
|
91
|
-
|
110
|
+
render_inheritable (1.0.0)
|
111
|
+
rails (~> 3.0)
|
92
112
|
rubyzip (0.9.4)
|
93
|
-
selenium-webdriver (0.
|
94
|
-
|
113
|
+
selenium-webdriver (0.1.2)
|
114
|
+
childprocess (~> 0.1.5)
|
115
|
+
ffi (~> 0.6.3)
|
95
116
|
json_pure
|
96
117
|
rubyzip
|
97
118
|
shoulda (2.11.3)
|
98
|
-
sqlite3-ruby (1.
|
99
|
-
thor (0.14.
|
100
|
-
treetop (1.4.
|
119
|
+
sqlite3-ruby (1.2.1)
|
120
|
+
thor (0.14.6)
|
121
|
+
treetop (1.4.9)
|
101
122
|
polyglot (>= 0.3.1)
|
102
|
-
tzinfo (0.3.
|
123
|
+
tzinfo (0.3.24)
|
124
|
+
will_paginate (3.0.pre2)
|
125
|
+
xpath (0.1.3)
|
126
|
+
nokogiri (~> 1.3)
|
103
127
|
|
104
128
|
PLATFORMS
|
105
129
|
ruby
|
@@ -107,14 +131,18 @@ PLATFORMS
|
|
107
131
|
DEPENDENCIES
|
108
132
|
acts_as_list
|
109
133
|
acts_as_tree
|
110
|
-
|
134
|
+
dragonfly (~> 0.8.1)
|
111
135
|
factory_girl
|
112
136
|
fastercsv (= 1.5.3)
|
113
137
|
mocha
|
114
138
|
mysql
|
115
|
-
paginator (= 1.1.1)
|
116
139
|
paperclip
|
117
140
|
pg
|
118
|
-
|
141
|
+
rack-cache
|
142
|
+
rails (~> 3.0)
|
143
|
+
render_inheritable
|
119
144
|
shoulda
|
120
|
-
sqlite3-ruby
|
145
|
+
sqlite3-ruby (= 1.2.1)
|
146
|
+
tartare!
|
147
|
+
typus!
|
148
|
+
will_paginate (~> 3.0.pre2)
|
data/MIT-LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Typus: Admin Panel for Ruby on Rails applications
|
2
|
+
|
3
|
+
**Typus** is designed for a single activity:
|
4
|
+
|
5
|
+
Trusted users editing structured content.
|
6
|
+
|
7
|
+
**Typus** doesn't try to be all the things to all the people but it's
|
8
|
+
extensible enough to match lots of use cases.
|
9
|
+
|
10
|
+
## Key Features
|
11
|
+
|
12
|
+
- Built-in Authentication.
|
13
|
+
- User Permissions by using Access Control Lists. (stored in yaml files)
|
14
|
+
- CRUD and custom actions for your models on a clean interface.
|
15
|
+
- Internationalized interface (Català, German, Greek, English, Español,
|
16
|
+
Français, Magyar, Italiano, Portuguese, Russian, 中文)
|
17
|
+
- Customizable and extensible templates.
|
18
|
+
- Integrated [paperclip][1] and [dragonfly][2] attachments viewer.
|
19
|
+
- Low memory footprint.
|
20
|
+
- Works with `Rails 3.0`.
|
21
|
+
- Tested with `Ruby 1.8.7-p300` and `Ruby 1.9.2-p136`.
|
22
|
+
- Tested with SQLite, MySQL and PostgreSQL.
|
23
|
+
- MIT License, the same as Rails.
|
24
|
+
|
25
|
+
## Links
|
26
|
+
|
27
|
+
- [Documentation](http://core.typuscms.com/)
|
28
|
+
- [Demo](http://demo.typuscms.com/) ([Code][3])
|
29
|
+
- [Source Code](http://github.com/fesplugas/typus)
|
30
|
+
- [Mailing List](http://groups.google.com/group/typus)
|
31
|
+
- [Gems](http://rubygems.org/gems/typus)
|
32
|
+
- [Contributors List](http://github.com/fesplugas/typus/contributors)
|
33
|
+
- [Continous Integration](http://ci.typuscms.com/)
|
34
|
+
|
35
|
+
## Installing
|
36
|
+
|
37
|
+
Add **Typus** to your `Gemfile`
|
38
|
+
|
39
|
+
gem 'typus', :git => 'https://github.com/fesplugas/typus.git'
|
40
|
+
|
41
|
+
Update your bundle
|
42
|
+
|
43
|
+
$ bundle install
|
44
|
+
|
45
|
+
Run the generator
|
46
|
+
|
47
|
+
$ rails generate typus
|
48
|
+
|
49
|
+
Start the application server
|
50
|
+
|
51
|
+
$ rails server
|
52
|
+
|
53
|
+
and go to <http://0.0.0.0:3000/admin>.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
Copyright © 2007-2011 Francesc Esplugas, released under the MIT license.
|
58
|
+
|
59
|
+
[1]: http://rubygems.org/gems/paperclip
|
60
|
+
[2]: http://rubygems.org/gems/dragonfly
|
61
|
+
[3]: https://github.com/fesplugas/typus/tree/master/test/fixtures/rails_app
|
data/Rakefile
CHANGED
@@ -3,20 +3,20 @@ class Admin::AccountController < Admin::BaseController
|
|
3
3
|
layout 'admin/session'
|
4
4
|
|
5
5
|
skip_before_filter :reload_config_and_roles
|
6
|
-
skip_before_filter :set_preferences
|
7
6
|
skip_before_filter :authenticate
|
7
|
+
skip_before_filter :set_locale
|
8
8
|
|
9
9
|
before_filter :sign_in?, :except => [:forgot_password, :show]
|
10
10
|
before_filter :new?, :only => [:forgot_password]
|
11
11
|
|
12
12
|
def new
|
13
|
-
flash[:notice] =
|
13
|
+
flash[:notice] = Typus::I18n.t("Enter your email below to create the first user.")
|
14
14
|
end
|
15
15
|
|
16
16
|
def create
|
17
17
|
user = Typus.user_class.generate(:email => params[:typus_user][:email])
|
18
18
|
user.status = true
|
19
|
-
redirect_to
|
19
|
+
redirect_to user.save ? { :action => "show", :id => user.token } : { :action => :new }
|
20
20
|
end
|
21
21
|
|
22
22
|
def forgot_password
|
@@ -25,20 +25,17 @@ class Admin::AccountController < Admin::BaseController
|
|
25
25
|
if user = Typus.user_class.find_by_email(params[:typus_user][:email])
|
26
26
|
url = admin_account_url(user.token)
|
27
27
|
Admin::Mailer.reset_password_link(user, url).deliver
|
28
|
-
notice
|
29
|
-
path = new_admin_session_path
|
28
|
+
redirect_to new_admin_session_path, :notice => Typus::I18n.t("Password recovery link sent to your email.")
|
30
29
|
else
|
31
|
-
render :action => :forgot_password
|
30
|
+
render :action => :forgot_password
|
32
31
|
end
|
33
|
-
|
34
|
-
redirect_to path, :notice => notice
|
35
32
|
end
|
36
33
|
|
37
34
|
def show
|
38
|
-
flash[:notice] =
|
35
|
+
flash[:notice] = Typus::I18n.t("Please set a new password.")
|
39
36
|
typus_user = Typus.user_class.find_by_token!(params[:id])
|
40
37
|
session[:typus_user_id] = typus_user.id
|
41
|
-
redirect_to :controller => "admin/#{Typus.user_class.to_resource}", :action => "edit", :id => typus_user.id
|
38
|
+
redirect_to :controller => "/admin/#{Typus.user_class.to_resource}", :action => "edit", :id => typus_user.id
|
42
39
|
end
|
43
40
|
|
44
41
|
private
|
@@ -1,14 +1,25 @@
|
|
1
1
|
class Admin::BaseController < ActionController::Base
|
2
2
|
|
3
|
+
render_inheritable
|
4
|
+
|
3
5
|
include Typus::Authentication::const_get(Typus.authentication.to_s.classify)
|
4
6
|
|
7
|
+
before_filter :set_models_constantized
|
5
8
|
before_filter :reload_config_and_roles
|
6
9
|
before_filter :authenticate
|
10
|
+
before_filter :set_locale
|
11
|
+
|
12
|
+
helper_method :admin_user
|
7
13
|
|
8
|
-
|
14
|
+
def user_guide
|
15
|
+
end
|
9
16
|
|
10
17
|
protected
|
11
18
|
|
19
|
+
def set_models_constantized
|
20
|
+
Typus::Configuration.models_constantized!
|
21
|
+
end
|
22
|
+
|
12
23
|
def reload_config_and_roles
|
13
24
|
Typus.reload! unless Rails.env.production?
|
14
25
|
end
|
@@ -17,4 +28,8 @@ class Admin::BaseController < ActionController::Base
|
|
17
28
|
@back_to || request.referer || admin_dashboard_path
|
18
29
|
end
|
19
30
|
|
31
|
+
def set_locale
|
32
|
+
I18n.locale = admin_user.locale
|
33
|
+
end
|
34
|
+
|
20
35
|
end
|
@@ -1,56 +1,42 @@
|
|
1
|
-
require "typus/format"
|
2
|
-
|
3
1
|
class Admin::ResourcesController < Admin::BaseController
|
4
2
|
|
3
|
+
include Typus::Actions
|
4
|
+
include Typus::Filters
|
5
5
|
include Typus::Format
|
6
6
|
|
7
7
|
before_filter :get_model
|
8
|
-
|
9
|
-
before_filter :get_object,
|
10
|
-
|
11
|
-
:edit, :update, :destroy, :toggle,
|
12
|
-
:position, :relate, :unrelate,
|
13
|
-
:detach ]
|
14
|
-
|
15
|
-
before_filter :check_resource_ownership,
|
16
|
-
:only => [ :edit, :update, :destroy, :toggle,
|
17
|
-
:position, :relate, :unrelate ]
|
18
|
-
|
19
|
-
before_filter :check_if_user_can_perform_action_on_user,
|
20
|
-
:only => [ :edit, :update, :toggle, :destroy ]
|
8
|
+
before_filter :set_scope
|
9
|
+
before_filter :get_object, :only => [:show, :edit, :update, :destroy, :toggle, :position, :relate, :unrelate, :detach]
|
10
|
+
before_filter :check_resource_ownership, :only => [:edit, :update, :destroy, :toggle, :position, :relate, :unrelate ]
|
21
11
|
before_filter :check_if_user_can_perform_action_on_resources
|
12
|
+
before_filter :set_order, :only => [:index]
|
13
|
+
before_filter :set_fields, :only => [:index, :new, :edit, :create, :update, :show, :detach]
|
22
14
|
|
23
|
-
before_filter :
|
24
|
-
:only => [ :index ]
|
25
|
-
before_filter :set_fields,
|
26
|
-
:only => [ :index, :new, :edit, :create, :update, :show ]
|
15
|
+
before_filter :check_if_we_can_add_a_new_item, :only => [:new, :create]
|
27
16
|
|
28
17
|
##
|
29
18
|
# This is the main index of the model. With filters, conditions and more.
|
30
19
|
#
|
31
|
-
# By default application can
|
20
|
+
# By default application can respond to html, csv and xml, but you can add
|
32
21
|
# your formats.
|
33
22
|
#
|
34
23
|
def index
|
35
|
-
|
36
|
-
|
24
|
+
add_action(:action_name => default_action.titleize, :action => default_action)
|
25
|
+
add_action(:action_name => "Trash", :action => "destroy", :confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete')
|
26
|
+
|
27
|
+
get_objects
|
37
28
|
|
38
29
|
respond_to do |format|
|
39
|
-
format.html { generate_html
|
30
|
+
format.html { generate_html }
|
40
31
|
@resource.typus_export_formats.each { |f| format.send(f) { send("generate_#{f}") } }
|
41
32
|
end
|
42
33
|
end
|
43
34
|
|
44
35
|
def new
|
45
|
-
check_ownership_of_referal_item
|
46
|
-
|
47
36
|
item_params = params.dup
|
48
|
-
rejections = %w(
|
37
|
+
rejections = %w(controller action resource resource_id back_to selected)
|
49
38
|
item_params.delete_if { |k, v| rejections.include?(k) }
|
50
|
-
|
51
39
|
@item = @resource.new(item_params)
|
52
|
-
|
53
|
-
select_template
|
54
40
|
end
|
55
41
|
|
56
42
|
##
|
@@ -63,150 +49,160 @@ class Admin::ResourcesController < Admin::BaseController
|
|
63
49
|
|
64
50
|
set_attributes_on_create
|
65
51
|
|
66
|
-
if @item.
|
67
|
-
|
68
|
-
@item.save
|
69
|
-
redirect_on_success
|
52
|
+
if @item.save
|
53
|
+
params[:back_to] ? create_with_back_to : redirect_on_success
|
70
54
|
else
|
71
|
-
|
55
|
+
render :new
|
72
56
|
end
|
73
57
|
end
|
74
58
|
|
75
59
|
def edit
|
76
|
-
|
60
|
+
add_action(:action_name => default_action.titleize, :action => default_action)
|
61
|
+
add_action(:action_name => "Unrelate", :action => "unrelate", :confirm => "#{Typus::I18n.t("Unrelate")}?", :resource => @resource.model_name, :resource_id => @item.id)
|
77
62
|
end
|
78
63
|
|
79
64
|
def show
|
80
|
-
check_resource_ownership
|
81
|
-
select_template
|
65
|
+
check_resource_ownership if @resource.typus_options_for(:only_user_items)
|
82
66
|
end
|
83
67
|
|
84
68
|
def update
|
85
|
-
|
86
|
-
|
87
|
-
|
69
|
+
respond_to do |format|
|
70
|
+
if @item.update_attributes(params[@object_name])
|
71
|
+
set_attributes_on_update
|
72
|
+
reload_locales
|
73
|
+
format.html { redirect_on_success }
|
74
|
+
format.json { render :json => @item }
|
75
|
+
else
|
76
|
+
format.html { render :edit }
|
77
|
+
format.json { render :json => @item.errors.full_messages }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def detach
|
83
|
+
if @item.update_attributes(params[:attribute] => nil)
|
88
84
|
redirect_on_success
|
89
85
|
else
|
90
|
-
|
86
|
+
render :edit
|
91
87
|
end
|
92
88
|
end
|
93
89
|
|
94
90
|
def destroy
|
95
|
-
@item.destroy
|
96
|
-
|
97
|
-
|
91
|
+
if @item.destroy
|
92
|
+
notice = Typus::I18n.t("%{model} successfully removed.", :model => @resource.model_name.human)
|
93
|
+
else
|
94
|
+
alert = @item.errors.full_messages
|
95
|
+
end
|
96
|
+
redirect_to set_path, :notice => notice, :alert => alert
|
98
97
|
end
|
99
98
|
|
100
99
|
def toggle
|
101
100
|
@item.toggle(params[:field])
|
102
101
|
@item.save!
|
103
102
|
|
104
|
-
notice =
|
105
|
-
:model => @resource.model_name.human,
|
106
|
-
:attribute => params[:field].humanize.downcase)
|
103
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
107
104
|
|
108
|
-
|
105
|
+
respond_to do |format|
|
106
|
+
format.html { redirect_to set_path, :notice => notice }
|
107
|
+
format.json { render :json => @item }
|
108
|
+
end
|
109
109
|
end
|
110
110
|
|
111
111
|
##
|
112
|
-
# Change item position
|
113
|
-
# then move items:
|
112
|
+
# Change item position:
|
114
113
|
#
|
115
114
|
# params[:go] = 'move_to_top'
|
116
115
|
#
|
117
116
|
# Available positions are move_to_top, move_higher, move_lower, move_to_bottom.
|
118
117
|
#
|
118
|
+
# NOTE: Only works if `acts_as_list` is installed.
|
119
|
+
#
|
119
120
|
def position
|
120
121
|
@item.send(params[:go])
|
121
|
-
notice =
|
122
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
122
123
|
redirect_to set_path, :notice => notice
|
123
124
|
end
|
124
125
|
|
125
126
|
##
|
126
|
-
#
|
127
|
-
#
|
127
|
+
# Action to relate models which respond to:
|
128
|
+
#
|
129
|
+
# - has_and_belongs_to_many
|
130
|
+
# - has_many
|
131
|
+
#
|
132
|
+
# For example:
|
133
|
+
#
|
134
|
+
# class Item < ActiveRecord::Base
|
135
|
+
# has_many :line_items
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# class LineItem < ActiveRecord::Base
|
139
|
+
# belongs_to :item
|
140
|
+
# end
|
141
|
+
#
|
142
|
+
# >> related_item = LineItem.find(params[:related][:id])
|
143
|
+
# => ...
|
144
|
+
# >> item = Item.find(params[:id])
|
145
|
+
# => ...
|
146
|
+
# >> item.line_items << related_item
|
147
|
+
# => ...
|
128
148
|
#
|
129
149
|
def relate
|
130
|
-
resource_class = params[:related][:model].
|
131
|
-
|
150
|
+
resource_class = params[:related][:model].typus_constantize
|
151
|
+
association_name = params[:related][:association_name].tableize
|
132
152
|
|
133
|
-
if @item.send(
|
134
|
-
flash[:notice] =
|
135
|
-
:model_a => resource_class.model_name.human,
|
136
|
-
:model_b => @resource.model_name.human)
|
137
|
-
else
|
138
|
-
flash[:alert] = _t("%{model_a} cannot be related to %{model_b}",
|
139
|
-
:model_a => resource_class.model_name.human,
|
140
|
-
:model_b => @resource.model_name.human)
|
153
|
+
if @item.send(association_name) << resource_class.find(params[:related][:id])
|
154
|
+
flash[:notice] = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
141
155
|
end
|
142
156
|
|
143
157
|
redirect_to set_path
|
144
158
|
end
|
145
159
|
|
146
160
|
##
|
147
|
-
#
|
161
|
+
# Action to unrelate models which respond to:
|
162
|
+
#
|
163
|
+
# - has_and_belongs_to_many
|
164
|
+
# - has_many
|
165
|
+
# - has_one
|
148
166
|
#
|
149
167
|
def unrelate
|
150
168
|
|
151
|
-
|
152
|
-
|
153
|
-
|
169
|
+
##
|
170
|
+
# Find the remote object which is named item!
|
171
|
+
#
|
154
172
|
|
155
|
-
|
173
|
+
item_class = params[:resource].typus_constantize
|
174
|
+
item = item_class.find(params[:resource_id])
|
156
175
|
|
157
|
-
|
158
|
-
|
159
|
-
|
176
|
+
##
|
177
|
+
# Detect which kind of relationship there's between both models.
|
178
|
+
#
|
179
|
+
# item respect @item
|
180
|
+
#
|
160
181
|
|
161
|
-
case
|
162
|
-
|
163
|
-
# attribute = resource_tableized.singularize
|
164
|
-
# saved_succesfully = @item.update_attribute attribute, nil
|
165
|
-
when :has_many
|
166
|
-
if options.has_key?(:as) # We are in a polymorphic relationship
|
167
|
-
interface = options[:as]
|
168
|
-
saved_succesfully = resource.update_attributes("#{interface}_type" => nil, "#{interface}_id" => nil)
|
169
|
-
else
|
170
|
-
# We have to verify we can unrelate. For example: A Category which has
|
171
|
-
# many posts and Post validates_presence_of Category should not be removed.
|
172
|
-
attribute = @resource.table_name.singularize
|
173
|
-
saved_succesfully = resource.update_attributes(attribute => nil)
|
174
|
-
end
|
175
|
-
when :has_and_belongs_to_many
|
176
|
-
attribute = resource_tableized
|
177
|
-
saved_succesfully = @item.send(attribute).delete(resource)
|
178
|
-
else
|
179
|
-
saved_succesfully = false
|
180
|
-
end
|
182
|
+
# This is not nil in case of a has_many :through association.
|
183
|
+
association_name = params[:association_name].to_sym unless params[:association_name].blank?
|
181
184
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
185
|
+
case item_class.relationship_with(@resource)
|
186
|
+
when :has_one
|
187
|
+
association_name = @resource.model_name.downcase.to_sym
|
188
|
+
worked = item.send(association_name).delete
|
186
189
|
else
|
187
|
-
|
188
|
-
|
189
|
-
:model_b => @resource.model_name.human)
|
190
|
+
association_name ||= @resource.model_name.tableize.to_sym
|
191
|
+
worked = item.send(association_name).delete(@item)
|
190
192
|
end
|
191
193
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
##
|
197
|
-
# Remove file attachments.
|
198
|
-
#
|
199
|
-
def detach
|
200
|
-
message = if @item.update_attributes(params[:attachment] => nil)
|
201
|
-
"%{attachment} removed."
|
202
|
-
else
|
203
|
-
"%{attachment} can't be removed."
|
204
|
-
end
|
194
|
+
##
|
195
|
+
# Finally delete the associated object. Depending on your models setup
|
196
|
+
# associated models will be removed or foreign_key will be set to nil.
|
197
|
+
#
|
205
198
|
|
206
|
-
|
207
|
-
|
199
|
+
if worked
|
200
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
201
|
+
else
|
202
|
+
alert = item.error.full_messages
|
203
|
+
end
|
208
204
|
|
209
|
-
redirect_to set_path, :notice => notice
|
205
|
+
redirect_to set_path, :notice => notice, :alert => alert
|
210
206
|
end
|
211
207
|
|
212
208
|
private
|
@@ -216,23 +212,39 @@ class Admin::ResourcesController < Admin::BaseController
|
|
216
212
|
@object_name = ActiveModel::Naming.singular(@resource)
|
217
213
|
end
|
218
214
|
|
215
|
+
def set_scope
|
216
|
+
@resource = @resource.unscoped
|
217
|
+
end
|
218
|
+
|
219
219
|
def get_object
|
220
220
|
@item = @resource.find(params[:id])
|
221
221
|
end
|
222
222
|
|
223
|
-
def
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
223
|
+
def get_objects
|
224
|
+
eager_loading = @resource.reflect_on_all_associations(:belongs_to).reject { |i| i.options[:polymorphic] }.map { |i| i.name }
|
225
|
+
|
226
|
+
@resource.build_conditions(params).each do |condition|
|
227
|
+
@resource = @resource.where(condition)
|
228
|
+
end
|
229
|
+
|
230
|
+
@resource.build_joins(params).each do |join|
|
231
|
+
@resource = @resource.joins(join)
|
232
|
+
end
|
229
233
|
|
230
|
-
|
234
|
+
if @resource.typus_options_for(:only_user_items)
|
235
|
+
check_resources_ownership
|
236
|
+
end
|
237
|
+
|
238
|
+
@items = @resource.order(set_order).includes(eager_loading)
|
239
|
+
end
|
240
|
+
|
241
|
+
def set_fields
|
242
|
+
@fields = @resource.typus_fields_for(params[:action].action_mapper)
|
231
243
|
end
|
232
244
|
|
233
245
|
def set_order
|
234
246
|
params[:sort_order] ||= "desc"
|
235
|
-
|
247
|
+
params[:order_by] ? "#{@resource.table_name}.#{params[:order_by]} #{params[:sort_order]}" : @resource.typus_order_by
|
236
248
|
end
|
237
249
|
|
238
250
|
def redirect_on_success
|
@@ -242,64 +254,163 @@ class Admin::ResourcesController < Admin::BaseController
|
|
242
254
|
when "create"
|
243
255
|
path = { :action => action }
|
244
256
|
path.merge!(:id => @item.id) unless action.eql?("index")
|
245
|
-
notice =
|
246
|
-
when "update"
|
257
|
+
notice = Typus::I18n.t("%{model} successfully created.", :model => @resource.model_name.human)
|
258
|
+
when "update", "detach"
|
247
259
|
path = case action
|
248
260
|
when "index"
|
249
261
|
params[:back_to] ? "#{params[:back_to]}##{@resource.to_resource}" : { :action => action }
|
250
262
|
else
|
251
|
-
{ :action => action,
|
252
|
-
:id => @item.id,
|
253
|
-
:back_to => params[:back_to] }
|
263
|
+
{ :action => action, :id => @item.id, :back_to => params[:back_to] }
|
254
264
|
end
|
255
|
-
notice =
|
265
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
256
266
|
end
|
257
267
|
|
258
268
|
redirect_to path, :notice => notice
|
259
269
|
end
|
260
270
|
|
261
271
|
##
|
262
|
-
#
|
272
|
+
# Here what we basically do is to associate objects after they have been
|
273
|
+
# created. It's similar to calling `relate`.
|
263
274
|
#
|
264
|
-
#
|
265
|
-
#
|
275
|
+
# We have two objects:
|
276
|
+
#
|
277
|
+
# - @item: Which is the create object.
|
278
|
+
# - item: Which is the object which be associated to.
|
279
|
+
#
|
280
|
+
# http://0.0.0.0:3000/admin/entries/new?back_to=%2Fadmin%2Fcategories%2Fedit%2F3&resource=categories&resource_id=3
|
266
281
|
#
|
267
282
|
def create_with_back_to
|
268
283
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
284
|
+
#
|
285
|
+
# Find the remote object which is named item!
|
286
|
+
#
|
287
|
+
|
288
|
+
item_class = params[:resource].typus_constantize
|
289
|
+
item = item_class.find(params[:resource_id]) if params[:resource_id]
|
290
|
+
|
291
|
+
##
|
292
|
+
# Detect which kind of relationship there's between both models.
|
293
|
+
#
|
294
|
+
|
295
|
+
##
|
296
|
+
# Here we have something like:
|
297
|
+
#
|
298
|
+
# Eg 1.
|
299
|
+
#
|
300
|
+
# - We are editing an Order and want to add a new Invoice.
|
301
|
+
# - Click on "Add New" and we are redirected to the form.
|
302
|
+
# - We want to know which kind of relationship there's between both
|
303
|
+
# objects.
|
304
|
+
#
|
305
|
+
# >> Order.relationship_with(Invoice)
|
306
|
+
# => :has_one
|
307
|
+
#
|
308
|
+
# Eg 2.
|
309
|
+
#
|
310
|
+
# - We are editing a Entry and want to add a new Attachment.
|
311
|
+
# - Click on "Add New" and we are redirected to the form.
|
312
|
+
# - We want to know which kind of relationship there's between both
|
313
|
+
# objects.
|
314
|
+
#
|
315
|
+
# >> Entry.relationship_with(Attachment)
|
316
|
+
# => :has_and_belongs_to_many
|
317
|
+
#
|
318
|
+
# Eg 3.
|
319
|
+
#
|
320
|
+
# - We are editing a Entry and want to add a new Comment.
|
321
|
+
# - Click on "Add New" and we are redirected to the form.
|
322
|
+
# - We want to know which kind of relationship there's between both
|
323
|
+
# objects.
|
324
|
+
#
|
325
|
+
# >> Entry.relationship_with(Comment)
|
326
|
+
# => :has_many
|
327
|
+
#
|
328
|
+
# Eg 4.
|
329
|
+
#
|
330
|
+
# - We are editing a Post (Entry) and want to add a new Attachment.
|
331
|
+
# - Click on "Add New" and we are redirected to the form.
|
332
|
+
# - We want to know which kind of relationship there's between both
|
333
|
+
# objects.
|
334
|
+
#
|
335
|
+
# >> Post.relationship_with(Attachment)
|
336
|
+
# => :has_and_belongs_to_many
|
337
|
+
#
|
338
|
+
|
339
|
+
case item_class.relationship_with(@resource)
|
340
|
+
when :has_one
|
341
|
+
# Order#invoice = @item
|
342
|
+
association_name = @resource.model_name.downcase.to_sym
|
343
|
+
item.send("#{association_name}=", @item)
|
344
|
+
worked = true
|
281
345
|
when :has_and_belongs_to_many
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
346
|
+
# Attachment#entries.push(item)
|
347
|
+
association_name = @resource.model_name.tableize.to_sym
|
348
|
+
worked = item.send(association_name).push(@item)
|
349
|
+
when :belongs_to
|
350
|
+
# Entry#comments.push(item)
|
351
|
+
association_name = item_class.model_name.tableize.to_sym
|
352
|
+
if item
|
353
|
+
worked = @item.send(association_name).push(item)
|
354
|
+
end
|
290
355
|
end
|
291
356
|
|
292
|
-
|
293
|
-
|
294
|
-
|
357
|
+
association = @resource.reflect_on_association(association_name)
|
358
|
+
|
359
|
+
##
|
360
|
+
# Set @back_to
|
361
|
+
#
|
362
|
+
|
363
|
+
@back_to = if item
|
364
|
+
params[:back_to]
|
365
|
+
else
|
366
|
+
"#{params[:back_to]}?#{association.primary_key_name}=#{@item.id}"
|
367
|
+
end
|
368
|
+
|
369
|
+
##
|
370
|
+
# Finally delete the associated object. Depending on your models setup
|
371
|
+
# associated models will be removed or foreign_key will be set to nil.
|
372
|
+
#
|
373
|
+
|
374
|
+
if item
|
375
|
+
if worked
|
376
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
377
|
+
else
|
378
|
+
alert = @item.error.full_messages
|
379
|
+
end
|
380
|
+
end
|
295
381
|
|
296
|
-
redirect_to
|
382
|
+
redirect_to set_path, :notice => notice, :alert => alert
|
383
|
+
end
|
297
384
|
|
385
|
+
def default_action
|
386
|
+
@resource.typus_options_for(:default_action_on_item)
|
298
387
|
end
|
299
388
|
|
300
|
-
|
301
|
-
|
302
|
-
|
389
|
+
##
|
390
|
+
# If we are trying to create a new Invoice which belongs_to Order, we should
|
391
|
+
# verify before the the Order doesn't have an Invoice, otherwise we would
|
392
|
+
# have and Order with many Invoices which is something not desired.
|
393
|
+
#
|
394
|
+
# Eg:
|
395
|
+
#
|
396
|
+
# @resource (Invoice)
|
397
|
+
# params[:resource] = "Order"
|
398
|
+
# params[:resource_id] = "1"
|
399
|
+
#
|
400
|
+
# Does this Order already has an Invoice. If true, redirect to back.
|
401
|
+
#
|
402
|
+
def check_if_we_can_add_a_new_item
|
403
|
+
if params[:resource] && params[:resource_id]
|
404
|
+
item_class = params[:resource].typus_constantize
|
405
|
+
item = item_class.find(params[:resource_id]) if params[:resource_id]
|
406
|
+
|
407
|
+
if item_class.relationship_with(@resource) == :has_one
|
408
|
+
association_name = @resource.model_name.downcase.to_sym
|
409
|
+
if item.send(association_name)
|
410
|
+
render :text => "Not allowed!", :status => :unprocessable_entity
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
303
414
|
end
|
304
415
|
|
305
|
-
end
|
416
|
+
end
|