typus 3.1.0.rc18 → 3.1.0.rc19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +14 -11
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG +253 -0
  4. data/Gemfile +69 -0
  5. data/Guardfile +11 -0
  6. data/README.md +14 -26
  7. data/Rakefile +24 -100
  8. data/app/assets/javascripts/typus/application.js +8 -2
  9. data/app/assets/javascripts/typus/custom.js +2 -0
  10. data/app/assets/javascripts/typus/jquery.application.js +14 -0
  11. data/app/assets/stylesheets/typus/application.css +18 -10
  12. data/app/assets/stylesheets/typus/content.css +0 -1
  13. data/app/assets/stylesheets/typus/custom.css +11 -0
  14. data/app/assets/stylesheets/typus/errors.css +1 -1
  15. data/app/assets/stylesheets/typus/forms.css +17 -5
  16. data/app/assets/stylesheets/typus/hacks.css +4 -0
  17. data/app/assets/stylesheets/typus/header.css +8 -2
  18. data/app/assets/stylesheets/typus/pagination.css +3 -3
  19. data/app/assets/stylesheets/typus/sidebar.css +4 -0
  20. data/app/assets/stylesheets/typus/tables.css +0 -1
  21. data/app/controllers/admin/account_controller.rb +1 -2
  22. data/app/controllers/admin/base_controller.rb +5 -2
  23. data/app/controllers/admin/dashboard_controller.rb +5 -0
  24. data/app/controllers/admin/resource_controller.rb +1 -2
  25. data/app/controllers/admin/resources_controller.rb +36 -51
  26. data/app/controllers/admin/session_controller.rb +2 -3
  27. data/app/helpers/admin/base_helper.rb +2 -5
  28. data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +35 -27
  29. data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +16 -3
  30. data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +45 -13
  31. data/app/helpers/admin/resources/data_types/has_many_helper.rb +27 -19
  32. data/app/helpers/admin/resources/data_types/has_one_helper.rb +24 -11
  33. data/app/helpers/admin/resources/data_types/paperclip_helper.rb +1 -1
  34. data/app/helpers/admin/resources/data_types/string_helper.rb +1 -1
  35. data/app/helpers/admin/resources/data_types/text_helper.rb +1 -1
  36. data/app/helpers/admin/resources/data_types/transversal_helper.rb +1 -1
  37. data/app/helpers/admin/resources/data_types/tree_helper.rb +1 -1
  38. data/app/helpers/admin/resources/display_helper.rb +10 -9
  39. data/app/helpers/admin/resources/filters_helper.rb +3 -10
  40. data/app/helpers/admin/resources/form_helper.rb +12 -2
  41. data/app/helpers/admin/resources/list_helper.rb +13 -5
  42. data/app/helpers/admin/resources/relationships_helper.rb +0 -21
  43. data/app/helpers/admin/resources_helper.rb +3 -3
  44. data/app/mailers/admin/mailer.rb +9 -4
  45. data/app/views/admin/base/user_guide.html.erb +1 -1
  46. data/app/views/admin/dashboard/{show.html.erb → index.html.erb} +0 -0
  47. data/app/views/admin/dashboard/widgets/_applications.html.erb +32 -10
  48. data/app/views/admin/mailer/reset_password_instructions.html.erb +9 -0
  49. data/app/views/admin/mailer/reset_password_instructions.text.erb +9 -0
  50. data/app/views/admin/resources/edit.html.erb +3 -13
  51. data/app/views/admin/resources/index.html.erb +11 -4
  52. data/app/views/admin/resources/new.html.erb +2 -2
  53. data/app/views/admin/resources/show.html.erb +1 -1
  54. data/app/views/admin/shared/_head.html.erb +2 -2
  55. data/app/views/admin/templates/_belongs_to.html.erb +6 -9
  56. data/app/views/admin/templates/_dragonfly.html.erb +1 -1
  57. data/app/views/admin/templates/_dragonfly_form_preview.html.erb +21 -0
  58. data/app/views/admin/templates/_dragonfly_preview.html.erb +1 -1
  59. data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +15 -0
  60. data/app/views/admin/templates/{_has_n.html.erb → _has_many.html.erb} +0 -0
  61. data/app/views/admin/templates/_password.html.erb +1 -1
  62. data/app/views/admin/templates/_selector.html.erb +1 -11
  63. data/app/views/admin/templates/_string.html.erb +2 -20
  64. data/app/views/admin/templates/_string_with_preview.html.erb +2 -3
  65. data/app/views/admin/templates/_text.html.erb +1 -8
  66. data/app/views/admin/templates/_text_with_ckeditor.html.erb +1 -1
  67. data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +12 -9
  68. data/app/views/helpers/admin/base/_apps.html.erb +12 -4
  69. data/app/views/helpers/admin/base/_login_info.html.erb +1 -1
  70. data/app/views/helpers/admin/resources/_filters.html.erb +2 -1
  71. data/app/views/helpers/admin/resources/_sidebar.html.erb +25 -41
  72. data/app/views/layouts/admin/base.html.erb +1 -1
  73. data/config/locales/typus.ca.yml +1 -1
  74. data/config/locales/typus.de.yml +40 -35
  75. data/config/locales/typus.el.yml +1 -1
  76. data/config/locales/typus.es.yml +1 -1
  77. data/config/locales/typus.fr.yml +1 -1
  78. data/config/locales/typus.hu.yml +1 -1
  79. data/config/locales/typus.it.yml +1 -1
  80. data/config/locales/typus.locale.models.yml.template +17 -0
  81. data/config/locales/typus.locale.yml.template +80 -0
  82. data/config/locales/typus.pt-BR.yml +1 -1
  83. data/config/locales/typus.pt-PT.yml +2 -2
  84. data/config/locales/typus.ru.yml +1 -1
  85. data/config/locales/typus.zh-CN.yml +1 -1
  86. data/config/routes.rb +5 -1
  87. data/lib/generators/templates/config/initializers/typus.rb +9 -0
  88. data/lib/generators/templates/config/typus/README +0 -6
  89. data/lib/support/active_record.rb +2 -10
  90. data/lib/support/string.rb +6 -1
  91. data/lib/typus.rb +49 -10
  92. data/lib/typus/authentication/base.rb +0 -4
  93. data/lib/typus/authentication/none_with_role.rb +15 -0
  94. data/lib/typus/configuration.rb +3 -7
  95. data/lib/typus/controller/ancestry.rb +1 -1
  96. data/lib/typus/controller/bulk.rb +6 -2
  97. data/lib/typus/controller/format.rb +38 -25
  98. data/lib/typus/orm/active_record/class_methods.rb +0 -1
  99. data/lib/typus/orm/active_record/search.rb +6 -2
  100. data/lib/typus/orm/base.rb +4 -3
  101. data/lib/typus/orm/mongoid.rb +4 -0
  102. data/lib/typus/orm/{mongo → mongoid}/class_methods.rb +4 -3
  103. data/lib/typus/resources.rb +9 -0
  104. data/lib/typus/version.rb +1 -1
  105. data/typus.gemspec +13 -13
  106. data/vendor/assets/chosen/chosen-sprite.png +0 -0
  107. data/vendor/assets/chosen/chosen.css +334 -0
  108. data/vendor/assets/chosen/chosen.jquery.min.js +10 -0
  109. data/vendor/assets/fancybox/jquery.fancybox-1.3.4.css +17 -17
  110. metadata +57 -131
  111. data/.gitmodules +0 -6
  112. data/app/assets/javascripts/typus.js +0 -8
  113. data/app/assets/stylesheets/typus.css +0 -20
  114. data/app/assets/stylesheets/typus/actions.css +0 -11
  115. data/app/views/admin/mailer/reset_password_link.text.erb +0 -9
  116. data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +0 -26
  117. data/lib/typus/controller/associations.rb +0 -146
  118. data/lib/typus/controller/autocomplete.rb +0 -16
  119. data/vendor/assets/fancybox/jquery.easing-1.3.pack.js +0 -72
  120. data/vendor/assets/fancybox/jquery.fancybox-1.3.4.js +0 -1156
  121. data/vendor/assets/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -14
  122. data/vendor/assets/formalize/css/_formalize.sass +0 -332
  123. data/vendor/assets/formalize/css/demo.css +0 -47
  124. data/vendor/assets/formalize/css/reset.css +0 -202
  125. data/vendor/assets/formalize/css/text.css +0 -81
  126. data/vendor/assets/formalize/js/dojo.formalize.js +0 -166
  127. data/vendor/assets/formalize/js/dojo.formalize.min.js +0 -1
  128. data/vendor/assets/formalize/js/extjs.formalize.js +0 -163
  129. data/vendor/assets/formalize/js/extjs.formalize.min.js +0 -1
  130. data/vendor/assets/formalize/js/jquery.formalize.js +0 -150
  131. data/vendor/assets/formalize/js/mootools.formalize.js +0 -155
  132. data/vendor/assets/formalize/js/mootools.formalize.min.js +0 -1
  133. data/vendor/assets/formalize/js/prototype.formalize.js +0 -163
  134. data/vendor/assets/formalize/js/prototype.formalize.min.js +0 -1
  135. data/vendor/assets/formalize/js/yui.formalize.js +0 -152
  136. data/vendor/assets/formalize/js/yui.formalize.min.js +0 -1
  137. data/vendor/assets/jquery-tokeninput/jquery.tokeninput.js +0 -736
  138. data/vendor/assets/jquery-tokeninput/token-input.css +0 -120
