zen 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.gems +34 -0
  2. data/.travis.yml +7 -0
  3. data/AUTHORS +5 -0
  4. data/CHANGELOG +14 -0
  5. data/{license.txt → LICENSE} +0 -0
  6. data/MANIFEST +67 -51
  7. data/README.md +18 -25
  8. data/Rakefile +2 -3
  9. data/bin/zen +2 -2
  10. data/lib/zen.rb +93 -57
  11. data/lib/zen/asset.rb +7 -8
  12. data/lib/zen/bin/app.rb +0 -2
  13. data/lib/zen/controller/admin_controller.rb +4 -9
  14. data/lib/zen/controller/base_controller.rb +0 -25
  15. data/lib/zen/controller/main_controller.rb +5 -5
  16. data/lib/zen/controller/preview.rb +50 -0
  17. data/lib/zen/helper/common.rb +4 -68
  18. data/lib/zen/helper/message.rb +82 -0
  19. data/lib/zen/helper/theme.rb +2 -2
  20. data/lib/zen/language.rb +68 -38
  21. data/lib/zen/language/en/zen_general.yml +1 -4
  22. data/lib/zen/language/nl/zen_general.yml +28 -0
  23. data/lib/zen/language/nl/zen_models.yml +13 -0
  24. data/lib/zen/layout/admin.xhtml +1 -1
  25. data/lib/zen/layout/login.xhtml +1 -1
  26. data/lib/zen/model/settings.rb +2 -0
  27. data/lib/zen/package.rb +29 -25
  28. data/lib/zen/package/all.rb +1 -1
  29. data/lib/zen/package/categories/lib/categories/controller/categories.rb +51 -63
  30. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -52
  31. data/lib/zen/package/categories/lib/categories/language/en/categories.yml +2 -2
  32. data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +39 -0
  33. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +33 -0
  34. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +2 -2
  35. data/lib/zen/package/comments/lib/comments.rb +31 -2
  36. data/lib/zen/package/comments/lib/comments/controller/comments.rb +42 -57
  37. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +36 -51
  38. data/lib/zen/package/comments/lib/comments/language/en/comments.yml +7 -3
  39. data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +48 -0
  40. data/lib/zen/package/comments/lib/comments/model/comment.rb +45 -4
  41. data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +152 -0
  42. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +5 -6
  43. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +2 -2
  44. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +43 -52
  45. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +68 -67
  46. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +1 -1
  47. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +32 -0
  48. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +52 -0
  49. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +3 -3
  50. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +4 -7
  51. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
  52. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +37 -44
  53. data/lib/zen/package/menus/lib/menus/controller/menus.rb +33 -43
  54. data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +5 -10
  55. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +41 -0
  56. data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +39 -0
  57. data/lib/zen/package/menus/lib/menus/model/menu.rb +3 -3
  58. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +3 -3
  59. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +5 -6
  60. data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +1 -1
  61. data/lib/zen/package/sections/lib/sections.rb +20 -0
  62. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +85 -79
  63. data/lib/zen/package/sections/lib/sections/controller/sections.rb +58 -66
  64. data/lib/zen/package/sections/lib/sections/language/en/sections.yml +0 -1
  65. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +43 -0
  66. data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +47 -0
  67. data/lib/zen/package/sections/lib/sections/model/section.rb +11 -15
  68. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -5
  69. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +7 -8
  70. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +3 -4
  71. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +0 -4
  72. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +8 -2
  73. data/lib/zen/package/sections/migrations/1306772479_remove_unique_slug.rb +28 -0
  74. data/lib/zen/package/settings/lib/settings.rb +21 -34
  75. data/lib/zen/package/settings/lib/settings/controller/settings.rb +29 -22
  76. data/lib/zen/package/settings/lib/settings/language/en/settings.yml +7 -5
  77. data/lib/zen/package/settings/lib/settings/language/nl/settings.yml +39 -0
  78. data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -5
  79. data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +3 -4
  80. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +3 -5
  81. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +11 -4
  82. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +5 -5
  83. data/lib/zen/package/settings/migrations/1299538742_add_language_key.rb +8 -8
  84. data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +2 -5
  85. data/lib/zen/package/users/lib/users/controller/access_rules.rb +54 -61
  86. data/lib/zen/package/users/lib/users/controller/user_groups.rb +49 -57
  87. data/lib/zen/package/users/lib/users/controller/users.rb +58 -73
  88. data/lib/zen/package/users/lib/users/language/en/users.yml +6 -0
  89. data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +37 -0
  90. data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +31 -0
  91. data/lib/zen/package/users/lib/users/language/nl/users.yml +56 -0
  92. data/lib/zen/package/users/lib/users/model/user.rb +16 -1
  93. data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +27 -2
  94. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +15 -3
  95. data/lib/zen/package/users/migrations/1304939855_user_settings.rb +15 -0
  96. data/lib/zen/plugin.rb +7 -9
  97. data/lib/zen/public/admin/css/{buttons.css → zen/buttons.css} +11 -7
  98. data/lib/zen/public/admin/css/{datepicker.css → zen/datepicker.css} +0 -0
  99. data/lib/zen/public/admin/css/{editor.css → zen/editor.css} +10 -5
  100. data/lib/zen/public/admin/css/{forms.css → zen/forms.css} +1 -1
  101. data/lib/zen/public/admin/css/{general.css → zen/general.css} +7 -7
  102. data/lib/zen/public/admin/css/{grid.css → zen/grid.css} +0 -0
  103. data/lib/zen/public/admin/css/{layout.css → zen/layout.css} +4 -5
  104. data/lib/zen/public/admin/css/zen/messages.css +61 -0
  105. data/lib/zen/public/admin/css/{notifications.css → zen/notifications.css} +4 -4
  106. data/lib/zen/public/admin/css/{reset.css → zen/reset.css} +0 -0
  107. data/lib/zen/public/admin/css/{tables.css → zen/tables.css} +3 -3
  108. data/lib/zen/public/admin/css/{tabs.css → zen/tabs.css} +5 -5
  109. data/lib/zen/public/admin/css/zen/window.css +79 -0
  110. data/lib/zen/public/admin/images/{icons → zen/icons}/accept.png +0 -0
  111. data/lib/zen/public/admin/images/{icons → zen/icons}/add.png +0 -0
  112. data/lib/zen/public/admin/images/{icons → zen/icons}/back.png +0 -0
  113. data/lib/zen/public/admin/images/{icons → zen/icons}/bold.png +0 -0
  114. data/lib/zen/public/admin/images/zen/icons/close.png +0 -0
  115. data/lib/zen/public/admin/images/{icons → zen/icons}/delete.png +0 -0
  116. data/lib/zen/public/admin/images/{icons → zen/icons}/edit.png +0 -0
  117. data/lib/zen/public/admin/images/{icons → zen/icons}/error.png +0 -0
  118. data/lib/zen/public/admin/images/{icons → zen/icons}/help.png +0 -0
  119. data/lib/zen/public/admin/images/{icons → zen/icons}/info.png +0 -0
  120. data/lib/zen/public/admin/images/{icons → zen/icons}/italic.png +0 -0
  121. data/lib/zen/public/admin/images/{icons → zen/icons}/large/error.png +0 -0
  122. data/lib/zen/public/admin/images/{icons → zen/icons}/large/notice.png +0 -0
  123. data/lib/zen/public/admin/images/{icons → zen/icons}/large/success.png +0 -0
  124. data/lib/zen/public/admin/images/{icons → zen/icons}/link.png +0 -0
  125. data/lib/zen/public/admin/images/{icons → zen/icons}/logout.png +0 -0
  126. data/lib/zen/public/admin/images/{icons → zen/icons}/ol.png +0 -0
  127. data/lib/zen/public/admin/images/{icons → zen/icons}/pdf.png +0 -0
  128. data/lib/zen/public/admin/images/zen/icons/preview.png +0 -0
  129. data/lib/zen/public/admin/images/{icons → zen/icons}/ul.png +0 -0
  130. data/lib/zen/public/admin/images/{icons → zen/icons}/user.png +0 -0
  131. data/lib/zen/public/admin/images/{icons → zen/icons}/view.png +0 -0
  132. data/lib/zen/public/admin/js/zen/core.js +73 -0
  133. data/lib/zen/public/admin/js/zen/editor.js +527 -0
  134. data/lib/zen/public/admin/js/zen/editor/markdown.js +84 -0
  135. data/lib/zen/public/admin/js/zen/editor/textile.js +84 -0
  136. data/lib/zen/public/admin/js/zen/init.js +12 -66
  137. data/lib/zen/public/admin/js/zen/tabs.js +5 -0
  138. data/lib/zen/public/admin/js/zen/window.js +206 -0
  139. data/lib/zen/task/build.rake +23 -6
  140. data/lib/zen/task/clean.rake +6 -7
  141. data/lib/zen/task/db.rake +7 -9
  142. data/lib/zen/task/package.rake +6 -6
  143. data/lib/zen/task/test.rake +6 -0
  144. data/lib/zen/task/theme.rake +3 -3
  145. data/lib/zen/theme.rb +3 -4
  146. data/lib/zen/validation.rb +7 -9
  147. data/lib/zen/version.rb +3 -4
  148. data/lib/zen/view/bottom.xhtml +0 -5
  149. data/lib/zen/view/main.xhtml +2 -0
  150. data/proto/app/app.rb +6 -4
  151. data/proto/app/config/config.rb +1 -7
  152. data/proto/app/config/database.rb +47 -43
  153. data/proto/app/config/middlewares.rb +0 -40
  154. data/proto/app/start.rb +1 -6
  155. data/proto/app/{vendor → theme}/.gitkeep +0 -0
  156. data/proto/migration.rb +3 -3
  157. data/proto/package/lib/package.rb +0 -1
  158. data/proto/package/lib/package/controller/controllers.rb +7 -40
  159. data/proto/package/lib/package/model/model.rb +3 -3
  160. metadata +106 -79
  161. data/CHANGELOG.md +0 -27
  162. data/ROADMAP.md +0 -53
  163. data/lib/zen/database.rb +0 -112
  164. data/lib/zen/logger.rb +0 -56
  165. data/lib/zen/public/admin/css/modals.css +0 -63
  166. data/lib/zen/public/admin/images/icons/close.png +0 -0
  167. data/lib/zen/public/admin/js/vendor/yepnope.js +0 -1
  168. data/lib/zen/public/admin/js/zen/editor/base.js +0 -262
  169. data/lib/zen/public/admin/js/zen/editor/drivers/html.js +0 -89
  170. data/lib/zen/public/admin/js/zen/editor/drivers/markdown.js +0 -87
  171. data/lib/zen/public/admin/js/zen/editor/drivers/textile.js +0 -87
  172. data/lib/zen/public/admin/js/zen/modal.js +0 -146
  173. data/lib/zen/public/admin/js/zen/notification.js +0 -211
  174. data/proto/app/config/requires.rb +0 -10
  175. data/proto/app/vendor/theme/.gitkeep +0 -0
  176. data/proto/package/lib/package/view/admin/package/edit.xhtml +0 -0
  177. data/proto/package/lib/package/view/admin/package/form.xhtml +0 -0
  178. data/proto/package/lib/package/view/admin/package/new.xhtml +0 -0
