typus 3.0.2 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -4,23 +4,28 @@ module Admin
4
4
 
5
5
  def setup_relationship(field)
6
6
  @field = field
7
- @model_to_relate = @resource.reflect_on_association(field.to_sym).class_name.constantize
7
+ @model_to_relate = @resource.reflect_on_association(field.to_sym).class_name.typus_constantize
8
8
  @model_to_relate_as_resource = @model_to_relate.to_resource
9
9
  @reflection = @resource.reflect_on_association(field.to_sym)
10
- @association = @reflection.macro
10
+ @association_name = @reflection.through_reflection ? @reflection.name.to_s : @model_to_relate.model_name.tableize
11
11
  end
12
12
 
13
13
  def typus_form_has_many(field)
14
-
15
14
  setup_relationship(field)
15
+ if @reflection.through_reflection
16
+ @items_to_relate = @model_to_relate.all - @item.send(field)
17
+ else
18
+ @items_to_relate = @model_to_relate.where(@reflection.primary_key_name => nil) - @item.send(field)
19
+ end
16
20
 
17
- foreign_key = @reflection.through_reflection ? @reflection.primary_key_name.pluralize : @reflection.primary_key_name
18
-
19
- @items_to_relate = @model_to_relate.send("find_all_by_#{foreign_key}", nil)
20
- if set_condition && !@items_to_relate.empty?
21
+ if set_condition && @items_to_relate.any?
21
22
  form = build_relate_form
22
23
  end
23
24
 
25
+ unless @reflection.through_reflection
26
+ foreign_key = @reflection.primary_key_name
27
+ end
28
+
24
29
  options = { foreign_key => @item.id }
25
30
 
26
31
  build_pagination
@@ -28,19 +33,19 @@ module Admin
28
33
  render "admin/templates/has_n",
29
34
  :model_to_relate => @model_to_relate,
30
35
  :model_to_relate_as_resource => @model_to_relate_as_resource,
36
+ :association_name => @association_name,
31
37
  :foreign_key => foreign_key,
32
- :add_new => raw(build_add_new(options)),
38
+ :add_new => build_add_new(options),
33
39
  :form => form,
34
40
  :table => build_relationship_table
35
-
36
41
  end
37
42
 
38
43
  def typus_form_has_and_belongs_to_many(field)
39
-
40
44
  setup_relationship(field)
41
45
 
42
- @items_to_relate = (@model_to_relate.all - @item.send(field))
43
- if set_condition && !@items_to_relate.empty?
46
+ @items_to_relate = @model_to_relate.all - @item.send(field)
47
+
48
+ if set_condition && @items_to_relate.any?
44
49
  form = build_relate_form
45
50
  end
46
51
 
@@ -49,23 +54,24 @@ module Admin
49
54
  render "admin/templates/has_n",
50
55
  :model_to_relate => @model_to_relate,
51
56
  :model_to_relate_as_resource => @model_to_relate_as_resource,
52
- :add_new => raw(build_add_new),
57
+ :association_name => @association_name,
58
+ :add_new => build_add_new,
53
59
  :form => form,
54
60
  :table => build_relationship_table
55
-
56
61
  end
57
62
 
58
63
  def build_pagination
59
64
  options = { :order => @model_to_relate.typus_order_by, :conditions => set_conditions }
60
65
  items_per_page = @model_to_relate.typus_options_for(:per_page)
61
- data = @resource.find(params[:id]).send(@field).all(options)
66
+ data = @resource.unscoped.find(params[:id]).send(@field).all(options)
62
67
  @items = data.paginate(:per_page => items_per_page, :page => params[:page])
63
68
  end
64
69
 
65
70
  def build_relate_form
66
71
  render "admin/templates/relate_form",
67
72
  :model_to_relate => @model_to_relate,
68
- :items_to_relate => @items_to_relate
73
+ :items_to_relate => @items_to_relate,
74
+ :association_name => @association_name
69
75
  end
70
76
 
71
77
  def build_relationship_table
@@ -74,110 +80,89 @@ module Admin
74
80
  @items,
75
81
  @model_to_relate_as_resource,
76
82
  {},
77
- @association)
83
+ @reflection.macro,
84
+ @association_name)
78
85
  end
79
86
 
80
87
  def build_add_new(options = {})