@@ -10,11 +10,8 @@ module Admin::BaseHelper
10
10
  end
11
11
 
12
12
  def admin_title
13
- if defined?(Admin::Setting)
14
- Admin::Setting.admin_title || Typus.admin_title
15
- else
16
- Typus.admin_title
17
- end
13
+ setting = defined?(Admin::Setting) && Admin::Setting.admin_title
14
+ setting || Typus.admin_title
18
15
  end
19
16
 
20
17
  def has_root_path?
@@ -10,31 +10,21 @@ module Admin::Resources::DataTypes::BelongsToHelper
10
10
  end
11
11
  related_fk = association.foreign_key
12
12
 
13
- # TODO: Use the build_add_new method.
14
- if admin_user.can?('create', related)
15
- options = { :controller => "/admin/#{related.to_resource}",
16
- :action => 'new',
17
- :resource => @resource.model_name,
18
- :layout => 'admin/headless' }
19
- # Pass the resource_id only to edit/update because only there is where
20
- # the record actually exists.
21
- options.merge!(:resource_id => @item.id) if %w(edit update).include?(params[:action])
22
- message = link_to Typus::I18n.t("Add New"), options, { :class => 'iframe' }
23
- end
24
-
25
- # By default the used template is ALWAYS `belongs_to` unless we have the
26
- # `Typus.autocomplete` feature enabled.
27
- template = Typus.autocomplete ? "belongs_to_with_autocomplete" : "belongs_to"
13
+ html_options = { :disabled => attribute_disabled?(attribute) }
14
+ label_text = @resource.human_attribute_name(attribute)
28
15
 
