zen 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/.gitignore +15 -0
  2. data/.mailmap +2 -0
  3. data/.rvmrc +2 -0
  4. data/.travis.yml +8 -3
  5. data/AUTHORS +1 -2
  6. data/CHANGELOG.md +48 -17
  7. data/README.md +44 -39
  8. data/Rakefile +4 -0
  9. data/bin/zen +5 -30
  10. data/lib/zen.rb +13 -19
  11. data/lib/zen/asset.rb +99 -64
  12. data/lib/zen/bin/create.rb +94 -0
  13. data/lib/zen/bin/runner.rb +118 -0
  14. data/lib/zen/controller/admin_controller.rb +52 -36
  15. data/lib/zen/controller/base_controller.rb +5 -5
  16. data/lib/zen/controller/frontend_controller.rb +7 -7
  17. data/lib/zen/controller/main_controller.rb +12 -10
  18. data/lib/zen/controller/preview.rb +15 -11
  19. data/lib/zen/helper/acl.rb +73 -53
  20. data/lib/zen/helper/blue_form_vendor.rb +689 -0
  21. data/lib/zen/helper/breadcrumb.rb +23 -19
  22. data/lib/zen/helper/message.rb +3 -3
  23. data/lib/zen/helper/theme.rb +18 -13
  24. data/lib/zen/language.rb +62 -58
  25. data/lib/zen/language/en/zen_general.yml +2 -4
  26. data/lib/zen/language/nl/zen_general.yml +2 -4
  27. data/lib/zen/layout/admin.xhtml +3 -12
  28. data/lib/zen/layout/login.xhtml +1 -6
  29. data/lib/zen/model/methods.rb +6 -6
  30. data/lib/zen/model/settings.rb +5 -4
  31. data/lib/zen/package.rb +47 -38
  32. data/lib/zen/package/all.rb +3 -5
  33. data/lib/zen/package/base.rb +7 -7
  34. data/lib/zen/package/categories/lib/categories.rb +8 -3
  35. data/lib/zen/package/categories/lib/categories/controller/categories.rb +81 -55
  36. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -44
  37. data/lib/zen/package/categories/lib/categories/helper/category.rb +88 -0
  38. data/lib/zen/package/categories/lib/categories/language/en/categories.yml +5 -4
  39. data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +5 -4
  40. data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +5 -4
  41. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +5 -4
  42. data/lib/zen/package/categories/lib/categories/model/category.rb +15 -13
  43. data/lib/zen/package/categories/lib/categories/model/category_group.rb +3 -3
  44. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +36 -25
  45. data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +49 -56
  46. data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +48 -35
  47. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/form.xhtml +36 -29
  48. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +42 -37
  49. data/lib/zen/package/comments/lib/comments.rb +4 -1
  50. data/lib/zen/package/comments/lib/comments/controller/comments.rb +39 -32
  51. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +45 -26
  52. data/lib/zen/package/comments/lib/comments/helper/comment.rb +35 -0
  53. data/lib/zen/package/comments/lib/comments/language/en/comments.yml +9 -7
  54. data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +10 -8
  55. data/lib/zen/package/comments/lib/comments/model/comment.rb +31 -17
  56. data/lib/zen/package/comments/lib/comments/model/comment_status.rb +15 -0
  57. data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +27 -18
  58. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +25 -20
  59. data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +61 -54
  60. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +38 -23
  61. data/lib/zen/package/comments/migrations/1308774099_comment_status.rb +60 -0
  62. data/lib/zen/package/custom_fields/lib/custom_fields.rb +33 -7
  63. data/lib/zen/package/custom_fields/lib/custom_fields/blue_form_parameters.rb +209 -0
  64. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +50 -47
  65. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_types.rb +215 -0
  66. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +111 -73
  67. data/lib/zen/package/custom_fields/lib/custom_fields/helper/custom_field.rb +79 -0
  68. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_groups.yml +20 -19
  69. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_types.yml +40 -0
  70. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +34 -32
  71. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +5 -4
  72. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_types.yml +40 -0
  73. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +18 -16
  74. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +31 -11
  75. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_method.rb +15 -0
  76. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb +50 -0
  77. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +28 -7
  78. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/form.xhtml +33 -28
  79. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +48 -46
  80. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/form.xhtml +61 -0
  81. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/index.xhtml +93 -0
  82. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +105 -99
  83. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +43 -39
  84. data/lib/zen/package/custom_fields/migrations/1295255665_create_schema.rb +47 -16
  85. data/lib/zen/package/custom_fields/migrations/1310659580_custom_field_types.rb +148 -0
  86. data/lib/zen/package/custom_fields/migrations/1311694920_rename_css_class.rb +11 -0
  87. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +40 -35
  88. data/lib/zen/package/menus/lib/menus/controller/menus.rb +47 -43
  89. data/lib/zen/package/menus/lib/menus/helper/{menu_item.rb → menu.rb} +42 -15
  90. data/lib/zen/package/menus/lib/menus/language/en/menu_items.yml +5 -5
  91. data/lib/zen/package/menus/lib/menus/language/en/menus.yml +9 -8
  92. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +8 -8
  93. data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +11 -10
  94. data/lib/zen/package/menus/lib/menus/model/menu.rb +5 -5
  95. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +6 -5
  96. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +41 -43
  97. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +59 -63
  98. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +35 -30
  99. data/lib/zen/package/menus/lib/menus/view/admin/menus/form.xhtml +46 -37
  100. data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +37 -37
  101. data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +5 -5
  102. data/lib/zen/package/menus/migrations/1308671733_rename_order_column.rb +11 -0
  103. data/lib/zen/package/menus/migrations/1311695030_rename_css_class.rb +17 -0
  104. data/lib/zen/package/sections/lib/sections.rb +18 -11
  105. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +115 -109
  106. data/lib/zen/package/sections/lib/sections/controller/sections.rb +72 -50
  107. data/lib/zen/package/sections/lib/sections/helper/section.rb +53 -0
  108. data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +5 -4
  109. data/lib/zen/package/sections/lib/sections/language/en/sections.yml +5 -4
  110. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +5 -4
  111. data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +5 -4
  112. data/lib/zen/package/sections/lib/sections/model/section.rb +17 -9
  113. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +192 -13
  114. data/lib/zen/package/sections/lib/sections/model/section_entry_status.rb +13 -0
  115. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +60 -39
  116. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +14 -11
  117. data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +100 -97
  118. data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +41 -39
  119. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +95 -215
  120. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +48 -40
  121. data/lib/zen/package/sections/migrations/1308672298_use_id_for_default_section.rb +40 -0
  122. data/lib/zen/package/sections/migrations/1308813320_section_entry_statuses.rb +58 -0
  123. data/lib/zen/package/settings/lib/settings/controller/settings.rb +5 -8
  124. data/lib/zen/package/settings/lib/settings/model/setting.rb +2 -37
  125. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +18 -1
  126. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +13 -7
  127. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +2 -1
  128. data/lib/zen/package/users/lib/users.rb +3 -1
  129. data/lib/zen/package/users/lib/users/controller/access_rules.rb +77 -60
  130. data/lib/zen/package/users/lib/users/controller/user_groups.rb +41 -36
  131. data/lib/zen/package/users/lib/users/controller/users.rb +48 -42
  132. data/lib/zen/package/users/lib/users/helper/users.rb +72 -0
  133. data/lib/zen/package/users/lib/users/language/en/access_rules.yml +6 -5
  134. data/lib/zen/package/users/lib/users/language/en/user_groups.yml +5 -4
  135. data/lib/zen/package/users/lib/users/language/en/users.yml +1 -0
  136. data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +5 -4
  137. data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +5 -4
  138. data/lib/zen/package/users/lib/users/language/nl/users.yml +1 -0
  139. data/lib/zen/package/users/lib/users/model/access_rule.rb +5 -1
  140. data/lib/zen/package/users/lib/users/model/user.rb +17 -10
  141. data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +10 -37
  142. data/lib/zen/package/users/lib/users/public/admin/js/users/lib/access_rules.js +49 -0
  143. data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +105 -96
  144. data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +48 -41
  145. data/lib/zen/package/users/lib/users/view/admin/user-groups/form.xhtml +42 -32
  146. data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +43 -38
  147. data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +76 -67
  148. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +43 -41
  149. data/lib/zen/package/users/lib/users/view/admin/users/login.xhtml +12 -9
  150. data/lib/zen/package/users/migrations/1295281013_create_schema.rb +2 -2
  151. data/lib/zen/plugin.rb +56 -50
  152. data/lib/zen/plugin/markup/lib/markup/markup.rb +33 -21
  153. data/lib/zen/public/admin/css/zen/buttons.css +11 -7
  154. data/lib/zen/public/admin/css/zen/datepicker.css +6 -6
  155. data/lib/zen/public/admin/css/zen/forms.css +2 -1
  156. data/lib/zen/public/admin/css/zen/general.css +15 -10
  157. data/lib/zen/public/admin/css/zen/layout.css +51 -20
  158. data/lib/zen/public/admin/css/zen/tables.css +39 -11
  159. data/lib/zen/public/admin/css/zen/tabs.css +6 -4
  160. data/lib/zen/public/admin/css/zen/window.css +11 -11
  161. data/lib/zen/public/{favicon.ico → admin/favicon.ico} +0 -0
  162. data/lib/zen/public/admin/images/zen/icons/asc.png +0 -0
  163. data/lib/zen/public/admin/images/zen/icons/desc.png +0 -0
  164. data/lib/zen/public/admin/js/vendor/datepicker.js +0 -11
  165. data/lib/zen/public/admin/js/{mootools → vendor/mootools}/core.js +0 -1
  166. data/lib/zen/public/admin/js/{mootools → vendor/mootools}/more.js +100 -29
  167. data/lib/zen/public/admin/js/zen/index.js +48 -0
  168. data/lib/zen/public/admin/js/zen/lib/asset.js +111 -0
  169. data/lib/zen/public/admin/js/zen/{editor.js → lib/editor.js} +107 -127
  170. data/lib/zen/public/admin/js/zen/{editor → lib/editor}/markdown.js +7 -9
  171. data/lib/zen/public/admin/js/zen/{editor → lib/editor}/textile.js +7 -9
  172. data/lib/zen/public/admin/js/zen/lib/html_table.js +143 -0
  173. data/lib/zen/public/admin/js/zen/{tabs.js → lib/tabs.js} +40 -37
  174. data/lib/zen/public/admin/js/zen/{window.js → lib/window.js} +24 -20
  175. data/lib/zen/spec/bacon/color_output.rb +39 -0
  176. data/lib/zen/spec/helper.rb +152 -0
  177. data/lib/zen/spec/simplecov.rb +22 -0
  178. data/lib/zen/task/build.rake +20 -43
  179. data/lib/zen/task/clean.rake +2 -6
  180. data/lib/zen/task/db.rake +8 -12
  181. data/lib/zen/task/package.rake +4 -10
  182. data/lib/zen/task/plugin.rake +3 -9
  183. data/lib/zen/task/proto.rake +0 -62
  184. data/lib/zen/task/test.rake +6 -3
  185. data/lib/zen/task/theme.rake +4 -11
  186. data/lib/zen/theme.rb +22 -24
  187. data/lib/zen/validation.rb +34 -27
  188. data/lib/zen/version.rb +2 -8
  189. data/lib/zen/view/head.xhtml +7 -0
  190. data/lib/zen/view/main.xhtml +7 -22
  191. data/{proto/package/migrations → pkg}/.gitkeep +0 -0
  192. data/proto/app/app.rb +1 -0
  193. data/proto/app/config/config.rb +5 -4
  194. data/proto/app/config/database.rb +19 -41
  195. data/proto/app/config/middlewares.rb +32 -29
  196. data/proto/{package/lib/package/view/admin/package/index.xhtml → app/log/database/dev/.gitkeep} +0 -0
  197. data/proto/app/log/database/live/.gitkeep +0 -0
  198. data/spec/Rakefile +26 -0
  199. data/spec/fixtures/zen/asset.rb +18 -0
  200. data/spec/fixtures/zen/helper/acl.rb +39 -0
  201. data/spec/fixtures/zen/helper/message.rb +19 -0
  202. data/spec/fixtures/zen/language/en/spec.yml +10 -0
  203. data/spec/fixtures/zen/language/nl/spec.yml +7 -0
  204. data/spec/fixtures/zen/package.rb +17 -0
  205. data/spec/fixtures/zen/package/comments/controller/comments_form.rb +27 -0
  206. data/spec/fixtures/zen/package/settings/plugin/settings.rb +20 -0
  207. data/spec/fixtures/zen/plugin.rb +7 -0
  208. data/spec/fixtures/zen/theme/404.xhtml +1 -0
  209. data/spec/fixtures/zen/theme/default-section/index.xhtml +1 -0
  210. data/spec/fixtures/zen/theme/helper/404.xhtml +1 -0
  211. data/spec/fixtures/zen/theme/helper/partial.xhtml +1 -0
  212. data/spec/fixtures/zen/theme/helper/wrong_partial.xhtml +1 -0
  213. data/spec/fixtures/zen/theme/partials/partial.xhtml +1 -0
  214. data/spec/fixtures/zen/theme/theme.rb +11 -0
  215. data/spec/fixtures/zen/validation.rb +22 -0
  216. data/spec/helper.rb +41 -0
  217. data/spec/zen/all.rb +5 -0
  218. data/spec/zen/asset.rb +97 -0
  219. data/spec/zen/bin/create.rb +89 -0
  220. data/spec/zen/bin/runner.rb +47 -0
  221. data/spec/zen/controller/admin_controller.rb +26 -0
  222. data/spec/zen/controller/main_controller.rb +81 -0
  223. data/spec/zen/controller/preview.rb +33 -0
  224. data/spec/zen/helper/acl.rb +149 -0
  225. data/spec/zen/helper/breadcrumb.rb +38 -0
  226. data/spec/zen/helper/message.rb +31 -0
  227. data/spec/zen/helper/theme.rb +58 -0
  228. data/spec/zen/language.rb +55 -0
  229. data/spec/zen/package.rb +23 -0
  230. data/spec/zen/package/categories/controller/categories.rb +123 -0
  231. data/spec/zen/package/categories/controller/category_groups.rb +108 -0
  232. data/spec/zen/package/categories/helper/category.rb +75 -0
  233. data/spec/zen/package/categories/plugin/categories.rb +92 -0
  234. data/spec/zen/package/comments/controller/comments.rb +134 -0
  235. data/spec/zen/package/comments/controller/comments_form.rb +343 -0
  236. data/spec/zen/package/comments/helper/comment.rb +47 -0
  237. data/spec/zen/package/comments/plugin/anti_spam.rb +59 -0
  238. data/spec/zen/package/comments/plugin/comments.rb +107 -0
  239. data/spec/zen/package/custom_fields/blue_form_parameters.rb +183 -0
  240. data/spec/zen/package/custom_fields/controller/custom_field_groups.rb +120 -0
  241. data/spec/zen/package/custom_fields/controller/custom_field_types.rb +169 -0
  242. data/spec/zen/package/custom_fields/controller/custom_fields.rb +158 -0
  243. data/spec/zen/package/custom_fields/helper/custom_field.rb +86 -0
  244. data/spec/zen/package/menus/controller/menu_items.rb +110 -0
  245. data/spec/zen/package/menus/controller/menus.rb +110 -0
  246. data/spec/zen/package/menus/helper/menu.rb +75 -0
  247. data/spec/zen/package/menus/plugin/menus.rb +120 -0
  248. data/spec/zen/package/sections/controller/section_entries.rb +201 -0
  249. data/spec/zen/package/sections/controller/sections.rb +116 -0
  250. data/spec/zen/package/sections/helper/section.rb +74 -0
  251. data/spec/zen/package/sections/plugin/section_entries.rb +161 -0
  252. data/spec/zen/package/sections/plugin/sections.rb +75 -0
  253. data/spec/zen/package/settings/controller/settings.rb +36 -0
  254. data/spec/zen/package/settings/plugin/settings.rb +33 -0
  255. data/spec/zen/package/users/controller/access_rules.rb +90 -0
  256. data/spec/zen/package/users/controller/user_groups.rb +101 -0
  257. data/spec/zen/package/users/controller/users.rb +130 -0
  258. data/spec/zen/package/users/helper/users.rb +97 -0
  259. data/spec/zen/plugin.rb +64 -0
  260. data/spec/zen/plugin/helper.rb +11 -0
  261. data/spec/zen/plugin/markup.rb +44 -0
  262. data/spec/zen/theme.rb +41 -0
  263. data/spec/zen/validation.rb +63 -0
  264. data/zen.gemspec +36 -0
  265. metadata +159 -113
  266. data/MANIFEST +0 -266
  267. data/lib/zen/bin/app.rb +0 -40
  268. data/lib/zen/ext/string.rb +0 -185
  269. data/lib/zen/helper/common.rb +0 -106
  270. data/lib/zen/package/categories/lib/categories/view/admin/categories/edit.xhtml +0 -7
  271. data/lib/zen/package/categories/lib/categories/view/admin/categories/new.xhtml +0 -7
  272. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/edit.xhtml +0 -7
  273. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/new.xhtml +0 -7
  274. data/lib/zen/package/comments/lib/comments/view/admin/comments/edit.xhtml +0 -7
  275. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/edit.xhtml +0 -7
  276. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/new.xhtml +0 -7
  277. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/edit.xhtml +0 -7
  278. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/new.xhtml +0 -7
  279. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/edit.xhtml +0 -7
  280. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/new.xhtml +0 -7
  281. data/lib/zen/package/menus/lib/menus/view/admin/menus/edit.xhtml +0 -7
  282. data/lib/zen/package/menus/lib/menus/view/admin/menus/new.xhtml +0 -7
  283. data/lib/zen/package/sections/lib/sections/view/admin/edit.xhtml +0 -7
  284. data/lib/zen/package/sections/lib/sections/view/admin/new.xhtml +0 -7
  285. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/edit.xhtml +0 -7
  286. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/new.xhtml +0 -7
  287. data/lib/zen/package/users/lib/users/view/admin/access-rules/edit.xhtml +0 -7
  288. data/lib/zen/package/users/lib/users/view/admin/access-rules/new.xhtml +0 -7
  289. data/lib/zen/package/users/lib/users/view/admin/user-groups/edit.xhtml +0 -7
  290. data/lib/zen/package/users/lib/users/view/admin/user-groups/new.xhtml +0 -7
  291. data/lib/zen/package/users/lib/users/view/admin/users/edit.xhtml +0 -7
  292. data/lib/zen/package/users/lib/users/view/admin/users/new.xhtml +0 -7
  293. data/lib/zen/plugin/controller.rb +0 -59
  294. data/lib/zen/public/admin/css/zen/notifications.css +0 -84
  295. data/lib/zen/public/admin/images/zen/icons/large/error.png +0 -0
  296. data/lib/zen/public/admin/images/zen/icons/large/notice.png +0 -0
  297. data/lib/zen/public/admin/images/zen/icons/large/success.png +0 -0
  298. data/lib/zen/public/admin/js/zen/core.js +0 -73
  299. data/lib/zen/public/admin/js/zen/init.js +0 -80
  300. data/proto/package/lib/package.rb +0 -21
  301. data/proto/package/lib/package/controller/controllers.rb +0 -50
  302. data/proto/package/lib/package/language/en/languages.yml +0 -4
  303. data/proto/package/lib/package/model/model.rb +0 -12
