typus-rails4 4.0.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +488 -0
  3. data/Gemfile +57 -0
  4. data/Gemfile.lock +253 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +101 -0
  7. data/Rakefile +51 -0
  8. data/app/assets/javascripts/typus/application.js +11 -0
  9. data/app/assets/javascripts/typus/custom.js +2 -0
  10. data/app/assets/javascripts/typus/jquery-2.1.1.min.js +4 -0
  11. data/app/assets/javascripts/typus/jquery.application.js +30 -0
  12. data/app/assets/stylesheets/typus/application.css +6 -0
  13. data/app/assets/stylesheets/typus/custom.scss +4 -0
  14. data/app/assets/stylesheets/typus/overrides.scss +10 -0
  15. data/app/assets/stylesheets/typus/signin.scss +45 -0
  16. data/app/controllers/admin/account_controller.rb +47 -0
  17. data/app/controllers/admin/base_controller.rb +40 -0
  18. data/app/controllers/admin/dashboard_controller.rb +6 -0
  19. data/app/controllers/admin/resource_controller.rb +8 -0
  20. data/app/controllers/admin/resources_controller.rb +268 -0
  21. data/app/controllers/admin/session_controller.rb +43 -0
  22. data/app/controllers/concerns/admin/actions.rb +88 -0
  23. data/app/controllers/concerns/admin/acts_as_list.rb +35 -0
  24. data/app/controllers/concerns/admin/ancestry.rb +26 -0
  25. data/app/controllers/concerns/admin/autocomplete.rb +11 -0
  26. data/app/controllers/concerns/admin/bulk.rb +76 -0
  27. data/app/controllers/concerns/admin/featured_image.rb +22 -0
  28. data/app/controllers/concerns/admin/filters.rb +57 -0
  29. data/app/controllers/concerns/admin/format.rb +49 -0
  30. data/app/controllers/concerns/admin/headless.rb +23 -0
  31. data/app/controllers/concerns/admin/hooks.rb +4 -0
  32. data/app/controllers/concerns/admin/multisite.rb +10 -0
  33. data/app/controllers/concerns/admin/navigation.rb +27 -0
  34. data/app/controllers/concerns/admin/trash.rb +65 -0
  35. data/app/helpers/admin/base_helper.rb +78 -0
  36. data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +88 -0
  37. data/app/helpers/admin/resources/data_types/boolean_helper.rb +33 -0
  38. data/app/helpers/admin/resources/data_types/date_helper.rb +16 -0
  39. data/app/helpers/admin/resources/data_types/datetime_helper.rb +19 -0
  40. data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +49 -0
  41. data/app/helpers/admin/resources/data_types/float_helper.rb +2 -0
  42. data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +59 -0
  43. data/app/helpers/admin/resources/data_types/has_many_helper.rb +76 -0
  44. data/app/helpers/admin/resources/data_types/has_one_helper.rb +44 -0
  45. data/app/helpers/admin/resources/data_types/integer_helper.rb +13 -0
  46. data/app/helpers/admin/resources/data_types/paperclip_helper.rb +49 -0
  47. data/app/helpers/admin/resources/data_types/selector_helper.rb +11 -0
  48. data/app/helpers/admin/resources/data_types/string_helper.rb +38 -0
  49. data/app/helpers/admin/resources/data_types/text_helper.rb +6 -0
  50. data/app/helpers/admin/resources/data_types/transversal_helper.rb +8 -0
  51. data/app/helpers/admin/resources/data_types/tree_helper.rb +28 -0
  52. data/app/helpers/admin/resources/display_helper.rb +27 -0
  53. data/app/helpers/admin/resources/filters_helper.rb +18 -0
  54. data/app/helpers/admin/resources/form_helper.rb +85 -0
  55. data/app/helpers/admin/resources/list_helper.rb +31 -0
  56. data/app/helpers/admin/resources/pagination_helper.rb +28 -0
  57. data/app/helpers/admin/resources/relationships_helper.rb +33 -0
  58. data/app/helpers/admin/resources/sidebar_helper.rb +34 -0
  59. data/app/helpers/admin/resources/table_helper.rb +69 -0
  60. data/app/helpers/admin/resources_helper.rb +25 -0
  61. data/app/mailers/admin/mailer.rb +19 -0
  62. data/app/views/admin/account/_form.html.erb +17 -0
  63. data/app/views/admin/account/forgot_password.html.erb +16 -0
  64. data/app/views/admin/account/new.html.erb +10 -0
  65. data/app/views/admin/dashboard/_sidebar.html.erb +14 -0
  66. data/app/views/admin/dashboard/index.html.erb +8 -0
  67. data/app/views/admin/dashboard/styles.html.erb +153 -0
  68. data/app/views/admin/dashboard/widgets/_applications.html.erb +44 -0
  69. data/app/views/admin/dashboard/widgets/_default.html.erb +43 -0
  70. data/app/views/admin/dashboard/widgets/_models.html.erb +23 -0
  71. data/app/views/admin/dashboard/widgets/_models_extended.html.erb +25 -0
  72. data/app/views/admin/dashboard/widgets/_resources.html.erb +23 -0
  73. data/app/views/admin/dashboard/widgets/_users.html.erb +23 -0
  74. data/app/views/admin/mailer/reset_password_instructions.html.erb +7 -0
  75. data/app/views/admin/mailer/reset_password_instructions.text.erb +7 -0
  76. data/app/views/admin/resource/_sidebar.html.erb +14 -0
  77. data/app/views/admin/resources/_edit.html.erb +0 -0
  78. data/app/views/admin/resources/_form.html.erb +28 -0
  79. data/app/views/admin/resources/_form_javascripts.html.erb +0 -0
  80. data/app/views/admin/resources/_form_modal.html.erb +13 -0
  81. data/app/views/admin/resources/_index.html.erb +0 -0
  82. data/app/views/admin/resources/_new.html.erb +0 -0
  83. data/app/views/admin/resources/_pagination.html.erb +15 -0
  84. data/app/views/admin/resources/_show.html.erb +0 -0
  85. data/app/views/admin/resources/_sidebar.html.erb +1 -0
  86. data/app/views/admin/resources/destroy.html.erb +16 -0
  87. data/app/views/admin/resources/edit.html.erb +22 -0
  88. data/app/views/admin/resources/edit/_actions.html.erb +7 -0
  89. data/app/views/admin/resources/edit/_recently_edited.html.erb +8 -0
  90. data/app/views/admin/resources/index.html.erb +29 -0
  91. data/app/views/admin/resources/new.html.erb +20 -0
  92. data/app/views/admin/resources/show.html.erb +26 -0
  93. data/app/views/admin/session/new.html.erb +18 -0
  94. data/app/views/admin/shared/_head.html.erb +24 -0
  95. data/app/views/admin/shared/_modals.html.erb +3 -0
  96. data/app/views/admin/shared/_sidebar_placeholder.html.erb +0 -0
  97. data/app/views/admin/templates/README.md +5 -0
  98. data/app/views/admin/templates/_belongs_to.html.erb +8 -0
  99. data/app/views/admin/templates/_boolean.html.erb +7 -0
  100. data/app/views/admin/templates/_date.html.erb +6 -0
  101. data/app/views/admin/templates/_datetime.html.erb +8 -0
  102. data/app/views/admin/templates/_dragonfly.html.erb +6 -0
  103. data/app/views/admin/templates/_dragonfly_form_preview.html.erb +21 -0
  104. data/app/views/admin/templates/_dragonfly_preview.html.erb +12 -0
  105. data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +21 -0
  106. data/app/views/admin/templates/_has_many.html.erb +18 -0
  107. data/app/views/admin/templates/_has_one.html.erb +14 -0
  108. data/app/views/admin/templates/_json.html.erb +11 -0
  109. data/app/views/admin/templates/_paperclip.html.erb +5 -0
  110. data/app/views/admin/templates/_paperclip_form_preview.html.erb +21 -0
  111. data/app/views/admin/templates/_paperclip_preview.html.erb +12 -0
  112. data/app/views/admin/templates/_password.html.erb +6 -0
  113. data/app/views/admin/templates/_position.html.erb +5 -0
  114. data/app/views/admin/templates/_profile_sidebar.html.erb +4 -0
  115. data/app/views/admin/templates/_selector.html.erb +4 -0
  116. data/app/views/admin/templates/_string.html.erb +4 -0
  117. data/app/views/admin/templates/_string_with_preview.html.erb +11 -0
  118. data/app/views/admin/templates/_text.html.erb +11 -0
  119. data/app/views/admin/templates/_text_with_ckeditor.html.erb +24 -0
  120. data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +38 -0
  121. data/app/views/admin/templates/_time.html.erb +9 -0
  122. data/app/views/admin/templates/_tree.html.erb +6 -0
  123. data/app/views/admin/templates/modals/_belongs_to.html.erb +60 -0
  124. data/app/views/admin/templates/modals/_dragonfly.html.erb +13 -0
  125. data/app/views/admin/templates/modals/_has_and_belongs_to_many.html.erb +25 -0
  126. data/app/views/admin/templates/modals/_has_many.html.erb +59 -0
  127. data/app/views/admin/templates/modals/_paperclip.html.erb +13 -0
  128. data/app/views/helpers/admin/base/_apps.html.erb +86 -0
  129. data/app/views/helpers/admin/base/_breadcrumbs.html.erb +6 -0
  130. data/app/views/helpers/admin/base/_flash_message.html.erb +3 -0
  131. data/app/views/helpers/admin/base/_login_info.html.erb +0 -0
  132. data/app/views/helpers/admin/dashboard/_resources.html.erb +19 -0
  133. data/app/views/helpers/admin/resources/_actions.html.erb +18 -0
  134. data/app/views/helpers/admin/resources/_errors.html.erb +12 -0
  135. data/app/views/helpers/admin/resources/_filters.html.erb +16 -0
  136. data/app/views/helpers/admin/resources/_search.html.erb +17 -0
  137. data/app/views/helpers/admin/resources/_sidebar.html.erb +4 -0
  138. data/app/views/helpers/admin/resources/_table.html.erb +45 -0
  139. data/app/views/helpers/admin/resources/sidebar/_item.html.erb +26 -0
  140. data/app/views/helpers/admin/resources/sidebar/_items.html.erb +14 -0
  141. data/app/views/helpers/admin/resources/sidebar/_items_index.html.erb +57 -0
  142. data/app/views/layouts/admin/base.html.erb +30 -0
  143. data/app/views/layouts/admin/headless.html.erb +1 -0
  144. data/app/views/layouts/admin/session.html.erb +26 -0
  145. data/bin/run-tests +7 -0
  146. data/bin/setup +9 -0
  147. data/config/locales/typus.en.yml +125 -0
  148. data/config/routes.rb +46 -0
  149. data/lib/generators/templates/config/initializers/typus.rb +34 -0
  150. data/lib/generators/templates/config/initializers/typus_authentication.rb +18 -0
  151. data/lib/generators/templates/config/initializers/typus_resources.rb +24 -0
  152. data/lib/generators/templates/config/typus/README +58 -0
  153. data/lib/generators/templates/config/typus/application.yml +3 -0
  154. data/lib/generators/templates/config/typus/application_roles.yml +4 -0
  155. data/lib/generators/templates/config/typus/typus.yml +15 -0
  156. data/lib/generators/templates/config/typus/typus_roles.yml +4 -0
  157. data/lib/generators/templates/controller.erb +2 -0
  158. data/lib/generators/templates/migration.erb +22 -0
  159. data/lib/generators/templates/view.html.erb +13 -0
  160. data/lib/generators/typus/config_generator.rb +67 -0
  161. data/lib/generators/typus/controller_generator.rb +26 -0
  162. data/lib/generators/typus/initializers_generator.rb +20 -0
  163. data/lib/generators/typus/migration_generator.rb +94 -0
  164. data/lib/generators/typus/model_generator.rb +93 -0
  165. data/lib/generators/typus/typus_generator.rb +54 -0
  166. data/lib/generators/typus/views_generator.rb +19 -0
  167. data/lib/support/active_record.rb +42 -0
  168. data/lib/support/fake_user.rb +47 -0
  169. data/lib/support/hash.rb +8 -0
  170. data/lib/support/object.rb +9 -0
  171. data/lib/support/string.rb +40 -0
  172. data/lib/tasks/typus.rake +11 -0
  173. data/lib/typus.rb +215 -0
  174. data/lib/typus/authentication/base.rb +39 -0
  175. data/lib/typus/authentication/devise.rb +19 -0
  176. data/lib/typus/authentication/http_basic.rb +18 -0
  177. data/lib/typus/authentication/none.rb +15 -0
  178. data/lib/typus/authentication/none_with_role.rb +15 -0
  179. data/lib/typus/authentication/session.rb +123 -0
  180. data/lib/typus/configuration.rb +43 -0
  181. data/lib/typus/engine.rb +4 -0
  182. data/lib/typus/orm/active_record.rb +10 -0
  183. data/lib/typus/orm/active_record/admin_user.rb +65 -0
  184. data/lib/typus/orm/active_record/class_methods.rb +104 -0
  185. data/lib/typus/orm/active_record/instance_methods.rb +76 -0
  186. data/lib/typus/orm/active_record/search.rb +43 -0
  187. data/lib/typus/orm/base/class_methods.rb +188 -0
  188. data/lib/typus/orm/base/search.rb +70 -0
  189. data/lib/typus/regex.rb +11 -0
  190. data/lib/typus/resources.rb +55 -0
  191. data/lib/typus/version.rb +10 -0
  192. data/typus.gemspec +27 -0
  193. data/vendor/assets/chosen/LICENSE.md +24 -0
  194. data/vendor/assets/chosen/chosen-sprite.png +0 -0
  195. data/vendor/assets/chosen/chosen-sprite@2x.png +0 -0
  196. data/vendor/assets/chosen/chosen.jquery.js +1239 -0
  197. data/vendor/assets/chosen/chosen.scss +437 -0
  198. metadata +271 -0