29
- # If `Typus.autocomplete` is enabled we don't set the values as will be
30
- # autocompleted.
31
- if related.respond_to?(:roots)
32
- values = expand_tree_into_select_field(related.roots, related_fk)
33
- elsif !Typus.autocomplete
34
- values = related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
16
+ label_text = @resource.human_attribute_name(attribute)
17
+ if (text = build_label_text_for_belongs_to(related, html_options))
18
+ label_text += "<small>#{text}</small>"
35
19
  end
36
20
 
37
- render "admin/templates/#{template}",
21
+ values = if related.respond_to?(:roots)
22
+ expand_tree_into_select_field(related.roots, related_fk)
23
+ else
24
+ related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
25
+ end
26
+
27
+ render "admin/templates/belongs_to",
38
28
  :association => association,
39
29
  :resource => @resource,
40
30
  :attribute => attribute,
@@ -42,10 +32,9 @@ module Admin::Resources::DataTypes::BelongsToHelper
42
32
  :form => form,
43
33
  :related_fk => related_fk,
44
34
  :related => related,
45
- :message => message,
46
- :label_text => @resource.human_attribute_name(attribute),
35
+ :label_text => label_text.html_safe,
47
36
  :values => values,
48
- :html_options => { :disabled => attribute_disabled?(attribute) },
37
+ :html_options => html_options,
49
38
  :options => { :include_blank => true }
50
39
  end
51
40
 
@@ -58,13 +47,13 @@ module Admin::Resources::DataTypes::BelongsToHelper
58
47
  end
59
48
  end
60
49
 
61
- message || "&mdash;".html_safe
50
+ message || mdash
62
51
  end
63
52
 
64
53
  def display_belongs_to(item, attribute)
65
54
  data = item.send(attribute)
