typus 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. data/Gemfile +20 -9
  2. data/Gemfile.lock +93 -65
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +61 -0
  5. data/Rakefile +5 -0
  6. data/app/controllers/admin/account_controller.rb +7 -10
  7. data/app/controllers/admin/base_controller.rb +16 -1
  8. data/app/controllers/admin/resources_controller.rb +270 -159
  9. data/app/controllers/admin/session_controller.rb +8 -9
  10. data/app/helpers/admin/base_helper.rb +13 -28
  11. data/app/helpers/admin/dashboard_helper.rb +4 -10
  12. data/app/helpers/admin/file_preview_helper.rb +70 -0
  13. data/app/helpers/admin/filters_helper.rb +64 -45
  14. data/app/helpers/admin/form_helper.rb +37 -62
  15. data/app/helpers/admin/relationships_helper.rb +63 -78
  16. data/app/helpers/admin/resources_helper.rb +10 -31
  17. data/app/helpers/admin/search_helper.rb +6 -9
  18. data/app/helpers/admin/sidebar_helper.rb +15 -20
  19. data/app/helpers/admin/table_helper.rb +79 -170
  20. data/app/mailers/admin/mailer.rb +1 -1
  21. data/app/views/admin/account/forgot_password.html.erb +2 -2
  22. data/app/views/admin/account/new.html.erb +8 -4
  23. data/app/views/admin/base/user_guide.html.erb +85 -0
  24. data/app/views/admin/dashboard/_sidebar.html.erb +3 -1
  25. data/app/views/admin/dashboard/show.html.erb +2 -2
  26. data/app/views/admin/dashboard/styles.html.erb +2 -2
  27. data/app/views/admin/helpers/_apps.html.erb +5 -4
  28. data/app/views/admin/helpers/_file_preview.html.erb +3 -0
  29. data/app/views/admin/helpers/_header.html.erb +3 -3
  30. data/app/views/admin/helpers/_login_info.html.erb +2 -2
  31. data/app/views/admin/helpers/dashboard/_applications.html.erb +6 -9
  32. data/app/views/admin/helpers/dashboard/_resources.html.erb +2 -3
  33. data/app/views/admin/helpers/filters/_filters.html.erb +1 -1
  34. data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +1 -1
  35. data/app/views/admin/helpers/resources/_errors.html.erb +10 -0
  36. data/app/views/admin/helpers/search/_search.html.erb +1 -1
  37. data/app/views/admin/helpers/sidebar/_sidebar.html.erb +6 -3
  38. data/app/views/admin/helpers/table/_table.html.erb +17 -5
  39. data/app/views/admin/mailer/reset_password_link.text.erb +2 -2
  40. data/app/views/admin/resources/_form.html.erb +3 -12
  41. data/app/views/admin/resources/edit.html.erb +7 -5
  42. data/app/views/admin/resources/index.html.erb +13 -18
  43. data/app/views/admin/resources/new.html.erb +4 -4
  44. data/app/views/admin/resources/show.html.erb +9 -13
  45. data/app/views/admin/session/new.html.erb +8 -4
  46. data/app/views/admin/templates/_belongs_to.html.erb +1 -1
  47. data/app/views/admin/templates/_boolean.html.erb +2 -2
  48. data/app/views/admin/templates/_date.html.erb +2 -2
  49. data/app/views/admin/templates/_datetime.html.erb +2 -2
  50. data/app/views/admin/templates/_file.html.erb +3 -19
  51. data/app/views/admin/templates/_has_n.html.erb +4 -4
  52. data/app/views/admin/templates/_has_one.html.erb +14 -0
  53. data/app/views/admin/templates/_password.html.erb +2 -2
  54. data/app/views/admin/templates/_profile_sidebar.html.erb +3 -0
  55. data/app/views/admin/templates/_relate_form.html.erb +2 -1
  56. data/app/views/admin/templates/_selector.html.erb +1 -1
  57. data/app/views/admin/templates/_string.html.erb +6 -6
  58. data/app/views/admin/templates/_text.html.erb +11 -4
  59. data/app/views/admin/templates/_time.html.erb +2 -2
  60. data/app/views/admin/templates/_tree.html.erb +1 -1
  61. data/app/views/layouts/admin/base.html.erb +7 -6
  62. data/app/views/layouts/admin/session.html.erb +4 -14
  63. data/config/{available_locales/ca_models.yml → locales/typus.ca.models.yml} +5 -4
  64. data/config/locales/typus.ca.yml +81 -0
  65. data/config/{available_locales/de_models.yml → locales/typus.de.models.yml} +6 -2
  66. data/config/locales/typus.de.yml +80 -0
  67. data/config/locales/typus.el.models.yml +17 -0
  68. data/config/locales/typus.el.yml +82 -0
  69. data/config/{available_locales/es_models.yml → locales/typus.es.models.yml} +9 -4
  70. data/config/locales/typus.es.yml +82 -0
  71. data/config/{available_locales/fr_models.yml → locales/typus.fr.models.yml} +8 -3
  72. data/config/locales/typus.fr.yml +87 -0
  73. data/config/{available_locales/hu_models.yml → locales/typus.hu.models.yml} +6 -2
  74. data/config/locales/typus.hu.yml +80 -0
  75. data/config/{available_locales/it_models.yml → locales/typus.it.models.yml} +7 -4
  76. data/config/locales/typus.it.yml +89 -0
  77. data/config/{available_locales/language_models.yml.template → locales/typus.locale.models.yml.template} +8 -4
  78. data/config/locales/typus.locale.yml.template +81 -0
  79. data/config/{available_locales/pt-BR_models.yml → locales/typus.pt-BR.models.yml} +6 -2
  80. data/config/locales/typus.pt-BR.yml +80 -0
  81. data/config/{available_locales/ru_models.yml → locales/typus.ru.models.yml} +6 -2
  82. data/config/locales/typus.ru.yml +80 -0
  83. data/config/locales/typus.zh-CN.models.yml +17 -0
  84. data/config/locales/typus.zh-CN.yml +79 -0
  85. data/config/routes.rb +11 -7
  86. data/lib/generators/templates/config/initializers/typus.rb +8 -5
  87. data/lib/generators/templates/config/initializers/typus_resources.rb +0 -3
  88. data/lib/generators/templates/config/typus/README +6 -6
  89. data/lib/generators/templates/config/typus/typus.yml +5 -5
  90. data/lib/generators/templates/controller.rb +1 -1
  91. data/lib/generators/templates/migration.rb +1 -0
  92. data/lib/generators/templates/public/admin/javascripts/application.js +0 -4
  93. data/lib/generators/templates/public/admin/javascripts/jquery-1.4.4.min.js +167 -0
  94. data/lib/generators/templates/public/admin/javascripts/jquery.application.js +16 -0
  95. data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +50 -22
  96. data/lib/generators/templates/public/admin/stylesheets/screen.css +43 -34
  97. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
  98. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +32 -32
  99. data/lib/generators/templates/public/admin/vendor/fancybox/{jquery.fancybox-1.3.1.css → jquery.fancybox-1.3.4.css} +359 -363
  100. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.js +1156 -0
  101. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
  102. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
  103. data/lib/generators/typus/assets_generator.rb +23 -0
  104. data/lib/generators/typus/controller_generator.rb +29 -0
  105. data/lib/generators/typus/migration_generator.rb +39 -20
  106. data/lib/generators/typus/typus_generator.rb +17 -57
  107. data/lib/generators/typus/views_generator.rb +2 -6
  108. data/lib/support/active_record.rb +8 -20
  109. data/lib/support/fake_user.rb +6 -1
  110. data/lib/support/hash.rb +1 -2
  111. data/lib/support/object.rb +4 -17
  112. data/lib/support/string.rb +34 -3
  113. data/lib/tasks/typus.rake +1 -1
  114. data/lib/typus.rb +60 -48
  115. data/lib/typus/actions.rb +27 -0
  116. data/lib/typus/authentication/base.rb +3 -4
  117. data/lib/typus/authentication/http_basic.rb +1 -1
  118. data/lib/typus/authentication/none.rb +1 -1
  119. data/lib/typus/authentication/session.rb +53 -108
  120. data/lib/typus/configuration.rb +13 -11
  121. data/lib/typus/filters.rb +12 -0
  122. data/lib/typus/format.rb +9 -13
  123. data/lib/typus/i18n.rb +30 -0
  124. data/lib/typus/orm/active_record.rb +97 -194
  125. data/lib/typus/orm/active_record/search.rb +91 -0
  126. data/lib/typus/resources.rb +6 -10
  127. data/lib/typus/user.rb +20 -40
  128. data/lib/typus/version.rb +1 -1
  129. metadata +77 -231
  130. data/CHANGELOG +0 -102
  131. data/README.rdoc +0 -48
  132. data/app/helpers/admin/preview_helper.rb +0 -46
  133. data/app/views/admin/helpers/_preview.html.erb +0 -13
  134. data/app/views/admin/templates/_has_many.html.erb +0 -22
  135. data/config/available_locales/ca.yml +0 -122
  136. data/config/available_locales/de.yml +0 -122
  137. data/config/available_locales/es.yml +0 -122
  138. data/config/available_locales/fr.yml +0 -127
  139. data/config/available_locales/hu.yml +0 -122
  140. data/config/available_locales/it.yml +0 -132
  141. data/config/available_locales/language.yml.template +0 -120
  142. data/config/available_locales/pt-BR.yml +0 -122
  143. data/config/available_locales/ru.yml +0 -122
  144. data/lib/generators/templates/functional_test.rb +0 -10
  145. data/lib/generators/templates/model.rb +0 -8
  146. data/lib/generators/templates/public/admin/images/ui-icons.png +0 -0
  147. data/lib/generators/templates/public/admin/javascripts/jquery-1.4.2.min.js +0 -154
  148. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.js +0 -1077
  149. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
  150. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.2.pack.js +0 -13
  151. data/lib/typus/pagination.rb +0 -18
  152. data/test/factories.rb +0 -43
  153. data/test/fixtures/config/broken/application.yml +0 -68
  154. data/test/fixtures/config/broken/application_roles.yml +0 -20
  155. data/test/fixtures/config/broken/empty.yml +0 -0
  156. data/test/fixtures/config/broken/empty_roles.yml +0 -0
  157. data/test/fixtures/config/broken/undefined.yml +0 -3
  158. data/test/fixtures/config/broken/undefined_roles.yml +0 -6
  159. data/test/fixtures/config/default/typus.yml +0 -13
  160. data/test/fixtures/config/default/typus_roles.yml +0 -2
  161. data/test/fixtures/config/empty/empty_01.yml +0 -0
  162. data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
  163. data/test/fixtures/config/empty/empty_02.yml +0 -0
  164. data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
  165. data/test/fixtures/config/locales/es.yml +0 -10
  166. data/test/fixtures/config/namespaced/application.yml +0 -5
  167. data/test/fixtures/config/namespaced/application_roles.yml +0 -2
  168. data/test/fixtures/config/ordered/001_roles.yml +0 -2
  169. data/test/fixtures/config/ordered/002_roles.yml +0 -2
  170. data/test/fixtures/config/unordered/app_one_roles.yml +0 -2
  171. data/test/fixtures/config/unordered/app_two_roles.yml +0 -2
  172. data/test/fixtures/config/working/application.yml +0 -73
  173. data/test/fixtures/config/working/application_roles.yml +0 -24
  174. data/test/fixtures/config/working/typus.yml +0 -13
  175. data/test/fixtures/config/working/typus_roles.yml +0 -2
  176. data/test/fixtures/rails_app/Rakefile +0 -7
  177. data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +0 -2
  178. data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +0 -2
  179. data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +0 -2
  180. data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +0 -2
  181. data/test/fixtures/rails_app/app/controllers/admin/pictures_controller.rb +0 -2
  182. data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +0 -2
  183. data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +0 -2
  184. data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +0 -2
  185. data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +0 -2
  186. data/test/fixtures/rails_app/app/controllers/application_controller.rb +0 -3
  187. data/test/fixtures/rails_app/app/models/asset.rb +0 -5
  188. data/test/fixtures/rails_app/app/models/category.rb +0 -11
  189. data/test/fixtures/rails_app/app/models/comment.rb +0 -6
  190. data/test/fixtures/rails_app/app/models/custom_user.rb +0 -2
  191. data/test/fixtures/rails_app/app/models/delayed/task.rb +0 -5
  192. data/test/fixtures/rails_app/app/models/page.rb +0 -5
  193. data/test/fixtures/rails_app/app/models/picture.rb +0 -6
  194. data/test/fixtures/rails_app/app/models/post.rb +0 -21
  195. data/test/fixtures/rails_app/app/models/typus_user.rb +0 -8
  196. data/test/fixtures/rails_app/app/models/view.rb +0 -5
  197. data/test/fixtures/rails_app/app/views/admin/categories/_form.html.erb +0 -1
  198. data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +0 -1
  199. data/test/fixtures/rails_app/app/views/admin/mailer/reset_password_link.text.erb +0 -6
  200. data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +0 -1
  201. data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +0 -1
  202. data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +0 -1
  203. data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +0 -1
  204. data/test/fixtures/rails_app/app/views/admin/posts/_sidebar.html.erb +0 -1
  205. data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +0 -1
  206. data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +0 -1
  207. data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +0 -1
  208. data/test/fixtures/rails_app/config.ru +0 -4
  209. data/test/fixtures/rails_app/config/application.rb +0 -53
  210. data/test/fixtures/rails_app/config/boot.rb +0 -13
  211. data/test/fixtures/rails_app/config/database.yml +0 -14
  212. data/test/fixtures/rails_app/config/environment.rb +0 -5
  213. data/test/fixtures/rails_app/config/environments/test.rb +0 -34
  214. data/test/fixtures/rails_app/config/initializers/secret_token.rb +0 -7
  215. data/test/fixtures/rails_app/config/initializers/session_store.rb +0 -8
  216. data/test/fixtures/rails_app/config/initializers/typus.rb +0 -6
  217. data/test/fixtures/rails_app/config/routes.rb +0 -5
  218. data/test/fixtures/rails_app/config/typus/application.yml +0 -79
  219. data/test/fixtures/rails_app/config/typus/application_roles.yml +0 -25
  220. data/test/fixtures/rails_app/config/typus/typus.yml +0 -12
  221. data/test/fixtures/rails_app/config/typus/typus_roles.yml +0 -2
  222. data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
  223. data/test/fixtures/rails_app/tmp/export-posts-20101012213057.csv +0 -2
  224. data/test/fixtures/rails_app/tmp/export-posts-20101012213132.csv +0 -2
  225. data/test/fixtures/rails_app/tmp/export-posts-20101012213234.csv +0 -2
  226. data/test/fixtures/rails_app/tmp/export-posts-20101012213506.csv +0 -2
  227. data/test/fixtures/rails_app/tmp/export-posts-20101012215057.csv +0 -2
  228. data/test/fixtures/rails_app/tmp/export-posts-20101012215217.csv +0 -2
  229. data/test/fixtures/rails_app/tmp/export-posts-20101012215415.csv +0 -2
  230. data/test/fixtures/rails_app/tmp/export-posts-20101012215443.csv +0 -2
  231. data/test/fixtures/rails_app/tmp/export-posts-20101012215509.csv +0 -2
  232. data/test/fixtures/rails_app/tmp/export-posts-20101012215528.csv +0 -2
  233. data/test/fixtures/rails_app/tmp/export-posts-20101012215551.csv +0 -2
  234. data/test/fixtures/rails_app/tmp/export-posts-20101012215615.csv +0 -2
  235. data/test/fixtures/rails_app/tmp/export-posts-20101012215640.csv +0 -2
  236. data/test/fixtures/rails_app/tmp/export-posts-20101012215714.csv +0 -2
  237. data/test/fixtures/rails_app/tmp/export-posts-20101012215744.csv +0 -2
  238. data/test/fixtures/rails_app/tmp/export-posts-20101012215814.csv +0 -2
  239. data/test/fixtures/rails_app/tmp/export-posts-20101012215836.csv +0 -2
  240. data/test/fixtures/rails_app/tmp/export-posts-20101012215906.csv +0 -2
  241. data/test/fixtures/rails_app/tmp/export-posts-20101012220659.csv +0 -2
  242. data/test/fixtures/rails_app/tmp/export-posts-20101012221043.csv +0 -2
  243. data/test/fixtures/rails_app/tmp/export-posts-20101012221258.csv +0 -2
  244. data/test/fixtures/rails_app/tmp/export-posts-20101012222558.csv +0 -2
  245. data/test/fixtures/rails_app/tmp/export-posts-20101012222752.csv +0 -2
  246. data/test/fixtures/rails_app/tmp/export-posts-20101012222848.csv +0 -2
  247. data/test/fixtures/rails_app/tmp/export-posts-20101012223433.csv +0 -2
  248. data/test/fixtures/rails_app/tmp/export-posts-20101012223535.csv +0 -2
  249. data/test/fixtures/rails_app/tmp/export-posts-20101012224003.csv +0 -2
  250. data/test/fixtures/rails_app/tmp/export-posts-20101012224052.csv +0 -2
  251. data/test/fixtures/rails_app/tmp/export-posts-20101012224109.csv +0 -2
  252. data/test/fixtures/rails_app/tmp/export-posts-20101012224139.csv +0 -2
  253. data/test/fixtures/rails_app/tmp/export-posts-20101012224205.csv +0 -2
  254. data/test/fixtures/rails_app/tmp/export-posts-20101012224243.csv +0 -2
  255. data/test/fixtures/rails_app/tmp/export-posts-20101012225119.csv +0 -2
  256. data/test/fixtures/rails_app/tmp/export-posts-20101013063215.csv +0 -2
  257. data/test/fixtures/rails_app/tmp/export-posts-20101013063300.csv +0 -2
  258. data/test/fixtures/rails_app/tmp/export-posts-20101013063352.csv +0 -2
  259. data/test/fixtures/rails_app/tmp/export-posts-20101013063427.csv +0 -2
  260. data/test/fixtures/rails_app/tmp/export-posts-20101013063448.csv +0 -2
  261. data/test/fixtures/rails_app/tmp/export-posts-20101013063530.csv +0 -2
  262. data/test/fixtures/rails_app/tmp/export-posts-20101013063559.csv +0 -2
  263. data/test/fixtures/rails_app/tmp/export-posts-20101013063646.csv +0 -2
  264. data/test/fixtures/rails_app/tmp/export-posts-20101013063737.csv +0 -2
  265. data/test/fixtures/rails_app/tmp/export-posts-20101013063822.csv +0 -2
  266. data/test/fixtures/rails_app/tmp/export-posts-20101013063837.csv +0 -2
  267. data/test/fixtures/rails_app/tmp/export-posts-20101013063919.csv +0 -2
  268. data/test/fixtures/rails_app/tmp/export-posts-20101013063939.csv +0 -2
  269. data/test/fixtures/rails_app/tmp/export-posts-20101013063952.csv +0 -2
  270. data/test/fixtures/rails_app/tmp/export-posts-20101013064220.csv +0 -2
  271. data/test/fixtures/rails_app/tmp/export-posts-20101013064253.csv +0 -2
  272. data/test/fixtures/rails_app/tmp/export-posts-20101013064318.csv +0 -2
  273. data/test/fixtures/rails_app/tmp/export-posts-20101013064404.csv +0 -2
  274. data/test/fixtures/rails_app/tmp/export-posts-20101013064452.csv +0 -2
  275. data/test/fixtures/rails_app/tmp/export-posts-20101013064536.csv +0 -2
  276. data/test/fixtures/rails_app/tmp/export-posts-20101013064652.csv +0 -2
  277. data/test/fixtures/rails_app/tmp/export-posts-20101013064845.csv +0 -2
  278. data/test/fixtures/rails_app/tmp/export-posts-20101013065023.csv +0 -2
  279. data/test/fixtures/rails_app/tmp/export-posts-20101013065137.csv +0 -2
  280. data/test/fixtures/rails_app/tmp/export-posts-20101013065713.csv +0 -2
  281. data/test/fixtures/rails_app/tmp/export-posts-20101013065954.csv +0 -2
  282. data/test/fixtures/rails_app/tmp/export-posts-20101013070057.csv +0 -2
  283. data/test/fixtures/rails_app/tmp/export-posts-20101013070116.csv +0 -2
  284. data/test/fixtures/rails_app/tmp/export-posts-20101013070156.csv +0 -2
  285. data/test/fixtures/rails_app/tmp/export-posts-20101013070349.csv +0 -2
  286. data/test/fixtures/rails_app/tmp/export-posts-20101013070429.csv +0 -2
  287. data/test/fixtures/rails_app/tmp/export-posts-20101013070448.csv +0 -2
  288. data/test/fixtures/rails_app/tmp/export-posts-20101013070514.csv +0 -2
  289. data/test/fixtures/rails_app/tmp/export-posts-20101013070709.csv +0 -2
  290. data/test/fixtures/rails_app/tmp/export-posts-20101013070745.csv +0 -2
  291. data/test/fixtures/rails_app/tmp/export-posts-20101013070809.csv +0 -2
  292. data/test/fixtures/rails_app/tmp/export-posts-20101013070905.csv +0 -2
  293. data/test/fixtures/rails_app/tmp/export-posts-20101013070955.csv +0 -2
  294. data/test/fixtures/rails_app/tmp/export-posts-20101013071116.csv +0 -2
  295. data/test/fixtures/rails_app/tmp/export-posts-20101013071209.csv +0 -2
  296. data/test/fixtures/rails_app/tmp/export-posts-20101013071335.csv +0 -2
  297. data/test/fixtures/rails_app/tmp/export-posts-20101013071632.csv +0 -2
  298. data/test/fixtures/rails_app/tmp/export-posts-20101013071643.csv +0 -2
  299. data/test/fixtures/rails_app/tmp/export-posts-20101013071735.csv +0 -2
  300. data/test/fixtures/rails_app/tmp/export-posts-20101013071749.csv +0 -2
  301. data/test/fixtures/rails_app/tmp/export-posts-20101013072030.csv +0 -2
  302. data/test/fixtures/rails_app/tmp/export-posts-20101013072050.csv +0 -2
  303. data/test/fixtures/rails_app/tmp/export-posts-20101013072108.csv +0 -2
  304. data/test/fixtures/rails_app/tmp/export-posts-20101013072713.csv +0 -2
  305. data/test/fixtures/rails_app/tmp/export-posts-20101013072751.csv +0 -2
  306. data/test/fixtures/rails_app/tmp/export-posts-20101013072912.csv +0 -2
  307. data/test/fixtures/rails_app/tmp/export-posts-20101013074546.csv +0 -2
  308. data/test/fixtures/rails_app/tmp/export-posts-20101018180512.csv +0 -2
  309. data/test/fixtures/rails_app/tmp/export-posts-20101018183359.csv +0 -2
  310. data/test/fixtures/rails_app/tmp/export-posts-20101018183608.csv +0 -2
  311. data/test/fixtures/rails_app/tmp/export-posts-20101018183759.csv +0 -2
  312. data/test/functional/admin/account_controller_test.rb +0 -90
  313. data/test/functional/admin/assets_controller_test.rb +0 -55
  314. data/test/functional/admin/categories_controller_test.rb +0 -62
  315. data/test/functional/admin/comments_controller_test.rb +0 -21
  316. data/test/functional/admin/dashboard_controller_test.rb +0 -138
  317. data/test/functional/admin/posts_controller_test.rb +0 -548
  318. data/test/functional/admin/session_controller_test.rb +0 -85
  319. data/test/functional/admin/status_controller_test.rb +0 -46
  320. data/test/functional/admin/typus_users_controller_test.rb +0 -159
  321. data/test/helpers/admin/base_helper_test.rb +0 -67
  322. data/test/helpers/admin/dashboard_helper_test.rb +0 -19
  323. data/test/helpers/admin/form_helper_test.rb +0 -117
  324. data/test/helpers/admin/resources_helper_test.rb +0 -64
  325. data/test/helpers/admin/sidebar_helper_test.rb +0 -274
  326. data/test/helpers/admin/table_helper_test.rb +0 -219
  327. data/test/integration/login_test.rb +0 -13
  328. data/test/integration_test_helper.rb +0 -21
  329. data/test/lib/support/active_record_test.rb +0 -86
  330. data/test/lib/support/array_test.rb +0 -11
  331. data/test/lib/support/hash_test.rb +0 -11
  332. data/test/lib/support/string_test.rb +0 -39
  333. data/test/lib/typus/active_record_test.rb +0 -451
  334. data/test/lib/typus/configuration_test.rb +0 -52
  335. data/test/lib/typus/resource_test.rb +0 -17
  336. data/test/lib/typus/routes_test.rb +0 -29
  337. data/test/lib/typus_test.rb +0 -107
  338. data/test/schema.rb +0 -100
  339. data/test/test_helper.rb +0 -16
  340. data/test/unit/admin/mailer_test.rb +0 -32
  341. data/test/unit/typus_user_roles_test.rb +0 -105
  342. data/test/unit/typus_user_test.rb +0 -142
  343. data/typus.gemspec +0 -25