81
- default_options = { :controller => @field, :action => "new",
82
- :resource => @resource.name, :resource_id => @item.id,
88
+ default_options = { :controller => "/admin/#{@model_to_relate.to_resource}", :action => "new",
89
+ :resource => @resource.model_name, :resource_id => @item.id,
83
90
  :back_to => @back_to }
84
91
 
85
- return unless set_condition && current_user.can?("create", @model_to_relate)
86
-
87
- link_to _t("Add new"), default_options.merge(options)
92
+ if set_condition && admin_user.can?("create", @model_to_relate)
93
+ link_to Typus::I18n.t("Add new"), default_options.merge(options)
94
+ end
88
95
  end
89
96
 
90
97
  def set_condition
91
- if @resource.typus_user_id? && current_user.is_not_root?
92
- @item.owned_by?(current_user)
98
+ if @resource.typus_user_id? && admin_user.is_not_root?
99
+ @item.owned_by?(admin_user)
93
100
  else
94
101
  true
95
102
  end
96
103
  end
97
104
 
98
105
  def set_conditions
99
- if @model_to_relate.typus_options_for(:only_user_items) && current_user.is_not_root?
100
- { Typus.user_fk => current_user }
106
+ if @model_to_relate.typus_options_for(:only_user_items) && admin_user.is_not_root?
107
+ { Typus.user_fk => admin_user }
101
108
  end
102
109
  end
103
110
 
104
- #--
105
- # TODO: Move html code to partial.
106
- #++
107
111
  def typus_form_has_one(field)
108
- html = ""
109
-
110
- model_to_relate = @resource.reflect_on_association(field.to_sym).class_name.constantize
111
- model_to_relate_as_resource = model_to_relate.to_resource
112
-
113
- reflection = @resource.reflect_on_association(field.to_sym)
114
- association = reflection.macro
115
-
116
- html << <<-HTML
117
- <a name="#{field}"></a>
118
- <div class="box_relationships" id="#{model_to_relate_as_resource}">
119
- <h2>
120
- #{link_to model_to_relate.model_name.human, :controller => "admin/#{model_to_relate_as_resource}"}
121
- </h2>
122
- HTML
123
- items = Array.new
124
- items << @resource.find(params[:id]).send(field) unless @resource.find(params[:id]).send(field).nil?
125
- unless items.empty?
126
- options = { :back_to => @back_to, :resource => @resource.to_resource, :resource_id => @item.id }
127
- html << build_list(model_to_relate,
128
- model_to_relate.typus_fields_for(:relationship),
129
- items,
130
- model_to_relate_as_resource,
131
- options,
132
- association)
133
- else
134
- message = _t("There are no %{records}.",
135
- :records => model_to_relate.model_name.human.downcase)
136
- html << <<-HTML
137
- <div id="flash" class="notice"><p>#{message}</p></div>
138
- HTML
112
+ setup_relationship(field)
113
+
114
+ @items = Array.new
115
+ if item = @resource.find(params[:id]).send(field)
116
+ @items << item
139
117
  end
140
- html << <<-HTML
141
- </div>
142
- HTML
143
118
 
144
- return html
119
+ render "admin/templates/has_one",
120
+ :model_to_relate => @model_to_relate,
121
+ :model_to_relate_as_resource => @model_to_relate_as_resource,
122
+ :add_new => @items.empty? ? build_add_new : nil,
123
+ :table => build_relationship_table
145
124
  end
146
125
 
147
126
  def typus_belongs_to_field(attribute, form)
148
-
149
127
  ##
150
- # We only can pass parameters to 'new' and 'edit', so this hack makes
151
- # the work to replace the current action.
128
+ # We can only pass parameters to 'new' and 'edit'. This hack replaces
129
+ # the current action.
152
130
  #
153
131
  params[:action] = (params[:action] == 'create') ? 'new' : params[:action]
154
132
 
155
133
  back_to = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id])
156
134
 
157
- related = @resource.reflect_on_association(attribute.to_sym).class_name.constantize
135
+ related = @resource.reflect_on_association(attribute.to_sym).class_name.typus_constantize
158
136
  related_fk = @resource.reflect_on_association(attribute.to_sym).primary_key_name
159
137
 
160
- confirm = [ _t("Are you sure you want to leave this page?"),
161
- _t("If you have made any changes to the fields without clicking the Save/Update entry button, your changes will be lost."),
162
- _t("Click OK to continue, or click Cancel to stay on this page.") ]
138
+ if params[:action] == 'edit'
139
+ options = { :resource => @resource.model_name,
140
+ :resource_id => @item.id }
141
+ else
142
+ options = { :resource => @resource.model_name }
143
+ end
144
+
145
+ default = { :controller => "/admin/#{related.to_resource}", :action => 'new', :back_to => back_to }
163
146
 