@@ -71,8 +71,8 @@ module Comments
71
71
 
72
72
  # Now that we have the entry and the section we can start retrieving all the
73
73
  # comments.
74
- comments = Comment.filter(:section_entry_id => entry.id)
75
- .limit(@options[:limit], @options[:offset])
74
+ comments = Comment.filter(:section_entry_id => entry.id) \
75
+ .limit(@options[:limit], @options[:offset]) \
76
76
  .all
77
77
 
78
78
  # Don't bother with all code below this if/end if we don't want to convert the
@@ -105,7 +105,6 @@ module Comments
105
105
 
106
106
  return comments
107
107
  end
108
-
109
- end
110
- end
111
- end
108
+ end # Comments
109
+ end # Plugin
110
+ end # Comments
@@ -21,7 +21,7 @@
21
21
  <th>#{lang('comments.labels.name')}</th>
22
22
  <th>#{lang('comments.labels.email')}</th>
23
23
  <th>#{lang('comments.labels.website')}</th>
24
- <th>#{lang('comments.labels.defensio_signature')}</th>
24
+ <th>#{lang('comments.labels.created_at')}</th>
25
25
  </thead>
26
26
  <tbody>
27
27
  <?r @comments.each do |comment| ?>
@@ -58,7 +58,7 @@
58
58
  <td>#{user.email}</td>