@@ -3,9 +3,9 @@ module CustomFields
3
3
  #:nodoc:
4
4
  module Controller
5
5
  ##
6
- # Controller for managing custom field groups. These groups are used
7
- # to organize individual fields into a larger group which in turn will
8
- # be assigned to a section.
6
+ # Controller for managing custom field groups. These groups are used to
7
+ # organize individual fields into a larger group which in turn will be
8
+ # assigned to a section.
9
9
  #
10
10
  # @author Yorick Peterse
11
11
  # @since 0.1
@@ -13,7 +13,8 @@ module CustomFields
13
13
  class CustomFieldGroups < Zen::Controller::AdminController
14
14
  include ::CustomFields::Model
15
15
 
16
- map('/admin/custom-field-groups')
16
+ helper :custom_field
17
+ map '/admin/custom-field-groups'
17
18
 
18
19
  before_all do
19
20
  csrf_protection(:save, :delete) do
@@ -22,8 +23,8 @@ module CustomFields
22
23
  end
23
24
 
24
25
  ##
25
- # Constructor method, called upon initialization. It's used to set the
26
- # URL to which forms send their data and load the language pack.
26
+ # Constructor method, called upon initialization. It's used to set the URL
27
+ # to which forms send their data and load the language pack.
27
28
  #