data/Gemfile CHANGED
@@ -1,20 +1,31 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gemspec
4
+
3
5
  gem "acts_as_list"
4
6
  gem "acts_as_tree"
5
- gem "paperclip"
6
- gem "fastercsv", "1.5.3" unless RUBY_VERSION >= '1.9'
7
- gem "paginator", "1.1.1"
7
+ gem "dragonfly", "~>0.8.1"
8
+ gem "factory_girl"
8
9
 
9
10
  group :test do
10
- gem "capybara"
11
- gem "factory_girl"
12
11
  gem "mysql"
13
- gem "paperclip"
14
12
  gem "pg"
15
- gem "rails", "3.0.0"
16
- gem "shoulda"
17
- gem "sqlite3-ruby"
13
+ end
14
+
15
+ gem "paperclip"
18
16
 
17
+ gem "rack-cache", :require => "rack/cache"
18
+ gem "rails", "~> 3.0"
19
+
20
+ gem 'sqlite3-ruby', '1.2.1'
21
+
22
+ # Keep this here because I use it as reference for development.
23
+ gem "fastercsv", "1.5.3" if RUBY_VERSION < '1.9'
24
+ gem "render_inheritable"
25
+ gem "will_paginate", "~> 3.0.pre2"
26
+
27
+ group :test do
28
+ gem "shoulda"
29
+ gem "tartare", :git => "https://github.com/fesplugas/rails-tartare.git", :require => false
19
30
  gem "mocha"