59
59
  <td>#{user.website}</td>
60
60
  <?r end ?>
61
- <td>#{comment.defensio_signature}</td>
61
+ <td>#{comment.created_at.strftime(session[:user].date_format)}</td>
62
62
  </tr>
63
63
  <?r end ?>
64
64
  </tbody>
@@ -14,13 +14,13 @@ module CustomFields
14
14
  include ::CustomFields::Model
15
15
 
16
16
  map('/admin/custom-field-groups')
17
-
17
+
18
18
  before_all do
19
19
  csrf_protection(:save, :delete) do
20
20
  respond(lang('zen_general.errors.csrf'), 403)
21
21
  end
22
22
  end
23
-
23
+
24
24
  ##
25
25
  # Constructor method, called upon initialization. It's used to set the
26
26
  # URL to which forms send their data and load the language pack.
@@ -34,19 +34,19 @@ module CustomFields
34
34
  #
35
35
  def initialize
36
36
  super
37
-
37
+
38
38
  @form_save_url = CustomFieldGroups.r(:save)
39
39
  @form_delete_url = CustomFieldGroups.r(:delete)
40
40
 
41
41
  Zen::Language.load('custom_field_groups')
42
-
42
+
43
43
  # Set the page title
44
44
  if !action.method.nil?
45
45
  method = action.method.to_sym