164
- message = link_to _t("Add"), { :controller => "admin/#{related.to_resource}",
165
- :action => 'new',
166
- :back_to => back_to,
167
- :selected => related_fk },
168
- :confirm => confirm.join("\n\n") if current_user.can?('create', related)
147
+ if admin_user.can?('create', related)
148
+ message = link_to Typus::I18n.t("Add"), default.merge(options)
149
+ end
150
+
151
+ values = related.respond_to?(:roots) ?
152
+ expand_tree_into_select_field(related.roots, related_fk) :
153
+ related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
169
154
 
170
155
  render "admin/templates/belongs_to",
171
156
  :resource => @resource,
157
+ :attribute => attribute,
172
158
  :form => form,
173
159
  :related_fk => related_fk,
174
160
  :message => message,
175
161
  :label_text => @resource.human_attribute_name(attribute),
176
- :values => related.all(:order => related.typus_order_by).collect { |p| [p.to_label, p.id] },
162
+ :values => values,
177
163
  # :html_options => { :disabled => attribute_disabled?(attribute) },
178
164
  :html_options => {},
179
165
  :options => { :include_blank => true }
180
-
181
166
  end
182
167
 
183
168
  end
@@ -2,48 +2,27 @@ module Admin
2
2
 
3
3
  module ResourcesHelper
4
4
 
5
- include FiltersHelper
6
- include FormHelper
7
- include RelationshipsHelper
8
- include PreviewHelper
9
- include SearchHelper
10
- include SidebarHelper
11
- include TableHelper
5
+ include Admin::FiltersHelper
6
+ include Admin::FormHelper
7
+ include Admin::RelationshipsHelper
8
+ include Admin::FilePreviewHelper
9
+ include Admin::SearchHelper
10
+ include Admin::SidebarHelper
11
+ include Admin::TableHelper
12
12
 
13
13
  #--
14
14
  # If partial `list` exists we will use it. This partial will have available
15
15
  # the `@items` so we can do whatever we want there. Notice that pagination
16
16
  # is still available.
17
17
  #++
18
- def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil)
18
+ def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil, association_name = nil)
19
19
  render "admin/#{resource}/list", :items => items
20
20
  rescue ActionView::MissingTemplate
21
- build_table(model, fields, items, link_options, association)
21
+ build_table(model, fields, items, link_options, association, association_name)
22
22
  end
23
23
 
24
24
  def display_link_to_previous
25
- return unless params[:back_to]
26
-
27
- options = {}
28
- options[:resource_from] = @resource.model_name.human
29
- options[:resource_to] = params[:resource].classify.constantize.model_name.human if params[:resource]
30
-
31
- editing = %w( edit update ).include?(params[:action])
32
- message = case
33
- when params[:resource] && editing
34
- "You're updating a %{resource_from} for %{resource_to}."
35
- when editing
36
- "You're updating a %{resource_from}."
37
- when params[:resource]
38
- "You're adding a new %{resource_from} to %{resource_to}."
39
- else
40
- "You're adding a new %{resource_from}."
41
- end
42
- message = _t(message,
43
- :resource_from => options[:resource_from],
44
- :resource_to => options[:resource_to])
45
-
46
- render File.join(path, "display_link_to_previous"), :message => message
25
+ render File.join(path, "display_link_to_previous") if params[:back_to]
47
26
  end
48
27
 
49
28
  private
@@ -3,15 +3,12 @@ module Admin
3
3
  module SearchHelper
4
4
 
5
5
  def search(resource = @resource)
6
- typus_search = resource.typus_defaults_for(:search)
7
- return if typus_search.empty?
8
-
9
- search_by = typus_search.collect { |x| resource.human_attribute_name(x) }.to_sentence
10
- search_params = params.dup
11
- %w(action controller id search page utf8).each { |p| search_params.delete(p) }
12
- hidden_params = search_params.map { |k, v| hidden_field_tag(k, v) }
13
-
14
- render "admin/helpers/search/search", :hidden_params => hidden_params, :search_by => search_by
6
+ if (typus_search = resource.typus_defaults_for(:search)) && typus_search.any?
7
+ search_params = params.dup
8
+ %w(action controller id search page utf8).each { |p| search_params.delete(p) }
9
+ options = { :hidden_params => search_params.map { |k, v| hidden_field_tag(k, v) } }
10
+ render "admin/helpers/search/search", options
11
+ end
15
12
  end