66
55
  link_to data.to_label, { :controller => data.class.to_resource,
67
- :action => data.class.typus_options_for(:default_action_on_item),
56
+ :action => params[:action],
68
57
  :id => data.id }
69
58
  end
70
59
 
@@ -77,4 +66,23 @@ module Admin::Resources::DataTypes::BelongsToHelper
77
66
  items += resource.order(resource.typus_order_by).map { |v| [v.to_label, v.id] }
78
67
  end
79
68
 
69
+ def build_label_text_for_belongs_to(klass, html_options)
70
+ if html_options[:disabled] == true
71
+ Typus::I18n.t("Read only")
72
+ elsif admin_user.can?('create', klass) && !headless_mode?
73
+ build_add_new_for_belongs_to(klass)
74
+ end
75
+ end
76
+
77
+ def build_add_new_for_belongs_to(klass)
78
+ options = { :controller => "/admin/#{klass.to_resource}",
79
+ :action => 'new',
80
+ :resource => @resource.model_name,
81
+ :layout => 'admin/headless' }
82
+ # Pass the resource_id only to edit/update because only there is where
83
+ # the record actually exists.
84
+ options.merge!(:resource_id => @item.id) if %w(edit update).include?(params[:action])
85
+ link_to Typus::I18n.t("Add New"), options, { :class => 'iframe' }
86
+ end
87
+
80
88
  end
@@ -1,8 +1,7 @@
1
1
  module Admin::Resources::DataTypes::DragonflyHelper
2
2
 
3
3
  def table_dragonfly_field(attribute, item)
4
- options = { :height => 25, :width => 25 }
5
- typus_dragonfly_preview(item, attribute, options)
4
+ typus_dragonfly_preview(item, attribute)
6
5
  end
7
6
 
8
7
  def link_to_detach_attribute_for_dragonfly(attribute)
@@ -19,12 +18,26 @@ module Admin::Resources::DataTypes::DragonflyHelper
19
18
  end
20
19
  end
21
20
 
22
- def typus_dragonfly_preview(item, attachment, options = {})
21
+ def typus_dragonfly_preview(item, attachment)
23
22
  data = item.send(attachment)
24
23
  return unless data
25
24
 
26
25
  if data.mime_type =~ /^image\/.+/
27
26
  render "admin/templates/dragonfly_preview",
27
+ :preview => data.process(:thumb, Typus.image_preview_size).url,
28
+ :thumb => data.process(:thumb, Typus.image_table_thumb_size).url
29
+ else
30
+ link_to data.name, data.url
31
+ end
32
+ end
33
+
34
+ def typus_dragonfly_form_preview(item, attachment, options = {})
35
+ data = item.send(attachment)
36
+ return unless data
37
+
38
+ if data.mime_type =~ /^image\/.+/
39
+ render "admin/templates/dragonfly_form_preview",
40
+ :attachment => data,
28
41
  :preview => data.process(:thumb, Typus.image_preview_size).url,
29
42
  :thumb => data.process(:thumb, Typus.image_thumb_size).url,
30
43
  :options => options
@@ -6,19 +6,51 @@ module Admin::Resources::DataTypes::HasAndBelongsToManyHelper
6
6
 
7
7
  alias_method :table_has_many_field, :table_has_and_belongs_to_many_field
8
8
 