46
46
  @page_title = lang("custom_field_groups.titles.#{method}") rescue nil
47
47
  end
48
48
  end
49
-
49
+
50
50
  ##
51
51
  # Show an overview of all existing custom field groups. Using this overview a user
52
52
  # can manage an existing field group, delete it or create a new one.
@@ -54,7 +54,7 @@ module CustomFields
54
54
  # This method requires the following permissions:
55
55
  #
56
56
  # * read
57
- #
57
+ #
58
58
  # @author Yorick Peterse
59
59
  # @since 0.1
60
60
  #
@@ -62,12 +62,12 @@ module CustomFields
62
62
  if !user_authorized?([:read])
63
63
  respond(lang('zen_general.errors.not_authorized'), 403)
64
64
  end
65
-
65
+
66
66
  set_breadcrumbs(lang('custom_field_groups.titles.index'))
67
-
67
+
68
68
  @field_groups = CustomFieldGroup.all
69
69
  end
70
-
70
+
71
71
  ##
72
72
  # Show a form that lets the user edit an existing custom field group.
73
73
  #
@@ -77,27 +77,27 @@ module CustomFields
77
77
  # * update
78
78
  #
79
79
  # @author Yorick Peterse
80
- # @param [Integer] id The ID of the custom field group to retrieve so that we
80
+ # @param [Integer] id The ID of the custom field group to retrieve so that we
81
81
  # can edit it.
82
82
  # @since 0.1
83
83
  #
84
- def edit id
84
+ def edit(id)
85
85
  if !user_authorized?([:read, :update])
86
86
  respond(lang('zen_general.errors.not_authorized'), 403)
87
87
  end
88
-
88
+
89
89
  set_breadcrumbs(
90
- anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
90
+ anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
91
91
  @page_title
92
92
  )
93
-
93
+
94
94
  if flash[:form_data]
95
95
  @field_group = flash[:form_data]
96
96
  else
97
97
  @field_group = CustomFieldGroup[id.to_i]
98
98
  end
99
99
  end
100
-
100
+
101
101
  ##
102
102
  # Show a form that lets the user create a new custom field group.
103
103
  #
@@ -113,15 +113,15 @@ module CustomFields
113
113
  if !user_authorized?([:read, :create])
114
114
  respond(lang('zen_general.errors.not_authorized'), 403)
115
115
  end
116
-
116
+
117
117
  set_breadcrumbs(
118
- anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
118
+ anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
119
119
  @page_title
120
120
  )
121
-
121
+
122
122
  @field_group = CustomFieldGroup.new
123
123
  end
124
-
124
+
125
125
  ##
126
126
  # Method used for processing the form data and redirecting the user back to
127
127
  # the proper URL. Based on the value of a hidden field named 'id' we'll determine
@@ -139,43 +139,46 @@ module CustomFields
139
139
  if !user_authorized?([:create, :update])
140
140
  respond(lang('zen_general.errors.not_authorized'), 403)
141
141
  end
142
-
143
- post = request.params.dup
144
-
142
+
143
+ post = request.subset(:id, :name, :description)
144
+
145
145
  # Get or create a custom field group based on the ID from the hidden field.
146
146
  if post['id'] and !post['id'].empty?
147
- @field_group = CustomFieldGroup[post['id'].to_i]
147
+ @field_group = CustomFieldGroup[post['id']]
148
148
  save_action = :save
149
149
  else
150
150
  @field_group = CustomFieldGroup.new
151
151
  save_action = :new
