typus 1.0.0.pre8 → 1.0.0.pre9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/CHANGELOG +4 -6
  2. data/Gemfile +16 -13
  3. data/Gemfile.lock +26 -2
  4. data/Rakefile +2 -3
  5. data/app/controllers/admin/base_controller.rb +3 -5
  6. data/app/controllers/admin/resources_controller.rb +24 -26
  7. data/app/helpers/admin/base_helper.rb +14 -22
  8. data/app/helpers/admin/dashboard_helper.rb +2 -5
  9. data/app/helpers/admin/filters_helper.rb +6 -8
  10. data/app/helpers/admin/form_helper.rb +3 -9
  11. data/app/helpers/admin/preview_helper.rb +4 -6
  12. data/app/helpers/admin/relationships_helper.rb +9 -11
  13. data/app/helpers/admin/resources_helper.rb +6 -24
  14. data/app/helpers/admin/search_helper.rb +1 -1
  15. data/app/helpers/admin/sidebar_helper.rb +12 -15
  16. data/app/helpers/admin/table_helper.rb +13 -13
  17. data/app/views/admin/dashboard/show.html.erb +1 -1
  18. data/app/views/admin/helpers/_apps.html.erb +4 -3
  19. data/app/views/admin/helpers/_header.html.erb +2 -2
  20. data/app/views/admin/helpers/dashboard/_applications.html.erb +3 -3
  21. data/app/views/admin/helpers/dashboard/_resources.html.erb +17 -13
  22. data/app/views/admin/helpers/filters/_filters.html.erb +9 -27
  23. data/app/views/admin/helpers/resources/_pagination.html.erb +8 -9
  24. data/app/views/admin/helpers/search/_search.html.erb +1 -1
  25. data/app/views/admin/mailer/reset_password_link.text.erb +3 -0
  26. data/app/views/admin/resources/_form.html.erb +4 -4
  27. data/app/views/admin/resources/edit.html.erb +2 -3
  28. data/app/views/admin/resources/index.html.erb +15 -13
  29. data/app/views/admin/resources/new.html.erb +2 -2
  30. data/app/views/admin/resources/show.html.erb +1 -2
  31. data/app/views/admin/templates/_boolean.html.erb +1 -1
  32. data/app/views/admin/templates/_has_many.html.erb +2 -4
  33. data/app/views/admin/templates/_has_n.html.erb +1 -1
  34. data/app/views/admin/templates/_selector.html.erb +0 -1
  35. data/app/views/admin/templates/_string.html.erb +1 -1
  36. data/app/views/layouts/admin/session.html.erb +1 -1
  37. data/config/available_locales/ca.yml +3 -5
  38. data/config/available_locales/de.yml +2 -4
  39. data/config/available_locales/es.yml +2 -4
  40. data/config/available_locales/fr.yml +40 -39
  41. data/config/available_locales/fr_models.yml +2 -2
  42. data/config/available_locales/hu.yml +3 -5
  43. data/config/available_locales/it.yml +0 -4
  44. data/config/available_locales/language.yml.template +2 -4
  45. data/config/available_locales/pt-BR.yml +2 -4
  46. data/config/available_locales/ru.yml +2 -4
  47. data/config/routes.rb +1 -0
  48. data/lib/generators/templates/config/initializers/typus.rb +5 -5
  49. data/lib/generators/templates/config/initializers/typus_authentication.rb +5 -5
  50. data/lib/generators/templates/config/initializers/typus_resources.rb +7 -7
  51. data/lib/generators/templates/config/typus/README +11 -13
  52. data/lib/generators/templates/controller.rb +0 -2
  53. data/lib/generators/templates/functional_test.rb +4 -15
  54. data/lib/generators/typus/migration_generator.rb +0 -1
  55. data/lib/support/active_record.rb +18 -9
  56. data/lib/support/fake_user.rb +42 -0
  57. data/lib/support/object.rb +1 -0
  58. data/lib/support/string.rb +0 -32
  59. data/lib/tasks/typus.rake +0 -8
  60. data/lib/typus.rb +34 -18
  61. data/lib/typus/authentication/base.rb +26 -0
  62. data/lib/typus/authentication/http_basic.rb +22 -0
  63. data/lib/typus/authentication/none.rb +19 -0
  64. data/lib/typus/authentication/session.rb +190 -0
  65. data/lib/typus/format.rb +12 -19
  66. data/lib/typus/orm/active_record.rb +13 -51
  67. data/lib/typus/resources.rb +0 -9
  68. data/lib/typus/version.rb +1 -1
  69. data/test/factories.rb +43 -0
  70. data/test/fixtures/rails_app/app/controllers/application_controller.rb +0 -1
  71. data/test/fixtures/rails_app/app/models/page.rb +0 -4
  72. data/test/fixtures/rails_app/config/application.rb +6 -3
  73. data/test/fixtures/rails_app/config/database.yml +12 -20
  74. data/test/fixtures/rails_app/config/typus/application.yml +4 -8
  75. data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
  76. data/test/fixtures/rails_app/log/test.log +227115 -0
  77. data/test/fixtures/rails_app/tmp/export-posts-20101012213057.csv +2 -0
  78. data/test/fixtures/rails_app/tmp/export-posts-20101012213132.csv +2 -0
  79. data/test/fixtures/rails_app/tmp/export-posts-20101012213234.csv +2 -0
  80. data/test/fixtures/rails_app/tmp/export-posts-20101012213506.csv +2 -0
  81. data/test/fixtures/rails_app/tmp/export-posts-20101012215057.csv +2 -0
  82. data/test/fixtures/rails_app/tmp/export-posts-20101012215217.csv +2 -0
  83. data/test/fixtures/rails_app/tmp/export-posts-20101012215415.csv +2 -0
  84. data/test/fixtures/rails_app/tmp/export-posts-20101012215443.csv +2 -0
  85. data/test/fixtures/rails_app/tmp/export-posts-20101012215509.csv +2 -0
  86. data/test/fixtures/rails_app/tmp/export-posts-20101012215528.csv +2 -0
  87. data/test/fixtures/rails_app/tmp/export-posts-20101012215551.csv +2 -0
  88. data/test/fixtures/rails_app/tmp/export-posts-20101012215615.csv +2 -0
  89. data/test/fixtures/rails_app/tmp/export-posts-20101012215640.csv +2 -0
  90. data/test/fixtures/rails_app/tmp/export-posts-20101012215714.csv +2 -0
  91. data/test/fixtures/rails_app/tmp/export-posts-20101012215744.csv +2 -0
  92. data/test/fixtures/rails_app/tmp/export-posts-20101012215814.csv +2 -0
  93. data/test/fixtures/rails_app/tmp/export-posts-20101012215836.csv +2 -0
  94. data/test/fixtures/rails_app/tmp/export-posts-20101012215906.csv +2 -0
  95. data/test/fixtures/rails_app/tmp/export-posts-20101012220659.csv +2 -0
  96. data/test/fixtures/rails_app/tmp/export-posts-20101012221043.csv +2 -0
  97. data/test/fixtures/rails_app/tmp/export-posts-20101012221258.csv +2 -0
  98. data/test/fixtures/rails_app/tmp/export-posts-20101012222558.csv +2 -0
  99. data/test/fixtures/rails_app/tmp/export-posts-20101012222752.csv +2 -0
  100. data/test/fixtures/rails_app/tmp/export-posts-20101012222848.csv +2 -0
  101. data/test/fixtures/rails_app/tmp/export-posts-20101012223433.csv +2 -0
  102. data/test/fixtures/rails_app/tmp/export-posts-20101012223535.csv +2 -0
  103. data/test/fixtures/rails_app/tmp/export-posts-20101012224003.csv +2 -0
  104. data/test/fixtures/rails_app/tmp/export-posts-20101012224052.csv +2 -0
  105. data/test/fixtures/rails_app/tmp/export-posts-20101012224109.csv +2 -0
  106. data/test/fixtures/rails_app/tmp/export-posts-20101012224139.csv +2 -0
  107. data/test/fixtures/rails_app/tmp/export-posts-20101012224205.csv +2 -0
  108. data/test/fixtures/rails_app/tmp/export-posts-20101012224243.csv +2 -0
  109. data/test/fixtures/rails_app/tmp/export-posts-20101012225119.csv +2 -0
  110. data/test/fixtures/rails_app/tmp/export-posts-20101013063215.csv +2 -0
  111. data/test/fixtures/rails_app/tmp/export-posts-20101013063300.csv +2 -0
  112. data/test/fixtures/rails_app/tmp/export-posts-20101013063352.csv +2 -0
  113. data/test/fixtures/rails_app/tmp/export-posts-20101013063427.csv +2 -0
  114. data/test/fixtures/rails_app/tmp/export-posts-20101013063448.csv +2 -0
  115. data/test/fixtures/rails_app/tmp/export-posts-20101013063530.csv +2 -0
  116. data/test/fixtures/rails_app/tmp/export-posts-20101013063559.csv +2 -0
  117. data/test/fixtures/rails_app/tmp/export-posts-20101013063646.csv +2 -0
  118. data/test/fixtures/rails_app/tmp/export-posts-20101013063737.csv +2 -0
  119. data/test/fixtures/rails_app/tmp/export-posts-20101013063822.csv +2 -0
  120. data/test/fixtures/rails_app/tmp/export-posts-20101013063837.csv +2 -0
  121. data/test/fixtures/rails_app/tmp/export-posts-20101013063919.csv +2 -0
  122. data/test/fixtures/rails_app/tmp/export-posts-20101013063939.csv +2 -0
  123. data/test/fixtures/rails_app/tmp/export-posts-20101013063952.csv +2 -0
  124. data/test/fixtures/rails_app/tmp/export-posts-20101013064220.csv +2 -0
  125. data/test/fixtures/rails_app/tmp/export-posts-20101013064253.csv +2 -0
  126. data/test/fixtures/rails_app/tmp/export-posts-20101013064318.csv +2 -0
  127. data/test/fixtures/rails_app/tmp/export-posts-20101013064404.csv +2 -0
  128. data/test/fixtures/rails_app/tmp/export-posts-20101013064452.csv +2 -0
  129. data/test/fixtures/rails_app/tmp/export-posts-20101013064536.csv +2 -0
  130. data/test/fixtures/rails_app/tmp/export-posts-20101013064652.csv +2 -0
  131. data/test/fixtures/rails_app/tmp/export-posts-20101013064845.csv +2 -0
  132. data/test/fixtures/rails_app/tmp/export-posts-20101013065023.csv +2 -0
  133. data/test/fixtures/rails_app/tmp/export-posts-20101013065137.csv +2 -0
  134. data/test/fixtures/rails_app/tmp/export-posts-20101013065713.csv +2 -0
  135. data/test/fixtures/rails_app/tmp/export-posts-20101013065954.csv +2 -0
  136. data/test/fixtures/rails_app/tmp/export-posts-20101013070057.csv +2 -0
  137. data/test/fixtures/rails_app/tmp/export-posts-20101013070116.csv +2 -0
  138. data/test/fixtures/rails_app/tmp/export-posts-20101013070156.csv +2 -0
  139. data/test/fixtures/rails_app/tmp/export-posts-20101013070349.csv +2 -0
  140. data/test/fixtures/rails_app/tmp/export-posts-20101013070429.csv +2 -0
  141. data/test/fixtures/rails_app/tmp/export-posts-20101013070448.csv +2 -0
  142. data/test/fixtures/rails_app/tmp/export-posts-20101013070514.csv +2 -0
  143. data/test/fixtures/rails_app/tmp/export-posts-20101013070709.csv +2 -0
  144. data/test/fixtures/rails_app/tmp/export-posts-20101013070745.csv +2 -0
  145. data/test/fixtures/rails_app/tmp/export-posts-20101013070809.csv +2 -0
  146. data/test/fixtures/rails_app/tmp/export-posts-20101013070905.csv +2 -0
  147. data/test/fixtures/rails_app/tmp/export-posts-20101013070955.csv +2 -0
  148. data/test/fixtures/rails_app/tmp/export-posts-20101013071116.csv +2 -0
  149. data/test/fixtures/rails_app/tmp/export-posts-20101013071209.csv +2 -0
  150. data/test/fixtures/rails_app/tmp/export-posts-20101013071335.csv +2 -0
  151. data/test/fixtures/rails_app/tmp/export-posts-20101013071632.csv +2 -0
  152. data/test/fixtures/rails_app/tmp/export-posts-20101013071643.csv +2 -0
  153. data/test/fixtures/rails_app/tmp/export-posts-20101013071735.csv +2 -0
  154. data/test/fixtures/rails_app/tmp/export-posts-20101013071749.csv +2 -0
  155. data/test/fixtures/rails_app/tmp/export-posts-20101013072030.csv +2 -0
  156. data/test/fixtures/rails_app/tmp/export-posts-20101013072050.csv +2 -0
  157. data/test/fixtures/rails_app/tmp/export-posts-20101013072108.csv +2 -0
  158. data/test/fixtures/rails_app/tmp/export-posts-20101013072713.csv +2 -0
  159. data/test/fixtures/rails_app/tmp/export-posts-20101013072751.csv +2 -0
  160. data/test/fixtures/rails_app/tmp/export-posts-20101013072912.csv +2 -0
  161. data/test/fixtures/rails_app/tmp/export-posts-20101013074546.csv +2 -0
  162. data/test/fixtures/rails_app/tmp/export-posts-20101018180512.csv +2 -0
  163. data/test/fixtures/rails_app/tmp/export-posts-20101018183359.csv +2 -0
  164. data/test/fixtures/rails_app/tmp/export-posts-20101018183608.csv +2 -0
  165. data/test/fixtures/rails_app/tmp/export-posts-20101018183759.csv +2 -0
  166. data/test/functional/admin/account_controller_test.rb +1 -1
  167. data/test/functional/admin/{resources_controller_assets_relationships.rb → assets_controller_test.rb} +12 -16
  168. data/test/functional/admin/categories_controller_test.rb +62 -0
  169. data/test/functional/admin/{resources_controller_comments_toggle_test.rb → comments_controller_test.rb} +0 -0
  170. data/test/functional/admin/dashboard_controller_test.rb +34 -2
  171. data/test/functional/admin/posts_controller_test.rb +548 -0
  172. data/test/functional/admin/session_controller_test.rb +2 -2
  173. data/test/functional/admin/{resources_controller_tableless_resource_test.rb → status_controller_test.rb} +0 -0
  174. data/test/functional/admin/{resources_controller_typus_users_test.rb → typus_users_controller_test.rb} +2 -2
  175. data/test/helpers/admin/base_helper_test.rb +35 -37
  176. data/test/helpers/admin/dashboard_helper_test.rb +4 -8
  177. data/test/helpers/admin/form_helper_test.rb +9 -34
  178. data/test/helpers/admin/resources_helper_test.rb +28 -16
  179. data/test/helpers/admin/sidebar_helper_test.rb +14 -27
  180. data/test/helpers/admin/table_helper_test.rb +24 -68
  181. data/test/integration/login_test.rb +13 -0
  182. data/test/integration_test_helper.rb +21 -0
  183. data/test/lib/support/active_record_test.rb +72 -21
  184. data/test/lib/support/array_test.rb +2 -6
  185. data/test/lib/support/string_test.rb +21 -30
  186. data/test/lib/typus/active_record_test.rb +162 -100
  187. data/test/lib/typus/resource_test.rb +2 -3
  188. data/test/lib/typus_test.rb +25 -22
  189. data/test/test_helper.rb +4 -17
  190. data/test/unit/admin/mailer_test.rb +2 -2
  191. data/test/unit/typus_user_roles_test.rb +23 -23
  192. data/test/unit/typus_user_test.rb +30 -24
  193. data/typus.gemspec +0 -1
  194. metadata +111 -60
  195. data/app/models/admin/fake_user.rb +0 -46
  196. data/lib/generators/templates/model.yml +0 -10
  197. data/lib/typus/authentication.rb +0 -241
  198. data/lib/vendor/paginator.rb +0 -143
  199. data/test/factories/assets.rb +0 -5
  200. data/test/factories/categories.rb +0 -3
  201. data/test/factories/comments.rb +0 -6
  202. data/test/factories/pages.rb +0 -5
  203. data/test/factories/pictures.rb +0 -7
  204. data/test/factories/posts.rb +0 -6
  205. data/test/factories/typus_users.rb +0 -8
  206. data/test/fixtures/rails_app/README +0 -244
  207. data/test/fixtures/rails_app/app/helpers/application_helper.rb +0 -2
  208. data/test/fixtures/rails_app/app/views/layouts/application.html.erb +0 -14
  209. data/test/fixtures/rails_app/config/environments/development.rb +0 -19
  210. data/test/fixtures/rails_app/config/environments/production.rb +0 -42
  211. data/test/fixtures/rails_app/config/initializers/acts_as_list.rb +0 -258
  212. data/test/fixtures/rails_app/config/initializers/acts_as_tree.rb +0 -98
  213. data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  214. data/test/fixtures/rails_app/config/initializers/inflections.rb +0 -10
  215. data/test/fixtures/rails_app/config/initializers/mime_types.rb +0 -5
  216. data/test/fixtures/rails_app/config/locales/en.yml +0 -5
  217. data/test/fixtures/rails_app/db/seeds.rb +0 -7
  218. data/test/fixtures/rails_app/public/404.html +0 -26
  219. data/test/fixtures/rails_app/public/422.html +0 -26
  220. data/test/fixtures/rails_app/public/500.html +0 -26
  221. data/test/fixtures/rails_app/public/favicon.ico +0 -0
  222. data/test/fixtures/rails_app/public/images/rails.png +0 -0
  223. data/test/fixtures/rails_app/public/index.html +0 -279
  224. data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
  225. data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
  226. data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
  227. data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
  228. data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -4874
  229. data/test/fixtures/rails_app/public/javascripts/rails.js +0 -118
  230. data/test/fixtures/rails_app/public/robots.txt +0 -5
  231. data/test/fixtures/rails_app/script/rails +0 -9
  232. data/test/functional/admin/dashboard_controller_http_basic_test.rb +0 -24
  233. data/test/functional/admin/dashboard_controller_none_test.rb +0 -18
  234. data/test/functional/admin/resources_controller_categories_before_test.rb +0 -10
  235. data/test/functional/admin/resources_controller_categories_lists_test.rb +0 -44
  236. data/test/functional/admin/resources_controller_categories_views_test.rb +0 -10
  237. data/test/functional/admin/resources_controller_posts_before_test.rb +0 -10
  238. data/test/functional/admin/resources_controller_posts_crud_custom_test.rb +0 -27
  239. data/test/functional/admin/resources_controller_posts_crud_test.rb +0 -44
  240. data/test/functional/admin/resources_controller_posts_formats_test.rb +0 -39
  241. data/test/functional/admin/resources_controller_posts_forms_test.rb +0 -58
  242. data/test/functional/admin/resources_controller_posts_permissions_test.rb +0 -100
  243. data/test/functional/admin/resources_controller_posts_relationships_test.rb +0 -91
  244. data/test/functional/admin/resources_controller_posts_roles.rb +0 -52
  245. data/test/functional/admin/resources_controller_posts_views_test.rb +0 -143
  246. data/test/lib/vendor/paginator_test.rb +0 -141
  247. data/typus-1.0.0.pre7.gem +0 -0