28
29
  # This method loads the following language files:
29
30
  #
@@ -35,9 +36,6 @@ module CustomFields
35
36
  def initialize
36
37
  super
37
38
 
38
- @form_save_url = CustomFieldGroups.r(:save)
39
- @form_delete_url = CustomFieldGroups.r(:delete)
40
-
41
39
  Zen::Language.load('custom_field_groups')
42
40
 
43
41
  # Set the page title
@@ -48,8 +46,9 @@ module CustomFields
48
46
  end
49
47
 
50
48
  ##
51
- # Show an overview of all existing custom field groups. Using this overview a user
52
- # can manage an existing field group, delete it or create a new one.
49
+ # Show an overview of all existing custom field groups. Using this
50
+ # overview a user can manage an existing field group, delete it or create
51
+ # a new one.
53
52
  #
54
53
  # This method requires the following permissions:
55
54
  #
@@ -59,13 +58,11 @@ module CustomFields
59
58
  # @since 0.1
60
59
  #
61
60
  def index
62
- if !user_authorized?([:read])
63
- respond(lang('zen_general.errors.not_authorized'), 403)
64
- end
61
+ require_permissions(:read)
65
62
 
66
63
  set_breadcrumbs(lang('custom_field_groups.titles.index'))
67
64
 
68
- @field_groups = CustomFieldGroup.all
65
+ @field_groups = paginate(CustomFieldGroup)
69
66
  end