20
31
  end
data/Gemfile.lock CHANGED
@@ -1,105 +1,129 @@
1
+ GIT
2
+ remote: https://github.com/fesplugas/rails-tartare.git
3
+ revision: 3d74044310943023ec7d218d4c3c8b29c5b8ebed
4
+ specs:
5
+ tartare (1.0.0)
6
+ capybara (>= 0.4.0)
7
+ rails (>= 3.0.0)
8
+
9
+ PATH
10
+ remote: .
11
+ specs:
12
+ typus (3.0.3)
13
+ fastercsv (= 1.5.3)
14
+ render_inheritable
15
+ will_paginate (~> 3.0.pre2)
16
+
1
17
  GEM
2
18
  remote: http://rubygems.org/
3
19
  specs:
4
20
  abstract (1.0.0)
5
- actionmailer (3.0.0)
6
- actionpack (= 3.0.0)
7
- mail (~> 2.2.5)
8
- actionpack (3.0.0)
9
- activemodel (= 3.0.0)
10
- activesupport (= 3.0.0)
21
+ actionmailer (3.0.3)
22
+ actionpack (= 3.0.3)
23
+ mail (~> 2.2.9)
24
+ actionpack (3.0.3)
25
+ activemodel (= 3.0.3)
26
+ activesupport (= 3.0.3)
11
27
  builder (~> 2.1.2)