9
- def typus_form_has_and_belongs_to_many(field)
10
- setup_relationship(field)
11
- build_pagination
12
-
13
- # TODO: Find a cleaner way to add these actions ...
14
- @resource_actions = [["Edit", { :action => "edit", :layout => 'admin/headless' }, { :class => 'iframe' }],
15
- ["Unrelate", { :resource_id => @item.id,
16
- :resource => @resource.model_name,
17
- :action => "unrelate"},
18
- { :confirm =>"Unrelate?" }]]
19
-
20
- locals = { :association_name => @association_name, :add_new => build_add_new, :table => build_relationship_table }
21
- render "admin/templates/has_n", locals
9
+ def typus_has_and_belongs_to_many_field(attribute, form)
10
+ klass = attribute.singularize.capitalize.constantize
11
+ resource_ids = "#{attribute.singularize}_ids"
12
+
13
+ html_options = { :disabled => attribute_disabled?(resource_ids.to_sym) }
14
+
15
+ label_text = @resource.human_attribute_name(attribute)
16
+ if (text = build_label_text_for_has_and_belongs_to_many(klass, html_options))
17
+ label_text += "<small>#{text}</small>"
18
+ end
19
+
20
+ locals = { :attribute => attribute,
21
+ :attribute_id => "#{@resource.table_name}_#{attribute}",
22
+ :related_klass => klass,
23
+ :related_items => klass.all,
24
+ :related_ids => "#{@resource.name.downcase}[#{resource_ids}][]",
25
+ :values => @item.send(attribute),
26
+ :form => form,
27
+ :label_text => label_text.html_safe,
28
+ :html_options => html_options }
29
+
30
+ render "admin/templates/has_and_belongs_to_many", locals
31
+ end
32
+
33
+ def build_label_text_for_has_and_belongs_to_many(klass, html_options)
34
+ if html_options[:disabled] == true
35
+ Typus::I18n.t("Read only")
36
+ =begin
37
+ # TODO: Take this back at some point in the future. Adding a new item
38
+ # using the pop-up should update the items on the selector. I know
39
+ # this might be the most trivial thing in the world, but I don't
40
+ # know how to do it.
41
+ elsif admin_user.can?('create', klass) && !headless_mode?
42
+ build_add_new_for_has_and_belongs_to_many(klass)
43
+ =end
44
+ end
45
+ end
46
+
47
+ def build_add_new_for_has_and_belongs_to_many(klass)
48
+ options = { :controller => "/admin/#{klass.to_resource}",
49
+ :action => "new",
50
+ :layout => "admin/headless",
51
+ :return_to => request.path }
52
+
53
+ link_to Typus::I18n.t("Add New"), options, { :class => "iframe" }
22
54
  end
23
55
 
24
56
  end
@@ -14,30 +14,38 @@ module Admin::Resources::DataTypes::HasManyHelper
14
14
  def typus_form_has_many(field)
15
15
  setup_relationship(field)
16
16
 
17
- options = @reflection.through_reflection ? {} : { @reflection.foreign_key => @item.id }
17
+ options = { @reflection.foreign_key => @item.id }
18
+
19
+ if @reflection.options && (as = @reflection.options[:as])
20
+ klass = @resource.is_sti? ? @resource.superclass : @resource
21
+ options.merge!("#{as}_type" => klass)
22
+ end
18
23
 
19
24
  count_items_to_relate = @model_to_relate.order(@model_to_relate.typus_order_by).count - @item.send(field).count
20
25
 
21
26
  build_pagination
27
+ set_has_many_resource_actions
28
+
29
+ locals = { :association_name => @association_name,
30
+ :add_new => build_add_new_for_has_many(@model_to_relate, field, options),
31
+ :table => build_relationship_table }
32
+
33
+ render "admin/templates/has_many", locals
34
+ end
35
+
36
+ def build_add_new_for_has_many(klass, field, options = {})
37
+ if admin_user.can?("create", klass)
38
+ default_options = { :controller => "/admin/#{klass.to_resource}",
39
+ :action => "new",
40
+ :layout => "admin/headless" }
41
+
42
+ link_to Typus::I18n.t("Add New"), default_options.merge(options), { :class => "iframe_with_reload" }
43
+ end
44
+ end
22
45
 
23
- # If we are on a through_reflection set the association name!
24
- @resource_actions = if @reflection.through_reflection
25
- [["Edit", { :action => "edit", :layout => 'admin/headless' }, { :class => 'iframe' }],
26
- ["Unrelate", { :resource_id => @item.id,
27
- :resource => @resource.model_name,
28
- :action => "unrelate",
29
- :association_name => @association_name},
30
- { :confirm => "Unrelate?" } ]]
31
- else
32
- [["Edit", { :action => "edit", :layout => 'admin/headless' }, { :class => 'iframe' }],
33
- ["Trash", { :resource_id => @item.id,
34
- :resource => @resource.model_name,
35
- :action => "destroy" },
36
- { :confirm => "Trash?" } ]]
37
- end
38
-
39
- locals = { :association_name => @association_name, :add_new => build_add_new(options), :table => build_relationship_table }
40
- render "admin/templates/has_n", locals
46
+ def set_has_many_resource_actions
47
+ @resource_actions = [["Edit", { :action => "edit", :layout => 'admin/headless' }, { :class => 'iframe' }],
48
+ ["Trash", { :action => "destroy" }, { :confirm => "Trash?" } ]]
41
49
  end