70
67
 
71
68
  ##
@@ -77,25 +74,25 @@ module CustomFields
77
74
  # * update
78
75
  #
79
76
  # @author Yorick Peterse
80
- # @param [Integer] id The ID of the custom field group to retrieve so that we
81
- # can edit it.
77
+ # @param [Integer] id The ID of the custom field group to retrieve so
78
+ # that we can edit it.
82
79
  # @since 0.1
83
80
  #
84
81
  def edit(id)
85
- if !user_authorized?([:read, :update])
86
- respond(lang('zen_general.errors.not_authorized'), 403)
87
- end
82
+ require_permissions(:read, :update)
88
83
 
89
84
  set_breadcrumbs(
90
- anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
85
+ CustomFieldGroups.a(lang('custom_field_groups.titles.index'), :index),
91
86
  @page_title
92
87
  )
93
88
 
94
89
  if flash[:form_data]
95
90
  @field_group = flash[:form_data]
96
91
  else
97
- @field_group = CustomFieldGroup[id.to_i]
92
+ @field_group = validate_custom_field_group(id)
98
93
  end
94
+
95
+ render_view(:form)
99
96
  end
100
97
 
101
98
  ##
@@ -110,22 +107,23 @@ module CustomFields
110
107
  # @since 0.1
111
108
  #