@@ -38,11 +38,9 @@ module Admin
38
38
 
39
39
  setup_relationship(field)
40
40
 
41
- if @model_to_relate.count < @model_to_relate.typus_options_for(:habtm_limit)
42
- @items_to_relate = (@model_to_relate.all - @item.send(field))
43
- if set_condition && !@items_to_relate.empty?
44
- form = build_relate_form
45
- end
41
+ @items_to_relate = (@model_to_relate.all - @item.send(field))
42
+ if set_condition && !@items_to_relate.empty?
43
+ form = build_relate_form
46
44
  end
47
45
 
48
46
  build_pagination
@@ -89,22 +87,22 @@ module Admin
89
87
  :resource => @resource.name, :resource_id => @item.id,
90
88
  :back_to => @back_to }
91
89
 
92
- return unless set_condition && @current_user.can?("create", @model_to_relate)
90
+ return unless set_condition && current_user.can?("create", @model_to_relate)
93
91
 
94
92
  link_to _t("Add new"), default_options.merge(options)
95
93
  end
96
94
 
97
95
  def set_condition
98
- if @resource.typus_user_id? && @current_user.is_not_root?
99
- @item.owned_by?(@current_user)
96
+ if @resource.typus_user_id? && current_user.is_not_root?
97
+ @item.owned_by?(current_user)
100
98
  else
