Module: AbAdmin::Views::AdminHelpers
- Defined in:
- lib/ab_admin/views/admin_helpers.rb
Instance Method Summary collapse
- #admin_comments ⇒ Object
- #admin_editable(item, attr, options = nil) ⇒ Object
- #admin_form_for(object, *args, &block) ⇒ Object
- #admin_pretty_data(object) ⇒ Object
- #admin_tree(items) ⇒ Object
- #admin_tree_item(item) ⇒ Object
- #call_method_or_proc_on(obj, symbol_or_proc, options = {}) ⇒ Object
- #color_bool(val, success_class = 'badge-success') ⇒ Object
- #ha(attr) ⇒ Object
- #icon(name, white = false) ⇒ Object
-
#input_set(title, options = {}, &block) ⇒ Object
input_set ‘title’, :legend_class => ‘do_sort’, :label_class => ‘label-info’ do.
- #item_image(item, assoc = :photo, size = :thumb) ⇒ Object
- #item_image_link(item, options = {}) ⇒ Object
- #layout_css ⇒ Object
- #options_for_ckeditor(options = {}) ⇒ Object
- #pretty_data(object) ⇒ Object
Instance Method Details
#admin_comments ⇒ Object
64 65 66 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 64 def admin_comments render 'admin/admin_comments/comments' end |
#admin_editable(item, attr, options = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 22 def admin_editable(item, attr, =nil) = {} unless .is_a?(Hash) [:type] ||= case attr.to_s when /_at$/ 'date' when /^is_/ 'select' when /description|body|content/ 'textarea' else 'text' end [:source] ||= {'true' => 'yes', 'false' => 'no'} if [:type] == 'select' data = { :type => [:type], :source => [:source].try(:to_json), :model => resource_class.model_name.singular, :url => resource_path(item), :name => attr, :value => item[attr] } link_to admin_pretty_data(item[attr]).html_safe, '#', :class => 'editable', :data => data end |
#admin_form_for(object, *args, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 5 def admin_form_for(object, *args, &block) = args. [:remote] = true if request.xhr? [:html] ||= {} [:html][:class] ||= 'form-horizontal' [:builder] ||= ::AbAdmin::Views::FormBuilder [:html]['data-id'] = Array(object).last.id if controller_name == 'manager' && resource_class == Array(object).last.class [:url] ||= object.new_record? ? collection_path : resource_path end if .delete(:nested) simple_nested_form_for([:admin, object].flatten, *(args << ), &block) else simple_form_for([:admin, object].flatten, *(args << ), &block) end end |
#admin_pretty_data(object) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 76 def admin_pretty_data(object) case object when String, Integer, BigDecimal, Float object when TrueClass, FalseClass color_bool(object) when Date, DateTime, Time, ActiveSupport::TimeWithZone I18n.l(object, :format => :long) when NilClass '' when ActiveRecord::Base admin_show_link(object) else AbAdmin.safe_display_name(object) || object end end |
#admin_tree(items) ⇒ Object
51 52 53 54 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 51 def admin_tree(items) return if items.blank? items.map { |item| admin_tree_item(item) }.join.html_safe end |
#admin_tree_item(item) ⇒ Object
47 48 49 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 47 def admin_tree_item(item) render 'tree_item', :item => item, :child_tree => admin_tree(item.cached_children) end |
#call_method_or_proc_on(obj, symbol_or_proc, options = {}) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 122 def call_method_or_proc_on(obj, symbol_or_proc, = {}) exec = [:exec].nil? ? true : [:exec] case symbol_or_proc when Symbol, String obj.send(symbol_or_proc.to_sym) when Proc if exec instance_exec(obj, &symbol_or_proc) else symbol_or_proc.call(obj) end end end |
#color_bool(val, success_class = 'badge-success') ⇒ Object
68 69 70 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 68 def color_bool(val, success_class='badge-success') %(<span class="badge #{success_class if val}">#{val ? '+' : '-'}</span>).html_safe end |
#ha(attr) ⇒ Object
118 119 120 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 118 def ha(attr) resource_class.han(attr) end |
#icon(name, white = false) ⇒ Object
72 73 74 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 72 def icon(name, white=false) "<i class='icon-#{name} #{'icon-white' if white}'></i> ".html_safe end |
#input_set(title, options = {}, &block) ⇒ Object
input_set ‘title’, :legend_class => ‘do_sort’, :label_class => ‘label-info’ do
111 112 113 114 115 116 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 111 def input_set(title, ={}, &block) .reverse_merge!(:class => "inputs well well-small #{.delete(:legend_class) || 'do_sort'}", :id => .delete(:legend_id)) html = content_tag(:label, title, :class => "input_set label #{.delete(:label_class)}") html.concat(capture(&block)) if block_given? content_tag(:fieldset, html, ) end |
#item_image(item, assoc = :photo, size = :thumb) ⇒ Object
106 107 108 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 106 def item_image(item, assoc=:photo, size=:thumb) image_tag_if(item.send(assoc).try(:url, size)) end |
#item_image_link(item, options = {}) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 97 def item_image_link(item, ={}) .reverse_merge!(:url => resource_path(item), :assoc => :picture) image = item.send([:assoc]) return nil unless image version = [:version] || image.class.thumb_size popover_data = {:content => "<img src='#{image.url}'></img>", :title => item.name} link_to image_tag(image.url(version)), [:url], :data => popover_data, :rel => 'popover' end |
#layout_css ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 56 def layout_css css = [] css << 'content_with_sidebar' if settings[:sidebar] || content_for?(:sidebar) css << 'well' if settings[:well] css << "#{settings[:index_view]}_view" css end |
#options_for_ckeditor(options = {}) ⇒ Object
43 44 45 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 43 def ( = {}) {:width => 930, :height => 200, :toolbar => 'VeryEasy', :namespace => ''}.update() end |
#pretty_data(object) ⇒ Object
93 94 95 |
# File 'lib/ab_admin/views/admin_helpers.rb', line 93 def pretty_data(object) AbAdmin.pretty_data(object) end |