12
28
  erubis (~> 2.6.6)
13
- i18n (~> 0.4.1)
29
+ i18n (~> 0.4)
14
30
  rack (~> 1.2.1)
15
- rack-mount (~> 0.6.12)
16
- rack-test (~> 0.5.4)
31
+ rack-mount (~> 0.6.13)
32
+ rack-test (~> 0.5.6)
17
33
  tzinfo (~> 0.3.23)
18
- activemodel (3.0.0)
19
- activesupport (= 3.0.0)
34
+ activemodel (3.0.3)
35
+ activesupport (= 3.0.3)
20
36
  builder (~> 2.1.2)
21
- i18n (~> 0.4.1)
22
- activerecord (3.0.0)
23
- activemodel (= 3.0.0)
24
- activesupport (= 3.0.0)
25
- arel (~> 1.0.0)
37
+ i18n (~> 0.4)
38
+ activerecord (3.0.3)
39
+ activemodel (= 3.0.3)
40
+ activesupport (= 3.0.3)
41
+ arel (~> 2.0.2)
26
42
  tzinfo (~> 0.3.23)
27
- activeresource (3.0.0)
28
- activemodel (= 3.0.0)
29
- activesupport (= 3.0.0)
30
- activesupport (3.0.0)
43
+ activeresource (3.0.3)
44
+ activemodel (= 3.0.3)
45
+ activesupport (= 3.0.3)
46
+ activesupport (3.0.3)
31
47
  acts_as_list (0.1.2)
32
48
  acts_as_tree (0.1.1)
33
- arel (1.0.1)
34
- activesupport (~> 3.0.0)
49
+ arel (2.0.7)
35
50
  builder (2.1.2)
36
- capybara (0.3.9)
51
+ capybara (0.4.0)
52
+ celerity (>= 0.7.9)
37
53
  culerity (>= 0.2.4)
38
54
  mime-types (>= 1.16)
39
55
  nokogiri (>= 1.3.3)
40
56
  rack (>= 1.0.0)
41
57
  rack-test (>= 0.5.4)
42
- selenium-webdriver (>= 0.0.3)
43
- culerity (0.2.12)
58
+ selenium-webdriver (>= 0.0.27)
59
+ xpath (~> 0.1.2)
60
+ celerity (0.8.7)
61
+ childprocess (0.1.6)
62
+ ffi (~> 0.6.3)
63
+ culerity (0.2.14)
64
+ dragonfly (0.8.2)
65
+ rack
44
66
  erubis (2.6.6)
45
67
  abstract (>= 1.0.0)
46
- factory_girl (1.3.2)
68
+ factory_girl (1.3.3)
47
69
  fastercsv (1.5.3)
48
70
  ffi (0.6.3)
49
71
  rake (>= 0.8.7)
50
- hoe (2.6.2)
51
- rake (>= 0.8.7)
52
- rubyforge (>= 2.0.4)
53
- i18n (0.4.1)
72
+ i18n (0.5.0)
54
73
  json_pure (1.4.6)
55
- mail (2.2.5)
74
+ mail (2.2.14)
56
75
  activesupport (>= 2.3.6)
57
- mime-types
58
- treetop (>= 1.4.5)
76
+ i18n (>= 0.4.0)
77
+ mime-types (~> 1.16)
78
+ treetop (~> 1.4.8)
59
79
  mime-types (1.16)