101
99
  true
102
100
  end
103
101
  end
104
102
 
105
103
  def set_conditions
106
- if @model_to_relate.typus_options_for(:only_user_items) && @current_user.is_not_root?
107
- { Typus.user_fk => @current_user }
104
+ if @model_to_relate.typus_options_for(:only_user_items) && current_user.is_not_root?
105
+ { Typus.user_fk => current_user }
108
106
  end
109
107
  end
110
108
 
@@ -172,7 +170,7 @@ module Admin
172
170
  :action => 'new',
173
171
  :back_to => back_to,
174
172
  :selected => related_fk },
175
- :confirm => confirm.join("\n\n") if @current_user.can?('create', related)
173
+ :confirm => confirm.join("\n\n") if current_user.can?('create', related)
176
174
 
177
175
  render "admin/templates/belongs_to",
178
176
  :resource => @resource,
@@ -11,18 +11,14 @@ module Admin
11
11
  include TableHelper
12
12
 
13
13
  #--
14
- # If there's a partial with a "microformat" of the data we want to
15
- # display, this will be used, otherwise we use a default table which
16
- # it's build from the options defined on the yaml configuration file.
14
+ # If partial `list` exists we will use it. This partial will have available
15
+ # the `@items` so we can do whatever we want there. Notice that pagination
16
+ # is still available.
17
17
  #++