112
109
  def new
113
- if !user_authorized?([:read, :create])
114
- respond(lang('zen_general.errors.not_authorized'), 403)
115
- end
110
+ require_permissions(:read, :create)
116
111
 
117
112
  set_breadcrumbs(
118
- anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
113
+ CustomFieldGroups.a(lang('custom_field_groups.titles.index'), :index),
119
114
  @page_title
120
115
  )
121
116
 
122
117
  @field_group = CustomFieldGroup.new
118
+
119
+ render_view(:form)
123
120
  end
124
121
 
125
122
  ##
126
- # Method used for processing the form data and redirecting the user back to
127
- # the proper URL. Based on the value of a hidden field named 'id' we'll determine
128
- # if the data will be used to create a new group or to update an existing one.
123
+ # Method used for processing the form data and redirecting the user back
124
+ # to the proper URL. Based on the value of a hidden field named 'id' we'll
125
+ # determine if the data will be used to create a new group or to update an
126
+ # existing one.
129
127
  #
130
128
  # This method requires the following permissions:
131
129
  #
@@ -136,17 +134,16 @@ module CustomFields
136
134
  # @since 0.1
137
135
  #
138
136
  def save
139
- if !user_authorized?([:create, :update])
140
- respond(lang('zen_general.errors.not_authorized'), 403)
141
- end
142
-
143
137
  post = request.subset(:id, :name, :description)
144
138
 
145
- # Get or create a custom field group based on the ID from the hidden field.
146
139
  if post['id'] and !post['id'].empty?
147
- @field_group = CustomFieldGroup[post['id']]
140
+ require_permissions(:update)
141
+
142
+ @field_group = validate_custom_field_group(post['id'])
148
143
  save_action = :save
149
144
  else
145
+ require_permissions(:create)
146
+
150
147
  @field_group = CustomFieldGroup.new
151
148
  save_action = :new
152
149
  end
@@ -160,26 +157,30 @@ module CustomFields
160
157
  begin
161
158
  @field_group.update(post)
162
159
  message(:success, flash_success)
163
- rescue
160
+ rescue => e
161
+ Ramaze::Log.error(e.inspect)
164
162
  message(:error, flash_error)
165
163
 
166
164
  flash[:form_errors] = @field_group.errors
167
165
  flash[:form_data] = @field_group
166
+
167
+ redirect_referrer
168
168
  end
169
169
 
170
170
  if !@field_group.nil? and @field_group.id
171
171
  redirect(CustomFieldGroups.r(:edit, @field_group.id))
172
172
  else
173
- redirect(CustomFieldGroups.r(:new))
173
+ redirect_referrer
174
174
  end
175
175
  end
176
176
 
177
177
  ##
178
178
  # Delete an existing custom field group.
179
179
  #
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
182
- # contain the primary values of each field group that has to be deleted.
180
+ # In order to delete a custom field group you'll need to send a POST
181
+ # request that contains a field named 'custom_field_group_ids[]'. This
182
+ # field should contain the primary values of each field group that has to
183
+ # be deleted.
183
184
  #
184
185
  # This method requires the following permissions:
185
186
  #
@@ -189,21 +190,23 @@ module CustomFields
189
190
  # @since 0.1
190
191
  #
191
192
  def delete
192
- if !user_authorized?([:delete])
193
- respond(lang('zen_general.errors.not_authorized'), 403)
194
- end
193
+ require_permissions(:delete)
195
194
 
196
- if !request.params['custom_field_group_ids'] or request.params['custom_field_group_ids'].empty?
195
+ if !request.params['custom_field_group_ids'] \
196
+ or request.params['custom_field_group_ids'].empty?
197
197
  message(:error, lang('custom_field_groups.errors.no_delete'))
198
- redirect(CustomFieldGroups.r(:index))
198
+ redirect_referrer
199
199
  end
200
200
 
201
201
  request.params['custom_field_group_ids'].each do |id|
202
202
  begin
203
- CustomFieldGroup[id.to_i].destroy
203
+ CustomFieldGroup[id].destroy
204
204
  message(:success, lang('custom_field_groups.success.delete'))
205
- rescue
205
+ rescue => e
206
+ Ramaze::Log.error(e.inspect)
206
207
  message(:error, lang('custom_field_groups.errors.delete') % id)
208
+
209
+ redirect_referrer
207
210
  end
208
211
  end
209
212
 