16
13
 
17
14
  end
@@ -6,13 +6,13 @@ module Admin
6
6
  resources = ActiveSupport::OrderedHash.new
7
7
  app_name = @resource.typus_application
8
8
 
9
- Typus.application(app_name).sort {|a,b| a.constantize.model_name.human <=> b.constantize.model_name.human}.each do |resource|
10
- next unless current_user.resources.include?(resource)
11
- klass = resource.constantize
9
+ Typus.application(app_name).sort {|a,b| a.typus_constantize.model_name.human <=> b.typus_constantize.model_name.human}.each do |resource|
10
+ next unless admin_user.resources.include?(resource)
11
+ klass = resource.typus_constantize
12
12
 
13
13
  resources[resource] = default_actions(klass)
14
- resources[resource] += export(klass) if params[:action] == 'index'
15
14
  resources[resource] += custom_actions(klass)
15
+ resources[resource] += export(klass) if params[:action] == 'index'
16
16
 
17
17
  resources[resource].compact!
18
18
  end
@@ -21,31 +21,26 @@ module Admin
21
21
  end
22
22
 
23
23
  def default_actions(klass)
24
- actions = []
25
-
26
- if current_user.can?("create", klass)
27
- actions << link_to_unless_current(_t("Add new"), :action => "new")
28
- end
29
-
30
- actions << link_to_unless_current(_t("List"), :action => "index")
31
-
32
- return actions
33
- end
34
-
35
- def export(klass)
36
- klass.typus_export_formats.map do |format|
37
- link_to _t("Export as %{format}", :format => format.upcase), params.merge(:format => format)
24
+ Array.new.tap do |tap|
25
+ tap << link_to_unless_current(Typus::I18n.t("Add new"), :action => "new") if admin_user.can?("create", klass)
26
+ tap << link_to_unless_current(Typus::I18n.t("List"), :action => "index")
38
27
  end
39
28
  end
40
29
 
41
30
  def custom_actions(klass)
42
31
  klass.typus_actions_on(params[:action]).map do |action|
43
- if current_user.can?(action, klass)
44
- link_to_unless_current(_t(action.humanize), params.merge(:action => action))
32
+ if admin_user.can?(action, klass)
33
+ link_to_unless_current(Typus::I18n.t(action.humanize), params.merge(:action => action))
45
34
  end
46
35
  end
47
36
  end
48
37
 
38
+ def export(klass, params = params)
39
+ klass.typus_export_formats.map do |format|
40
+ link_to Typus::I18n.t("Export as %{mime}", :mime => format.upcase), params.merge(:format => format)
41
+ end
42
+ end
43
+
49
44
  end
50
45
 
51
46
  end
@@ -2,26 +2,27 @@ module Admin
2
2
 
3
3
  module TableHelper
4
4
 
5
- def build_table(model, fields, items, link_options = {}, association = nil)
5
+ def build_table(model, fields, items, link_options = {}, association = nil, association_name = nil)
6
6
  render "admin/helpers/table/table",
7
7
  :model => model,
8
8
  :fields => fields,
9
9
  :items => items,
10
10
  :link_options => link_options,
11
- :headers => table_header(model, fields)
11
+ :headers => table_header(model, fields),
12
+ :association_name => association_name
12
13
  end
13
14
 
14
- def table_header(model, fields)
15
+ def table_header(model, fields, params = params)
15
16
  fields.map do |key, value|
16
17
 
17
18
  key = key.gsub(".", " ") if key.match(/\./)
18
19
  content = model.human_attribute_name(key)
19
20
 
20
- if params[:action] == "index"
21
+ if params[:action].eql?('index') && model.typus_options_for(:sortable)
21
22
  association = model.reflect_on_association(key.to_sym)
22
23
  order_by = association ? association.primary_key_name : key
23
24
 
24
- if (model.model_fields.map(&:first).collect { |i| i.to_s }.include?(key) || model.reflect_on_all_associations(:belongs_to).map(&:name).include?(key.to_sym))
25
+ if (model.model_fields.map(&:first).map { |i| i.to_s }.include?(key) || model.reflect_on_all_associations(:belongs_to).map(&:name).include?(key.to_sym))
25
26
  sort_order = case params[:sort_order]