18
18
  def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil)
19
- template = "app/views/admin/#{resource}/_#{resource.singularize}.html.erb"
20
-
21
- if File.exist?(template)
22
- render :partial => template.gsub('/_', '/'), :collection => items, :as => :item
23
- else
24
- build_table(model, fields, items, link_options, association)
25
- end
19
+ render "admin/#{resource}/list", :items => items
20
+ rescue ActionView::MissingTemplate
21
+ build_table(model, fields, items, link_options, association)
26
22
  end
27
23
 
28
24
  def display_link_to_previous
@@ -55,20 +51,6 @@ module Admin
55
51
  render File.join(path, "pagination") if @items.prev || @items.next
56
52
  end
57
53
 
58
- =begin
59
-
60
- # TODO: This method should show a list of actions for the actual record.
61
- def custom_actions(klass)
62
- options = { :controller => klass.to_resource }
63
- items = klass.typus_actions_on("index").map do |action|
64
- if @current_user.can?(action, klass)
65
- (link_to _t(action.humanize), options.merge(:action => action))
66
- end
67
- end
68
- end
69
-
70
- =end
71
-
72
54
  private
73
55
 
74
56
  def path
@@ -8,7 +8,7 @@ module Admin
8
8
 
9
9
  search_by = typus_search.collect { |x| resource.human_attribute_name(x) }.to_sentence