@@ -0,0 +1,215 @@
1
+ #:nodoc:
2
+ module CustomFields
3
+ #:nodoc:
4
+ module Controller
5
+ ##
6
+ # Controller that can be used to manage individual custom field types.
7
+ #
8
+ # @author Yorick Peterse
9
+ # @since 0.2.8
10
+ #
11
+ class CustomFieldTypes < Zen::Controller::AdminController
12
+ include ::CustomFields::Model
13
+
14
+ map '/admin/custom-field-types'
15
+ helper :custom_field
16
+
17
+ before_all do
18
+ csrf_protection(:save, :delete) do
19
+ respond(lang('zen_general.errors.csrf'), 403)
20
+ end
21
+ end
22
+
23
+ ##
24
+ # Creates a new instance of the controller, loads all the required
25
+ # language files and sets the page title.
26
+ #
27
+ # @author Yorick Peterse
28
+ # @since 0.2.8
29
+ #
30
+ def initialize
31
+ super
32
+
33
+ Zen::Language.load('custom_field_types')
34
+
35
+ if !action.method.nil?
36
+ @page_title = lang(
37
+ "custom_field_types.titles.#{action.method}"
38
+ ) rescue nil
39
+ end
40
+
41
+ @boolean_hash = {
42
+ true => lang('zen_general.special.boolean_hash.true'),
43
+ false => lang('zen_general.special.boolean_hash.false')
44
+ }
45
+ end
46
+
47
+ ##
48
+ # Shows an overview of all the available custom field types and allows the
49
+ # user to create new ones, edit existing ones or delete a group of field
50
+ # types.
51
+ #
52
+ # This method requires read permissions for a user to be able to view all
53
+ # the field types.
54
+ #
55
+ # @author Yorick Peterse
56
+ # @since 0.2.8
57
+ #
58
+ def index
59
+ require_permissions(:read)
60
+
61
+ set_breadcrumbs(lang('custom_field_types.titles.index'))
62
+
63
+ @field_types = paginate(CustomFieldType.eager(:custom_field_method))
64
+ end
65
+
66
+ ##
67
+ # Allows a user to edit an existing custom field type.
68
+ #
69
+ # This method requires the following permissions:
70
+ #
71
+ # * read
72
+ # * update
73
+ #
74
+ # @author Yorick Peterse
75
+ # @since 0.2.8
76
+ # @param [Fixnum] custom_field_type_id The ID of the custom field type to
77
+ # edit.
78
+ #
79
+ def edit(custom_field_type_id)
80
+ require_permissions(:read, :update)
81
+
82
+ set_breadcrumbs(
83
+ CustomFieldTypes.a(lang('custom_field_types.titles.index'), :index),
84
+ lang('custom_field_types.titles.edit')
85
+ )
86
+
87
+ if flash[:form_data]
88
+ @custom_field_type = flash[:form_data]
89
+ else
90
+ @custom_field_type = validate_custom_field_type(custom_field_type_id)
91
+ end
92
+
93
+ @custom_field_methods = CustomFieldMethod.pk_hash(:name)
94
+
95
+ render_view :form
96
+ end
97
+
98
+ ##
99
+ # Allows a user to add a new custom field type.
100
+ #
101
+ # This method requires the following permissions:
102
+ #
103
+ # * read
104
+ # * create
105
+ #
106
+ # @author Yorick Peterse
107
+ # @since 0.2.8
108
+ #
109
+ def new
110
+ require_permissions(:read, :create)
111
+
112
+ set_breadcrumbs(
113
+ CustomFieldTypes.a(lang('custom_field_types.titles.index'), :index),
114
+ lang('custom_field_types.titles.new')
115
+ )
116
+
117
+ @custom_field_methods = CustomFieldMethod.pk_hash(:name)
118
+ @custom_field_type = CustomFieldType.new
119
+
120
+ render_view :form
121
+ end
122
+
123
+ ##
124
+ # Saves the data submitted by CustomFieldTypes#edit() and
125
+ # CustomFieldTypes#add().
126
+ #
127
+ # This method requires either create or update permissions based on the
128
+ # supplied data.
129
+ #
130
+ # @author Yorick Peterse
131
+ # @since 0.2.8
132
+ #
133
+ def save
134
+ post = request.subset(
135
+ :id,
136
+ :name,
137
+ :language_string,
138
+ :html_class,
139
+ :serialize,
140
+ :allow_markup,
141
+ :custom_field_method_id
142
+ )
143
+
144
+ if post['id'] and !post['id'].empty?
145
+ require_permissions(:update)
146
+
147
+ field_type = validate_custom_field_type(post['id'])
148
+ save_action = :save
149
+ else
150
+ require_permissions(:create)
151
+
152
+ field_type = CustomFieldType.new
153
+ save_action = :new
154
+ end
155
+
156
+ post.delete('id')
157
+
158
+ success = lang("custom_field_types.success.#{save_action}")
159
+ error = lang("custom_field_types.errors.#{save_action}")
160
+
161
+ begin
162
+ field_type.update(post)
163
+ message(:success, success)
164
+ rescue => e
165
+ Ramaze::Log.error(e.inspect)
166
+ message(:error, error)
167
+
168
+ flash[:form_data] = field_type
169
+ flash[:form_errors] = field_type.errors
170
+
171
+ redirect_referrer
172
+ end
173
+
174
+ if field_type.id
175
+ redirect(CustomFieldTypes.r(:edit, field_type.id))
176
+ else
177
+ redirect_referrer
178
+ end
179
+ end
180
+
181
+ ##
182
+ # Deletes a number of custom field types.
183
+ #
184
+ # This method requires delete permissions for a user to be able to remove
185
+ # a number of database records.
186
+ #
187
+ # @author Yorick Peterse
188
+ # @since 0.2.8
189
+ #
190
+ def delete
191
+ require_permissions(:delete)
192
+
193
+ if !request.params['custom_field_type_ids'] \
194
+ or request.params['custom_field_type_ids'].empty?
195
+ message(:error, lang('custom_field_types.errors.no_delete'))
196
+ redirect_referrer
197
+ end
198
+
199
+ request.params['custom_field_type_ids'].each do |id|
200
+ begin
201
+ CustomFieldType[id].destroy
202
+ rescue => e
203
+ Ramaze::Log.error(e.inspect)
204
+ message(:error, lang('custom_field_types.errors.delete') % id)
205
+
206
+ redirect_referrer
207
+ end
208
+ end
209
+
210
+ message(:success, lang('custom_field_types.success.delete'))
211
+ redirect_referrer
212
+ end
213
+ end # CustomFieldTypes
214
+ end # Controller
215
+ end # CustomFields
@@ -9,16 +9,17 @@ module CustomFields
9
9
  # being able to use a custom field you'll need to add it to a group
10
10
  # and bind that group to a section.
11
11
  #
12
- # @author Yorick Peterse
13
- # @since 0.1
12
+ # @author Yorick Peterse
13
+ # @since 0.1
14
14
  #
15
15
  class CustomFields < Zen::Controller::AdminController
16
16
  include ::CustomFields::Model
17
17
 
18
- map('/admin/custom-fields')
18
+ helper :custom_field
19
+ map '/admin/custom-fields'
19
20
 
20
21
  # Load all required Javascript files
21
- javascript ['zen/tabs']
22
+ javascript ['zen/lib/tabs']
22
23
 
