zen 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +15 -0
- data/.mailmap +2 -0
- data/.rvmrc +2 -0
- data/.travis.yml +8 -3
- data/AUTHORS +1 -2
- data/CHANGELOG.md +48 -17
- data/README.md +44 -39
- data/Rakefile +4 -0
- data/bin/zen +5 -30
- data/lib/zen.rb +13 -19
- data/lib/zen/asset.rb +99 -64
- data/lib/zen/bin/create.rb +94 -0
- data/lib/zen/bin/runner.rb +118 -0
- data/lib/zen/controller/admin_controller.rb +52 -36
- data/lib/zen/controller/base_controller.rb +5 -5
- data/lib/zen/controller/frontend_controller.rb +7 -7
- data/lib/zen/controller/main_controller.rb +12 -10
- data/lib/zen/controller/preview.rb +15 -11
- data/lib/zen/helper/acl.rb +73 -53
- data/lib/zen/helper/blue_form_vendor.rb +689 -0
- data/lib/zen/helper/breadcrumb.rb +23 -19
- data/lib/zen/helper/message.rb +3 -3
- data/lib/zen/helper/theme.rb +18 -13
- data/lib/zen/language.rb +62 -58
- data/lib/zen/language/en/zen_general.yml +2 -4
- data/lib/zen/language/nl/zen_general.yml +2 -4
- data/lib/zen/layout/admin.xhtml +3 -12
- data/lib/zen/layout/login.xhtml +1 -6
- data/lib/zen/model/methods.rb +6 -6
- data/lib/zen/model/settings.rb +5 -4
- data/lib/zen/package.rb +47 -38
- data/lib/zen/package/all.rb +3 -5
- data/lib/zen/package/base.rb +7 -7
- data/lib/zen/package/categories/lib/categories.rb +8 -3
- data/lib/zen/package/categories/lib/categories/controller/categories.rb +81 -55
- data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -44
- data/lib/zen/package/categories/lib/categories/helper/category.rb +88 -0
- data/lib/zen/package/categories/lib/categories/language/en/categories.yml +5 -4
- data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +5 -4
- data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +5 -4
- data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +5 -4
- data/lib/zen/package/categories/lib/categories/model/category.rb +15 -13
- data/lib/zen/package/categories/lib/categories/model/category_group.rb +3 -3
- data/lib/zen/package/categories/lib/categories/plugin/categories.rb +36 -25
- data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +49 -56
- data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +48 -35
- data/lib/zen/package/categories/lib/categories/view/admin/category-groups/form.xhtml +36 -29
- data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +42 -37
- data/lib/zen/package/comments/lib/comments.rb +4 -1
- data/lib/zen/package/comments/lib/comments/controller/comments.rb +39 -32
- data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +45 -26
- data/lib/zen/package/comments/lib/comments/helper/comment.rb +35 -0
- data/lib/zen/package/comments/lib/comments/language/en/comments.yml +9 -7
- data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +10 -8
- data/lib/zen/package/comments/lib/comments/model/comment.rb +31 -17
- data/lib/zen/package/comments/lib/comments/model/comment_status.rb +15 -0
- data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +27 -18
- data/lib/zen/package/comments/lib/comments/plugin/comments.rb +25 -20
- data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +61 -54
- data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +38 -23
- data/lib/zen/package/comments/migrations/1308774099_comment_status.rb +60 -0
- data/lib/zen/package/custom_fields/lib/custom_fields.rb +33 -7
- data/lib/zen/package/custom_fields/lib/custom_fields/blue_form_parameters.rb +209 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +50 -47
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_types.rb +215 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +111 -73
- data/lib/zen/package/custom_fields/lib/custom_fields/helper/custom_field.rb +79 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_groups.yml +20 -19
- data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_types.yml +40 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +34 -32
- data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +5 -4
- data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_types.yml +40 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +18 -16
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +31 -11
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_method.rb +15 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb +50 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +28 -7
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/form.xhtml +33 -28
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +48 -46
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/form.xhtml +61 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/index.xhtml +93 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +105 -99
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +43 -39
- data/lib/zen/package/custom_fields/migrations/1295255665_create_schema.rb +47 -16
- data/lib/zen/package/custom_fields/migrations/1310659580_custom_field_types.rb +148 -0
- data/lib/zen/package/custom_fields/migrations/1311694920_rename_css_class.rb +11 -0
- data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +40 -35
- data/lib/zen/package/menus/lib/menus/controller/menus.rb +47 -43
- data/lib/zen/package/menus/lib/menus/helper/{menu_item.rb → menu.rb} +42 -15
- data/lib/zen/package/menus/lib/menus/language/en/menu_items.yml +5 -5
- data/lib/zen/package/menus/lib/menus/language/en/menus.yml +9 -8
- data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +8 -8
- data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +11 -10
- data/lib/zen/package/menus/lib/menus/model/menu.rb +5 -5
- data/lib/zen/package/menus/lib/menus/model/menu_item.rb +6 -5
- data/lib/zen/package/menus/lib/menus/plugin/menus.rb +41 -43
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +59 -63
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +35 -30
- data/lib/zen/package/menus/lib/menus/view/admin/menus/form.xhtml +46 -37
- data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +37 -37
- data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +5 -5
- data/lib/zen/package/menus/migrations/1308671733_rename_order_column.rb +11 -0
- data/lib/zen/package/menus/migrations/1311695030_rename_css_class.rb +17 -0
- data/lib/zen/package/sections/lib/sections.rb +18 -11
- data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +115 -109
- data/lib/zen/package/sections/lib/sections/controller/sections.rb +72 -50
- data/lib/zen/package/sections/lib/sections/helper/section.rb +53 -0
- data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +5 -4
- data/lib/zen/package/sections/lib/sections/language/en/sections.yml +5 -4
- data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +5 -4
- data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +5 -4
- data/lib/zen/package/sections/lib/sections/model/section.rb +17 -9
- data/lib/zen/package/sections/lib/sections/model/section_entry.rb +192 -13
- data/lib/zen/package/sections/lib/sections/model/section_entry_status.rb +13 -0
- data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +60 -39
- data/lib/zen/package/sections/lib/sections/plugin/sections.rb +14 -11
- data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +100 -97
- data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +41 -39
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +95 -215
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +48 -40
- data/lib/zen/package/sections/migrations/1308672298_use_id_for_default_section.rb +40 -0
- data/lib/zen/package/sections/migrations/1308813320_section_entry_statuses.rb +58 -0
- data/lib/zen/package/settings/lib/settings/controller/settings.rb +5 -8
- data/lib/zen/package/settings/lib/settings/model/setting.rb +2 -37
- data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +18 -1
- data/lib/zen/package/settings/lib/settings/plugin/settings.rb +13 -7
- data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +2 -1
- data/lib/zen/package/users/lib/users.rb +3 -1
- data/lib/zen/package/users/lib/users/controller/access_rules.rb +77 -60
- data/lib/zen/package/users/lib/users/controller/user_groups.rb +41 -36
- data/lib/zen/package/users/lib/users/controller/users.rb +48 -42
- data/lib/zen/package/users/lib/users/helper/users.rb +72 -0
- data/lib/zen/package/users/lib/users/language/en/access_rules.yml +6 -5
- data/lib/zen/package/users/lib/users/language/en/user_groups.yml +5 -4
- data/lib/zen/package/users/lib/users/language/en/users.yml +1 -0
- data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +5 -4
- data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +5 -4
- data/lib/zen/package/users/lib/users/language/nl/users.yml +1 -0
- data/lib/zen/package/users/lib/users/model/access_rule.rb +5 -1
- data/lib/zen/package/users/lib/users/model/user.rb +17 -10
- data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +10 -37
- data/lib/zen/package/users/lib/users/public/admin/js/users/lib/access_rules.js +49 -0
- data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +105 -96
- data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +48 -41
- data/lib/zen/package/users/lib/users/view/admin/user-groups/form.xhtml +42 -32
- data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +43 -38
- data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +76 -67
- data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +43 -41
- data/lib/zen/package/users/lib/users/view/admin/users/login.xhtml +12 -9
- data/lib/zen/package/users/migrations/1295281013_create_schema.rb +2 -2
- data/lib/zen/plugin.rb +56 -50
- data/lib/zen/plugin/markup/lib/markup/markup.rb +33 -21
- data/lib/zen/public/admin/css/zen/buttons.css +11 -7
- data/lib/zen/public/admin/css/zen/datepicker.css +6 -6
- data/lib/zen/public/admin/css/zen/forms.css +2 -1
- data/lib/zen/public/admin/css/zen/general.css +15 -10
- data/lib/zen/public/admin/css/zen/layout.css +51 -20
- data/lib/zen/public/admin/css/zen/tables.css +39 -11
- data/lib/zen/public/admin/css/zen/tabs.css +6 -4
- data/lib/zen/public/admin/css/zen/window.css +11 -11
- data/lib/zen/public/{favicon.ico → admin/favicon.ico} +0 -0
- data/lib/zen/public/admin/images/zen/icons/asc.png +0 -0
- data/lib/zen/public/admin/images/zen/icons/desc.png +0 -0
- data/lib/zen/public/admin/js/vendor/datepicker.js +0 -11
- data/lib/zen/public/admin/js/{mootools → vendor/mootools}/core.js +0 -1
- data/lib/zen/public/admin/js/{mootools → vendor/mootools}/more.js +100 -29
- data/lib/zen/public/admin/js/zen/index.js +48 -0
- data/lib/zen/public/admin/js/zen/lib/asset.js +111 -0
- data/lib/zen/public/admin/js/zen/{editor.js → lib/editor.js} +107 -127
- data/lib/zen/public/admin/js/zen/{editor → lib/editor}/markdown.js +7 -9
- data/lib/zen/public/admin/js/zen/{editor → lib/editor}/textile.js +7 -9
- data/lib/zen/public/admin/js/zen/lib/html_table.js +143 -0
- data/lib/zen/public/admin/js/zen/{tabs.js → lib/tabs.js} +40 -37
- data/lib/zen/public/admin/js/zen/{window.js → lib/window.js} +24 -20
- data/lib/zen/spec/bacon/color_output.rb +39 -0
- data/lib/zen/spec/helper.rb +152 -0
- data/lib/zen/spec/simplecov.rb +22 -0
- data/lib/zen/task/build.rake +20 -43
- data/lib/zen/task/clean.rake +2 -6
- data/lib/zen/task/db.rake +8 -12
- data/lib/zen/task/package.rake +4 -10
- data/lib/zen/task/plugin.rake +3 -9
- data/lib/zen/task/proto.rake +0 -62
- data/lib/zen/task/test.rake +6 -3
- data/lib/zen/task/theme.rake +4 -11
- data/lib/zen/theme.rb +22 -24
- data/lib/zen/validation.rb +34 -27
- data/lib/zen/version.rb +2 -8
- data/lib/zen/view/head.xhtml +7 -0
- data/lib/zen/view/main.xhtml +7 -22
- data/{proto/package/migrations → pkg}/.gitkeep +0 -0
- data/proto/app/app.rb +1 -0
- data/proto/app/config/config.rb +5 -4
- data/proto/app/config/database.rb +19 -41
- data/proto/app/config/middlewares.rb +32 -29
- data/proto/{package/lib/package/view/admin/package/index.xhtml → app/log/database/dev/.gitkeep} +0 -0
- data/proto/app/log/database/live/.gitkeep +0 -0
- data/spec/Rakefile +26 -0
- data/spec/fixtures/zen/asset.rb +18 -0
- data/spec/fixtures/zen/helper/acl.rb +39 -0
- data/spec/fixtures/zen/helper/message.rb +19 -0
- data/spec/fixtures/zen/language/en/spec.yml +10 -0
- data/spec/fixtures/zen/language/nl/spec.yml +7 -0
- data/spec/fixtures/zen/package.rb +17 -0
- data/spec/fixtures/zen/package/comments/controller/comments_form.rb +27 -0
- data/spec/fixtures/zen/package/settings/plugin/settings.rb +20 -0
- data/spec/fixtures/zen/plugin.rb +7 -0
- data/spec/fixtures/zen/theme/404.xhtml +1 -0
- data/spec/fixtures/zen/theme/default-section/index.xhtml +1 -0
- data/spec/fixtures/zen/theme/helper/404.xhtml +1 -0
- data/spec/fixtures/zen/theme/helper/partial.xhtml +1 -0
- data/spec/fixtures/zen/theme/helper/wrong_partial.xhtml +1 -0
- data/spec/fixtures/zen/theme/partials/partial.xhtml +1 -0
- data/spec/fixtures/zen/theme/theme.rb +11 -0
- data/spec/fixtures/zen/validation.rb +22 -0
- data/spec/helper.rb +41 -0
- data/spec/zen/all.rb +5 -0
- data/spec/zen/asset.rb +97 -0
- data/spec/zen/bin/create.rb +89 -0
- data/spec/zen/bin/runner.rb +47 -0
- data/spec/zen/controller/admin_controller.rb +26 -0
- data/spec/zen/controller/main_controller.rb +81 -0
- data/spec/zen/controller/preview.rb +33 -0
- data/spec/zen/helper/acl.rb +149 -0
- data/spec/zen/helper/breadcrumb.rb +38 -0
- data/spec/zen/helper/message.rb +31 -0
- data/spec/zen/helper/theme.rb +58 -0
- data/spec/zen/language.rb +55 -0
- data/spec/zen/package.rb +23 -0
- data/spec/zen/package/categories/controller/categories.rb +123 -0
- data/spec/zen/package/categories/controller/category_groups.rb +108 -0
- data/spec/zen/package/categories/helper/category.rb +75 -0
- data/spec/zen/package/categories/plugin/categories.rb +92 -0
- data/spec/zen/package/comments/controller/comments.rb +134 -0
- data/spec/zen/package/comments/controller/comments_form.rb +343 -0
- data/spec/zen/package/comments/helper/comment.rb +47 -0
- data/spec/zen/package/comments/plugin/anti_spam.rb +59 -0
- data/spec/zen/package/comments/plugin/comments.rb +107 -0
- data/spec/zen/package/custom_fields/blue_form_parameters.rb +183 -0
- data/spec/zen/package/custom_fields/controller/custom_field_groups.rb +120 -0
- data/spec/zen/package/custom_fields/controller/custom_field_types.rb +169 -0
- data/spec/zen/package/custom_fields/controller/custom_fields.rb +158 -0
- data/spec/zen/package/custom_fields/helper/custom_field.rb +86 -0
- data/spec/zen/package/menus/controller/menu_items.rb +110 -0
- data/spec/zen/package/menus/controller/menus.rb +110 -0
- data/spec/zen/package/menus/helper/menu.rb +75 -0
- data/spec/zen/package/menus/plugin/menus.rb +120 -0
- data/spec/zen/package/sections/controller/section_entries.rb +201 -0
- data/spec/zen/package/sections/controller/sections.rb +116 -0
- data/spec/zen/package/sections/helper/section.rb +74 -0
- data/spec/zen/package/sections/plugin/section_entries.rb +161 -0
- data/spec/zen/package/sections/plugin/sections.rb +75 -0
- data/spec/zen/package/settings/controller/settings.rb +36 -0
- data/spec/zen/package/settings/plugin/settings.rb +33 -0
- data/spec/zen/package/users/controller/access_rules.rb +90 -0
- data/spec/zen/package/users/controller/user_groups.rb +101 -0
- data/spec/zen/package/users/controller/users.rb +130 -0
- data/spec/zen/package/users/helper/users.rb +97 -0
- data/spec/zen/plugin.rb +64 -0
- data/spec/zen/plugin/helper.rb +11 -0
- data/spec/zen/plugin/markup.rb +44 -0
- data/spec/zen/theme.rb +41 -0
- data/spec/zen/validation.rb +63 -0
- data/zen.gemspec +36 -0
- metadata +159 -113
- data/MANIFEST +0 -266
- data/lib/zen/bin/app.rb +0 -40
- data/lib/zen/ext/string.rb +0 -185
- data/lib/zen/helper/common.rb +0 -106
- data/lib/zen/package/categories/lib/categories/view/admin/categories/edit.xhtml +0 -7
- data/lib/zen/package/categories/lib/categories/view/admin/categories/new.xhtml +0 -7
- data/lib/zen/package/categories/lib/categories/view/admin/category-groups/edit.xhtml +0 -7
- data/lib/zen/package/categories/lib/categories/view/admin/category-groups/new.xhtml +0 -7
- data/lib/zen/package/comments/lib/comments/view/admin/comments/edit.xhtml +0 -7
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/edit.xhtml +0 -7
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/new.xhtml +0 -7
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/edit.xhtml +0 -7
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/new.xhtml +0 -7
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/edit.xhtml +0 -7
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/new.xhtml +0 -7
- data/lib/zen/package/menus/lib/menus/view/admin/menus/edit.xhtml +0 -7
- data/lib/zen/package/menus/lib/menus/view/admin/menus/new.xhtml +0 -7
- data/lib/zen/package/sections/lib/sections/view/admin/edit.xhtml +0 -7
- data/lib/zen/package/sections/lib/sections/view/admin/new.xhtml +0 -7
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/edit.xhtml +0 -7
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/new.xhtml +0 -7
- data/lib/zen/package/users/lib/users/view/admin/access-rules/edit.xhtml +0 -7
- data/lib/zen/package/users/lib/users/view/admin/access-rules/new.xhtml +0 -7
- data/lib/zen/package/users/lib/users/view/admin/user-groups/edit.xhtml +0 -7
- data/lib/zen/package/users/lib/users/view/admin/user-groups/new.xhtml +0 -7
- data/lib/zen/package/users/lib/users/view/admin/users/edit.xhtml +0 -7
- data/lib/zen/package/users/lib/users/view/admin/users/new.xhtml +0 -7
- data/lib/zen/plugin/controller.rb +0 -59
- data/lib/zen/public/admin/css/zen/notifications.css +0 -84
- data/lib/zen/public/admin/images/zen/icons/large/error.png +0 -0
- data/lib/zen/public/admin/images/zen/icons/large/notice.png +0 -0
- data/lib/zen/public/admin/images/zen/icons/large/success.png +0 -0
- data/lib/zen/public/admin/js/zen/core.js +0 -73
- data/lib/zen/public/admin/js/zen/init.js +0 -80
- data/proto/package/lib/package.rb +0 -21
- data/proto/package/lib/package/controller/controllers.rb +0 -50
- data/proto/package/lib/package/language/en/languages.yml +0 -4
- data/proto/package/lib/package/model/model.rb +0 -12
|
@@ -3,10 +3,10 @@ module Sections
|
|
|
3
3
|
#:nodoc:
|
|
4
4
|
module Controller
|
|
5
5
|
##
|
|
6
|
-
# Sections can be seen as mini applications inside your website.
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
6
|
+
# Sections can be seen as mini applications inside your website. Examples
|
|
7
|
+
# of sections can be a blog, pages, a products listing, etc. Before being
|
|
8
|
+
# able to properly add section entries you need to assign the following data
|
|
9
|
+
# to a section:
|
|
10
10
|
#
|
|
11
11
|
# * a category group
|
|
12
12
|
# * a custom field group
|
|
@@ -17,10 +17,11 @@ module Sections
|
|
|
17
17
|
class Sections < Zen::Controller::AdminController
|
|
18
18
|
include ::Sections::Model
|
|
19
19
|
|
|
20
|
-
map
|
|
20
|
+
map '/admin'
|
|
21
|
+
helper :section
|
|
21
22
|
|
|
22
23
|
# Load all required Javascript files
|
|
23
|
-
javascript
|
|
24
|
+
javascript(['zen/lib/tabs'], :method => [:edit, :new])
|
|
24
25
|
|
|
25
26
|
before_all do
|
|
26
27
|
csrf_protection(:save, :delete) do
|
|
@@ -29,8 +30,8 @@ module Sections
|
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
##
|
|
32
|
-
# Constructor method, called upon initialization. It's used to set the
|
|
33
|
-
#
|
|
33
|
+
# Constructor method, called upon initialization. It's used to set the URL
|
|
34
|
+
# to which forms send their data and load the language pack.
|
|
34
35
|
#
|
|
35
36
|
# This method loads the following language files:
|
|
36
37
|
#
|
|
@@ -42,9 +43,6 @@ module Sections
|
|
|
42
43
|
def initialize
|
|
43
44
|
super
|
|
44
45
|
|
|
45
|
-
@form_save_url = Sections.r(:save)
|
|
46
|
-
@form_delete_url = Sections.r(:delete)
|
|
47
|
-
|
|
48
46
|
Zen::Language.load('sections')
|
|
49
47
|
|
|
50
48
|
# Set the page title
|
|
@@ -52,6 +50,11 @@ module Sections
|
|
|
52
50
|
method = action.method.to_sym
|
|
53
51
|
@page_title = lang("sections.titles.#{method}") rescue nil
|
|
54
52
|
end
|
|
53
|
+
|
|
54
|
+
@boolean_hash = {
|
|
55
|
+
true => lang('zen_general.special.boolean_hash.true'),
|
|
56
|
+
false => lang('zen_general.special.boolean_hash.false')
|
|
57
|
+
}
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
##
|
|
@@ -66,13 +69,25 @@ module Sections
|
|
|
66
69
|
# @since 0.1
|
|
67
70
|
#
|
|
68
71
|
def index
|
|
69
|
-
|
|
70
|
-
respond(lang('zen_general.errors.not_authorized'), 403)
|
|
71
|
-
end
|
|
72
|
+
require_permissions(:read)
|
|
72
73
|
|
|
73
74
|
set_breadcrumbs(lang('sections.titles.index'))
|
|
74
75
|
|
|
75
|
-
@sections = Section
|
|
76
|
+
@sections = paginate(Section)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
##
|
|
80
|
+
# Hook that is executed before the edit() and new() methods.
|
|
81
|
+
#
|
|
82
|
+
# @author Yorick Peterse
|
|
83
|
+
# @since 0.2.8
|
|
84
|
+
#
|
|
85
|
+
before(:edit, :new) do
|
|
86
|
+
@custom_field_group_pk_hash = CustomFields::Model::CustomFieldGroup \
|
|
87
|
+
.pk_hash(:name)
|
|
88
|
+
|
|
89
|
+
@category_group_pk_hash = Categories::Model::CategoryGroup \
|
|
90
|
+
.pk_hash(:name)
|
|
76
91
|
end
|
|
77
92
|
|
|
78
93
|
##
|
|
@@ -84,27 +99,25 @@ module Sections
|
|
|
84
99
|
# * update
|
|
85
100
|
#
|
|
86
101
|
# @author Yorick Peterse
|
|
87
|
-
# @param [Integer] id The ID of the section to retrieve so that we can
|
|
102
|
+
# @param [Integer] id The ID of the section to retrieve so that we can
|
|
103
|
+
# edit it.
|
|
88
104
|
# @since 0.1
|
|
89
105
|
#
|
|
90
106
|
def edit(id)
|
|
91
|
-
|
|
92
|
-
respond(lang('zen_general.errors.not_authorized'), 403)
|
|
93
|
-
end
|
|
107
|
+
require_permissions(:read, :update)
|
|
94
108
|
|
|
95
109
|
set_breadcrumbs(
|
|
96
|
-
|
|
110
|
+
Sections.a(lang('sections.titles.index'), :index),
|
|
97
111
|
@page_title
|
|
98
112
|
)
|
|
99
113
|
|
|
100
|
-
@custom_field_group_pk_hash = CustomFields::Model::CustomFieldGroup.pk_hash(:name)
|
|
101
|
-
@category_group_pk_hash = Categories::Model::CategoryGroup.pk_hash(:name)
|
|
102
|
-
|
|
103
114
|
if flash[:form_data]
|
|
104
115
|
@section = flash[:form_data]
|
|
105
116
|
else
|
|
106
|
-
@section =
|
|
117
|
+
@section = validate_section(id)
|
|
107
118
|
end
|
|
119
|
+
|
|
120
|
+
render_view(:form)
|
|
108
121
|
end
|
|
109
122
|
|
|
110
123
|
##
|
|
@@ -119,24 +132,23 @@ module Sections
|
|
|
119
132
|
# @since 0.1
|
|
120
133
|
#
|
|
121
134
|
def new
|
|
122
|
-
|
|
123
|
-
respond(lang('zen_general.errors.not_authorized'), 403)
|
|
124
|
-
end
|
|
135
|
+
require_permissions(:create, :read)
|
|
125
136
|
|
|
126
137
|
set_breadcrumbs(
|
|
127
|
-
|
|
138
|
+
Sections.a(lang('sections.titles.index'), :index),
|
|
128
139
|
@page_title
|
|
129
140
|
)
|
|
130
141
|
|
|
131
|
-
@
|
|
132
|
-
|
|
133
|
-
|
|
142
|
+
@section = Section.new
|
|
143
|
+
|
|
144
|
+
render_view(:form)
|
|
134
145
|
end
|
|
135
146
|
|
|
136
147
|
##
|
|
137
|
-
# Method used for processing the form data and redirecting the user back
|
|
138
|
-
# the proper URL. Based on the value of a hidden field named "id" we'll
|
|
139
|
-
# if the data will be used to create a new section or to update
|
|
148
|
+
# Method used for processing the form data and redirecting the user back
|
|
149
|
+
# to the proper URL. Based on the value of a hidden field named "id" we'll
|
|
150
|
+
# determine if the data will be used to create a new section or to update
|
|
151
|
+
# an existing one.
|
|
140
152
|
#
|
|
141
153
|
# This method requires the following permissions:
|
|
142
154
|
#
|
|
@@ -147,19 +159,27 @@ module Sections
|
|
|
147
159
|
# @since 0.1
|
|
148
160
|
#
|
|
149
161
|
def save
|
|
150
|
-
if !user_authorized?([:create, :update])
|
|
151
|
-
respond(lang('zen_general.errors.not_authorized'), 403)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
162
|
post = request.subset(
|
|
155
|
-
:id,
|
|
156
|
-
:
|
|
163
|
+
:id,
|
|
164
|
+
:name,
|
|
165
|
+
:slug,
|
|
166
|
+
:description,
|
|
167
|
+
:comment_allow,
|
|
168
|
+
:comment_require_account,
|
|
169
|
+
:comment_moderate,
|
|
170
|
+
:comment_format,
|
|
171
|
+
:custom_field_group_pks,
|
|
172
|
+
:category_group_pks
|
|
157
173
|
)
|
|
158
174
|
|
|
159
175
|
if post['id'] and !post['id'].empty?
|
|
160
|
-
|
|
176
|
+
require_permissions(:update)
|
|
177
|
+
|
|
178
|
+
@section = validate_section(post['id'])
|
|
161
179
|
save_action = :save
|
|
162
180
|
else
|
|
181
|
+
require_permissions(:create)
|
|
182
|
+
|
|
163
183
|
@section = Section.new
|
|
164
184
|
save_action = :new
|
|
165
185
|
end
|
|
@@ -167,11 +187,11 @@ module Sections
|
|
|
167
187
|
flash_success = lang("sections.success.#{save_action}")
|
|
168
188
|
flash_error = lang("sections.errors.#{save_action}")
|
|
169
189
|
|
|
170
|
-
|
|
171
190
|
post['custom_field_group_pks'] ||= []
|
|
172
191
|
post['category_group_pks'] ||= []
|
|
173
192
|
|
|
174
|
-
# The primary keys have to be integers otherwise Sequel will soil it's
|
|
193
|
+
# The primary keys have to be integers otherwise Sequel will soil it's
|
|
194
|
+
# pants
|
|
175
195
|
['custom_field_group_pks', 'category_group_pks'].each do |k|
|
|
176
196
|
post[k].map! { |value| value.to_i }
|
|
177
197
|
end
|
|
@@ -195,6 +215,8 @@ module Sections
|
|
|
195
215
|
|
|
196
216
|
flash[:form_data] = @section
|
|
197
217
|
flash[:form_errors] = @section.errors
|
|
218
|
+
|
|
219
|
+
redirect_referrer
|
|
198
220
|
end
|
|
199
221
|
|
|
200
222
|
if @section.id
|
|
@@ -205,10 +227,10 @@ module Sections
|
|
|
205
227
|
end
|
|
206
228
|
|
|
207
229
|
##
|
|
208
|
-
# Delete an existing section. Poor section, what did he do wrong?
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
-
# each section that has to be deleted.
|
|
230
|
+
# Delete an existing section. Poor section, what did he do wrong? In order
|
|
231
|
+
# to delete a section you'll need to send a POST request that contains a
|
|
232
|
+
# field named "section_ids[]". This field should contain the primary
|
|
233
|
+
# values of each section that has to be deleted.
|
|
212
234
|
#
|
|
213
235
|
# This method requires the following permissions:
|
|
214
236
|
#
|
|
@@ -218,9 +240,7 @@ module Sections
|
|
|
218
240
|
# @since 0.1
|
|
219
241
|
#
|
|
220
242
|
def delete
|
|
221
|
-
|
|
222
|
-
respond(lang('zen_general.errors.not_authorized'), 403)
|
|
223
|
-
end
|
|
243
|
+
require_permissions(:delete)
|
|
224
244
|
|
|
225
245
|
if !request.params['section_ids'] or request.params['section_ids'].empty?
|
|
226
246
|
message(:error, lang('sections.errors.no_delete'))
|
|
@@ -234,6 +254,8 @@ module Sections
|
|
|
234
254
|
rescue => e
|
|
235
255
|
Ramaze::Log.error(e.inspect)
|
|
236
256
|
message(:error, lang('sections.errors.delete') % id)
|
|
257
|
+
|
|
258
|
+
redirect_referrer
|
|
237
259
|
end
|
|
238
260
|
end
|
|
239
261
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Ramaze
|
|
2
|
+
module Helper
|
|
3
|
+
##
|
|
4
|
+
# Helper for the sections package.
|
|
5
|
+
#
|
|
6
|
+
# @author Yorick Peterse
|
|
7
|
+
# @since 0.2.8
|
|
8
|
+
#
|
|
9
|
+
module Section
|
|
10
|
+
##
|
|
11
|
+
# Validates the section ID and returns the section if it's valid.
|
|
12
|
+
#
|
|
13
|
+
# @author Yorick Peterse
|
|
14
|
+
# @since 0.2.8
|
|
15
|
+
# @param [Fixnum] section_id The ID of the section to validate.
|
|
16
|
+
# @return [Sections::Model::Section]
|
|
17
|
+
#
|
|
18
|
+
def validate_section(section_id)
|
|
19
|
+
section = Sections::Model::Section[section_id]
|
|
20
|
+
|
|
21
|
+
if section.nil?
|
|
22
|
+
message(:error, lang('sections.errors.invalid_section'))
|
|
23
|
+
redirect(Sections::Controller::Sections.r(:index))
|
|
24
|
+
else
|
|
25
|
+
return section
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
# Validates a section entry and returns it if it's valid.
|
|
31
|
+
#
|
|
32
|
+
#
|
|
33
|
+
# @author Yorick Peterse
|
|
34
|
+
# @since 0.2.8
|
|
35
|
+
# @param [Fixnum] section_entry_id The ID of the section entry to
|
|
36
|
+
# validate.
|
|
37
|
+
# @param [Fixnum] section_id The ID of the section to use when
|
|
38
|
+
# redirecting the user to the overview of all entries.
|
|
39
|
+
# @return [Sections::Model::SectionEntry]
|
|
40
|
+
#
|
|
41
|
+
def validate_section_entry(section_entry_id, section_id)
|
|
42
|
+
entry = Sections::Model::SectionEntry[section_entry_id]
|
|
43
|
+
|
|
44
|
+
if entry.nil?
|
|
45
|
+
message(:error, lang('section_entries.errors.invalid_entry'))
|
|
46
|
+
redirect(Sections::Controller::SectionEntries.r(:index, section_id))
|
|
47
|
+
else
|
|
48
|
+
return entry
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end # Section
|
|
52
|
+
end # Helper
|
|
53
|
+
end # Ramaze
|
|
@@ -27,10 +27,11 @@ messages:
|
|
|
27
27
|
no_categories : 'No categories have been assigned to the current section.'
|
|
28
28
|
|
|
29
29
|
errors:
|
|
30
|
-
new
|
|
31
|
-
save
|
|
32
|
-
delete
|
|
33
|
-
no_delete
|
|
30
|
+
new : 'Failed to create a new section entry.'
|
|
31
|
+
save : 'Failed to save the section entry.'
|
|
32
|
+
delete : 'Failed to delete the section entry with ID#%s'
|
|
33
|
+
no_delete : "You haven't specified any section entries to delete."
|
|
34
|
+
invalid_entry: 'The specified entry is invalid.'
|
|
34
35
|
|
|
35
36
|
success:
|
|
36
37
|
new : 'The new section entry has been created.'
|
|
@@ -31,10 +31,11 @@ messages:
|
|
|
31
31
|
no_sections: "No sections have been created yet."
|
|
32
32
|
|
|
33
33
|
errors:
|
|
34
|
-
new
|
|
35
|
-
save
|
|
36
|
-
delete
|
|
37
|
-
no_delete
|
|
34
|
+
new : 'Failed to create a new section.'
|
|
35
|
+
save : 'Failed to modify the section.'
|
|
36
|
+
delete : 'Failed to delete the section with ID #%s.'
|
|
37
|
+
no_delete : 'You need to specify at least one section to delete.'
|
|
38
|
+
invalid_section: 'The specified section is invalid.'
|
|
38
39
|
|
|
39
40
|
success:
|
|
40
41
|
new : 'The new section has been created.'
|
|
@@ -32,10 +32,11 @@ success:
|
|
|
32
32
|
delete: 'Alle geselecteerde items zijn verwijderd.'
|
|
33
33
|
|
|
34
34
|
errors:
|
|
35
|
-
new
|
|
36
|
-
save
|
|
37
|
-
delete
|
|
38
|
-
no_delete: 'U moet ten minste 1 item specificeren om te verwijderen.'
|
|
35
|
+
new : 'Het sectie item kon niet worden aangemaakt.'
|
|
36
|
+
save : 'Het sectie item kon niet worden aangepast.'
|
|
37
|
+
delete : 'Het sectie item met ID #%s kon niet worden verwijderd.'
|
|
38
|
+
no_delete : 'U moet ten minste 1 item specificeren om te verwijderen.'
|
|
39
|
+
invalid_entry: 'Het opgegeven item is ongeldig.'
|
|
39
40
|
|
|
40
41
|
buttons:
|
|
41
42
|
new : 'Sectie item toevoegen'
|
|
@@ -36,10 +36,11 @@ success:
|
|
|
36
36
|
delete: 'Alle geselecteerde secties zijn verwijderd.'
|
|
37
37
|
|
|
38
38
|
errors:
|
|
39
|
-
new
|
|
40
|
-
save
|
|
41
|
-
delete
|
|
42
|
-
no_delete: 'U moet ten minste 1 sectie specificeren om te verwijderen.'
|
|
39
|
+
new : 'De sectie kon niet worden aangemaakt.'
|
|
40
|
+
save : 'De sectie kon niet worden aangepast.'
|
|
41
|
+
delete : 'De sectie met ID #%s kon niet worden verwijderd.'
|
|
42
|
+
no_delete : 'U moet ten minste 1 sectie specificeren om te verwijderen.'
|
|
43
|
+
invalid_section: 'De opgegeven sectie is ongeldig.'
|
|
43
44
|
|
|
44
45
|
buttons:
|
|
45
46
|
new : 'Sectie toevoegen'
|
|
@@ -21,11 +21,18 @@ module Sections
|
|
|
21
21
|
one_to_many(
|
|
22
22
|
:section_entries,
|
|
23
23
|
:class => "Sections::Model::SectionEntry",
|
|
24
|
-
:eager => [:custom_field_values]
|
|
24
|
+
:eager => [:custom_field_values, :section_entry_status]
|
|
25
25
|
)
|
|
26
26
|
|
|
27
|
-
many_to_many(
|
|
28
|
-
|
|
27
|
+
many_to_many(
|
|
28
|
+
:custom_field_groups,
|
|
29
|
+
:class => "CustomFields::Model::CustomFieldGroup"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
many_to_many(
|
|
33
|
+
:category_groups,
|
|
34
|
+
:class => "Categories::Model::CategoryGroup"
|
|
35
|
+
)
|
|
29
36
|
|
|
30
37
|
plugin(:sluggable, :source => :name, :freeze => false)
|
|
31
38
|
|
|
@@ -36,12 +43,13 @@ module Sections
|
|
|
36
43
|
# @since 0.1
|
|
37
44
|
#
|
|
38
45
|
def validate
|
|
39
|
-
validates_presence(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
validates_presence([
|
|
47
|
+
:name,
|
|
48
|
+
:comment_allow,
|
|
49
|
+
:comment_require_account,
|
|
50
|
+
:comment_moderate,
|
|
51
|
+
:comment_format
|
|
52
|
+
])
|
|
45
53
|
|
|
46
54
|
validates_presence(:slug) unless new?
|
|
47
55
|
validates_max_length(255, [:name, :slug])
|
|
@@ -20,37 +20,216 @@ module Sections
|
|
|
20
20
|
# @since 0.1
|
|
21
21
|
#
|
|
22
22
|
class SectionEntry < Sequel::Model
|
|
23
|
-
one_to_many(
|
|
23
|
+
one_to_many(
|
|
24
|
+
:comments,
|
|
25
|
+
:class => "Comments::Model::Comment"
|
|
26
|
+
)
|
|
24
27
|
|
|
25
28
|
one_to_many(
|
|
26
|
-
:custom_field_values,
|
|
27
|
-
:class => "CustomFields::Model::CustomFieldValue",
|
|
29
|
+
:custom_field_values,
|
|
30
|
+
:class => "CustomFields::Model::CustomFieldValue",
|
|
28
31
|
:eager => [:custom_field]
|
|
29
32
|
)
|
|
30
|
-
|
|
31
|
-
many_to_one(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
many_to_one(
|
|
35
|
+
:user,
|
|
36
|
+
:class => "Users::Model::User"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
many_to_many(
|
|
40
|
+
:categories,
|
|
41
|
+
:class => "Categories::Model::Category"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
many_to_one(
|
|
45
|
+
:section,
|
|
46
|
+
:class => "Sections::Model::Section"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
many_to_one(
|
|
50
|
+
:section_entry_status,
|
|
51
|
+
:class => 'Sections::Model::SectionEntryStatus'
|
|
52
|
+
)
|
|
53
|
+
|
|
35
54
|
plugin(:sluggable , :source => :title , :freeze => false)
|
|
36
55
|
plugin(:timestamps, :create => :created_at, :update => false)
|
|
37
|
-
|
|
56
|
+
|
|
38
57
|
##
|
|
39
58
|
# Specify our validation rules.
|
|
40
59
|
#
|
|
41
60
|
# @author Yorick Peterse
|
|
42
61
|
# @since 0.1
|
|
43
|
-
#
|
|
62
|
+
#
|
|
44
63
|
def validate
|
|
45
|
-
validates_presence([:title, :
|
|
64
|
+
validates_presence([:title, :user_id])
|
|
46
65
|
validates_presence(:slug) unless new?
|
|
66
|
+
validates_integer(:section_entry_status_id)
|
|
47
67
|
|
|
48
68
|
# Check if the slug is unique for the current section
|
|
49
|
-
if !SectionEntry
|
|
50
|
-
|
|
69
|
+
if !SectionEntry \
|
|
70
|
+
.filter({:slug => slug, :section_id => section_id}, ~{:id => id}) \
|
|
71
|
+
.all.empty?
|
|
51
72
|
errors.add(:slug, lang('zen_models.unique'))
|
|
52
73
|
end
|
|
53
74
|
end
|
|
75
|
+
|
|
76
|
+
##
|
|
77
|
+
# Returns a hash containing all the entry statuses. The keys of this hash
|
|
78
|
+
# are the IDs and the values the names.
|
|
79
|
+
#
|
|
80
|
+
# @author Yorick Peterse
|
|
81
|
+
# @since 0.2.8
|
|
82
|
+
# @return [Hash]
|
|
83
|
+
#
|
|
84
|
+
def self.status_hash
|
|
85
|
+
::Zen::Language.load('section_entries')
|
|
86
|
+
|
|
87
|
+
statuses = {}
|
|
88
|
+
|
|
89
|
+
::Sections::Model::SectionEntryStatus.all.each do |status|
|
|
90
|
+
statuses[status.id] = lang(
|
|
91
|
+
"section_entries.special.status_hash.#{status.name}"
|
|
92
|
+
)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
return statuses
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
##
|
|
99
|
+
# Retrieves all custom fields for a section entry.
|
|
100
|
+
#
|
|
101
|
+
# @author Yorick Peterse
|
|
102
|
+
# @since 0.2.8
|
|
103
|
+
# @return [Array]
|
|
104
|
+
#
|
|
105
|
+
def custom_fields
|
|
106
|
+
return CustomFields::Model::CustomField.select_all(
|
|
107
|
+
:custom_fields
|
|
108
|
+
).join(
|
|
109
|
+
:custom_field_groups,
|
|
110
|
+
:custom_field_groups__id => :custom_fields__custom_field_group_id
|
|
111
|
+
).join(
|
|
112
|
+
:custom_field_groups_sections,
|
|
113
|
+
:custom_field_groups_sections__custom_field_group_id \
|
|
114
|
+
=> :custom_field_groups__id
|
|
115
|
+
).filter(
|
|
116
|
+
:custom_field_groups_sections__section_id => section_id
|
|
117
|
+
).all
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
##
|
|
121
|
+
# Retrieves all the possible categories for an entry and returns these as
|
|
122
|
+
# a hash. This hash is a multi dimensional hash where the keys are the
|
|
123
|
+
# names of all available category groups and the values hashes with the
|
|
124
|
+
# IDs and names of all the categories for that group.
|
|
125
|
+
#
|
|
126
|
+
# @example
|
|
127
|
+
# e = Sections::Model::SectionEntry[1]
|
|
128
|
+
# e.possible_categories # => {'Blog' => {1 => 'General', 2 => 'Code'}}
|
|
129
|
+
#
|
|
130
|
+
# @author Yorick Peterse
|
|
131
|
+
# @since 0.2.8
|
|
132
|
+
# @return [Hash]
|
|
133
|
+
#
|
|
134
|
+
def possible_categories
|
|
135
|
+
hash = {}
|
|
136
|
+
query = Zen.database[:category_groups_sections] \
|
|
137
|
+
.select(
|
|
138
|
+
:categories__id,
|
|
139
|
+
:categories__name,
|
|
140
|
+
:category_groups__name => :category_group_name
|
|
141
|
+
) \
|
|
142
|
+
.left_join(
|
|
143
|
+
:categories,
|
|
144
|
+
:category_groups_sections__category_group_id \
|
|
145
|
+
=> :categories__category_group_id
|
|
146
|
+
) \
|
|
147
|
+
.left_join(
|
|
148
|
+
:category_groups,
|
|
149
|
+
:category_groups_sections__category_group_id => :category_groups__id
|
|
150
|
+
) \
|
|
151
|
+
.filter(
|
|
152
|
+
:category_groups_sections__section_id => section_id
|
|
153
|
+
) \
|
|
154
|
+
.all
|
|
155
|
+
|
|
156
|
+
query.each do |row|
|
|
157
|
+
hash[row[:category_group_name]] ||= {}
|
|
158
|
+
hash[row[:category_group_name]][row[:id]] = row[:name]
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
return hash
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
##
|
|
165
|
+
# Gathers all the custom field groups, custom fields and custom field
|
|
166
|
+
# values and returns them as a hash. This hash can be used in views to
|
|
167
|
+
# build the HTML for all the fields.
|
|
168
|
+
#
|
|
169
|
+
# @author Yorick Peterse
|
|
170
|
+
# @since 0.2.8
|
|
171
|
+
# @return [Hash]
|
|
172
|
+
#
|
|
173
|
+
def custom_fields_hash
|
|
174
|
+
result = {}
|
|
175
|
+
values = {}
|
|
176
|
+
groups = section.custom_field_groups
|
|
177
|
+
group_ids = groups.map { |g| g.id }
|
|
178
|
+
fields = {}
|
|
179
|
+
|
|
180
|
+
# Get all the custom fields in one go rather than running a query for
|
|
181
|
+
# each group.
|
|
182
|
+
CustomFields::Model::CustomField.filter(
|
|
183
|
+
:custom_field_group_id => group_ids
|
|
184
|
+
).each do |field|
|
|
185
|
+
fields[field.custom_field_group_id] ||= []
|
|
186
|
+
fields[field.custom_field_group_id].push(field)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# Index the custom field values hash so that the keys are the IDs of the
|
|
190
|
+
# custom fields and the values the instances of
|
|
191
|
+
# CustomFields::Model::CustomFieldValue.
|
|
192
|
+
custom_field_values.each do |val|
|
|
193
|
+
values[val.custom_field_id] = val
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Build the hash containing all the details of each field
|
|
197
|
+
groups.each do |group|
|
|
198
|
+
result[group.id] ||= {:name => group.name, :fields => []}
|
|
199
|
+
|
|
200
|
+
fields[group.id].each do |field|
|
|
201
|
+
m = field.custom_field_type.custom_field_method.name
|
|
202
|
+
|
|
203
|
+
begin
|
|
204
|
+
result[group.id][:fields].push(
|
|
205
|
+
CustomFields::BlueFormParameters.send(
|
|
206
|
+
m, field, values[field.id]
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
rescue => e
|
|
210
|
+
Ramaze::Log.error(e)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
return result
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
##
|
|
219
|
+
# Hook that is executed before saving an existing section entry.
|
|
220
|
+
#
|
|
221
|
+
# @author Yorick Peterse
|
|
222
|
+
# @since 0.2.8
|
|
223
|
+
#
|
|
224
|
+
def before_save
|
|
225
|
+
if self.section_entry_status_id.nil?
|
|
226
|
+
self.section_entry_status_id = ::Sections::Model::SectionEntryStatus[
|
|
227
|
+
:name => 'draft'
|
|
228
|
+
].id
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
super
|
|
232
|
+
end
|
|
54
233
|
end # SectionEntry
|
|
55
234
|
end # Model
|
|
56
235
|
end # Sections
|