10
10
  search_params = params.dup
11
- %w(action controller id search page).each { |p| search_params.delete(p) }
11
+ %w(action controller id search page utf8).each { |p| search_params.delete(p) }
12
12
  hidden_params = search_params.map { |k, v| hidden_field_tag(k, v) }
13
13
 
14
14
  render "admin/helpers/search/search", :hidden_params => hidden_params, :search_by => search_by
@@ -7,9 +7,13 @@ module Admin
7
7
  app_name = @resource.typus_application
8
8
 
9
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)
10
+ next unless current_user.resources.include?(resource)
11
11
  klass = resource.constantize
12
- resources[resource] = default_actions(klass) + export(klass) + custom_actions(klass)
12
+
13
+ resources[resource] = default_actions(klass)
14
+ resources[resource] += export(klass) if params[:action] == 'index'
15
+ resources[resource] += custom_actions(klass)
16
+
13
17
  resources[resource].compact!
14
18
  end
15
19
 
@@ -19,32 +23,25 @@ module Admin
19
23
  def default_actions(klass)
20
24
  actions = []
21
25
 
22
- if @current_user.can?("create", klass)
23
- options = { :controller => klass.to_resource }
24
- message = _t("Add new")
25
- actions << (link_to_unless_current message, options.merge(:action => "new"))
26
+ if current_user.can?("create", klass)
27
+ actions << link_to_unless_current(_t("Add new"), :action => "new")
26
28
  end