60
- mocha (0.9.8)
80
+ mocha (0.9.10)
61
81
  rake
62
82
  mysql (2.8.1)
63
- nokogiri (1.4.3.1)
64
- paginator (1.1.1)
65
- hoe (>= 1.6.0)
66
- paperclip (2.3.3)
83
+ nokogiri (1.4.4)
84
+ paperclip (2.3.8)
67
85
  activerecord
68
86
  activesupport
69
- pg (0.9.0)
87
+ pg (0.10.0)
70
88
  polyglot (0.3.1)
71
89
  rack (1.2.1)
90
+ rack-cache (1.0)
91
+ rack (>= 0.4)
72
92
  rack-mount (0.6.13)
73
93
  rack (>= 1.0.0)
74
- rack-test (0.5.4)
94
+ rack-test (0.5.7)
75
95
  rack (>= 1.0)
76
- rails (3.0.0)
77
- actionmailer (= 3.0.0)
78
- actionpack (= 3.0.0)
79
- activerecord (= 3.0.0)
80
- activeresource (= 3.0.0)
81
- activesupport (= 3.0.0)
82
- bundler (~> 1.0.0)
83
- railties (= 3.0.0)
84
- railties (3.0.0)
85
- actionpack (= 3.0.0)
86
- activesupport (= 3.0.0)
87
- rake (>= 0.8.4)
88
- thor (~> 0.14.0)
96
+ rails (3.0.3)
97
+ actionmailer (= 3.0.3)
98
+ actionpack (= 3.0.3)
99
+ activerecord (= 3.0.3)
100
+ activeresource (= 3.0.3)
101
+ activesupport (= 3.0.3)
102
+ bundler (~> 1.0)
103
+ railties (= 3.0.3)
104
+ railties (3.0.3)
105
+ actionpack (= 3.0.3)
106
+ activesupport (= 3.0.3)
107
+ rake (>= 0.8.7)
108
+ thor (~> 0.14.4)
89
109
  rake (0.8.7)
90
- rubyforge (2.0.4)
91
- json_pure (>= 1.1.7)
110
+ render_inheritable (1.0.0)
111
+ rails (~> 3.0)
92
112
  rubyzip (0.9.4)
93
- selenium-webdriver (0.0.28)
94
- ffi (>= 0.6.1)
113
+ selenium-webdriver (0.1.2)
114
+ childprocess (~> 0.1.5)
115
+ ffi (~> 0.6.3)
95
116
  json_pure
96
117
  rubyzip
97
118
  shoulda (2.11.3)
98
- sqlite3-ruby (1.3.1)
99
- thor (0.14.0)
100
- treetop (1.4.8)
119
+ sqlite3-ruby (1.2.1)
120
+ thor (0.14.6)
121
+ treetop (1.4.9)
101
122
  polyglot (>= 0.3.1)
102
- tzinfo (0.3.23)
123
+ tzinfo (0.3.24)
124
+ will_paginate (3.0.pre2)
125
+ xpath (0.1.3)
126
+ nokogiri (~> 1.3)
103
127
 
104
128
  PLATFORMS
105
129
  ruby
@@ -107,14 +131,18 @@ PLATFORMS
107
131
  DEPENDENCIES
108
132
  acts_as_list
109
133
  acts_as_tree
110
- capybara
134
+ dragonfly (~> 0.8.1)
111
135
  factory_girl
112
136
  fastercsv (= 1.5.3)
113
137
  mocha
114
138
  mysql
115
- paginator (= 1.1.1)
116
139
  paperclip
117
140
  pg
118
- rails (= 3.0.0)
141
+ rack-cache
142
+ rails (~> 3.0)
143
+ render_inheritable
119
144
  shoulda
