typus-rails4 4.0.0.beta6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,76 @@
1
+ module Admin::Resources::DataTypes::HasManyHelper
2
+
3
+ def has_many_filter(filter)
4
+ att_assoc = @resource.reflect_on_association(filter.to_sym)
5
+ class_name = att_assoc.options[:class_name] || filter.classify
6
+ resource = class_name.constantize
7
+
8
+ view_all = t('typus.filters.view_all', attribute: @resource.human_attribute_name(filter).downcase.pluralize)
9
+
10
+ items = [[view_all, '']]
11
+ items += resource.order(resource.typus_order_by).map { |v| [v.to_label, v.id] }
12
+ end
13
+
14
+ alias_method :has_and_belongs_to_many_filter, :has_many_filter
15
+
16
+ def typus_form_has_many(field)
17
+ setup_relationship(field)
18
+
19
+ options = { "resource[#{@reflection.foreign_key}]" => @item.id }
20
+
21
+ if @reflection.options && (as = @reflection.options[:as])
22
+ klass = @resource.is_sti? ? @resource.superclass : @resource
23
+ options.merge!("#{as}_type" => klass)
24
+ end
25
+
26
+ build_pagination
27
+ set_has_many_resource_actions
28
+
29
+ locals = {
30
+ association_name: @association_name,
31
+ add_new: build_add_new_for_has_many(@model_to_relate, field, options),
32
+ table: build_relationship_table,
33
+ }
34
+
35
+ render 'admin/templates/has_many', locals
36
+ end
37
+
38
+ def build_add_new_for_has_many(klass, field, options = {})
39
+ if admin_user.can?('create', klass)
40
+
41
+ html_options = set_modal_options_for(klass)
42
+ html_options['url'] = "/admin/#{klass.to_resource}/new?_popup=true"
43
+
44
+ link_to t('typus.buttons.add'), "##{html_options['data-controls-modal']}", html_options
45
+ end
46
+ end
47
+
48
+ def set_has_many_resource_actions
49
+ klass = @model_to_relate
50
+
51
+ @resource_actions = [
52
+ set_has_many_resource_edit_action(klass),
53
+ set_has_many_resource_show_action(klass),
54
+ set_has_many_resource_destroy_action(klass),
55
+ ]
56
+ end
57
+
58
+ def set_has_many_resource_edit_action(klass)
59
+ html_options = set_modal_options_for(klass)
60
+ html_options[:glyphicon] = 'edit'
61
+ [ 'typus.buttons.edit', { action: 'edit', anchor: html_options['data-controls-modal'] }, html_options ]
62
+ end
63
+
64
+ def set_has_many_resource_show_action(klass)
65
+ html_options = set_modal_options_for(klass)
66
+ html_options[:glyphicon] = 'info-sign'
67
+ [ 'typus.buttons.show', { action: 'show', anchor: html_options['data-controls-modal'] }, html_options ]
68
+ end
69
+
70
+ def set_has_many_resource_destroy_action(klass)
71
+ html_options = {}
72
+ html_options[:glyphicon] = 'remove'
73
+ [ 'typus.buttons.destroy', { action: 'destroy' }, html_options ]
74
+ end
75
+
76
+ end
@@ -0,0 +1,44 @@
1
+ module Admin::Resources::DataTypes::HasOneHelper
2
+
3
+ def typus_form_has_one(field)
4
+ setup_relationship(field)
5
+
6
+ related_items = @item.send(field)
7
+ @items = related_items ? [related_items] : []
8
+
9
+ set_has_one_resource_actions
10
+
11
+ locals = {
12
+ association_name: @association_name,
13
+ table: build_relationship_table,
14
+ add_new: nil,
15
+ }
16
+
17
+ if @items.empty?
18
+ options = { "resource[#{@reflection.foreign_key}]" => @item.id }
19
+ locals[:add_new] = build_add_new_for_has_one(@model_to_relate, field, options)
20
+ end
21
+
22
+ render 'admin/templates/has_one', locals
23
+ end
24
+
25
+ def build_add_new_for_has_one(klass, field, options = {})
26
+ if admin_user.can?('create', klass)
27
+ default_options = {
28
+ controller: "/admin/#{klass.to_resource}",
29
+ action: 'new',
30
+ _popup: true,
31
+ }
32
+
33
+ link_to t('typus.buttons.add'), default_options.merge(options), { class: 'iframe_with_page_reload' }
34
+ end
35
+ end
36
+
37
+ def set_has_one_resource_actions
38
+ @resource_actions = [
39
+ ['typus.buttons.edit', { action: 'edit' }, {}],
40
+ ['typus.buttons.destroy', { action: 'destroy' }, { data: { confirm: t('typus.shared.confirm_question') } }],
41
+ ]
42
+ end
43
+
44
+ end
@@ -0,0 +1,13 @@
1
+ module Admin::Resources::DataTypes::IntegerHelper
2
+
3
+ def integer_filter(filter)
4
+ values = set_context.send(filter.to_s.pluralize).to_a
5
+ attribute = @resource.human_attribute_name(filter)
6
+
7
+ items = [[attribute.titleize, '']]
8
+ array = values.first.is_a?(Array) ? values : values.map { |i| ["#{attribute}:#{i}", i] }
9
+
10
+ items + array
11
+ end
12
+
13
+ end
@@ -0,0 +1,49 @@
1
+ module Admin::Resources::DataTypes::PaperclipHelper
2
+
3
+ def display_paperclip(item, attribute)
4
+ typus_paperclip_preview(item, attribute, 'paperclip_form_preview')
5
+ end
6
+
7
+ def table_paperclip_field(attribute, item)
8
+ typus_paperclip_preview(item, attribute)
9
+ end
10
+
11
+ def link_to_detach_attribute_for_paperclip(attribute)
12
+ validators = @item.class.validators.delete_if { |i| i.class != Paperclip::Validators::AttachmentPresenceValidator }.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
+ link = link_to(
18
+ t('typus.buttons.remove'),
19
+ { action: 'update', id: @item.id, _nullify: attribute, _continue: true },
20
+ { data: { confirm: t('typus.shared.confirm_question') } }
21
+ )
22
+
23
+ label_text = <<-HTML
24
+ #{attribute_i18n}
25
+ <small>#{link}</small>
26
+ HTML
27
+ label_text.html_safe
28
+ end
29
+ end
30
+
31
+ def typus_paperclip_preview(item, attribute, partial = 'paperclip_preview')
32
+ data = item.send(attribute)
33
+ return unless data.exists?
34
+
35
+ styles = data.styles.keys
36
+ if data.content_type =~ /^image\/.+/ && styles.include?(Typus.file_preview) && styles.include?(Typus.file_thumbnail)
37
+ render "admin/templates/#{partial}",
38
+ attachment: data,
39
+ preview: data.url(Typus.file_preview),
40
+ table_thumb: data.url(Typus.file_thumbnail),
41
+ thumb: data.url(Typus.file_thumbnail),
42
+ item: item,
43
+ attribute: attribute
44
+ else
45
+ link_to data.original_filename, data.url(:original, false)
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,11 @@
1
+ module Admin::Resources::DataTypes::SelectorHelper
2
+
3
+ def table_selector_field(attribute, item)
4
+ item.mapping(attribute)
5
+ end
6
+
7
+ def display_selector(item, attribute)
8
+ item.mapping(attribute)
9
+ end
10
+
11
+ end
@@ -0,0 +1,38 @@
1
+ module Admin::Resources::DataTypes::StringHelper
2
+
3
+ def display_string(item, attribute)
4
+ if (data = item.send(attribute)).present?
5
+ data
6
+ else
7
+ mdash
8
+ end
9
+ end
10
+
11
+ alias_method :display_decimal, :display_string
12
+ alias_method :display_float, :display_string
13
+ alias_method :display_integer, :display_string
14
+ alias_method :display_position, :display_string
15
+ alias_method :display_text, :display_string
16
+ alias_method :display_virtual, :display_string
17
+
18
+ def string_filter(filter)
19
+ values = set_context.send(filter.to_s.pluralize).to_a
20
+ attribute = @resource.human_attribute_name(filter)
21
+
22
+ items = [[attribute.capitalize, '']]
23
+ array = values.first.is_a?(Array) ? values : values.map { |i| ["#{attribute}:#{i}", i] }
24
+
25
+ items + array
26
+ end
27
+
28
+ def table_string_field(attribute, item)
29
+ (raw_content = item.send(attribute)).present? ? raw_content : mdash
30
+ end
31
+
32
+ alias_method :table_decimal_field, :table_string_field
33
+ alias_method :table_float_field, :table_string_field
34
+ alias_method :table_integer_field, :table_string_field
35
+ alias_method :table_virtual_field, :table_string_field
36
+ alias_method :table_password_field, :table_string_field
37
+ alias_method :table_json_field, :table_string_field
38
+ end
@@ -0,0 +1,6 @@
1
+ module Admin::Resources::DataTypes::TextHelper
2
+
3
+ def table_text_field(attribute, item)
4
+ (raw_content = item.send(attribute)).present? ? truncate(raw_content) : mdash
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Admin::Resources::DataTypes::TransversalHelper
2
+
3
+ def table_transversal_field(attribute, item)
4
+ field_1, field_2 = attribute.split('.')
5
+ (related_item = item.send(field_1)) ? related_item.send(field_2) : mdash
6
+ end
7
+
8
+ end
@@ -0,0 +1,28 @@
1
+ module Admin::Resources::DataTypes::TreeHelper
2
+
3
+ def table_tree_field(attribute, item)
4
+ item.parent ? item.parent.to_label : mdash
5
+ end
6
+
7
+ def typus_tree_field(attribute, form)
8
+ locals = {
9
+ attribute: attribute,
10
+ attribute_id: "#{@resource.table_name}_#{attribute}",
11
+ form: form,
12
+ label_text: @resource.human_attribute_name(attribute),
13
+ values: raw(expand_tree_into_select_field(@resource.roots, 'parent_id')),
14
+ }
15
+
16
+ render 'admin/templates/tree', locals
17
+ end
18
+
19
+ def expand_tree_into_select_field(items, attribute)
20
+ String.new.tap do |html|
21
+ items.each do |item|
22
+ html << %{<option #{'selected' if @item.send(attribute) == item.id} value="#{item.id}">#{'&nbsp;' * item.ancestors.size * 2} #{item.to_label}</option>\n}
23
+ html << expand_tree_into_select_field(item.children, attribute) unless item.children.empty?
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,27 @@
1
+ module Admin::Resources::DisplayHelper
2
+
3
+ def mdash
4
+ '&mdash;'.html_safe
5
+ end
6
+
7
+ def build_display(item, fields)
8
+ fields.map do |attribute, type|
9
+ condition = (type == :boolean) || item.respond_to?(attribute)
10
+ next unless condition
11
+ [@resource.human_attribute_name(attribute), send("display_#{type}", item, attribute)]
12
+ end.compact
13
+ end
14
+
15
+ def typus_relationships
16
+ String.new.tap do |html|
17
+ @resource.typus_defaults_for(:relationships).each do |relationship|
18
+ association = @resource.reflect_on_association(relationship.to_sym)
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
23
+ end
24
+ end.html_safe
25
+ end
26
+
27
+ end
@@ -0,0 +1,18 @@
1
+ module Admin::Resources::FiltersHelper
2
+
3
+ def build_filters(resource = @resource, params = self.params)
4
+ if (typus_filters = resource.typus_filters).any?
5
+ locals = {}
6
+
7
+ locals[:filters] = typus_filters.map do |key, value|
8
+ { key: key, value: send("#{value}_filter", key) }
9
+ end
10
+
11
+ rejections = %w(controller action locale utf8 sort_order order_by subdomain) + locals[:filters].map { |f| f[:key] }
12
+ locals[:hidden_filters] = params.dup.delete_if { |k, _| rejections.include?(k) }
13
+
14
+ render 'helpers/admin/resources/filters', locals
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,85 @@
1
+ module Admin::Resources::FormHelper
2
+
3
+ def build_form(fields, form)
4
+ String.new.tap do |html|
5
+ fields.each do |key, value|
6
+ value = :template if (template = @resource.typus_template(key))
7
+ html << case value
8
+ when :belongs_to
9
+ typus_belongs_to_field(key, form)
10
+ when :tree
11
+ typus_tree_field(key, form)
12
+ when :boolean, :date, :datetime, :text, :time, :password, :selector, :dragonfly, :paperclip, :json
13
+ typus_template_field(key, value, form)
14
+ when :template
15
+ typus_template_field(key, template, form)
16
+ when :has_and_belongs_to_many
17
+ typus_has_and_belongs_to_many_field(key, form)
18
+ else
19
+ typus_template_field(key, :string, form)
20
+ end
21
+ end
22
+ end.html_safe
23
+ end
24
+
25
+ def typus_template_field(attribute, template, form)
26
+ options = {
27
+ start_year: @resource.typus_options_for(:start_year),
28
+ end_year: @resource.typus_options_for(:end_year),
29
+ minute_step: @resource.typus_options_for(:minute_step),
30
+ include_blank: true,
31
+ class: 'form-control',
32
+ }
33
+
34
+ label_text = @resource.human_attribute_name(attribute)
35
+
36
+ locals = {
37
+ resource: @resource,
38
+ attribute: attribute,
39
+ attribute_id: "#{@resource.table_name}_#{attribute}",
40
+ options: options,
41
+ html_options: {},
42
+ form: form,
43
+ label_text: label_text,
44
+ help_block: help_block,
45
+ }
46
+
47
+ render "admin/templates/#{template}", locals
48
+ end
49
+
50
+ # Placeholder
51
+ def help_block
52
+ false
53
+ end
54
+
55
+ def build_save_options
56
+ save_options_for_user_class || save_options_for_headless_mode || save_options
57
+ end
58
+
59
+ def save_options
60
+ options = {}
61
+
62
+ if admin_user.can?('create', @resource.model_name)
63
+ options[:_addanother] = 'typus.buttons.save_addanother'
64
+ end
65
+
66
+ if admin_user.can?('edit', @resource.model_name)
67
+ options[:_continue] = 'typus.buttons.save_continue'
68
+ end
69
+
70
+ options[:_save] = 'typus.buttons.save'
71
+
72
+ options
73
+ end
74
+
75
+ def save_options_for_headless_mode
76
+ return unless headless_mode?
77
+ { _continue: 'typus.buttons.save' }
78
+ end
79
+
80
+ def save_options_for_user_class
81
+ return unless defined?(Typus.user_class) && Typus.user_class == @resource && admin_user.is_not_root?
82
+ { _continue: 'typus.buttons.save_continue' }
83
+ end
84
+
85
+ end
@@ -0,0 +1,31 @@
1
+ module Admin::Resources::ListHelper
2
+
3
+ def list_actions
4
+ resources_actions_for_current_role.map do |body, url, options|
5
+ path = params.dup.merge!(url).compact.cleanup
6
+ link_to t(body), path, options
7
+ end.compact.reverse.join(' / ').html_safe
8
+ end
9
+
10
+ def resources_actions_for_current_role
11
+ resources_actions.reject do |_, url, _|
12
+ admin_user.cannot?(url[:action], @resource.name)
13
+ end
14
+ end
15
+
16
+ def build_actions(&block)
17
+ render 'helpers/admin/resources/actions', block: block
18
+ end
19
+
20
+ #--
21
+ # If partial `list` exists we will use it. This partial will have available
22
+ # the `@items` so we can do whatever we want there. Notice that pagination
23
+ # is still available.
24
+ #++
25
+ def build_list(model, fields, items, resource = @resource.to_resource, link_options = {}, association = nil, association_name = nil)
26
+ render "admin/#{resource}/list", items: items
27
+ rescue ActionView::MissingTemplate
28
+ build_table(model, fields, items, link_options, association, association_name)
29
+ end
30
+
31
+ end