27
29
 
28
- message = _t("List")
29
- options = { :controller => klass.to_resource }
30
- actions << (link_to_unless_current message, options)
30
+ actions << link_to_unless_current(_t("List"), :action => "index")
31
31
 
32
32
  return actions
33
33
  end
34
34
 
35
35
  def export(klass)
36
- return [] unless params[:action] == "index"
37
-
38
36
  klass.typus_export_formats.map do |format|
39
37
  link_to _t("Export as %{format}", :format => format.upcase), params.merge(:format => format)
40
38
  end
41
39
  end
42
40
 
43
41
  def custom_actions(klass)
44
- options = { :controller => klass.to_resource }
45
- klass.typus_actions_on("index").map do |action|
46
- if @current_user.can?(action, klass)
47
- (link_to_unless_current _t(action.humanize), options.merge(:action => action))
42
+ 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))
48
45
  end
49
46
  end
50
47
  end
@@ -63,10 +63,10 @@ module Admin
63
63
  end
64
64
 
65
65
  def table_default_action(model, item)
66
- action = if model.typus_user_id? && @current_user.is_not_root?
66
+ action = if model.typus_user_id? && current_user.is_not_root?
67
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)
68
+ item.owned_by?(current_user) ? item.class.typus_options_for(:default_action_on_item) : "show"
69
+ elsif current_user.cannot?("edit", model)
70
70
  'show'
71
71
  else
72
72
  item.class.typus_options_for(:default_action_on_item)
@@ -104,12 +104,12 @@ module Admin
104
104
 
105
105
  case params[:action]
106
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))
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
110
  false
111
111
  else
112
- @current_user.can?('destroy', model)
112
+ current_user.can?('destroy', model)
113
113
  end
114
114
  confirm = _t("Remove %{resource}?", :resource => item.class.model_name.human)
115
115
  when 'edit'
@@ -122,8 +122,8 @@ module Admin
122
122
  # the owners of the owner record.
123
123
  # If the owner record doesn't have a foreign key (Typus.user_fk) we look
124
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)
125
+ condition = if @resource.typus_user_id? && current_user.is_not_root?
126
+ @item.owned_by?(current_user)
127
127
  end