23
24
  before_all do
24
25
  csrf_protection(:save, :delete) do
@@ -26,6 +27,16 @@ module CustomFields
26
27
  end
27
28
  end
28
29
 
30
+ ##
31
+ # Hook that is executed before the index(), edit() and new() methods.
32
+ #
33
+ # @author Yorick Peterse
34
+ # @since 0.2.8
35
+ #
36
+ before(:index, :edit, :new) do
37
+ @custom_field_types = CustomFieldType.type_hash
38
+ end
39
+
29
40
  ##
30
41
  # Constructor method, called upon initialization. It's used to set the
31
42
  # URL to which forms send their data and load the language pack.
@@ -41,9 +52,6 @@ module CustomFields
41
52
  def initialize
42
53
  super
43
54
 
44
- @form_save_url = CustomFields.r(:save)
45
- @form_delete_url = CustomFields.r(:delete)
46
-
47
55
  Zen::Language.load('custom_fields')
48
56
  Zen::Language.load('custom_field_groups')
49
57
 
@@ -53,43 +61,41 @@ module CustomFields
53
61
  @page_title = lang("custom_fields.titles.#{method}") rescue nil
54
62
  end
55
63
 
56
- # Build our array containing all custom field formats
57
- @field_type_hash = {
58
- 'textbox' => lang('custom_fields.special.type_hash.textbox'),
59
- 'textarea' => lang('custom_fields.special.type_hash.textarea'),
60
- 'radio' => lang('custom_fields.special.type_hash.radio'),
61
- 'checkbox' => lang('custom_fields.special.type_hash.checkbox'),
62
- 'date' => lang('custom_fields.special.type_hash.date'),
63
- 'select' => lang('custom_fields.special.type_hash.select'),
64
- 'select_multiple' => lang('custom_fields.special.type_hash.select_multiple')
64
+ @boolean_hash = {
65
+ true => lang('zen_general.special.boolean_hash.true'),
66
+ false => lang('zen_general.special.boolean_hash.false')
65
67
  }
66
68
  end
67
69
 
68
70
  ##
69
- # Show an overview of all existing custom fields. Using this overview a user
70
- # can manage an existing field, delete it or create a new one.
71
+ # Show an overview of all existing custom fields. Using this overview a
72
+ # user can manage an existing field, delete it or create a new one.
71
73
  #
72
74
  # This method requires the following permissions:
73
75
  #
74
76
  # * read
75
77
  #
76
78
  # @author Yorick Peterse
77
- # @param [Integer] custom_field_group_id The ID of the custom field group to
78
- # which all fields belong.
79
+ # @param [Fixnum] custom_field_group_id The ID of the custom field group
80
+ # to which all fields belong.
79
81
  # @since 0.1
80
82
  #
81
83
  def index(custom_field_group_id)
82
- if !user_authorized?([:read])
83
- respond(lang('zen_general.errors.not_authorized'), 403)
84
- end
84
+ require_permissions(:read)
85
+
86
+ field_group = validate_custom_field_group(custom_field_group_id)
85
87
 
86
88
  set_breadcrumbs(
87
- anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
89
+ CustomFieldGroups.a(lang('custom_field_groups.titles.index'), :index),
88
90
  lang('custom_fields.titles.index')
89
91
  )
90
92
 
91
- @custom_field_group_id = custom_field_group_id.to_i
92
- @custom_fields = CustomFieldGroup[@custom_field_group_id].custom_fields
93
+ @custom_field_group_id = custom_field_group_id
94
+ @custom_fields = CustomField.filter(
95
+ :custom_field_group_id => custom_field_group_id
96
+ )
97
+
98
+ @custom_fields = paginate(@custom_fields)
93
99
  end
94
100
 
95
101
  ##
@@ -101,19 +107,24 @@ module CustomFields
101
107
  # * update
102
108
  #
103
109
  # @author Yorick Peterse
104
- # @param [Integer] custom_field_group_id The ID of the custom field group to
105
- # which all fields belong.
106
- # @param [Integer] id The ID of the custom field to retrieve so that we can edit it.
110
+ # @param [Fixnum] custom_field_group_id The ID of the custom field
111
+ # group to which all fields belong.
112
+ # @param [Fixnum] id The ID of the custom field to retrieve so that we
113
+ # can edit it.
107
114
  # @since 0.1
108
115
  #
109
116
  def edit(custom_field_group_id, id)
110
- if !user_authorized?([:read, :update])
111
- respond(lang('zen_general.errors.not_authorized'), 403)
112
- end
117
+ require_permissions(:read, :update)
118
+
119
+ validate_custom_field_group(custom_field_group_id)
113
120
 
114
121
  set_breadcrumbs(
115
- anchor_to(lang('custom_field_groups.titles.index'), CustomFieldGroups.r(:index)),
116
- anchor_to(lang('custom_fields.titles.index'), CustomFields.r(:index, custom_field_group_id)),
122
+ CustomFieldGroups.a(
123
+ lang('custom_field_groups.titles.index'), :index
124
+ ),
125
+ CustomFields.a(
126
+ lang('custom_fields.titles.index'), :index, custom_field_group_id
127
+ ),
117
128
  lang('custom_fields.titles.edit')
118
129
  )
119
130
 
@@ -122,8 +133,10 @@ module CustomFields
122
133
  if flash[:form_data]
123
134
  @custom_field = flash[:form_data]
124
135
  else
125
- @custom_field = CustomField[id.to_i]
136
+ @custom_field = validate_custom_field(id, custom_field_group_id)
126
137
  end
138
+
139
+ render_view(:form)
127
140
  end
128
141
 
129
142
  ##
@@ -135,35 +148,36 @@ module CustomFields
135
148
  # * read
136
149
  #
137
150
  # @author Yorick Peterse
138
- # @param [Integer] custom_field_group_id The ID of the custom field group to
139
- # which all fields belong.
151
+ # @param [Fixnum] custom_field_group_id The ID of the custom field group
152
+ # to which all fields belong.
140
153
  # @since 0.1
141
154
  #
142
155
  def new(custom_field_group_id)
143
- if !user_authorized?([:read, :create])
144
- respond(lang('zen_general.errors.not_authorized'), 403)
145
- end
156
+ require_permissions(:read, :create)
157
+
158
+ validate_custom_field_group(custom_field_group_id)
146
159
 
147
160
  set_breadcrumbs(
148
- anchor_to(
149
- lang('custom_field_groups.titles.index'),
150
- CustomFieldGroups.r(:index)
161
+ CustomFieldGroups.a(
162
+ lang('custom_field_groups.titles.index'), :index
151
163
  ),
152
- anchor_to(
153
- lang('custom_fields.titles.index'),
154
- CustomFields.r(:index, custom_field_group_id)
164
+ CustomFields.a(
165
+ lang('custom_fields.titles.index'), :index, custom_field_group_id
155
166
  ),
156
- lang('custom_fields.titles.index')
167
+ lang('custom_fields.titles.new')
157
168
  )
158
169
 
159
170
  @custom_field_group_id = custom_field_group_id
160
171
  @custom_field = CustomField.new
172
+
173
+ render_view(:form)
161
174
  end
162
175
 
163
176
  ##
164
- # Method used for processing the form data and redirecting the user back to
165
- # the proper URL. Based on the value of a hidden field named 'id' we'll determine
166
- # if the data will be used to create a new custom field or to update an existing one.
177
+ # Method used for processing the form data and redirecting the user back
178
+ # to the proper URL. Based on the value of a hidden field named 'id' we'll
179
+ # determine if the data will be used to create a new custom field or to
180
+ # update an existing one.
167
181
  #
168
182
  # This method requires the following permissions:
169
183
  #
@@ -174,22 +188,39 @@ module CustomFields
174
188
  # @since 0.1
175
189
  #
176
190
  def save
177
- if !user_authorized?([:create, :update])
178
- respond(lang('zen_general.errors.not_authorized'), 403)
179
- end
180
-
181
191
  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
192
+ :id,
193
+ :name,
194
+ :slug,
195
+ :description,
196
+ :sort_order,
197
+ :format,
198
+ :possible_values,
199
+ :required,
200
+ :text_editor,
201
+ :textarea_rows,
202
+ :text_limit,
203
+ :custom_field_group_id,
204
+ :custom_field_type_id
184
205
  )
185
206
 
186
- # Get or create a custom field group based on the ID from the hidden field.
207
+ validate_custom_field_group(post['custom_field_group_id'])
208
+
209
+ # Get or create a custom field group based on the ID from the hidden
210
+ # field.
187
211
  if post['id'] and !post['id'].empty?
188
- @custom_field = CustomField[post['id']]
189
- save_action = :save
212
+ require_permissions(:update)
213
+
214
+ custom_field = validate_custom_field(
215
+ post['id'], post['custom_field_group_id']
216
+ )
217
+
218
+ save_action = :save
190
219
  else
191
- @custom_field = CustomField.new
192
- save_action = :new
220
+ require_permissions(:create)
221
+
222
+ custom_field = CustomField.new
223
+ save_action = :new
193
224
  end
194
225
 
195
226
  post.delete('slug') if post['slug'].empty?
@@ -199,18 +230,24 @@ module CustomFields
199
230
  flash_error = lang("custom_fields.errors.#{save_action}")
200
231
 
201
232
  begin
202
- @custom_field.update(post)
233
+ custom_field.update(post)
203
234
  message(:success, flash_success)
204
235
  rescue => e
205
236
  Ramaze::Log.error(e.inspect)
206
237
  message(:error, flash_error)
207
238
 
208
- flash[:form_data] = @custom_field
209
- flash[:form_errors] = @custom_field.errors
239
+ flash[:form_data] = custom_field
240
+ flash[:form_errors] = custom_field.errors
241
+
242
+ redirect_referrer
210
243
  end
211
244
 
212
- if @custom_field.id
213
- redirect(CustomFields.r(:edit, post['custom_field_group_id'], @custom_field.id))
245
+ if custom_field.id
246
+ redirect(
247
+ CustomFields.r(
248
+ :edit, post['custom_field_group_id'], custom_field.id
249
+ )
250
+ )
214
251
  else
215
252
  redirect_referrer
216
253
  end
@@ -219,9 +256,9 @@ module CustomFields
219
256
  ##
220
257
  # Delete an existing custom field.
221
258
  #
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
224
- # primary values of each field that has to be deleted.
259
+ # In order to delete a custom field group you'll need to send a POST
260
+ # request that contains a field named 'custom_field_ids[]'. This field
261
+ # should contain the primary values of each field that has to be deleted.
225
262
  #
226
263
  # This method requires the following permissions:
227
264
  #
@@ -231,13 +268,12 @@ module CustomFields
231
268
  # @since 0.1
232
269
  #
233
270
  def delete
234
- if !user_authorized?([:delete])
235
- respond(lang('zen_general.errors.not_authorized'), 403)
236
- end
271
+ require_permissions(:delete)
237
272
 
238
273
  post = request.subset(:custom_field_ids, :custom_field_group_id)
239
274
 
240
- if !request.params['custom_field_ids'] or request.params['custom_field_ids'].empty?
275
+ if !request.params['custom_field_ids'] \
276
+ or request.params['custom_field_ids'].empty?
241
277
  message(:error, lang('custom_fields.errors.no_delete'))
242
278
  redirect(CustomFields.r(:index, post['custom_field_group_id']))
243
279
  end
@@ -249,6 +285,8 @@ module CustomFields
249
285
  rescue => e
250
286
  Ramaze::Log.error(e.inspect)
251
287
  message(:error, lang('custom_fields.errors.delete') % id)
288
+
289
+ redirect_referrer
252
290
  end
253
291
  end
254
292