Module: AbAdmin::Views::AdminNavigationHelpers
- Defined in:
- lib/ab_admin/views/admin_navigation_helpers.rb
Instance Method Summary collapse
- #action_link(action) ⇒ Object
- #admin_edit_link(record, options = {}) ⇒ Object
- #admin_menu_link(name, path) ⇒ Object
- #admin_menu_link_without_model(name, path, path_name) ⇒ Object
- #admin_record_link(record, action, options = {}) ⇒ Object
- #admin_show_link(record, options = {}) ⇒ Object
- #auto_edit_link(rec, opts = {}) ⇒ Object
- #auto_show_link(rec, opts = {}) ⇒ Object
- #batch_action_item(item) ⇒ Object
- #batch_action_toggle ⇒ Object
- #id_link(item) ⇒ Object
- #item_index_actions(item) ⇒ Object
- #item_link_to_can?(act, item, *args, &block) ⇒ Boolean
- #link_to_can?(act, *args, &block) ⇒ Boolean
- #model_admin_menu_link(model) ⇒ Object
- #order_indicator_for(order) ⇒ Object
- #pagination_info(c) ⇒ Object
- #search_admin_form_for(object, *args, &block) ⇒ Object
- #short_action_link(action, item) ⇒ Object
- #sort_link(search, attribute, *args) ⇒ Object
Instance Method Details
#action_link(action) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 78 def action_link(action) case action when :new link_to_can? :create, t('admin.actions.new.link'), new_resource_path, :class => 'btn btn-primary new_resource', :remote => settings[:list_edit] when :edit link_to_can? :update, t('admin.actions.edit.link'), edit_resource_path, :class => 'btn btn-primary' when :destroy link_to_can? :destroy, t('admin.actions.destroy.link'), resource_path, :method => :delete, :data => {:confirm => t('admin.delete_confirmation')}, :class => 'btn btn-danger' when :show link_to_can? :show, t('admin.actions.show.link'), resource_path, :class => 'btn btn-info' when :preview if path = preview_resource_path(resource) link_to t('admin.actions.preview.link'), path, :class => 'btn btn-inverse', :title => t('admin.actions.preview.link'), :target => '_blank' end when AbAdmin::Config::ActionItem instance_exec(&action.data) if action.for_context?(self) else meth = "#{resource_instance_name}_action_link" send(meth, action) if respond_to? meth end end |
#admin_edit_link(record, options = {}) ⇒ Object
188 189 190 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 188 def admin_edit_link(record, = {}) admin_record_link(record, :edit, ) end |
#admin_menu_link(name, path) ⇒ Object
122 123 124 125 126 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 122 def (name, path) content_tag :li, :class => ('active' if path == request.path_info.split('/')[2]) do link_to name, "/admin/#{path}" end end |
#admin_menu_link_without_model(name, path, path_name) ⇒ Object
128 129 130 131 132 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 128 def (name, path, path_name) content_tag :li, :class => ('active' if path_name == request.url.split('/').last) do link_to name, path end end |
#admin_record_link(record, action, options = {}) ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 196 def admin_record_link(record, action, ={}) return unless record record_title = .delete(:title) || AbAdmin.display_name(record) #url_options = {:controller => record.class.model_name.plural, :action => action, :id => record.id} action_url_part = action == :show ? '' : "/#{action}" url = "/admin/#{record.class.model_name.plural}/#{record.id}#{action_url_part}" = .delete(:html_options) || {} link_to record_title, url, end |
#admin_show_link(record, options = {}) ⇒ Object
192 193 194 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 192 def admin_show_link(record, = {}) admin_record_link(record, :show, ) end |
#auto_edit_link(rec, opts = {}) ⇒ Object
178 179 180 181 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 178 def auto_edit_link(rec, opts = {}) return if !rec || cannot?(:edit, rec) admin_edit_link(rec, opts) end |
#auto_show_link(rec, opts = {}) ⇒ Object
183 184 185 186 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 183 def auto_show_link(rec, opts = {}) return if !rec || cannot?(:read, rec) admin_show_link(rec, opts) end |
#batch_action_item(item) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 159 def batch_action_item(item) if settings[:batch] content_tag :td do check_box_tag 'ids[]', item.id, false, :id => "batch_action_item_#{item.id}" end end end |
#batch_action_toggle ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 151 def batch_action_toggle if settings[:batch] content_tag :th do check_box_tag '', '', false, :id => nil, :class => 'toggle' end end end |
#id_link(item) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 167 def id_link(item) opts = {:remote => settings[:list_edit], :class => 'resource_id_link'} if can?(:edit, item) link_to item.id, edit_resource_path(item), opts elsif can?(:read, item) link_to item.id, resource_path(item), opts else item.id end end |
#item_index_actions(item) ⇒ Object
145 146 147 148 149 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 145 def item_index_actions(item) resource_action_items.map do |act| short_action_link(act, item) end.join(' ').html_safe end |
#item_link_to_can?(act, item, *args, &block) ⇒ Boolean
105 106 107 108 109 110 111 112 113 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 105 def item_link_to_can?(act, item, *args, &block) if can?(act, get_subject) if block_given? link_to(*args, &block) else link_to(*args) end end end |
#link_to_can?(act, *args, &block) ⇒ Boolean
101 102 103 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 101 def link_to_can?(act, *args, &block) item_link_to_can?(act, get_subject, *args, &block) end |
#model_admin_menu_link(model) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 115 def (model) content_tag :li, :class => ('active' if controller_name.split('/').last == model.model_name.plural) do link_to model.model_name.human(:count => 9), "/admin/#{model.model_name.plural}" #link_to model.model_name.human(:count => 9), {:action => :index, :controller => "admin/#{model.model_name.plural}"} end end |
#order_indicator_for(order) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 44 def order_indicator_for(order) if order == 'asc' '▲' elsif order == 'desc' '▼' else '<span class="order_indicator">▲▼</div></span>' end end |
#pagination_info(c) ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 134 def pagination_info(c) offset = c.offset total_entries = c.total_entries if total_entries.zero? t('will_paginate.pagination_info_empty') else per_page = (params[:per_page] || resource_class.per_page).to_i t('will_paginate.pagination_info', :from => offset + 1, :to => [offset + per_page, total_entries].min, :count => total_entries).html_safe end end |
#search_admin_form_for(object, *args, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 5 def search_admin_form_for(object, *args, &block) params[:q] ||= {} = args. [:html] ||= {} [:html][:id] ||= 'search_form' [:html][:class] ||= 'pjax-form' [:builder] ||= ::AbAdmin::Views::SearchFormBuilder [:method] ||= :get form_for([:admin, object].flatten, *(args << ), &block) end |
#short_action_link(action, item) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 54 def short_action_link(action, item) case action when :edit item_link_to_can? :update, item, icon('pencil', true), edit_resource_path(item), :remote => settings[:list_edit], :class => 'btn btn-primary', :title => t('admin.actions.edit.link') when :destroy item_link_to_can? :destroy, item, icon('trash', true), resource_path(item, :return_to => request.url), :method => :delete, :data => {:confirm => t('admin.delete_confirmation')}, :class => 'btn btn-danger', :title => t('admin.actions.destroy.link') when :show item_link_to_can? :show, item, icon('info-sign', true), resource_path(item), :class => 'btn btn-info', :title => t('admin.actions.show.link') when :preview if path = preview_resource_path(item) link_to icon('eye-open', true), path, :class => 'btn btn-small btn-inverse', :title => t('admin.actions.preview.link'), :target => '_blank' end when AbAdmin::Config::ActionItem instance_exec(item, &action.data) if action.for_context?(self) else meth = "#{resource_instance_name}_short_action_link" send(meth, action, item) if respond_to? meth end end |
#sort_link(search, attribute, *args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ab_admin/views/admin_navigation_helpers.rb', line 16 def sort_link(search, attribute, *args) return unless search = args.first.is_a?(Hash) ? args.shift.dup : {} search_params = params[:q] || {}.with_indifferent_access attr_name = (.delete(:column) || attribute).to_s name = attribute.is_a?(Symbol) ? ha(attribute) : attribute if existing_sort = search.sorts.detect { |s| s.name == attr_name } prev_attr, prev_dir = existing_sort.name, existing_sort.dir end default_order = .delete :default_order current_dir = prev_attr == attr_name ? prev_dir : nil if current_dir new_dir = current_dir == 'desc' ? 'asc' : 'desc' else new_dir = default_order || 'asc' end = args.first.is_a?(Hash) ? args.shift.dup : {} [:class] = ['sort_link', current_dir, [:class]].compact.join(' ') .merge!(:q => search_params.merge(:s => "#{attr_name} #{new_dir}")) link_to [name, order_indicator_for(current_dir)].join(' ').html_safe, url_for(), end |