42
50
 
43
51
  end
@@ -3,21 +3,34 @@ module Admin::Resources::DataTypes::HasOneHelper
3
3
  def typus_form_has_one(field)
4
4
  setup_relationship(field)
5
5
 
6
- @items = Array.new
7
- if item = @item.send(field)
8
- @items << item
6
+ related_items = @item.send(field)
7
+ @items = related_items ? [related_items] : []
8
+
9
+ set_has_one_resource_actions
10
+
11
+ locals = { :association_name => @association_name, :table => build_relationship_table, :add_new => nil }
12
+
13
+ if @items.empty?
14
+ options = { :resource_id => nil, @reflection.foreign_key => @item.id }
15
+ locals[:add_new] = build_add_new_for_has_one(@model_to_relate, field, options)
9
16
  end
10
17
 
11
- # TODO: Find a cleaner way to add these actions ...
12
- @resource_actions = [["Edit", {:action=>"edit"}, {}],
13
- ["Trash", { :resource_id => @item.id, :resource => @resource.model_name, :action => "destroy" }, { :confirm => "Trash?" }]]
18
+ render "admin/templates/has_one", locals
19
+ end
14
20
 
15
- options = { :resource_id => nil, @reflection.foreign_key => @item.id }
21
+ def build_add_new_for_has_one(klass, field, options = {})
22
+ if admin_user.can?("create", klass)
23
+ default_options = { :controller => "/admin/#{klass.to_resource}",
24
+ :action => "new",
25
+ :layout => "admin/headless" }
26
+
27
+ link_to Typus::I18n.t("Add New"), default_options.merge(options), { :class => "iframe" }
28
+ end
29
+ end
16
30
 
17
- render "admin/templates/has_one",
18
- :association_name => @association_name,
19
- :add_new => @items.empty? ? build_add_new(options) : nil,
20
- :table => build_relationship_table
31
+ def set_has_one_resource_actions
32
+ @resource_actions = [["Edit", { :action => "edit" }, {}],
33
+ ["Trash", { :action => "destroy" }, { :confirm => "Trash?" }]]
21
34
  end
22
35
 
23
36
  end
@@ -1,7 +1,7 @@
1
1
  module Admin::Resources::DataTypes::PaperclipHelper
2
2
 
3
3
  def table_paperclip_field(attribute, item)
4
- options = { :height => 25, :width => 25 }
4
+ options = { :width => 25 }
5
5
  typus_paperclip_preview(item, attribute, options)
6
6
  end
7
7
 
@@ -19,7 +19,7 @@ module Admin::Resources::DataTypes::StringHelper
19
19
  end
20
20
 
21
21
  def table_string_field(attribute, item)
22
- (raw_content = item.send(attribute)).present? ? raw_content : "&mdash;".html_safe
22
+ (raw_content = item.send(attribute)).present? ? raw_content : mdash
23
23
  end
24
24
 
25
25
  alias_method :table_decimal_field, :table_string_field
@@ -1,7 +1,7 @@
1
1
  module Admin::Resources::DataTypes::TextHelper
2
2
 
3
3
  def table_text_field(attribute, item)
4
- (raw_content = item.send(attribute)).present? ? truncate(raw_content) : "&mdash;".html_safe
4
+ (raw_content = item.send(attribute)).present? ? truncate(raw_content) : mdash
5
5
  end
6
6
 
7
7
  end
@@ -2,7 +2,7 @@ module Admin::Resources::DataTypes::TransversalHelper
2
2
 
3
3
  def table_transversal_field(attribute, item)
4
4
  field_1, field_2 = attribute.split(".")
5
- (related_item = item.send(field_1)) ? related_item.send(field_2) : "&mdash;".html_safe
5
+ (related_item = item.send(field_1)) ? related_item.send(field_2) : mdash
6
6
  end
7
7
 
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module Admin::Resources::DataTypes::TreeHelper
2
2
 
3
3
  def table_tree_field(attribute, item)
4
- item.parent ? item.parent.to_label : "&mdash;".html_safe
4
+ item.parent ? item.parent.to_label : mdash
5
5
  end
6
6
 
7
7
  def typus_tree_field(attribute, form)
@@ -1,13 +1,13 @@
1
1
  module Admin::Resources::DisplayHelper