@@ -0,0 +1,10 @@
1
+ module Admin
2
+ module Multisite
3
+
4
+ def set_context
5
+ @resource = admin_user.site.send(@object_name.pluralize)
6
+ end
7
+ private :set_context
8
+
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_support/concern'
2
+
3
+ module Admin
4
+ module Navigation
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ # TODO: Decide if this piece of code can be removed. Seems to be useless.
9
+ included do
10
+ # before_filter :set_resources_action_on_lists, only: [:index, :trash]
11
+ # before_filter :set_resources_action, only: [:new, :create, :edit, :show]
12
+ end
13
+
14
+ def set_resources_action_on_lists
15
+ add_resources_action('typus.buttons.add', {action: 'new'})
16
+ end
17
+ private :set_resources_action_on_lists
18
+
19
+ def set_resources_action
20
+ unless params[:_popup] && !params[:_input]
21
+ add_resources_action('Back to list', {action: 'index', id: nil})
22
+ end
23
+ end
24
+ private :set_resources_action
25
+
26
+ end
27
+ end
@@ -0,0 +1,65 @@
1
+ # Module designed to work with `rails-trash`.
2
+
3
+ require 'active_support/concern'
4
+
5
+ module Admin
6
+ module Trash
7
+
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ before_filter :set_predefined_filter_for_trash, only: [:index, :trash]
12
+ end
13
+
14
+ def set_predefined_filter_for_trash
15
+ if admin_user.can?('edit', @resource.model_name)
16
+ add_predefined_filter('typus.filters.trash', 'trash', 'deleted')
17
+ end
18
+ end
19
+ private :set_predefined_filter_for_trash
20
+
21
+ def trash
22
+ set_deleted
23
+
24
+ get_objects
25
+
26
+ respond_to do |format|
27
+ format.html do
28
+ # Actions by resource.
29
+ add_resource_action 'typus.buttons.restore', { action: 'restore' }, { glyphicon: 'refresh', data: { confirm: I18n.t('typus.shared.restore_question', resource: @resource.model_name.human) } }
30
+ add_resource_action 'typus.buttons.destroy_permanently', { action: 'wipe' }, { glyphicon: 'remove', data: { confirm: I18n.t('typus.shared.confirm_question') } }
31
+ # Generate and render.
32
+ get_paginated_data
33
+ render 'index'
34
+ end
35
+
36
+ format.csv { generate_csv }
37
+ format.json { export(:json) }
38
+ format.xml { export(:xml) }
39
+ end
40
+ end
41
+
42
+ def restore
43
+ begin
44
+ @resource.restore(params[:id])
45
+ message = I18n.t('typus.flash.trash_recover_success', resource: @resource.model_name.human)
46
+ rescue ActiveRecord::RecordNotFound
47
+ message = I18n.t('typus.flash.trash_recover_failed', resource: @resource.model_name.human)
48
+ end
49
+
50
+ redirect_to :back, notice: message
51
+ end
52
+
53
+ def wipe
54
+ item = @resource.find_in_trash(params[:id])
55
+ item.disable_trash { item.destroy }
56
+ redirect_to :back, notice: I18n.t('typus.flash.wipe_success', resource: @resource.model_name.human)
57
+ end
58
+
59
+ def set_deleted
60
+ @resource = @resource.deleted
61
+ end
62
+ private :set_deleted
63
+
64
+ end
65
+ end
@@ -0,0 +1,78 @@
1
+ module Admin::BaseHelper
2
+
3
+ # a simple wrapper to prevent repeating "typus." in the key name
4
+ def tt(key, options = {})
5
+ t(key, {scope: "typus.#{options[:scope]}"}.merge(options))
6
+ end
7
+
8
+ def admin_title(page_title = nil)
9
+ if page_title
10
+ content_for(:title) { page_title }
11
+ else
12
+ setting = defined?(Admin::Setting) && Admin::Setting.admin_title
13
+ setting || Typus.admin_title
14
+ end
15
+ end
16
+
17
+ def admin_sign_out_path
18
+ case Typus.authentication
19
+ when :devise
20
+ send("destroy_#{Typus.user_class_name.underscore}_session_path")
21
+ else
22
+ destroy_admin_session_path
23
+ end
24
+ end
25
+
26
+ def admin_edit_user_path(user)
27
+ {
28
+ controller: "/admin/#{Typus.user_class.to_resource}",
29
+ action: 'edit',
30
+ id: user.id,
31
+ }
32
+ end
33
+
34
+ def admin_display_flash_message
35
+ if flash.any?
36
+ String.new.tap do |html|
37
+ flash.each do |type, message|
38
+ type = 'info' if type.to_sym == :notice
39
+ html << content_tag(:div, message, id: 'flash', class: "alert alert-#{type}")
40
+ end
41
+ end.html_safe
42
+ end
43
+ end
44
+
45
+ def set_modal_options_for(klass)
46
+ {
47
+ 'data-toggle' => 'modal',
48
+ 'data-controls-modal' => "modal-from-dom-#{klass.to_resource}",
49
+ 'data-backdrop' => 'true',
50
+ 'data-keyboard' => 'true',
51
+ 'class' => 'ajax-modal',
52
+ 'url' => 'override-this',
53
+ }
54
+ end
55
+
56
+ def body_class
57
+ klass = %w(base)
58
+
59
+ if params[:controller] == 'admin/dashboard'
60
+ klass << 'dashboard'
61
+ end
62
+
63
+ if @resource.try(:model_name)
64
+ klass << @resource.model_name.human.parameterize
65
+ end
66
+
67
+ klass << params[:action].parameterize
68
+
69
+ klass.join(' ')
70
+ end
71
+
72
+ def typus_search_path
73
+ path = params[:controller].remove_prefix
74
+ path = Typus.subdomain.nil? ? "/admin/#{path}" : "/#{path}"
75
+ path
76
+ end
77
+
78
+ end
@@ -0,0 +1,88 @@
1
+ module Admin::Resources::DataTypes::BelongsToHelper
2
+
3
+ def typus_belongs_to_field(attribute, form)
4
+ association = @resource.reflect_on_association(attribute.to_sym)
5
+
6
+ related = if defined?(set_belongs_to_context)
7
+ set_belongs_to_context.send(attribute.pluralize.to_sym)
8
+ else
9
+ association.class_name.constantize
10
+ end
11
+
12
+ related_fk = association.foreign_key
13
+ label_text = @resource.human_attribute_name(attribute)
14
+
15
+ values = if related.respond_to?(:roots) && related.respond_to?(:ancestry_column)
16
+ expand_tree_into_select_field(related.roots, related_fk)
17
+ else
18
+ related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
19
+ end
20
+
21
+ attribute_id = "#{@resource.name.underscore}_#{attribute}_id".gsub('/', '_')
22
+
23
+ render 'admin/templates/belongs_to',
24
+ attribute: attribute,
25
+ attribute_id: attribute_id,
26
+ form: form,
27
+ related_fk: related_fk,
28
+ related: related,
29
+ label_text: label_text.html_safe,
30
+ values: values,
31
+ html_options: { class: 'form-control' },
32
+ options: { include_blank: true, attribute: "#{@resource.name.underscore}_#{related_fk}" }
33
+ end
34
+
35
+ def table_belongs_to_field(attribute, item)
36
+ if att_value = item.send(attribute)
37
+ action = item.send(attribute).class.typus_options_for(:default_action_on_item)
38
+ message = att_value.to_label
39
+ if !params[:_popup] && admin_user.can?(action, att_value.class.name)
40
+ message = link_to(message, controller: "/admin/#{att_value.class.to_resource}", action: action, id: att_value.id)
41
+ end
42
+ end
43
+
44
+ message || mdash
45
+ end
46
+
47
+ def display_belongs_to(item, attribute)
48
+ data = item.send(attribute)
49
+
50
+ options = {
51
+ controller: data.class.to_resource,
52
+ action: params[:action],
53
+ id: data.id,
54
+ }
55
+
56
+ params[:_popup] ? data.to_label : link_to(data.to_label, options)
57
+ end
58
+
59
+ def belongs_to_filter(filter)
60
+ att_assoc = @resource.reflect_on_association(filter.to_sym)
61
+ class_name = att_assoc.options[:class_name] || filter.capitalize.camelize
62
+ resource = class_name.constantize
63
+
64
+ attribute = @resource.human_attribute_name(filter)
65
+
66
+ items = [[attribute, '']]
67
+ array = resource.order(resource.typus_order_by).map { |v| ["#{attribute}:#{v.to_label}", v.id] }
68
+
69
+ items + array
70
+ end
71
+
72
+ def build_label_text_for_belongs_to(klass, html_options, options)
73
+ if html_options[:disabled] == true
74
+ t('typus.labels.read_only')
75
+ elsif admin_user.can?('create', klass) && !headless_mode?
76
+ build_add_new_for_belongs_to(klass, options)
77
+ end
78
+ end
79
+
80
+ def build_add_new_for_belongs_to(klass, options)
81
+ html_options = set_modal_options_for(klass)
82
+ html_options['data-controls-modal'] = "modal-from-dom-#{options[:attribute]}"
83
+ html_options['url'] = "/admin/#{klass.to_resource}/new?_popup=true"
84
+
85
+ link_to t('typus.buttons.add'), { anchor: html_options['data-controls-modal'] }, html_options
86
+ end
87
+
88
+ end
@@ -0,0 +1,33 @@
1
+ module Admin::Resources::DataTypes::BooleanHelper
2
+
3
+ def display_boolean(item, attribute)
4
+ if (status = item.send(attribute).to_s).present?
5
+ item.class.typus_boolean(attribute).rassoc(status).first
6
+ else
7
+ mdash
8
+ end
9
+ end
10
+
11
+ def table_boolean_field(attribute, item)
12
+ options = {
13
+ controller: "/admin/#{item.class.to_resource}",
14
+ action: 'toggle',
15
+ id: item.id,
16
+ field: attribute.gsub(/\?$/, '')
17
+ }
18
+
19
+ human_boolean = display_boolean(item, attribute)
20
+ link_to human_boolean, options
21
+ end
22
+
23
+ def boolean_filter(filter)
24
+ values = @resource.typus_boolean(filter)
25
+ attribute = @resource.human_attribute_name(filter)
26
+
27
+ items = [[attribute.titleize, '']]
28
+ array = values.map { |k, v| ["#{attribute}:#{k.humanize}", v] }
29
+
30
+ items + array
31
+ end
32
+
33
+ end
@@ -0,0 +1,16 @@
1
+ module Admin::Resources::DataTypes::DateHelper
2
+
3
+ def date_filter(filter)
4
+ values = { all_day: "Today",
5
+ all_week: "This week",
6
+ all_month: "This month",
7
+ all_year: "This year" }
8
+
9
+ items = [[@resource.human_attribute_name(filter).capitalize, ""]]
10
+ items += values.map { |k, v| [t(v), k] }
11
+ end
12
+
13
+ alias_method :datetime_filter, :date_filter
14
+ alias_method :timestamp_filter, :date_filter
15
+
16
+ end
@@ -0,0 +1,19 @@
1
+ module Admin::Resources::DataTypes::DatetimeHelper
2
+
3
+ def table_datetime_field(attribute, item)
4
+ if field = item.send(attribute)
5
+ I18n.localize(field, format: item.class.typus_date_format(attribute))
6
+ end
7
+ end
8
+
9
+ alias_method :table_date_field, :table_datetime_field
10
+ alias_method :table_time_field, :table_datetime_field
11
+ alias_method :table_timestamp_field, :table_datetime_field
12
+
13
+ def display_datetime(item, attribute)
14
+ I18n.l(item.send(attribute), format: @resource.typus_date_format(attribute))
15
+ end
16
+
17
+ alias_method :display_date, :display_datetime
18
+
19
+ end
@@ -0,0 +1,49 @@
1
+ module Admin::Resources::DataTypes::DragonflyHelper
2
+
3
+ def display_dragonfly(item, attribute)
4
+ typus_dragonfly_preview(item, attribute, partial = 'dragonfly_form_preview')
5
+ end
6
+
7
+ def table_dragonfly_field(attribute, item)
8
+ typus_dragonfly_preview(item, attribute)
9
+ end
10
+
11
+ def link_to_detach_attribute_for_dragonfly(attribute)
12
+ validators = @item.class.validators.delete_if { |i| i.class != ActiveRecord::Validations::PresenceValidator }.map(&:attributes).flatten.map(&:to_s)
13
+ attachment = @item.send(attribute)
14
+
15
+ if attachment.present? && !validators.include?(attribute) && attachment
16
+ attribute_i18n = @item.class.human_attribute_name(attribute)
17
+
18
+ link = link_to(
19
+ t('typus.buttons.remove'),
20
+ { action: 'update', id: @item.id, _nullify: attribute, _continue: true },
21
+ { data: { confirm: t('typus.shared.confirm_question') } }
22
+ )
23
+
24
+ label_text = <<-HTML
25
+ #{attribute_i18n}
26
+ <small>#{link}</small>
27
+ HTML
28
+ label_text.html_safe
29
+ end
30
+ end
31
+
32
+ def typus_dragonfly_preview(item, attribute, partial = 'dragonfly_preview')
33
+ data = item.send(attribute)
34
+ return unless data
35
+
36
+ if data.mime_type =~ /^image\/.+/
37
+ render "admin/templates/#{partial}",
38
+ attachment: data,
39
+ preview: data.thumb(Typus.image_preview_size).url,
40
+ thumb: data.thumb(Typus.image_thumb_size).url,
41
+ table_thumb: data.thumb(Typus.image_table_thumb_size).url,
42
+ item: item,
43
+ attribute: attribute
44
+ else
45
+ params[:_popup] ? data.name : link_to(data.name, data.url, {target: '_blank'})
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,2 @@
1
+ module Admin::Resources::DataTypes::FloatHelper
2
+ end
@@ -0,0 +1,59 @@
1
+ module Admin::Resources::DataTypes::HasAndBelongsToManyHelper
2
+
3
+ def display_has_and_belongs_to_many(item, attribute)
4
+ item.send(attribute).map(&:to_label).join(', ')
5
+ end
6
+
7
+ def table_has_and_belongs_to_many_field(attribute, item)
8
+ item.send(attribute).map(&:to_label).join(', ')
9
+ end
10
+
11
+ alias_method :table_has_many_field, :table_has_and_belongs_to_many_field
12
+
13
+ def typus_has_and_belongs_to_many_field(attribute, form)
14
+ klass = @resource.reflect_on_association(attribute.to_sym).class_name.constantize
15
+
16
+ resource_ids = "#{attribute.singularize}_ids"
17
+ html_options = {}
18
+ model = @resource.name.underscore.gsub('/', '_')
19
+ options = { attribute: "#{model}_#{attribute}" }
20
+
21
+ label_text = @resource.human_attribute_name(attribute)
22
+ if (text = build_label_text_for_has_and_belongs_to_many(klass, html_options, options))
23
+ label_text += " <small>#{text}</small>"
24
+ end
25
+
26
+ locals = {
27
+ attribute: attribute,
28
+ attribute_id: "#{model}_#{attribute}",
29
+ related_klass: klass,
30
+ related_items: @item.send(attribute),
31
+ related_ids: "#{model}[#{resource_ids}][]",
32
+ values: klass,
33
+ form: form,
34
+ label_text: label_text.html_safe,
35
+ html_options: html_options,
36
+ }
37
+
38
+ render 'admin/templates/has_and_belongs_to_many', locals
39
+ end
40
+
41
+ def build_label_text_for_has_and_belongs_to_many(klass, html_options, options = {})
42
+ if html_options[:disabled] == true
43
+ I18n.t('typus.labels.read_only')
44
+ elsif admin_user.can?('create', klass) && !headless_mode?
45
+ build_add_new_for_has_and_belongs_to_many(klass, options)
46
+ end
47
+ end
48
+
49
+ def build_add_new_for_has_and_belongs_to_many(klass, options)
50
+ html_options = set_modal_options_for(klass)
51
+ html_options['url'] = url_for(controller: "/admin/#{klass.to_resource}", action: :new, _popup: true)
52
+ html_options['data-controls-modal'] = "modal-from-dom-#{options[:attribute]}"
53
+
54
+ options = { anchor: html_options['data-controls-modal'] }
55
+
56
+ link_to I18n.t('typus.buttons.add'), options, html_options
57
+ end
58
+
59
+ end