152
152
  end
153
-
153
+
154
+ post.delete('id')
155
+
156
+ # Set the messages
154
157
  flash_success = lang("custom_field_groups.success.#{save_action}")
155
158
  flash_error = lang("custom_field_groups.errors.#{save_action}")
156
-
159
+
157
160
  begin
158
161
  @field_group.update(post)
159
- notification(:success, lang("custom_field_groups.titles.index"), flash_success)
162
+ message(:success, flash_success)
160
163
  rescue
161
- notification(:error, lang("custom_field_groups.titles.index"), flash_error)
164
+ message(:error, flash_error)
162
165
 
163
166
  flash[:form_errors] = @field_group.errors
164
167
  flash[:form_data] = @field_group
165
168
  end
166
-
169
+
167
170
  if !@field_group.nil? and @field_group.id
168
171
  redirect(CustomFieldGroups.r(:edit, @field_group.id))
169
172
  else
170
173
  redirect(CustomFieldGroups.r(:new))
171
174
  end
172
175
  end
173
-
176
+
174
177
  ##
175
178
  # Delete an existing custom field group.
176
179
  #
177
- # In order to delete a custom field group you'll need to send a POST request
178
- # that contains a field named 'custom_field_group_ids[]'. This field should
180
+ # In order to delete a custom field group you'll need to send a POST request
181
+ # that contains a field named 'custom_field_group_ids[]'. This field should
179
182
  # contain the primary values of each field group that has to be deleted.
180
183
  #
181
184
  # This method requires the following permissions:
@@ -189,35 +192,23 @@ module CustomFields
189
192
  if !user_authorized?([:delete])
190
193
  respond(lang('zen_general.errors.not_authorized'), 403)
191
194
  end
192
-
195
+
193
196
  if !request.params['custom_field_group_ids'] or request.params['custom_field_group_ids'].empty?
194
- notification(
195
- :error,
196
- lang('custom_field_groups.titles.index'),
197
- lang('custom_field_groups.errors.no_delete')
198
- )
197
+ message(:error, lang('custom_field_groups.errors.no_delete'))
199
198
  redirect(CustomFieldGroups.r(:index))
200
199
  end
201
-
200
+
202
201
  request.params['custom_field_group_ids'].each do |id|
203
202
  begin
204
203
  CustomFieldGroup[id.to_i].destroy
205
- notification(
206
- :success,
207
- lang('custom_field_groups.titles.index'),
208
- lang('custom_field_groups.success.delete')
209
- )
204
+ message(:success, lang('custom_field_groups.success.delete'))
210
205
  rescue
211
- notification(
212
- :error,
213
- lang('custom_field_groups.titles.index'),
214
- lang('custom_field_groups.errors.delete') % id
215
- )
206
+ message(:error, lang('custom_field_groups.errors.delete') % id)
216
207
  end
217
208
  end
218
-
209
+
219
210
  redirect_referrer
220
211
  end
221
- end
222
- end
223
- end
212
+ end # CustomFieldGroups
213
+ end # Controller
214
+ end # CustomFields
@@ -16,13 +16,16 @@ module CustomFields
16
16
  include ::CustomFields::Model
17
17
 
18
18
  map('/admin/custom-fields')
19
-
19
+
20
+ # Load all required Javascript files
21
+ javascript ['zen/tabs']
22
+
20
23
  before_all do
21
24
  csrf_protection(:save, :delete) do
22
25
  respond(lang('zen_general.errors.csrf'), 403)
23
26
  end
24
27
  end
25
-
28
+
26
29
  ##
27
30
  # Constructor method, called upon initialization. It's used to set the
28
31
  # URL to which forms send their data and load the language pack.
@@ -37,13 +40,13 @@ module CustomFields
37
40
  #
38
41
  def initialize
39
42
  super
40
-
43
+
41
44
  @form_save_url = CustomFields.r(:save)
42
45
  @form_delete_url = CustomFields.r(:delete)
43
-
46
+
44
47
  Zen::Language.load('custom_fields')
45
48
  Zen::Language.load('custom_field_groups')
46
-
49
+
47
50
  # Set the page title
48
51
  if !action.method.nil?
49
52
  method = action.method.to_sym
@@ -61,7 +64,7 @@ module CustomFields
61
64
  'select_multiple' => lang('custom_fields.special.type_hash.select_multiple')
62
65
  }
63
66
  end