2
2
 
3
+ def mdash
4
+ "&mdash;".html_safe
5
+ end
6
+
3
7
  def build_display(item, fields)
4
8
  fields.map do |attribute, type|
5
- value = if (type == :boolean) || (data = item.send(attribute)).present?
6
- send("display_#{type}", item, attribute)
7
- else
8
- "&mdash;".html_safe
9
- end
10
-
9
+ condition = (type == :boolean) || item.send(attribute).present?
10
+ value = condition ? send("display_#{type}", item, attribute) : mdash
11
11
  [@resource.human_attribute_name(attribute), value]
12
12
  end
13
13
  end
@@ -16,9 +16,10 @@ module Admin::Resources::DisplayHelper
16
16
  String.new.tap do |html|
17
17
  @resource.typus_defaults_for(:relationships).each do |relationship|
18
18
  association = @resource.reflect_on_association(relationship.to_sym)
19
- next if association.macro == :belongs_to
20
- next if admin_user.cannot?('read', association.class_name.constantize)
21
- html << send("typus_form_#{association.macro}", relationship)
19
+ macro, klass = association.macro, association.class_name.constantize
20
+ if [:has_many, :has_one].include?(macro) && admin_user.can?('read', klass)
21
+ html << send("typus_form_#{macro}", relationship)
22
+ end
22
23
  end
23
24
  end.html_safe
24
25
  end
@@ -5,18 +5,11 @@ module Admin::Resources::FiltersHelper
5
5
  locals = {}
6
6
 
7
7
  locals[:filters] = typus_filters.map do |key, value|
8
- { :filter => set_filter(key, value), :items => send("#{value}_filter", key) }
8
+ { :key => set_filter(key, value), :value => send("#{value}_filter", key) }
9
9
  end
10
10
 
11
- locals[:hidden_filters] = params.dup
12
-
13
- # Remove default params.
14
- rejections = %w(controller action locale utf8 sort_order order_by)
15
- locals[:hidden_filters].delete_if { |k, v| rejections.include?(k) }
16
-
17
- # Remove also custom params.
18
- rejections = locals[:filters].map { |f| f[:filter] }
19
- locals[:hidden_filters].delete_if { |k, v| rejections.include?(k) }
11
+ rejections = %w(controller action locale utf8 sort_order order_by) + locals[:filters].map { |f| f[:key] }
12
+ locals[:hidden_filters] = params.dup.delete_if { |k, v| rejections.include?(k) }
20
13
 
21
14
  render "helpers/admin/resources/filters", locals
22
15
  end
@@ -13,6 +13,8 @@ module Admin::Resources::FormHelper
13
13
  typus_template_field(key, value, form)
14
14
  when :template
15
15
  typus_template_field(key, template, form)
16
+ when :has_and_belongs_to_many
17
+ typus_has_and_belongs_to_many_field(key, form)
16
18
  else
17
19
  typus_template_field(key, :string, form)
18
20
  end
@@ -29,13 +31,21 @@ module Admin::Resources::FormHelper
29
31
 
30
32
  html_options = attribute_disabled?(attribute) ? { :disabled => 'disabled' } : {}
31
33
 
34
+ label_text = @resource.human_attribute_name(attribute)
35
+
36
+ =begin
37
+ if options[:disabled] == true
38
+ label_text += "<small>#{Typus::I18n.t("Read only")}</small>"
39
+ end
40
+ =end
41
+
32
42
  locals = { :resource => @resource,
33
43
  :attribute => attribute,
34
44
  :attribute_id => "#{@resource.table_name}_#{attribute}",
35
45
  :options => options,
36
46
  :html_options => html_options,
37
47
  :form => form,
38
- :label_text => @resource.human_attribute_name(attribute) }
48
+ :label_text => label_text.html_safe }
39
49
 
40
50
  render "admin/templates/#{template}", locals
41
51
  end
@@ -59,7 +69,7 @@ module Admin::Resources::FormHelper
59
69
 
60
70
  def save_options_for_headless_mode
61
71
  return unless headless_mode?
62
- params[:resource] ? { "_saveandassign" => "Save and assign" } : { "_continue" => "Save and continue editing" }
72
+ { "_continue" => "Save and continue editing" }
63
73
  end
64
74
 
65
75
  def save_options_for_user_class