26
27
  when 'asc' then ['desc', '&darr;']
27
28
  when 'desc' then ['asc', '&uarr;']
@@ -29,8 +30,8 @@ module Admin
29
30
  end
30
31
  switch = sort_order.last if params[:order_by].eql?(order_by)
31
32
  options = { :order_by => order_by, :sort_order => sort_order.first }
32
- message = [ content, switch ].compact
33
- link_to raw(message.join(" ")), params.merge(options)
33
+ message = [content, switch].compact.join(" ").html_safe
34
+ link_to message, params.merge(options)
34
35
  else
35
36
  content
36
37
  end
@@ -42,206 +43,114 @@ module Admin
42
43
  end
43
44
  end
44
45
 
45
- def table_fields_for_item(item, fields, link_options)
46
- fields.map do |key, value|
47
- case value
48
- when :boolean then table_boolean_field(key, item)
49
- when :datetime then table_datetime_field(key, item, link_options)
50
- when :date then table_datetime_field(key, item, link_options)
51
- when :file then table_file_field(key, item, link_options)
52
- when :time then table_datetime_field(key, item, link_options)
53
- when :belongs_to then table_belongs_to_field(key, item)
54
- when :tree then table_tree_field(key, item)
55
- when :position then table_position_field(key, item)
56
- when :selector then table_selector(key, item)
57
- when :transversal then table_transversal(key, item)
58
- when :has_and_belongs_to_many then table_has_and_belongs_to_many_field(key, item)
59
- else
60
- table_string_field(key, item, link_options)
61
- end
62
- end
46
+ def table_fields_for_item(item, fields)
47
+ fields.map { |k, v| send("table_#{v}_field", k, item) }
63
48
  end
64
49
 
