Module: Admin::Resources::FormHelper
- Defined in:
- app/helpers/admin/resources/form_helper.rb
Instance Method Summary collapse
- #attribute_disabled?(attribute) ⇒ Boolean
- #build_form(fields, form) ⇒ Object
- #build_save_options ⇒ Object
- #save_options ⇒ Object
- #save_options_for_headless_mode ⇒ Object
- #save_options_for_user_class ⇒ Object
- #typus_template_field(attribute, template, form) ⇒ Object
Instance Method Details
#attribute_disabled?(attribute) ⇒ Boolean
51 52 53 54 55 |
# File 'app/helpers/admin/resources/form_helper.rb', line 51 def attribute_disabled?(attribute) if protected_attributes = @resource._protected_attributes protected_attributes[current_role].include?(attribute) end end |
#build_form(fields, form) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/admin/resources/form_helper.rb', line 3 def build_form(fields, form) String.new.tap do |html| fields.each do |key, value| value = :template if (template = @resource.typus_template(key)) html << case value when :belongs_to typus_belongs_to_field(key, form) when :tree typus_tree_field(key, form) when :boolean, :date, :datetime, :text, :time, :password, :selector, :dragonfly, :paperclip typus_template_field(key, value, form) when :template typus_template_field(key, template, form) when :has_and_belongs_to_many typus_has_and_belongs_to_many_field(key, form) else typus_template_field(key, :string, form) end end end.html_safe end |
#build_save_options ⇒ Object
57 58 59 |
# File 'app/helpers/admin/resources/form_helper.rb', line 57 def || || end |
#save_options ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/admin/resources/form_helper.rb', line 61 def = {} if admin_user.can?('create', @resource.model_name) ["_addanother"] = "Save and add another" end if admin_user.can?('edit', @resource.model_name) ["_continue"] = "Save and continue editing" end ["_save"] = "Save" end |
#save_options_for_headless_mode ⇒ Object
77 78 79 80 |
# File 'app/helpers/admin/resources/form_helper.rb', line 77 def return unless headless_mode? { "_continue" => "Save" } end |
#save_options_for_user_class ⇒ Object
82 83 84 85 |
# File 'app/helpers/admin/resources/form_helper.rb', line 82 def return unless !defined?(Typus.user_class) && Typus.user_class == @resource && admin_user.is_not_root? { "_continue" => "Save and continue editing" } end |
#typus_template_field(attribute, template, form) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/admin/resources/form_helper.rb', line 25 def typus_template_field(attribute, template, form) = { :start_year => @resource.(:start_year), :end_year => @resource.(:end_year), :minute_step => @resource.(:minute_step), :disabled => attribute_disabled?(attribute), :include_blank => true } = attribute_disabled?(attribute) ? { :disabled => 'disabled' } : {} label_text = @resource.human_attribute_name(attribute) if [:disabled] == true label_text += "<small>#{Typus::I18n.t("Read only")}</small>" end locals = { :resource => @resource, :attribute => attribute, :attribute_id => "#{@resource.table_name}_#{attribute}", :options => , :html_options => , :form => form, :label_text => label_text.html_safe } render "admin/templates/#{template}", locals end |