64
-
67
+
65
68
  ##
66
69
  # Show an overview of all existing custom fields. Using this overview a user
67
70
  # can manage an existing field, delete it or create a new one.
@@ -69,26 +72,26 @@ module CustomFields
69
72
  # This method requires the following permissions:
70
73
  #
71
74
  # * read
72
- #
75
+ #
73
76
  # @author Yorick Peterse
74
- # @param [Integer] custom_field_group_id The ID of the custom field group to
77
+ # @param [Integer] custom_field_group_id The ID of the custom field group to
75
78
  # which all fields belong.
76
79
  # @since 0.1
77
80
  #
78
- def index custom_field_group_id
81
+ def index(custom_field_group_id)
79
82
  if !user_authorized?([:read])
80
83
  respond(lang('zen_general.errors.not_authorized'), 403)
81
84
  end
82
-
85
+
83
86
  set_breadcrumbs(
84
87
  anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
85
88
  lang('custom_fields.titles.index')
86
89
  )
87
-
88
- @custom_field_group_id = custom_field_group_id.to_i
89
- @custom_fields = CustomFieldGroup[@custom_field_group_id].custom_fields
90
+
91
+ @custom_field_group_id = custom_field_group_id.to_i
92
+ @custom_fields = CustomFieldGroup[@custom_field_group_id].custom_fields
90
93
  end
91
-
94
+
92
95
  ##
93
96
  # Show a form that lets the user edit an existing custom field group.
94
97
  #
@@ -98,22 +101,22 @@ module CustomFields
98
101
  # * update
99
102
  #
100
103
  # @author Yorick Peterse
101
- # @param [Integer] custom_field_group_id The ID of the custom field group to
104
+ # @param [Integer] custom_field_group_id The ID of the custom field group to
102
105
  # which all fields belong.
103
106
  # @param [Integer] id The ID of the custom field to retrieve so that we can edit it.
104
107
  # @since 0.1
105
108
  #
106
- def edit custom_field_group_id, id
109
+ def edit(custom_field_group_id, id)
107
110
  if !user_authorized?([:read, :update])
108
111
  respond(lang('zen_general.errors.not_authorized'), 403)
109
112
  end
110
-
113
+
111
114
  set_breadcrumbs(
112
115
  anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
113
116
  anchor_to(lang('custom_fields.titles.index'), CustomFields.r(:index, custom_field_group_id)),
114
117
  lang('custom_fields.titles.edit')
115
118
  )
116
-
119
+
117
120
  @custom_field_group_id = custom_field_group_id
118
121
 
119
122
  if flash[:form_data]
@@ -122,7 +125,7 @@ module CustomFields
122
125
  @custom_field = CustomField[id.to_i]
123
126
  end
124
127
  end
125
-
128
+
126
129
  ##
127
130
  # Show a form that lets the user create a new custom field group.
128
131
  #
@@ -132,25 +135,31 @@ module CustomFields
132
135
  # * read
133
136
  #
134
137
  # @author Yorick Peterse
135
- # @param [Integer] custom_field_group_id The ID of the custom field group to
138
+ # @param [Integer] custom_field_group_id The ID of the custom field group to
136
139
  # which all fields belong.
137
140
  # @since 0.1
138
141
  #
139
- def new custom_field_group_id
142
+ def new(custom_field_group_id)
140
143
  if !user_authorized?([:read, :create])
141
144
  respond(lang('zen_general.errors.not_authorized'), 403)
142
145
  end
143
-
146
+
144
147
  set_breadcrumbs(
145
- anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
146
- anchor_to(lang('custom_fields.titles.index'), CustomFields.r(:index, custom_field_group_id)),
148
+ anchor_to(
149
+ lang('custom_field_groups.titles.index'),
150
+ CustomFieldGroups.r(:index)
151
+ ),
152
+ anchor_to(
153
+ lang('custom_fields.titles.index'),
154
+ CustomFields.r(:index, custom_field_group_id)
155
+ ),
147
156
  lang('custom_fields.titles.index')
148
157
  )
149
-
158
+
150
159
  @custom_field_group_id = custom_field_group_id
151
160
  @custom_field = CustomField.new
152
161
  end
153
-
162
+
154
163
  ##
155
164
  # Method used for processing the form data and redirecting the user back to
156
165
  # the proper URL. Based on the value of a hidden field named 'id' we'll determine
@@ -168,46 +177,50 @@ module CustomFields
168
177
  if !user_authorized?([:create, :update])