128
128
  confirm = _t("Unrelate %{unrelate_model} from %{unrelate_model_from}?",
129
129
  :unrelate_model => model.model_name.human,
@@ -145,7 +145,7 @@ module Admin
145
145
  unless att_value.nil?
146
146
  content = att_value.to_label
147
147
  action = item.send(attribute).class.typus_options_for(:default_action_on_item)
148
- if @current_user.can?(action, att_value.class.name)
148
+ if current_user.can?(action, att_value.class.name)
149
149
  content = link_to content, :controller => "admin/#{att_value.class.to_resource}", :action => action, :id => att_value.id
150
150
  end
151
151
  end
@@ -180,7 +180,7 @@ module Admin
180
180
  render "admin/helpers/preview",
181
181
  :attribute => attribute,
182
182
  :attachment => attribute,
183
- :content => item.send(attribute),
183
+ :content => item.to_label,
184
184
  :file_preview_is_image => file_preview_is_image,
185
185
  :has_file_preview => has_file_preview,
186
186
  :href => item.send(attribute).url(file_preview),
@@ -220,13 +220,13 @@ module Admin
220
220
  end
221
221
 
222
222
  def table_boolean_field(attribute, item)
223
- boolean_hash = item.class.typus_boolean(attribute)
223
+ boolean_hash = item.class.typus_boolean(attribute).invert
224
224
  status = item.send(attribute)
225
225
 
226
226
  content = if status.nil?
227
227
  Typus::Resources.human_nil
228
228
  else
229
- message = _t(boolean_hash["#{status}".to_sym])
229
+ message = _t(boolean_hash[status.to_s])
230
230
  options = { :controller => "admin/#{item.class.to_resource}",
231
231
  :action => "toggle",
232
232
  :id => item.id,
@@ -13,4 +13,4 @@
13
13
 
14
14
  <%= applications %>
15
15
 
16
- <%= resources %>
16
+ <%= resources(current_user) %>
@@ -1,7 +1,8 @@
1
1
  <ul>
2
- <li><%= link_to _t("Dashboard"), admin_dashboard_path %></li>
3
- <% @current_user.applications.each do |app| %>
4
- <% klass = Typus.application(app).include?(@resource.name) ? 'active' : nil %>
2
+ <% dashboard = 'active' if params[:controller].include?('dashboard') %>
3
+ <li><%= link_to _t("Dashboard"), admin_dashboard_path, :class => dashboard %></li>
4
+ <% current_user.applications.each do |app| %>
5
+ <% klass = (@resource && Typus.application(app).include?(@resource.name)) ? 'active' : nil %>
5
6
  <li><%= link_to _t(app), { :controller => Typus.application(app).sort {|a,b| a.constantize.model_name.human <=> b.constantize.model_name.human}.first.tableize }, { :class => klass } %></li>
6
7
  <% end %>
7
8
  </ul>
@@ -1,7 +1,7 @@
1
1
  <h1 class="logo">
2
- <% if Rails.application.routes.routes.map(&:name).include?(:root) %>
2
+ <% begin %>
3
3
  <%= link_to Typus.admin_title, root_path, :title => _t("View site") %>
4
- <% else %>
4
+ <% rescue %>
5
5
  <%= Typus.admin_title %>
6
6
  <% end %>
7
7
  </h1>
@@ -1,4 +1,4 @@
1
- <% @current_user.applications.each do |app| %>
1
+ <% current_user.applications.each do |app| %>
2
2
 
3
3
  <table>
4
4
 
@@ -8,7 +8,7 @@
8
8
  </tr>
9
9
  </thead>
10
10
 
11
- <% @current_user.application(app).each do |model| %>
11
+ <% current_user.application(app).each do |model| %>
12
12
 
13
13
  <%
14
14
  klass = model.constantize
@@ -21,7 +21,7 @@
21
21
  <%= link_to klass_human_name, admin_items_path %>
22
22
  </td>
23
23
  <td class="right">
24
- <%= link_to_if @current_user.can?("create", klass), _t("Add"), admin_items_path.merge(:action => "new") %>
24
+ <%= link_to_if current_user.can?("create", klass), _t("Add"), admin_items_path.merge(:action => "new") %>
25
25
  </td>
26
26
  </tr>
27
27
 
@@ -1,16 +1,20 @@
1
- <table>
1
+ <% if resources.any? %>
2
2
 
3
- <thead>
4
- <tr>
5
- <th colspan="2"><%= _t("Resources") %></th>
6
- </tr>
7
- </thead>
3
+ <table>
8
4
 
9
- <% resources.each do |resource| %>
10
- <tr class="<%= cycle("even", "odd") %>">
11
- <td><%= link_to _t(resource.titleize.capitalize), :controller => "admin/#{resource.underscore}" %></td>
12
- <td align="right" style="vertical-align: bottom;"></td>
13
- </tr>
14
- <% end %>
5
+ <thead>
6
+ <tr>
7
+ <th colspan="2"><%= _t("Resources") %></th>
8
+ </tr>
9
+ </thead>
15
10
 
16
- </table>
11
+ <% resources.each do |resource| %>
12
+ <tr class="<%= cycle("even", "odd") %>">
13
+ <td><%= link_to _t(resource.titleize.capitalize), :controller => "admin/#{resource.underscore}" %></td>
14
+ <td align="right" style="vertical-align: bottom;"></td>
15
+ </tr>
16
+ <% end %>
17
+
18
+ </table>
19
+
20
+ <% end %>
@@ -1,31 +1,13 @@
1
- <div id="filters">
2
-
3
- <ul>
4
-
5
- <%= form_tag nil, :method => :get do %>
1
+ <%= form_tag nil, :method => :get do %>
6
2
 
3
+ <div id="filters">
4
+ <ul>
7
5
  <% filters.each do |filter| %>
8
-
9
- <li>
10
- <select name="<%= filter[:filter] %>">
11
- <option value=""><%= filter[:message] %></option>
12
- <% filter[:items].each do |key, value| %>
13
- <% selected = "selected" if params[filter[:filter]].eql?(key.to_s) %>
14
- <option <%= selected %> value="<%= key %>"><%= value %></option>
15
- <% end %>
16
- </select>
17
- </li>
18
-
6
+ <li><%= select_tag filter[:filter], options_for_select(filter[:items], params[filter[:filter]]) %></li>
19
7
  <% end %>
8
+ <%= hidden_field_tag :search, params[:search] if params[:search] %>
9
+ <li><%= submit_tag _t("Filter"), :name => nil %></li>
10
+ </ul>
11
+ </div>
20
12
 
21
- <%= hidden_field_tag :search, params[:search] %>
22
-
23
- <li>
24
- <%= submit_tag _t("Filter"), :name => nil %>
25
- </li>
26
-
27
- <% end %>
28
-
29
- </ul>
30
-
31
- </div>
13
+ <% end %>
@@ -1,26 +1,25 @@
1
1
  <div id="pagination">
2
2
 
3
- <%
4
- previous_text = "&larr; " + _t("Previous")
5
- next_text = _t("Next") + " &rarr;"
6
- %>
7
-
8
3
  <div class="left">
9
4
 
5
+ <% previous_text = ("&larr; " + _t("Previous")).html_safe %>
6
+
10
7
  <% if @items.prev? %>
11
- <%= link_to raw(previous_text), params.merge(:page => @items.prev.number, :anchor => @options[:anchor]) %>
8
+ <%= link_to previous_text, params.merge(:page => @items.prev.number, :anchor => @options[:anchor]) %>
12
9
  <% else %>
13
- <span class="disabled"><%= raw(previous_text) %></span>
10
+ <span class="disabled"><%= previous_text %></span>
14
11
  <% end %>
15
12
 
16
13
  </div>
17
14
 
18
15
  <div class="right">
19
16
 
17
+ <% next_text = (_t("Next") + " &rarr;").html_safe %>
18
+
20
19
  <% if @items.next? %>
21
- <%= link_to raw(next_text), params.merge(:page => @items.next.number, :anchor => @options[:anchor]) %>
20
+ <%= link_to next_text, params.merge(:page => @items.next.number, :anchor => @options[:anchor]) %>
22
21
  <% else %>
23
- <span class="disabled"><%= raw(next_text) %></span>
22
+ <span class="disabled"><%= next_text %></span>
24
23
  <% end %>
25
24
 
26
25
  </div>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <%= form_tag url_for(:controller => params[:controller]), :method => :get do %>
4
4
  <ul>
5
- <li><input id="quicksearch" name="search" type="text" title="<%= params[:search] || _t("Search") %>"/></li>
5
+ <li><%= search_field_tag "search", nil, :id => "quicksearch", :title => (params[:search] || _t("Search")) %></li>
6
6
  </ul>
7
7
  <% hidden_params.each do |field| %>
8
8
  <%= field %>
@@ -4,3 +4,6 @@
4
4
  <%= @url %>
5
5
 
6
6
  <%= _t("If you didn't request a password update, you can ignore this message") %>
7
+
8
+ --
9
+ <%= Typus.admin_title %>
@@ -1,11 +1,11 @@
1
- <%= form_for @item, :url => options, :html => { :multipart => true } do |form| %>
1
+ <%= form_for @item, :url => options[:options], :html => { :multipart => true } do |form| %>
2
2
 
3
3
  <% if @item.errors.any? %>
4
4
  <div id="errorExplanation">
5
5
  <h3><%= pluralize(@item.errors.count, "error") %> prohibited this page from being saved:</h3>
6
6
  <ul>
7
- <% @item.errors.full_messages.each do |msg| %>
8
- <li><%= msg %></li>
7
+ <% @item.errors.full_messages.each do |full_message| %>
8
+ <li><%= full_message %></li>
9
9
  <% end %>
10
10
  </ul>
11
11
  </div>
@@ -19,7 +19,7 @@
19
19
 
20
20
  <fieldset class="buttons">
21
21
  <ol>
22
- <li><%= submit_tag button , :class => "commit" %> or <%= link_to _t("Cancel and go back").downcase, :action => "index" %></li>
22
+ <li><%= submit_tag options[:button] , :class => "commit" %> or <%= link_to _t("Cancel and go back").downcase, :action => "index" %></li>
23
23
  </ol>
24
24
  </fieldset>
25
25