zen 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gems +34 -0
- data/.travis.yml +7 -0
- data/AUTHORS +5 -0
- data/CHANGELOG +14 -0
- data/{license.txt → LICENSE} +0 -0
- data/MANIFEST +67 -51
- data/README.md +18 -25
- data/Rakefile +2 -3
- data/bin/zen +2 -2
- data/lib/zen.rb +93 -57
- data/lib/zen/asset.rb +7 -8
- data/lib/zen/bin/app.rb +0 -2
- data/lib/zen/controller/admin_controller.rb +4 -9
- data/lib/zen/controller/base_controller.rb +0 -25
- data/lib/zen/controller/main_controller.rb +5 -5
- data/lib/zen/controller/preview.rb +50 -0
- data/lib/zen/helper/common.rb +4 -68
- data/lib/zen/helper/message.rb +82 -0
- data/lib/zen/helper/theme.rb +2 -2
- data/lib/zen/language.rb +68 -38
- data/lib/zen/language/en/zen_general.yml +1 -4
- data/lib/zen/language/nl/zen_general.yml +28 -0
- data/lib/zen/language/nl/zen_models.yml +13 -0
- data/lib/zen/layout/admin.xhtml +1 -1
- data/lib/zen/layout/login.xhtml +1 -1
- data/lib/zen/model/settings.rb +2 -0
- data/lib/zen/package.rb +29 -25
- data/lib/zen/package/all.rb +1 -1
- data/lib/zen/package/categories/lib/categories/controller/categories.rb +51 -63
- data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -52
- data/lib/zen/package/categories/lib/categories/language/en/categories.yml +2 -2
- data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +39 -0
- data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +33 -0
- data/lib/zen/package/categories/lib/categories/plugin/categories.rb +2 -2
- data/lib/zen/package/comments/lib/comments.rb +31 -2
- data/lib/zen/package/comments/lib/comments/controller/comments.rb +42 -57
- data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +36 -51
- data/lib/zen/package/comments/lib/comments/language/en/comments.yml +7 -3
- data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +48 -0
- data/lib/zen/package/comments/lib/comments/model/comment.rb +45 -4
- data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +152 -0
- data/lib/zen/package/comments/lib/comments/plugin/comments.rb +5 -6
- data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +2 -2
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +43 -52
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +68 -67
- data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +1 -1
- data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +32 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +52 -0
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +4 -7
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
- data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +37 -44
- data/lib/zen/package/menus/lib/menus/controller/menus.rb +33 -43
- data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +5 -10
- data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +41 -0
- data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +39 -0
- data/lib/zen/package/menus/lib/menus/model/menu.rb +3 -3
- data/lib/zen/package/menus/lib/menus/model/menu_item.rb +3 -3
- data/lib/zen/package/menus/lib/menus/plugin/menus.rb +5 -6
- data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +1 -1
- data/lib/zen/package/sections/lib/sections.rb +20 -0
- data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +85 -79
- data/lib/zen/package/sections/lib/sections/controller/sections.rb +58 -66
- data/lib/zen/package/sections/lib/sections/language/en/sections.yml +0 -1
- data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +43 -0
- data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +47 -0
- data/lib/zen/package/sections/lib/sections/model/section.rb +11 -15
- data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -5
- data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +7 -8
- data/lib/zen/package/sections/lib/sections/plugin/sections.rb +3 -4
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +0 -4
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +8 -2
- data/lib/zen/package/sections/migrations/1306772479_remove_unique_slug.rb +28 -0
- data/lib/zen/package/settings/lib/settings.rb +21 -34
- data/lib/zen/package/settings/lib/settings/controller/settings.rb +29 -22
- data/lib/zen/package/settings/lib/settings/language/en/settings.yml +7 -5
- data/lib/zen/package/settings/lib/settings/language/nl/settings.yml +39 -0
- data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -5
- data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +3 -4
- data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +3 -5
- data/lib/zen/package/settings/lib/settings/plugin/settings.rb +11 -4
- data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +5 -5
- data/lib/zen/package/settings/migrations/1299538742_add_language_key.rb +8 -8
- data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +2 -5
- data/lib/zen/package/users/lib/users/controller/access_rules.rb +54 -61
- data/lib/zen/package/users/lib/users/controller/user_groups.rb +49 -57
- data/lib/zen/package/users/lib/users/controller/users.rb +58 -73
- data/lib/zen/package/users/lib/users/language/en/users.yml +6 -0
- data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +37 -0
- data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +31 -0
- data/lib/zen/package/users/lib/users/language/nl/users.yml +56 -0
- data/lib/zen/package/users/lib/users/model/user.rb +16 -1
- data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +27 -2
- data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +15 -3
- data/lib/zen/package/users/migrations/1304939855_user_settings.rb +15 -0
- data/lib/zen/plugin.rb +7 -9
- data/lib/zen/public/admin/css/{buttons.css → zen/buttons.css} +11 -7
- data/lib/zen/public/admin/css/{datepicker.css → zen/datepicker.css} +0 -0
- data/lib/zen/public/admin/css/{editor.css → zen/editor.css} +10 -5
- data/lib/zen/public/admin/css/{forms.css → zen/forms.css} +1 -1
- data/lib/zen/public/admin/css/{general.css → zen/general.css} +7 -7
- data/lib/zen/public/admin/css/{grid.css → zen/grid.css} +0 -0
- data/lib/zen/public/admin/css/{layout.css → zen/layout.css} +4 -5
- data/lib/zen/public/admin/css/zen/messages.css +61 -0
- data/lib/zen/public/admin/css/{notifications.css → zen/notifications.css} +4 -4
- data/lib/zen/public/admin/css/{reset.css → zen/reset.css} +0 -0
- data/lib/zen/public/admin/css/{tables.css → zen/tables.css} +3 -3
- data/lib/zen/public/admin/css/{tabs.css → zen/tabs.css} +5 -5
- data/lib/zen/public/admin/css/zen/window.css +79 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/accept.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/add.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/back.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/bold.png +0 -0
- data/lib/zen/public/admin/images/zen/icons/close.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/delete.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/edit.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/error.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/help.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/info.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/italic.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/large/error.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/large/notice.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/large/success.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/link.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/logout.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/ol.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/pdf.png +0 -0
- data/lib/zen/public/admin/images/zen/icons/preview.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/ul.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/user.png +0 -0
- data/lib/zen/public/admin/images/{icons → zen/icons}/view.png +0 -0
- data/lib/zen/public/admin/js/zen/core.js +73 -0
- data/lib/zen/public/admin/js/zen/editor.js +527 -0
- data/lib/zen/public/admin/js/zen/editor/markdown.js +84 -0
- data/lib/zen/public/admin/js/zen/editor/textile.js +84 -0
- data/lib/zen/public/admin/js/zen/init.js +12 -66
- data/lib/zen/public/admin/js/zen/tabs.js +5 -0
- data/lib/zen/public/admin/js/zen/window.js +206 -0
- data/lib/zen/task/build.rake +23 -6
- data/lib/zen/task/clean.rake +6 -7
- data/lib/zen/task/db.rake +7 -9
- data/lib/zen/task/package.rake +6 -6
- data/lib/zen/task/test.rake +6 -0
- data/lib/zen/task/theme.rake +3 -3
- data/lib/zen/theme.rb +3 -4
- data/lib/zen/validation.rb +7 -9
- data/lib/zen/version.rb +3 -4
- data/lib/zen/view/bottom.xhtml +0 -5
- data/lib/zen/view/main.xhtml +2 -0
- data/proto/app/app.rb +6 -4
- data/proto/app/config/config.rb +1 -7
- data/proto/app/config/database.rb +47 -43
- data/proto/app/config/middlewares.rb +0 -40
- data/proto/app/start.rb +1 -6
- data/proto/app/{vendor → theme}/.gitkeep +0 -0
- data/proto/migration.rb +3 -3
- data/proto/package/lib/package.rb +0 -1
- data/proto/package/lib/package/controller/controllers.rb +7 -40
- data/proto/package/lib/package/model/model.rb +3 -3
- metadata +106 -79
- data/CHANGELOG.md +0 -27
- data/ROADMAP.md +0 -53
- data/lib/zen/database.rb +0 -112
- data/lib/zen/logger.rb +0 -56
- data/lib/zen/public/admin/css/modals.css +0 -63
- data/lib/zen/public/admin/images/icons/close.png +0 -0
- data/lib/zen/public/admin/js/vendor/yepnope.js +0 -1
- data/lib/zen/public/admin/js/zen/editor/base.js +0 -262
- data/lib/zen/public/admin/js/zen/editor/drivers/html.js +0 -89
- data/lib/zen/public/admin/js/zen/editor/drivers/markdown.js +0 -87
- data/lib/zen/public/admin/js/zen/editor/drivers/textile.js +0 -87
- data/lib/zen/public/admin/js/zen/modal.js +0 -146
- data/lib/zen/public/admin/js/zen/notification.js +0 -211
- data/proto/app/config/requires.rb +0 -10
- data/proto/app/vendor/theme/.gitkeep +0 -0
- data/proto/package/lib/package/view/admin/package/edit.xhtml +0 -0
- data/proto/package/lib/package/view/admin/package/form.xhtml +0 -0
- data/proto/package/lib/package/view/admin/package/new.xhtml +0 -0
@@ -18,14 +18,9 @@ module Ramaze
|
|
18
18
|
# @since 0.2a
|
19
19
|
# @param [Integer] menu_id The ID of the menu to validate.
|
20
20
|
#
|
21
|
-
def validate_menu(menu_id
|
21
|
+
def validate_menu(menu_id)
|
22
22
|
if !menu_id or ::Menus::Model::Menu[menu_id].nil?
|
23
|
-
|
24
|
-
:error,
|
25
|
-
@menu_items_lang.titles[:index],
|
26
|
-
@menu_items_lang.errors[:invalid_menu]
|
27
|
-
)
|
28
|
-
|
23
|
+
message(:error, @menu_items_lang.errors[:invalid_menu])
|
29
24
|
redirect(::Menus::Controller::Menus.r(:index))
|
30
25
|
end
|
31
26
|
end
|
@@ -88,6 +83,6 @@ module Ramaze
|
|
88
83
|
end
|
89
84
|
end
|
90
85
|
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
86
|
+
end # MenuItem
|
87
|
+
end # Helper
|
88
|
+
end # Ramaze
|
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
titles:
|
3
|
+
index: 'Menu items'
|
4
|
+
edit : 'Menu item aanpassen'
|
5
|
+
new : 'Menu item aanmaken'
|
6
|
+
|
7
|
+
labels:
|
8
|
+
id : '#'
|
9
|
+
parent_id: 'Hoofd item'
|
10
|
+
name : 'Naam'
|
11
|
+
url : 'URL'
|
12
|
+
order : 'Volgorde'
|
13
|
+
css_class: 'CSS klasse'
|
14
|
+
css_id : 'CSS ID'
|
15
|
+
|
16
|
+
placeholders:
|
17
|
+
name : 'De naam/label van het menu item.'
|
18
|
+
url : 'De URL van het menu item.'
|
19
|
+
order : 'De sorteer volgorde.'
|
20
|
+
css_class: 'Een klasse die gebruikt kan worden in CSS bestanden.'
|
21
|
+
css_id : 'Een ID die gebruikt kan worden in CSS bestanden.'
|
22
|
+
|
23
|
+
messages:
|
24
|
+
no_items: 'Er zijn nog geen menu items aangemaakt.'
|
25
|
+
|
26
|
+
buttons:
|
27
|
+
new : 'Menu item toevoegen'
|
28
|
+
save : 'Menu item opslaan'
|
29
|
+
delete: 'Geselecteerde menu items verwijderen'
|
30
|
+
|
31
|
+
success:
|
32
|
+
new : 'Het menu item is aangemaakt.'
|
33
|
+
save : 'Het menu item is aangepast.'
|
34
|
+
delete: 'De menu items zijn verwijderd.'
|
35
|
+
|
36
|
+
errors:
|
37
|
+
new : 'Het menu item kon niet worden aangemaakt.'
|
38
|
+
save : 'Het menu item kon niet worden aangepast.'
|
39
|
+
delete : 'Het menu item met ID #%s kon niet worden verwijderd.'
|
40
|
+
no_delete : 'U moet ten minste 1 item specificeren om te verwijderen.'
|
41
|
+
invalid_menu: 'Het opgegeven menu is ongeldig of bestaat niet meer.'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
---
|
2
|
+
titles:
|
3
|
+
index: "Menu's"
|
4
|
+
edit : 'Menu aanpassen'
|
5
|
+
new : 'Menu aanmaken'
|
6
|
+
|
7
|
+
labels:
|
8
|
+
id : '#'
|
9
|
+
name : 'Naam'
|
10
|
+
slug : 'Slug'
|
11
|
+
description : 'Beschrijving'
|
12
|
+
css_class : 'CSS klasse'
|
13
|
+
css_id : 'CSS ID'
|
14
|
+
manage_items: 'Menu items beheren'
|
15
|
+
|
16
|
+
placeholders:
|
17
|
+
name : 'De naam van het menu.'
|
18
|
+
slug : 'Een URL vriendelijke versie van de menu naam.'
|
19
|
+
css_class: 'Een klasse die gebruikt kan worden in CSS bestanden.'
|
20
|
+
css_id : 'Een ID die gebruikt kan worden in CSS bestanden.'
|
21
|
+
|
22
|
+
messages:
|
23
|
+
no_menus: "Er zijn nog geen menu's aangemaakt."
|
24
|
+
|
25
|
+
buttons:
|
26
|
+
new : 'Menu toevoegen'
|
27
|
+
save : 'Menu opslaan'
|
28
|
+
delete: "Geselecteerde menu's verwijderen"
|
29
|
+
|
30
|
+
success:
|
31
|
+
new : 'Het menu is aangemaakt.'
|
32
|
+
save : 'Het menu is aangepast.'
|
33
|
+
delete: "De geselecteerde menu's zijn verwijderd."
|
34
|
+
|
35
|
+
errors:
|
36
|
+
new : 'Het menu kon niet worden aangemaakt.'
|
37
|
+
save : 'Het menu kon niet worden aangepast.'
|
38
|
+
delete : 'Het menu met ID #%s kon niet worden verwijderd.'
|
39
|
+
no_delete: 'U moet ten minste 1 menu specificeren om te verwijderen.'
|
@@ -75,8 +75,8 @@ module Menus
|
|
75
75
|
return if !menu
|
76
76
|
|
77
77
|
# Get all menu items
|
78
|
-
menu_items = MenuItem.filter(:menu_id => menu.id, :parent_id => nil)
|
79
|
-
.limit(@options[:limit], @options[:offset])
|
78
|
+
menu_items = MenuItem.filter(:menu_id => menu.id, :parent_id => nil) \
|
79
|
+
.limit(@options[:limit], @options[:offset]) \
|
80
80
|
.all
|
81
81
|
|
82
82
|
@g = Ramaze::Gestalt.new
|
@@ -146,7 +146,6 @@ module Menus
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
149
|
+
end # Menus
|
150
|
+
end # Plugin
|
151
|
+
end # Menus
|
@@ -21,7 +21,7 @@ Sequel.migration do
|
|
21
21
|
String :css_class
|
22
22
|
String :css_id
|
23
23
|
|
24
|
-
foreign_key :menu_id, :menus, :update => :on_cascade, :on_delete => :cascade, :key => :id
|
24
|
+
foreign_key :menu_id, :menus, :update => :on_cascade, :on_delete => :cascade, :key => :id
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -46,3 +46,23 @@ Zen::Plugin.add do |p|
|
|
46
46
|
p.url = 'http://yorickpeterse.com/'
|
47
47
|
p.plugin = Sections::Plugin::SectionEntries
|
48
48
|
end
|
49
|
+
|
50
|
+
# Register all the settings
|
51
|
+
section_hash = {}
|
52
|
+
|
53
|
+
begin
|
54
|
+
Sections::Model::Section.select(:name, :slug).each do |s|
|
55
|
+
section_hash[s.slug] = s.name
|
56
|
+
end
|
57
|
+
rescue => e
|
58
|
+
Ramaze::Log.warn("The settings plugin failed to retrieve all sections: #{e.message}")
|
59
|
+
end
|
60
|
+
|
61
|
+
plugin(:settings, :register) do |setting|
|
62
|
+
setting.title = lang('settings.labels.default_section')
|
63
|
+
setting.description = lang('settings.placeholders.default_section')
|
64
|
+
setting.name = 'default_section'
|
65
|
+
setting.group = 'general'
|
66
|
+
setting.type = 'select'
|
67
|
+
setting.values = section_hash
|
68
|
+
end
|
@@ -10,16 +10,22 @@ module Sections
|
|
10
10
|
# @since 0.1
|
11
11
|
#
|
12
12
|
class SectionEntries < Zen::Controller::AdminController
|
13
|
-
include ::Sections::Model
|
14
|
-
|
15
|
-
map
|
13
|
+
include ::Sections::Model
|
14
|
+
|
15
|
+
map '/admin/section-entries'
|
16
|
+
|
17
|
+
# Load all required Javascript files
|
18
|
+
javascript ['zen/tabs', 'zen/editor', 'vendor/datepicker']
|
19
|
+
|
20
|
+
# Load all required CSS files
|
21
|
+
stylesheet ['zen/datepicker']
|
16
22
|
|
17
23
|
before_all do
|
18
24
|
csrf_protection(:save, :delete) do
|
19
25
|
respond(lang('zen_general.errors.csrf'), 403)
|
20
26
|
end
|
21
27
|
end
|
22
|
-
|
28
|
+
|
23
29
|
##
|
24
30
|
# Constructor method, called upon initialization. It's used to set the
|
25
31
|
# URL to which forms send their data and load the language pack.
|
@@ -35,13 +41,13 @@ module Sections
|
|
35
41
|
#
|
36
42
|
def initialize
|
37
43
|
super
|
38
|
-
|
44
|
+
|
39
45
|
@form_save_url = SectionEntries.r(:save)
|
40
46
|
@form_delete_url = SectionEntries.r(:delete)
|
41
|
-
|
47
|
+
|
42
48
|
Zen::Language.load('section_entries')
|
43
49
|
Zen::Language.load('sections')
|
44
|
-
|
50
|
+
|
45
51
|
# Set the page title
|
46
52
|
if !action.method.nil?
|
47
53
|
method = action.method.to_sym
|
@@ -53,14 +59,14 @@ module Sections
|
|
53
59
|
'published' => lang('section_entries.special.status_hash.published')
|
54
60
|
}
|
55
61
|
end
|
56
|
-
|
62
|
+
|
57
63
|
##
|
58
64
|
# Show an overview of all entries for the current section.
|
59
65
|
#
|
60
66
|
# This method requires the following permissions:
|
61
67
|
#
|
62
68
|
# * read
|
63
|
-
#
|
69
|
+
#
|
64
70
|
# @author Yorick Peterse
|
65
71
|
# @param [Integer] section_id The ID of the current section.
|
66
72
|
# @since 0.1
|
@@ -69,17 +75,17 @@ module Sections
|
|
69
75
|
if !user_authorized?([:read])
|
70
76
|
respond(lang('zen_general.errors.not_authorized'), 403)
|
71
77
|
end
|
72
|
-
|
78
|
+
|
73
79
|
set_breadcrumbs(
|
74
80
|
anchor_to(lang('sections.titles.index'), Sections.r(:index)),
|
75
81
|
lang('section_entries.titles.index')
|
76
82
|
)
|
77
|
-
|
83
|
+
|
78
84
|
section = Section[section_id.to_i]
|
79
85
|
@section_id = section_id
|
80
86
|
@entries = section.section_entries
|
81
87
|
end
|
82
|
-
|
88
|
+
|
83
89
|
##
|
84
90
|
# Show a form that lets the user edit an existing section entry.
|
85
91
|
#
|
@@ -97,13 +103,19 @@ module Sections
|
|
97
103
|
if !user_authorized?([:read, :update])
|
98
104
|
respond(lang('zen_general.errors.not_authorized'), 403)
|
99
105
|
end
|
100
|
-
|
106
|
+
|
101
107
|
set_breadcrumbs(
|
102
|
-
anchor_to(
|
103
|
-
|
108
|
+
anchor_to(
|
109
|
+
lang('sections.titles.index'),
|
110
|
+
Sections.r(:index)
|
111
|
+
),
|
112
|
+
anchor_to(
|
113
|
+
lang('section_entries.titles.index'),
|
114
|
+
SectionEntries.r(:index, section_id)
|
115
|
+
),
|
104
116
|
lang('section_entries.titles.edit')
|
105
117
|
)
|
106
|
-
|
118
|
+
|
107
119
|
@section_id = section_id
|
108
120
|
|
109
121
|
if flash[:form_data]
|
@@ -113,10 +125,10 @@ module Sections
|
|
113
125
|
end
|
114
126
|
|
115
127
|
@users_hash = {}
|
116
|
-
|
128
|
+
|
117
129
|
Users::Model::User.each { |u| @users_hash[u.id] = u.name }
|
118
130
|
end
|
119
|
-
|
131
|
+
|
120
132
|
##
|
121
133
|
# Show a form that lets the user create a new section entry.
|
122
134
|
#
|
@@ -129,24 +141,30 @@ module Sections
|
|
129
141
|
# @param [Integer] section_id The ID of the current section.
|
130
142
|
# @since 0.1
|
131
143
|
#
|
132
|
-
def new
|
144
|
+
def new(section_id)
|
133
145
|
if !user_authorized?([:read, :create])
|
134
146
|
respond(lang('zen_general.errors.not_authorized'), 403)
|
135
147
|
end
|
136
|
-
|
148
|
+
|
137
149
|
set_breadcrumbs(
|
138
|
-
anchor_to(
|
139
|
-
|
150
|
+
anchor_to(
|
151
|
+
lang('sections.titles.index'),
|
152
|
+
Sections.r(:index)
|
153
|
+
),
|
154
|
+
anchor_to(
|
155
|
+
lang('section_entries.titles.index'),
|
156
|
+
SectionEntries.r(:index, section_id)
|
157
|
+
),
|
140
158
|
lang('section_entries.titles.new')
|
141
159
|
)
|
142
|
-
|
160
|
+
|
143
161
|
@section_id = section_id
|
144
162
|
@entry = SectionEntry.new(:section_id => @section_id)
|
145
163
|
@users_hash = {}
|
146
|
-
|
164
|
+
|
147
165
|
Users::Model::User.each { |u| @users_hash[u.id] = u.name }
|
148
166
|
end
|
149
|
-
|
167
|
+
|
150
168
|
##
|
151
169
|
# Method used for processing the form data and redirecting the user back to
|
152
170
|
# the proper URL. Based on the value of a hidden field named "id" we'll determine
|
@@ -166,15 +184,15 @@ module Sections
|
|
166
184
|
if !user_authorized?([:create, :update])
|
167
185
|
respond(lang('zen_general.errors.not_authorized'), 403)
|
168
186
|
end
|
169
|
-
|
187
|
+
|
170
188
|
post = request.params.dup
|
171
189
|
section_id = post['section_id']
|
172
190
|
field_values = post['custom_field_values']
|
173
191
|
custom_field_errors = {}
|
174
|
-
|
175
|
-
post.delete(
|
192
|
+
|
193
|
+
post.delete('custom_field_values')
|
176
194
|
post.delete('slug') if post['slug'].empty?
|
177
|
-
|
195
|
+
|
178
196
|
if !post['category_pks'].nil?
|
179
197
|
post['category_pks'].map! { |value| value.to_i }
|
180
198
|
else
|
@@ -184,7 +202,7 @@ module Sections
|
|
184
202
|
if post['id'] and !post['id'].empty?
|
185
203
|
@entry = SectionEntry[post['id']]
|
186
204
|
save_action = :save
|
187
|
-
|
205
|
+
|
188
206
|
# Section entries aren't considered to be updated whenever a custom field value
|
189
207
|
# is modified, this solves that problem
|
190
208
|
post['updated_at'] = Time.new
|
@@ -192,70 +210,70 @@ module Sections
|
|
192
210
|
@entry = SectionEntry.new
|
193
211
|
save_action = :new
|
194
212
|
end
|
195
|
-
|
213
|
+
|
214
|
+
post.delete('id')
|
215
|
+
|
196
216
|
flash_success = lang("section_entries.success.#{save_action}")
|
197
217
|
flash_error = lang("section_entries.errors.#{save_action}")
|
198
|
-
|
218
|
+
|
199
219
|
# Transactions ahoy!
|
200
220
|
begin
|
201
|
-
Zen
|
221
|
+
Zen.database.transaction do
|
202
222
|
# Update the entry itself
|
203
223
|
@entry.update(post)
|
204
|
-
|
205
|
-
|
224
|
+
message(:success, flash_success)
|
225
|
+
|
206
226
|
# Update the field values
|
207
227
|
field_values.each do |field_id, value|
|
208
228
|
field_value = CustomFields::Model::CustomFieldValue[
|
209
|
-
:custom_field_id => field_id,
|
229
|
+
:custom_field_id => field_id,
|
210
230
|
:section_entry_id => @entry.id
|
211
231
|
]
|
212
|
-
|
232
|
+
|
213
233
|
if field_value.nil?
|
214
234
|
field_value = @entry.add_custom_field_value(
|
215
|
-
:section_entry_id => @entry.id,
|
235
|
+
:section_entry_id => @entry.id,
|
216
236
|
:custom_field_id => field_id
|
217
237
|
)
|
218
238
|
end
|
219
|
-
|
239
|
+
|
220
240
|
# Get the custom field for the current value
|
221
241
|
custom_field = field_value.custom_field
|
222
|
-
|
242
|
+
|
223
243
|
if custom_field.required and value.empty?
|
224
|
-
custom_field_errors[:"custom_field_values[#{field_id}]"] =
|
244
|
+
custom_field_errors[:"custom_field_values[#{field_id}]"] = \
|
245
|
+
lang('zen_models.presence')
|
225
246
|
end
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
# No need for a particular exception as Sequel will undo the changes anyway
|
230
|
-
raise
|
231
|
-
end
|
232
|
-
|
247
|
+
|
248
|
+
raise unless custom_field_errors.empty?
|
249
|
+
|
233
250
|
field_value.value = value
|
234
251
|
field_value.save
|
235
252
|
end
|
236
253
|
end
|
237
|
-
|
254
|
+
|
238
255
|
# The rescue statement is called whenever the following happens:
|
239
|
-
#
|
256
|
+
#
|
240
257
|
# 1. The fields for the section entry (title, slug, etc) are invalid
|
241
258
|
# 2. Any custom field marked as required didn't have a value
|
242
259
|
# 3. Something else went wrong, god knows what.
|
243
|
-
rescue
|
244
|
-
|
245
|
-
|
260
|
+
rescue => e
|
261
|
+
Ramaze::Log.error(e.inspect)
|
262
|
+
message(:error, flash_error)
|
263
|
+
|
246
264
|
flash[:form_errors] = @entry.errors.merge(custom_field_errors)
|
247
265
|
flash[:form_data] = @entry
|
248
266
|
|
249
267
|
redirect_referrer
|
250
268
|
end
|
251
|
-
|
269
|
+
|
252
270
|
if @entry.id
|
253
271
|
redirect(SectionEntries.r(:edit, section_id, @entry.id))
|
254
272
|
else
|
255
273
|
redirect_referrer
|
256
274
|
end
|
257
275
|
end
|
258
|
-
|
276
|
+
|
259
277
|
##
|
260
278
|
# Delete a set of section entries based on the supplied POST
|
261
279
|
# field "section_entry_ids".
|
@@ -271,36 +289,24 @@ module Sections
|
|
271
289
|
if !user_authorized?([:delete])
|
272
290
|
respond(lang('zen_general.errors.not_authorized'), 403)
|
273
291
|
end
|
274
|
-
|
275
|
-
if !request.params['section_entry_ids'] or request.params['section_entry_ids'].empty?
|
276
|
-
notification(
|
277
|
-
:error,
|
278
|
-
lang('section_entries.titles.index'),
|
279
|
-
lang('section_entries.errors.no_delete')
|
280
|
-
)
|
281
292
|
|
293
|
+
if !request.params['section_entry_ids'] or request.params['section_entry_ids'].empty?
|
294
|
+
message(:error, lang('section_entries.errors.no_delete'))
|
282
295
|
redirect_referrer
|
283
296
|
end
|
284
|
-
|
297
|
+
|
285
298
|
request.params['section_entry_ids'].each do |id|
|
286
299
|
begin
|
287
|
-
SectionEntry[id
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
)
|
293
|
-
rescue
|
294
|
-
notification(
|
295
|
-
:error,
|
296
|
-
lang('section_entries.titles.index'),
|
297
|
-
lang('section_entries.errors.delete') % id
|
298
|
-
)
|
300
|
+
SectionEntry[id].destroy
|
301
|
+
message(:success, lang('section_entries.success.delete'))
|
302
|
+
rescue => e
|
303
|
+
Ramaze::Log.error(e.inspect)
|
304
|
+
message(:error,lang('section_entries.errors.delete') % id)
|
299
305
|
end
|
300
306
|
end
|
301
|
-
|
307
|
+
|
302
308
|
redirect_referrer
|
303
309
|
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|
310
|
+
end # SectionEntries
|
311
|
+
end # Controller
|
312
|
+
end # Sections
|