Module: Admin::AdminsiteApplicationHelper
- Defined in:
- app/helpers/admin/adminsite_application_helper.rb
Instance Method Summary collapse
- #display_referenced_resource(resource, add_td_wrappers = true) ⇒ Object
- #display_resource_value(resource, attr, add_td_wrappers = true) ⇒ Object
- #error_messages_for(obj) ⇒ Object
- #format_response_value(value, add_td_wrappers = true) ⇒ Object
- #image_extensions ⇒ Object
- #is_image?(path) ⇒ Boolean
- #is_url?(value) ⇒ Boolean
- #label_resource ⇒ Object
- #label_resource_class ⇒ Object
- #label_resource_class_plural ⇒ Object
- #link_to_back(text = 'Back', path = admin_resource_path) ⇒ Object
- #link_to_destroy(resource) ⇒ Object
- #link_to_edit(resource, text = '') ⇒ Object
- #link_to_new(text, path = admin_resource_path(nil, :new)) ⇒ Object
- #link_to_show(resource, text = '') ⇒ Object
- #publish_form_input(form, form_input) ⇒ Object
Instance Method Details
#display_referenced_resource(resource, add_td_wrappers = true) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 86 def display_referenced_resource(resource, add_td_wrappers = true) label_attr = Adminsite::AdminConfig::Base.admin_config_of_class(resource.class, nil, current_adminsite_admin_user).label_attribute(resource) label = display_resource_value(resource, label_attr, add_td_wrappers) begin if can?(:edit, resource) link_to label, send("edit_admin_#{resource.class.name.underscore.gsub('/','_')}_path", resource.id, admin_menu: params[:admin_menu]) elsif can?(:read, resource) link_to label, send("admin_#{resource.class.name.underscore.gsub('/','_')}_path", resource.id, admin_menu: params[:admin_menu]) else label end rescue return label end end |
#display_resource_value(resource, attr, add_td_wrappers = true) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 70 def display_resource_value(resource, attr, add_td_wrappers = true) value = nil attr.to_s.split('.').each{|a| value = (value || resource).send(a) } value = display_referenced_resource(value, false) if value.is_a?(ActiveRecord::Base) if value.is_a?(ActiveRecord::Associations::CollectionProxy) or value.is_a?(Array) value = value.collect do |r| if r.is_a?(ActiveRecord::Base) display_referenced_resource(r, false) else r end end.join(', ') end format_response_value(value, add_td_wrappers).html_safe end |
#error_messages_for(obj) ⇒ Object
32 33 34 35 36 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 32 def (obj) return if obj.errors.blank? msgs = obj.errors..collect{|msg| "<li>#{ h msg }</li>" } raw ['<ul>', msgs, '</ul>'].flatten.join end |
#format_response_value(value, add_td_wrappers = true) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 3 def format_response_value(value, add_td_wrappers = true) value = value.url if defined?(PictureUploader) && value.is_a?(PictureUploader) response = '' response = '<td>' if add_td_wrappers if is_url?(value) response += link_to(value,value, target: '_blank') response += "<br>#{image_tag(value)}" if is_image?(value) else response += h value end if add_td_wrappers response + '</td>' else response end end |
#image_extensions ⇒ Object
28 29 30 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 28 def image_extensions %w(.png .gif .jpg .tif) end |
#is_image?(path) ⇒ Boolean
24 25 26 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 24 def is_image?(path) image_extensions.include?( File.extname(path).split('?').first.try(:downcase) ) end |
#is_url?(value) ⇒ Boolean
20 21 22 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 20 def is_url?(value) value.is_a?(String) && value.match(/\A[\/]|\Ahttp[s]*:/) end |
#label_resource ⇒ Object
38 39 40 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 38 def label_resource @resource.send(resource_admin_config.label_attribute) end |
#label_resource_class ⇒ Object
42 43 44 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 42 def label_resource_class resource_class.name.underscore.gsub('_', ' ') end |
#label_resource_class_plural ⇒ Object
46 47 48 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 46 def label_resource_class_plural label_resource_class.pluralize end |
#link_to_back(text = 'Back', path = admin_resource_path) ⇒ Object
50 51 52 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 50 def link_to_back(text = 'Back', path = admin_resource_path) link_to text, path, :class => 'action back' end |
#link_to_destroy(resource) ⇒ Object
66 67 68 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 66 def link_to_destroy(resource) link_to image_tag('adminsite/admin/cross.png', :size => '16x16'), admin_resource_path(resource.id), :class => 'resource_action destroy', data: { :confirm => 'Are you sure?'} , :method => :delete if can?(:destroy, resource) end |
#link_to_edit(resource, text = '') ⇒ Object
62 63 64 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 62 def link_to_edit(resource, text = '') link_to h(text) + image_tag('adminsite/admin/pencil.png', :size => '16x16'), admin_resource_path(resource.id, :edit), :class => 'resource_action edit' if can?(:edit, resource) end |
#link_to_new(text, path = admin_resource_path(nil, :new)) ⇒ Object
54 55 56 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 54 def link_to_new(text, path = admin_resource_path(nil, :new) ) link_to text, path, :class => 'action new' end |
#link_to_show(resource, text = '') ⇒ Object
58 59 60 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 58 def link_to_show(resource, text = '') link_to h(text) + image_tag('adminsite/admin/magnifier.png', :size => '16x16'), admin_resource_path(resource.id), :class => 'resource_action show' end |
#publish_form_input(form, form_input) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'app/helpers/admin/adminsite_application_helper.rb', line 102 def publish_form_input(form, form_input) = {} if form_input.is_a?(Hash) attr_name = form_input.keys.first = form_input[attr_name] else attr_name = form_input end form.input(attr_name, ).html_safe end |