169
178
  respond(lang('zen_general.errors.not_authorized'), 403)
170
179
  end
171
-
172
- post = request.params.dup
173
- custom_field_group_id = post['custom_field_group_id']
174
-
175
- post.delete('slug') if post['slug'].empty?
180
+
181
+ post = request.subset(
182
+ :id, :name, :slug, :description, :sort_order, :type, :format, :possible_values,
183
+ :required, :visual_editor, :textarea_rows, :text_limit, :custom_field_group_id
184
+ )
176
185
 
177
186
  # Get or create a custom field group based on the ID from the hidden field.
178
187
  if post['id'] and !post['id'].empty?
179
- @custom_field = CustomField[post['id'].to_i]
188
+ @custom_field = CustomField[post['id']]
180
189
  save_action = :save
181
190
  else
182
191
  @custom_field = CustomField.new
183
192
  save_action = :new
184
193
  end
185
-
194
+
195
+ post.delete('slug') if post['slug'].empty?
196
+ post.delete('id')
197
+
186
198
  flash_success = lang("custom_fields.success.#{save_action}")
187
199
  flash_error = lang("custom_fields.errors.#{save_action}")
188
200
 
189
201
  begin
190
202
  @custom_field.update(post)
191
- notification(:success, lang('custom_fields.titles.index'), flash_success)
192
- rescue
193
- notification(:error, lang('custom_fields.titles.index'), flash_error)
203
+ message(:success, flash_success)
204
+ rescue => e
205
+ Ramaze::Log.error(e.inspect)
206
+ message(:error, flash_error)
194
207
 
195
208
  flash[:form_data] = @custom_field
196
209
  flash[:form_errors] = @custom_field.errors
197
210
  end
198
-
211
+
199
212
  if @custom_field.id
200
- redirect(CustomFields.r(:edit, custom_field_group_id, @custom_field.id))
213
+ redirect(CustomFields.r(:edit, post['custom_field_group_id'], @custom_field.id))
201
214
  else
202
- redirect(CustomFields.r(:new, custom_field_group_id))
215
+ redirect_referrer
203
216
  end
204
217
  end
205
-
218
+
206
219
  ##
207
220
  # Delete an existing custom field.
208
221
  #
209
- # In order to delete a custom field group you'll need to send a POST request that
210
- # contains a field named 'custom_field_ids[]'. This field should contain the
222
+ # In order to delete a custom field group you'll need to send a POST request that
223
+ # contains a field named 'custom_field_ids[]'. This field should contain the
211
224
  # primary values of each field that has to be deleted.
212
225
  #
213
226
  # This method requires the following permissions:
@@ -222,37 +235,25 @@ module CustomFields
222
235
  respond(lang('zen_general.errors.not_authorized'), 403)
223
236
  end
224
237
 
225
- post = request.params.dup
226
-
227
- if !request.params['custom_field_ids'] or request.params['custom_field_ids'].empty?
228
- notification(
229
- :error,
230
- lang('custom_fields.titles.index'),
231
- lang('custom_fields.errors.no_delete')
232
- )
238
+ post = request.subset(:custom_field_ids, :custom_field_group_id)
233
239
 
240
+ if !request.params['custom_field_ids'] or request.params['custom_field_ids'].empty?
241
+ message(:error, lang('custom_fields.errors.no_delete'))
234
242
  redirect(CustomFields.r(:index, post['custom_field_group_id']))
235
243
  end
236
-
244
+
237
245
  request.params['custom_field_ids'].each do |id|
238
246
  begin
239
- CustomField[id.to_i].destroy
240
- notification(
241
- :success,
242
- lang('custom_fields.titles.index'),
243
- lang('custom_fields.success.delete')
244
- )
245
- rescue
246
- notification(
247
- :error,
248
- lang('custom_fields.titles.index'),
249
- lang('custom_fields.errors.delete') % id
250
- )
247
+ CustomField[id].destroy
248
+ message(:success, lang('custom_fields.success.delete'))
249
+ rescue => e
250
+ Ramaze::Log.error(e.inspect)
251
+ message(:error, lang('custom_fields.errors.delete') % id)
251
252
  end
252
253
  end
253
-
254
+
254
255
  redirect_referrer
255
256
  end
256
- end
257
- end
258
- end
257
+ end # CustomFields
258
+ end # Controller
259
+ end # CustomFields