65
- def table_default_action(model, item)
66
- action = if model.typus_user_id? && current_user.is_not_root?
67
- # If there's a typus_user_id column on the table and logged user is not root ...
68
- item.owned_by?(current_user) ? item.class.typus_options_for(:default_action_on_item) : "show"
69
- elsif current_user.cannot?("edit", model)
70
- 'show'
71
- else
72
- item.class.typus_options_for(:default_action_on_item)
73
- end
74
-
75
- options = { :controller => "admin/#{item.class.to_resource}",
76
- :action => action,
77
- :id => item.id }
78
-
79
- link_to _t(action.capitalize), options
80
- end
81
-
82
- #--
83
- # This controls the action to perform. If we are on a model list we
84
- # will remove the entry, but if we inside a model we will remove the
85
- # relationship between the models.
86
- #
87
- # Only shown is the user can destroy/unrelate items.
88
- #++
89
- def table_action(model, item)
90
-
91
- condition = true
92
-
93
- case params[:action]
94
- when "index"
95
- action = "trash"
96
- options = { :action => 'destroy', :id => item.id }
97
- method = :delete
98
- when "edit", "show"
99
- action = "unrelate"
100
- options = { :action => 'unrelate', :id => params[:id], :resource => model, :resource_id => item.id }
101
- end
102
-
103
- title = _t(action.titleize)
104
-
105
- case params[:action]
106
- when 'index'
107
- condition = if model.typus_user_id? && current_user.is_not_root?
108
- item.owned_by?(current_user)
109
- elsif (current_user.id.eql?(item.id) && model.eql?(Typus.user_class))
110
- false
111
- else
112
- current_user.can?('destroy', model)
113
- end
114
- confirm = _t("Remove %{resource}?", :resource => item.class.model_name.human)
115
- when 'edit'
116
- # If we are editing content, we can relate and unrelate always!
117
- confirm = _t("Unrelate %{unrelate_model} from %{unrelate_model_from}?",
118
- :unrelate_model => model.model_name.human,
119
- :unrelate_model_from => @resource.model_name.human)
120
- when 'show'
121
- # If we are showing content, we only can relate and unrelate if we are
122
- # the owners of the owner record.
123
- # If the owner record doesn't have a foreign key (Typus.user_fk) we look
124
- # each item to verify the ownership.
125
- condition = if @resource.typus_user_id? && current_user.is_not_root?
126
- @item.owned_by?(current_user)
127
- end
128
- confirm = _t("Unrelate %{unrelate_model} from %{unrelate_model_from}?",
129
- :unrelate_model => model.model_name.human,
130
- :unrelate_model_from => @resource.model_name.human)
131
- end
132
-
133
- message = %(<div class="sprite #{action}">#{_t(action.titleize)}</div>)
134
-
135
- if condition
136
- link_to raw(message), options, :title => title, :confirm => confirm, :method => method
137
- end
50
+ def actions
51
+ @actions ||= []
52
+ end
138
53
 
54
+ def table_actions(model, item, association_name = nil)
55
+ actions.map do |action|
56
+ if admin_user.can?(action[:action], model.name)
57
+ link_to Typus::I18n.t(action[:action_name]),
58
+ { :controller => model.to_resource, :action => action[:action], :id => item.id, :resource => action[:resource], :resource_id => action[:resource_id], :association_name => association_name },
59
+ { :confirm => action[:confirm], :method => action[:method], :target => "_parent" }
60
+ end
61
+ end.compact.join(" / ").html_safe
139
62
  end
140
63
 
141
64
  def table_belongs_to_field(attribute, item)
142
- att_value = item.send(attribute)
143
- content = "&mdash;".html_safe
144
-
145
- unless att_value.nil?
146
- content = att_value.to_label
65
+ if att_value = item.send(attribute)
147
66
  action = item.send(attribute).class.typus_options_for(:default_action_on_item)
148
- if current_user.can?(action, att_value.class.name)
149
- content = link_to content, :controller => "admin/#{att_value.class.to_resource}", :action => action, :id => att_value.id
67
+ if admin_user.can?(action, att_value.class.name)
68
+ link_to att_value.to_label, :controller => "/admin/#{att_value.class.to_resource}", :action => action, :id => att_value.id
69
+ else
70
+ att_value.to_label
150
71
  end
72
+ else
73
+ "&mdash;".html_safe
151
74
  end
152
-
153
- return content_tag(:td, content)
154
75
  end
155
76
 
156
77
  def table_has_and_belongs_to_many_field(attribute, item)
157
- content = item.send(attribute).map { |i| i.to_label }.join(", ")
158
- return content_tag(:td, content)
78
+ item.send(attribute).map { |i| i.to_label }.join(", ")
159
79
  end
160
80
 
161
- def table_string_field(attribute, item, link_options = {})
162
- raw_content = item.send(attribute)
163
- content = raw_content.blank? ? "&#151;".html_safe : raw_content
164
- return content_tag(:td, content, :class => attribute)
165
- end
81
+ alias :table_has_many_field :table_has_and_belongs_to_many_field
166
82
 
167
- def table_selector(attribute, item)
168
- raw_content = item.mapping(attribute)
169
- return content_tag(:td, raw_content, :class => attribute)
83
+ def table_string_field(attribute, item)
84
+ (raw_content = item.send(attribute)).present? ? truncate(raw_content) : "&mdash;".html_safe
170
85
  end
171
86
 
172
- def table_file_field(attribute, item, link_options = {})
173
- file_preview = Typus.file_preview
174
- file_thumbnail = Typus.file_thumbnail
87
+ alias :table_text_field :table_string_field
175
88
 
176
- has_file_preview = item.send(attribute).styles.member?(file_preview)
177
- file_preview_is_image = item.send("#{attribute}_content_type") =~ /^image\/.+/
89
+ def table_generic_field(attribute, item)
90
+ (raw_content = item.send(attribute)).present? ? raw_content : "&mdash;".html_safe
91
+ end
178
92
 
179
- content = if has_file_preview && file_preview_is_image
180
- render "admin/helpers/preview",
181
- :attribute => attribute,
182
- :attachment => attribute,
183
- :content => item.to_label,
184
- :file_preview_is_image => file_preview_is_image,
185
- :has_file_preview => has_file_preview,
186
- :href => item.send(attribute).url(file_preview),
187
- :item => item
188
- else
189
- link_to item.send(attribute), item.send(attribute).url
190
- end
93
+ alias :table_float_field :table_generic_field
94
+ alias :table_integer_field :table_generic_field
95
+ alias :table_decimal_field :table_generic_field
96
+ alias :table_virtual_field :table_generic_field
191
97
 
192
- return content_tag(:td, content)
98
+ def table_selector_field(attribute, item)
99
+ item.mapping(attribute)
100
+ end
101
+
102
+ def table_file_field(attribute, item)
103
+ typus_file_preview(item, attribute)
193
104
  end
194
105
 
195
106
  def table_tree_field(attribute, item)
196
- content = item.parent ? item.parent.to_label : "&#151;".html_safe
197
- return content_tag(:td, content)
107
+ item.parent ? item.parent.to_label : "&mdash;".html_safe
198
108
  end
199
109
 
200
- def table_position_field(attribute, item)
110
+ def table_position_field(attribute, item, connector = " / ")
201
111
  html_position = []
202
112
 
203
- { :move_higher => "Up", :move_lower => "Down" }.each do |key, value|
204
- options = { :controller => item.class.to_resource, :action => "position", :id => item.id, :go => key }
205
- first_or_last = (item.respond_to?(:first?) && (key == :move_higher && item.first?)) || (item.respond_to?(:last?) && (key == :move_lower && item.last?))
206
- html_position << link_to_unless(first_or_last, _t(value), params.merge(options)) do |name|
207
- %(<span class="inactive">#{name}</span>)
113
+ [ [:move_to_top, "Top"],
114
+ [:move_higher, "Up"],
115
+ [:move_lower, "Down"],
116
+ [:move_to_bottom, "Bottom"] ].each do |key, value|
117
+
118
+ options = { :controller => "/admin/#{item.class.to_resource}", :action => "position", :id => item.id, :go => key }
119
+ should_be_inactive = (item.respond_to?(:first?) && ([:move_higher, :move_to_top].include?(key) && item.first?)) ||
120
+ (item.respond_to?(:last?) && ([:move_lower, :move_to_bottom].include?(key) && item.last?))
121
+ html_position << link_to_unless(should_be_inactive, Typus::I18n.t(value), params.merge(options)) do |name|
122
+ %w(<span class="inactive">#{name}</span>)
208
123
  end
209
124
  end
210
125
 
211
- content = html_position.join(" / ").html_safe
212
- return content_tag(:td, content)
126
+ "#{item.position}<br/><br/>#{html_position.compact.join(connector)}".html_safe
213
127
  end
214
128
 
215
- def table_datetime_field(attribute, item, link_options = {} )
216
- date_format = item.class.typus_date_format(attribute)
217
- content = !item.send(attribute).nil? ? item.send(attribute).to_s(date_format) : item.class.typus_options_for(:nil)
218
-
219
- return content_tag(:td, content)
129
+ def table_datetime_field(attribute, item)
130
+ if field = item.send(attribute)
131
+ I18n.localize(field, :format => item.class.typus_date_format(attribute))
132
+ end
220
133
  end
221
134
 
135
+ alias :table_date_field :table_datetime_field
136
+ alias :table_time_field :table_datetime_field
137
+
222
138
  def table_boolean_field(attribute, item)
223
- boolean_hash = item.class.typus_boolean(attribute).invert
224
139
  status = item.send(attribute)
140
+ boolean_hash = item.class.typus_boolean(attribute).invert
141
+ human_boolean = status ? boolean_hash["true"] : boolean_hash["false"]
142
+
143
+ options = { :controller => "/admin/#{item.class.to_resource}",
144
+ :action => "toggle",
145
+ :id => item.id,
146
+ :field => attribute.gsub(/\?$/, '') }
147
+ confirm = Typus::I18n.t("Change %{attribute}?", :attribute => item.class.human_attribute_name(attribute).downcase)
148
+ link_to Typus::I18n.t(human_boolean), options, :confirm => confirm
149
+ end
225
150
 
226
- content = if status.nil?
227
- Typus::Resources.human_nil
228
- else
229
- message = _t(boolean_hash[status.to_s])
230
- options = { :controller => "admin/#{item.class.to_resource}",
231
- :action => "toggle",
232
- :id => item.id,
233
- :field => attribute.gsub(/\?$/,'') }
234
- confirm = _t("Change %{attribute}?",
235
- :attribute => item.class.human_attribute_name(attribute).downcase)
236
- link_to message, options, :confirm => confirm
237
- end
238
-
239
- return content_tag(:td, content)
240
- end
241
-
242
- def table_transversal(attribute, item)
243
- _attribute, virtual = attribute.split(".")
244
- return content_tag(:td, item.send(_attribute).send(virtual))
151
+ def table_transversal_field(attribute, item)
152
+ field_1, field_2 = attribute.split(".")
153
+ item.send(field_1).send(field_2)
245
154
  end
246
155
 
247
156
  end