120
- sqlite3-ruby
145
+ sqlite3-ruby (= 1.2.1)
146
+ tartare!
147
+ typus!
148
+ will_paginate (~> 3.0.pre2)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2010 Francesc Esplugas Marti
1
+ Copyright (c) 2007-2011 Francesc Esplugas Marti
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Typus: Admin Panel for Ruby on Rails applications
2
+
3
+ **Typus** is designed for a single activity:
4
+
5
+ Trusted users editing structured content.
6
+
7
+ **Typus** doesn't try to be all the things to all the people but it's
8
+ extensible enough to match lots of use cases.
9
+
10
+ ## Key Features
11
+
12
+ - Built-in Authentication.
13
+ - User Permissions by using Access Control Lists. (stored in yaml files)
14
+ - CRUD and custom actions for your models on a clean interface.
15
+ - Internationalized interface (Català, German, Greek, English, Español,
16
+ Français, Magyar, Italiano, Portuguese, Russian, 中文)
17
+ - Customizable and extensible templates.
18
+ - Integrated [paperclip][1] and [dragonfly][2] attachments viewer.
19
+ - Low memory footprint.
20
+ - Works with `Rails 3.0`.
21
+ - Tested with `Ruby 1.8.7-p300` and `Ruby 1.9.2-p136`.
22
+ - Tested with SQLite, MySQL and PostgreSQL.
23
+ - MIT License, the same as Rails.
24
+
25
+ ## Links
26
+
27
+ - [Documentation](http://core.typuscms.com/)
28
+ - [Demo](http://demo.typuscms.com/) ([Code][3])
29
+ - [Source Code](http://github.com/fesplugas/typus)
30
+ - [Mailing List](http://groups.google.com/group/typus)
31
+ - [Gems](http://rubygems.org/gems/typus)
32
+ - [Contributors List](http://github.com/fesplugas/typus/contributors)
33
+ - [Continous Integration](http://ci.typuscms.com/)
34
+
35
+ ## Installing
36
+
37
+ Add **Typus** to your `Gemfile`
38
+
39
+ gem 'typus', :git => 'https://github.com/fesplugas/typus.git'
40
+
41
+ Update your bundle
42
+
43
+ $ bundle install
44
+
45
+ Run the generator
46
+
47
+ $ rails generate typus
48
+
49
+ Start the application server
50
+
51
+ $ rails server
52
+
53
+ and go to <http://0.0.0.0:3000/admin>.
54
+
55
+ ## License
56
+
57
+ Copyright © 2007-2011 Francesc Esplugas, released under the MIT license.
58
+
59
+ [1]: http://rubygems.org/gems/paperclip
60
+ [2]: http://rubygems.org/gems/dragonfly
61
+ [3]: https://github.com/fesplugas/typus/tree/master/test/fixtures/rails_app
data/Rakefile CHANGED
@@ -39,3 +39,8 @@ task :release => :build do
39
39
  system "gem push typus-#{Typus::VERSION}.gem"
40
40
  system "git clean -fd && rm -f typus-#{Typus::VERSION}.gem"
41
41
  end
42
+
43
+ desc 'Deploy'
44
+ task :deploy do
45
+ system "cd test/fixtures/rails_app && cap deploy"
46
+ end
@@ -3,20 +3,20 @@ class Admin::AccountController < Admin::BaseController
3
3
  layout 'admin/session'
4
4
 
5
5
  skip_before_filter :reload_config_and_roles
6
- skip_before_filter :set_preferences
7
6
  skip_before_filter :authenticate
7
+ skip_before_filter :set_locale
8
8
 
9
9
  before_filter :sign_in?, :except => [:forgot_password, :show]
10
10
  before_filter :new?, :only => [:forgot_password]
11
11
 
12
12
  def new
13
- flash[:notice] = _t("Enter your email below to create the first user.")
13
+ flash[:notice] = Typus::I18n.t("Enter your email below to create the first user.")
14
14
  end
15
15
 
16
16
  def create
17
17
  user = Typus.user_class.generate(:email => params[:typus_user][:email])
18
18
  user.status = true
19
- redirect_to (user.save ? { :action => "show", :id => user.token } : { :action => :new })
19
+ redirect_to user.save ? { :action => "show", :id => user.token } : { :action => :new }
20
20
  end
21
21
 
22
22
  def forgot_password
@@ -25,20 +25,17 @@ class Admin::AccountController < Admin::BaseController
25
25
  if user = Typus.user_class.find_by_email(params[:typus_user][:email])
26
26
  url = admin_account_url(user.token)
27
27
  Admin::Mailer.reset_password_link(user, url).deliver
28
- notice = _t("Password recovery link sent to your email.")
29
- path = new_admin_session_path
28
+ redirect_to new_admin_session_path, :notice => Typus::I18n.t("Password recovery link sent to your email.")
30
29
  else
31
- render :action => :forgot_password and return
30
+ render :action => :forgot_password
32
31
  end
33
-
34
- redirect_to path, :notice => notice
35
32
  end
36
33
 
37
34
  def show
38
- flash[:notice] = _t("Please set a new password.")
35
+ flash[:notice] = Typus::I18n.t("Please set a new password.")
39
36
  typus_user = Typus.user_class.find_by_token!(params[:id])
40
37
  session[:typus_user_id] = typus_user.id
41
- redirect_to :controller => "admin/#{Typus.user_class.to_resource}", :action => "edit", :id => typus_user.id
38
+ redirect_to :controller => "/admin/#{Typus.user_class.to_resource}", :action => "edit", :id => typus_user.id
42
39
  end
43
40
 
44
41
  private
@@ -1,14 +1,25 @@
1
1
  class Admin::BaseController < ActionController::Base
2
2
 
3
+ render_inheritable
4
+
3
5
  include Typus::Authentication::const_get(Typus.authentication.to_s.classify)
4
6
 
7
+ before_filter :set_models_constantized
5
8
  before_filter :reload_config_and_roles
6
9
  before_filter :authenticate
10
+ before_filter :set_locale
11
+
12
+ helper_method :admin_user
7
13
 
8
- helper_method :current_user
14
+ def user_guide
15
+ end
9
16
 
10
17
  protected
11
18
 
19
+ def set_models_constantized
20
+ Typus::Configuration.models_constantized!
21
+ end
22
+
12
23
  def reload_config_and_roles
13
24
  Typus.reload! unless Rails.env.production?
14
25
  end
@@ -17,4 +28,8 @@ class Admin::BaseController < ActionController::Base
17
28
  @back_to || request.referer || admin_dashboard_path
18
29
  end
19
30
 
31
+ def set_locale
32
+ I18n.locale = admin_user.locale
33
+ end
34
+
20
35
  end
@@ -1,56 +1,42 @@
1
- require "typus/format"
2
-
3
1
  class Admin::ResourcesController < Admin::BaseController
4
2
 
3
+ include Typus::Actions
4
+ include Typus::Filters
5
5
  include Typus::Format
6
6
 
7
7
  before_filter :get_model
8
-
9
- before_filter :get_object,
10
- :only => [ :show,
11
- :edit, :update, :destroy, :toggle,
12
- :position, :relate, :unrelate,
13
- :detach ]
14
-
15
- before_filter :check_resource_ownership,
16
- :only => [ :edit, :update, :destroy, :toggle,
17
- :position, :relate, :unrelate ]
18
-
19
- before_filter :check_if_user_can_perform_action_on_user,
20
- :only => [ :edit, :update, :toggle, :destroy ]
8
+ before_filter :set_scope
9
+ before_filter :get_object, :only => [:show, :edit, :update, :destroy, :toggle, :position, :relate, :unrelate, :detach]
10
+ before_filter :check_resource_ownership, :only => [:edit, :update, :destroy, :toggle, :position, :relate, :unrelate ]
21
11
  before_filter :check_if_user_can_perform_action_on_resources
12
+ before_filter :set_order, :only => [:index]
13
+ before_filter :set_fields, :only => [:index, :new, :edit, :create, :update, :show, :detach]
22
14
 
23
- before_filter :set_order,
24
- :only => [ :index ]
25
- before_filter :set_fields,
26
- :only => [ :index, :new, :edit, :create, :update, :show ]
15
+ before_filter :check_if_we_can_add_a_new_item, :only => [:new, :create]
27
16
 
28
17
  ##
29
18
  # This is the main index of the model. With filters, conditions and more.
30
19
  #
31
- # By default application can respond_to html, csv and xml, but you can add
20
+ # By default application can respond to html, csv and xml, but you can add
32
21
  # your formats.
33
22
  #
34
23
  def index
35
- @conditions, @joins = @resource.build_conditions(params)
36
- check_resource_ownerships if @resource.typus_options_for(:only_user_items)
24
+ add_action(:action_name => default_action.titleize, :action => default_action)
25
+ add_action(:action_name => "Trash", :action => "destroy", :confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete')
26
+
27
+ get_objects
37
28
 
38
29
  respond_to do |format|
39
- format.html { generate_html and select_template }
30
+ format.html { generate_html }
40
31
  @resource.typus_export_formats.each { |f| format.send(f) { send("generate_#{f}") } }
41
32
  end
42
33
  end
43
34
 
44
35
  def new
45
- check_ownership_of_referal_item
46
-
47
36
  item_params = params.dup
48
- rejections = %w( controller action resource resource_id back_to selected )
37
+ rejections = %w(controller action resource resource_id back_to selected)
49
38
  item_params.delete_if { |k, v| rejections.include?(k) }
50
-
51
39
  @item = @resource.new(item_params)
52
-
53
- select_template
54
40
  end
55
41
 
56
42
  ##
@@ -63,150 +49,160 @@ class Admin::ResourcesController < Admin::BaseController
63
49
 
64
50
  set_attributes_on_create
65
51
 
66
- if @item.valid?
67
- create_with_back_to and return if params[:back_to]
68
- @item.save
69
- redirect_on_success
52
+ if @item.save
53
+ params[:back_to] ? create_with_back_to : redirect_on_success
70
54
  else
71
- select_template(:new)
55
+ render :new
72
56
  end
73
57
  end
74
58
 
75
59
  def edit
76
- select_template
60
+ add_action(:action_name => default_action.titleize, :action => default_action)
61
+ add_action(:action_name => "Unrelate", :action => "unrelate", :confirm => "#{Typus::I18n.t("Unrelate")}?", :resource => @resource.model_name, :resource_id => @item.id)
77
62
  end
78
63
 
79
64
  def show
80
- check_resource_ownership and return if @resource.typus_options_for(:only_user_items)
81
- select_template
65
+ check_resource_ownership if @resource.typus_options_for(:only_user_items)
82
66
  end
83
67
 
84
68
  def update
85
- if @item.update_attributes(params[@object_name])
86
- set_attributes_on_update
87
- reload_locales
69
+ respond_to do |format|
70
+ if @item.update_attributes(params[@object_name])
71
+ set_attributes_on_update
72
+ reload_locales
73
+ format.html { redirect_on_success }
74
+ format.json { render :json => @item }
75
+ else
76
+ format.html { render :edit }
77
+ format.json { render :json => @item.errors.full_messages }
78
+ end
79
+ end
80
+ end
81
+
82
+ def detach
83
+ if @item.update_attributes(params[:attribute] => nil)
88
84
  redirect_on_success
89
85
  else
90
- select_template(:edit)
86
+ render :edit
91
87
  end
92
88
  end
93
89
 
94
90
  def destroy
95
- @item.destroy
96
- notice = _t("%{model} successfully removed.", :model => @resource.model_name.human)
97
- redirect_to set_path, :notice => notice
91
+ if @item.destroy
92
+ notice = Typus::I18n.t("%{model} successfully removed.", :model => @resource.model_name.human)
93
+ else
94
+ alert = @item.errors.full_messages
95
+ end
96
+ redirect_to set_path, :notice => notice, :alert => alert
98
97
  end
99
98
 
100
99
  def toggle
101
100
  @item.toggle(params[:field])
102
101
  @item.save!
103
102
 
104
- notice = _t("%{model} %{attribute} changed.",
105
- :model => @resource.model_name.human,
106
- :attribute => params[:field].humanize.downcase)
103
+ notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
107
104
 
108
- redirect_to set_path, :notice => notice
105
+ respond_to do |format|
106
+ format.html { redirect_to set_path, :notice => notice }
107
+ format.json { render :json => @item }
108
+ end
109
109
  end
110
110
 
111
111
  ##
112
- # Change item position. This only works if acts_as_list is installed. We can
113
- # then move items:
112
+ # Change item position:
114
113
  #
115
114
  # params[:go] = 'move_to_top'
116
115
  #
117
116
  # Available positions are move_to_top, move_higher, move_lower, move_to_bottom.
118
117
  #
118
+ # NOTE: Only works if `acts_as_list` is installed.
119
+ #
119
120
  def position
120
121
  @item.send(params[:go])
121
- notice = _t("Record moved %{to}.", :to => params[:go].gsub(/move_/, '').humanize.downcase)
122
+ notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
122
123
  redirect_to set_path, :notice => notice
123
124
  end
124
125
 
125
126
  ##
126
- # Relate a model object to another, this action is used only by the
127
- # has_and_belongs_to_many and has_many relationships.
127
+ # Action to relate models which respond to:
128
+ #
129
+ # - has_and_belongs_to_many
130
+ # - has_many
131
+ #
132
+ # For example:
133
+ #
134
+ # class Item < ActiveRecord::Base
135
+ # has_many :line_items
136
+ # end
137
+ #
138
+ # class LineItem < ActiveRecord::Base
139
+ # belongs_to :item
140
+ # end
141
+ #
142
+ # >> related_item = LineItem.find(params[:related][:id])
143
+ # => ...
144
+ # >> item = Item.find(params[:id])
145
+ # => ...
146
+ # >> item.line_items << related_item
147
+ # => ...
128
148
  #
129
149
  def relate
130
- resource_class = params[:related][:model].constantize
131
- resource_tableized = params[:related][:model].tableize
150
+ resource_class = params[:related][:model].typus_constantize
151
+ association_name = params[:related][:association_name].tableize
132
152
 
133
- if @item.send(resource_tableized) << resource_class.find(params[:related][:id])
134
- flash[:notice] = _t("%{model_a} related to %{model_b}",
135
- :model_a => resource_class.model_name.human,
136
- :model_b => @resource.model_name.human)
137
- else
138
- flash[:alert] = _t("%{model_a} cannot be related to %{model_b}",
139
- :model_a => resource_class.model_name.human,
140
- :model_b => @resource.model_name.human)
153
+ if @item.send(association_name) << resource_class.find(params[:related][:id])
154
+ flash[:notice] = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
141
155
  end
142
156
 
143
157
  redirect_to set_path
144
158
  end
145
159
 
146
160
  ##
147
- # Remove relationship between models, this action never removes items!
161
+ # Action to unrelate models which respond to:
162
+ #
163
+ # - has_and_belongs_to_many
164
+ # - has_many
165
+ # - has_one
148
166
  #
149
167
  def unrelate
150
168
 
151
- resource_class = params[:resource].classify.constantize
152
- resource_tableized = params[:resource].tableize
153
- resource = resource_class.find(params[:resource_id])
169
+ ##
170
+ # Find the remote object which is named item!
171
+ #
154
172
 
155
- # We consider that we are unrelating a has_many or has_and_belongs_to_many
173
+ item_class = params[:resource].typus_constantize
174
+ item = item_class.find(params[:resource_id])
156
175
 
157
- reflection = @resource.reflect_on_association(resource_class.table_name.to_sym)
158
- macro = reflection.try(:macro)
159
- options = reflection.try(:options)
176
+ ##
177
+ # Detect which kind of relationship there's between both models.
178
+ #
179
+ # item respect @item
180
+ #
160
181
 
161
- case macro
162
- # when :has_one
163
- # attribute = resource_tableized.singularize
164
- # saved_succesfully = @item.update_attribute attribute, nil
165
- when :has_many
166
- if options.has_key?(:as) # We are in a polymorphic relationship
167
- interface = options[:as]
168
- saved_succesfully = resource.update_attributes("#{interface}_type" => nil, "#{interface}_id" => nil)
169
- else
170
- # We have to verify we can unrelate. For example: A Category which has
171
- # many posts and Post validates_presence_of Category should not be removed.
172
- attribute = @resource.table_name.singularize
173
- saved_succesfully = resource.update_attributes(attribute => nil)
174
- end
175
- when :has_and_belongs_to_many
176
- attribute = resource_tableized
177
- saved_succesfully = @item.send(attribute).delete(resource)
178
- else
179
- saved_succesfully = false
180
- end
182
+ # This is not nil in case of a has_many :through association.
183
+ association_name = params[:association_name].to_sym unless params[:association_name].blank?
181
184
 
182
- if saved_succesfully
183
- flash[:notice] = _t("%{model_a} unrelated from %{model_b}",
184
- :model_a => resource_class.model_name.human,
185
- :model_b => @resource.model_name.human)
185
+ case item_class.relationship_with(@resource)
186
+ when :has_one
187
+ association_name = @resource.model_name.downcase.to_sym
188
+ worked = item.send(association_name).delete
186
189
  else
187
- flash[:alert] = _t("%{model_a} cannot be unrelated from %{model_b}",
188
- :model_a => resource_class.model_name.human,
189
- :model_b => @resource.model_name.human)
190
+ association_name ||= @resource.model_name.tableize.to_sym
191
+ worked = item.send(association_name).delete(@item)
190
192
  end
191
193
 
192
- redirect_to set_path
193
-
194
- end
195
-
196
- ##
197
- # Remove file attachments.
198
- #
199
- def detach
200
- message = if @item.update_attributes(params[:attachment] => nil)
201
- "%{attachment} removed."
202
- else
203
- "%{attachment} can't be removed."
204
- end
194
+ ##
195
+ # Finally delete the associated object. Depending on your models setup
196
+ # associated models will be removed or foreign_key will be set to nil.
197
+ #
205
198
 
206
- attachment = @resource.human_attribute_name(params[:attachment])
207
- notice = _t(message, :attachment => attachment)
199
+ if worked
200
+ notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
201
+ else
202
+ alert = item.error.full_messages
203
+ end
208
204
 
209
- redirect_to set_path, :notice => notice
205
+ redirect_to set_path, :notice => notice, :alert => alert
210
206
  end
211
207
 
212
208
  private
@@ -216,23 +212,39 @@ class Admin::ResourcesController < Admin::BaseController
216
212
  @object_name = ActiveModel::Naming.singular(@resource)
217
213
  end
218
214
 
215
+ def set_scope
216
+ @resource = @resource.unscoped
217
+ end
218
+
219
219
  def get_object
220
220
  @item = @resource.find(params[:id])
221
221
  end
222
222
 
223
- def set_fields
224
- mapping = case params[:action]
225
- when "index" then :list
226
- when "new", "edit", "create", "update" then :form
227
- else params[:action]
228
- end
223
+ def get_objects
224
+ eager_loading = @resource.reflect_on_all_associations(:belongs_to).reject { |i| i.options[:polymorphic] }.map { |i| i.name }
225
+
226
+ @resource.build_conditions(params).each do |condition|
227
+ @resource = @resource.where(condition)
228
+ end
229
+
230
+ @resource.build_joins(params).each do |join|
231
+ @resource = @resource.joins(join)
232
+ end
229
233
 
230
- @fields = @resource.typus_fields_for(mapping)
234
+ if @resource.typus_options_for(:only_user_items)
235
+ check_resources_ownership
236
+ end
237
+
238
+ @items = @resource.order(set_order).includes(eager_loading)
239
+ end
240
+
241
+ def set_fields
242
+ @fields = @resource.typus_fields_for(params[:action].action_mapper)
231
243
  end
232
244
 
233
245
  def set_order
234
246
  params[:sort_order] ||= "desc"
235
- @order = params[:order_by] ? "#{@resource.table_name}.#{params[:order_by]} #{params[:sort_order]}" : @resource.typus_order_by
247
+ params[:order_by] ? "#{@resource.table_name}.#{params[:order_by]} #{params[:sort_order]}" : @resource.typus_order_by
236
248
  end
237
249
 
238
250
  def redirect_on_success
@@ -242,64 +254,163 @@ class Admin::ResourcesController < Admin::BaseController
242
254
  when "create"
243
255
  path = { :action => action }
244
256
  path.merge!(:id => @item.id) unless action.eql?("index")
245
- notice = _t("%{model} successfully created.", :model => @resource.model_name.human)
246
- when "update"
257
+ notice = Typus::I18n.t("%{model} successfully created.", :model => @resource.model_name.human)
258
+ when "update", "detach"
247
259
  path = case action
248
260
  when "index"
249
261
  params[:back_to] ? "#{params[:back_to]}##{@resource.to_resource}" : { :action => action }
250
262
  else
251
- { :action => action,
252
- :id => @item.id,
253
- :back_to => params[:back_to] }
263
+ { :action => action, :id => @item.id, :back_to => params[:back_to] }
254
264
  end
255
- notice = _t("%{model} successfully updated.", :model => @resource.model_name.human)
265
+ notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
256
266
  end
257
267
 
258
268
  redirect_to path, :notice => notice
259
269
  end
260
270
 
261
271
  ##
262
- # When <tt>params[:back_to]</tt> is defined this action is used.
272
+ # Here what we basically do is to associate objects after they have been
273
+ # created. It's similar to calling `relate`.
263
274
  #
264
- # - <tt>has_and_belongs_to_many</tt> relationships.
265
- # - <tt>has_many</tt> relationships (polymorphic ones).
275
+ # We have two objects:
276
+ #
277
+ # - @item: Which is the create object.
278
+ # - item: Which is the object which be associated to.
279
+ #
280
+ # http://0.0.0.0:3000/admin/entries/new?back_to=%2Fadmin%2Fcategories%2Fedit%2F3&resource=categories&resource_id=3
266
281
  #
267
282
  def create_with_back_to
268
283
 
269
- if params[:resource] && params[:resource_id]
270
- resource_class = params[:resource].classify.constantize
271
- resource_id = params[:resource_id]
272
- resource = resource_class.find(resource_id)
273
- association = @resource.reflect_on_association(params[:resource].to_sym).macro rescue :polymorphic
274
- else
275
- association = :has_many
276
- end
277
-
278
- case association
279
- when :belongs_to
280
- @item.save
284
+ #
285
+ # Find the remote object which is named item!
286
+ #
287
+
288
+ item_class = params[:resource].typus_constantize
289
+ item = item_class.find(params[:resource_id]) if params[:resource_id]
290
+
291
+ ##
292
+ # Detect which kind of relationship there's between both models.
293
+ #
294
+
295
+ ##
296
+ # Here we have something like:
297
+ #
298
+ # Eg 1.
299
+ #
300
+ # - We are editing an Order and want to add a new Invoice.
301
+ # - Click on "Add New" and we are redirected to the form.
302
+ # - We want to know which kind of relationship there's between both
303
+ # objects.
304
+ #
305
+ # >> Order.relationship_with(Invoice)
306
+ # => :has_one
307
+ #
308
+ # Eg 2.
309
+ #
310
+ # - We are editing a Entry and want to add a new Attachment.
311
+ # - Click on "Add New" and we are redirected to the form.
312
+ # - We want to know which kind of relationship there's between both
313
+ # objects.
314
+ #
315
+ # >> Entry.relationship_with(Attachment)
316
+ # => :has_and_belongs_to_many
317
+ #
318
+ # Eg 3.
319
+ #
320
+ # - We are editing a Entry and want to add a new Comment.
321
+ # - Click on "Add New" and we are redirected to the form.
322
+ # - We want to know which kind of relationship there's between both
323
+ # objects.
324
+ #
325
+ # >> Entry.relationship_with(Comment)
326
+ # => :has_many
327
+ #
328
+ # Eg 4.
329
+ #
330
+ # - We are editing a Post (Entry) and want to add a new Attachment.
331
+ # - Click on "Add New" and we are redirected to the form.
332
+ # - We want to know which kind of relationship there's between both
333
+ # objects.
334
+ #
335
+ # >> Post.relationship_with(Attachment)
336
+ # => :has_and_belongs_to_many
337
+ #
338
+
339
+ case item_class.relationship_with(@resource)
340
+ when :has_one
341
+ # Order#invoice = @item
342
+ association_name = @resource.model_name.downcase.to_sym
343
+ item.send("#{association_name}=", @item)
344
+ worked = true
281
345
  when :has_and_belongs_to_many
282
- @item.save
283
- @item.send(params[:resource]) << resource
284
- when :has_many
285
- @item.save
286
- message = _t("%{model} successfully created.", :model => @resource.model_name.human)
287
- path = "#{params[:back_to]}?#{params[:selected]}=#{@item.id}"
288
- when :polymorphic
289
- resource.send(@item.class.to_resource).create(params[@object_name])
346
+ # Attachment#entries.push(item)
347
+ association_name = @resource.model_name.tableize.to_sym
348
+ worked = item.send(association_name).push(@item)
349
+ when :belongs_to
350
+ # Entry#comments.push(item)
351
+ association_name = item_class.model_name.tableize.to_sym
352
+ if item
353
+ worked = @item.send(association_name).push(item)
354
+ end
290
355
  end
291
356
 
292
- flash[:notice] = message || _t("%{model_a} successfully assigned to %{model_b}.",
293
- :model_a => @item.class.model_name.human,
294
- :model_b => resource_class.model_name.human)
357
+ association = @resource.reflect_on_association(association_name)
358
+
359
+ ##
360
+ # Set @back_to
361
+ #
362
+
363
+ @back_to = if item
364
+ params[:back_to]
365
+ else
366
+ "#{params[:back_to]}?#{association.primary_key_name}=#{@item.id}"
367
+ end
368
+
369
+ ##
370
+ # Finally delete the associated object. Depending on your models setup
371
+ # associated models will be removed or foreign_key will be set to nil.
372
+ #
373
+
374
+ if item
375
+ if worked
376
+ notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
377
+ else
378
+ alert = @item.error.full_messages
379
+ end
380
+ end
295
381
 
296
- redirect_to path || params[:back_to]
382
+ redirect_to set_path, :notice => notice, :alert => alert
383
+ end
297
384
 
385
+ def default_action
386
+ @resource.typus_options_for(:default_action_on_item)
298
387
  end
299
388
 
300
- def select_template(action = params[:action], resource = @resource.to_resource)
301
- folder = File.exist?("app/views/admin/#{resource}/#{action}.html.erb") ? resource : 'resources'
302
- render "admin/#{folder}/#{action}"
389
+ ##
390
+ # If we are trying to create a new Invoice which belongs_to Order, we should
391
+ # verify before the the Order doesn't have an Invoice, otherwise we would
392
+ # have and Order with many Invoices which is something not desired.
393
+ #
394
+ # Eg:
395
+ #
396
+ # @resource (Invoice)
397
+ # params[:resource] = "Order"
398
+ # params[:resource_id] = "1"
399
+ #
400
+ # Does this Order already has an Invoice. If true, redirect to back.
401
+ #
402
+ def check_if_we_can_add_a_new_item
403
+ if params[:resource] && params[:resource_id]
404
+ item_class = params[:resource].typus_constantize
405
+ item = item_class.find(params[:resource_id]) if params[:resource_id]
406
+
407
+ if item_class.relationship_with(@resource) == :has_one
408
+ association_name = @resource.model_name.downcase.to_sym
409
+ if item.send(association_name)
410
+ render :text => "Not allowed!", :status => :unprocessable_entity
411
+ end
412
+ end
413
+ end
303
414
  end
304
415
 
305
- end
416
+ end