Class: AdminAssistant::Index::View
- Inherits:
-
Object
- Object
- AdminAssistant::Index::View
- Defined in:
- lib/admin_assistant/index.rb
Instance Method Summary collapse
- #ajax_toggle_allowed? ⇒ Boolean
- #columns ⇒ Object
- #delete_link(record) ⇒ Object
- #destroy? ⇒ Boolean
- #edit? ⇒ Boolean
- #edit_link(record) ⇒ Object
- #header ⇒ Object
-
#initialize(index, action_view, admin_assistant) ⇒ View
constructor
A new instance of View.
- #multi_form? ⇒ Boolean
- #new? ⇒ Boolean
- #new_link ⇒ Object
- #render_after_index_header ⇒ Object
- #render_delete_link?(record) ⇒ Boolean
- #render_edit_link?(record) ⇒ Boolean
- #render_new_link? ⇒ Boolean
- #render_search_link? ⇒ Boolean
- #render_show_link?(record) ⇒ Boolean
- #right_column? ⇒ Boolean
- #right_column_lambdas ⇒ Object
- #right_column_links(record) ⇒ Object
- #show? ⇒ Boolean
- #show_link(record) ⇒ Object
- #tr_css_classes(record) ⇒ Object
Constructor Details
#initialize(index, action_view, admin_assistant) ⇒ View
Returns a new instance of View.
187 188 189 190 |
# File 'lib/admin_assistant/index.rb', line 187 def initialize(index, action_view, admin_assistant) @index, @action_view, @admin_assistant = index, action_view, admin_assistant end |
Instance Method Details
#ajax_toggle_allowed? ⇒ Boolean
200 201 202 |
# File 'lib/admin_assistant/index.rb', line 200 def ajax_toggle_allowed? @admin_assistant.update? end |
#columns ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/admin_assistant/index.rb', line 204 def columns unless @columns @columns = @index.columns.map { |c| c.index_view @action_view, @admin_assistant, :index => @index } end @columns end |
#delete_link(record) ⇒ Object
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/admin_assistant/index.rb', line 213 def delete_link(record) @action_view.link_to( 'Delete', {:action => 'destroy', :id => record.id}, { 'data-confirm' => 'Are you sure?', :rel => 'nofollow', 'data-method' => 'delete', :class => 'destroy' } ) end |
#destroy? ⇒ Boolean
224 225 226 |
# File 'lib/admin_assistant/index.rb', line 224 def destroy? @destroy ||= @admin_assistant.destroy? end |
#edit? ⇒ Boolean
228 229 230 |
# File 'lib/admin_assistant/index.rb', line 228 def edit? @edit ||= @admin_assistant.edit? end |
#edit_link(record) ⇒ Object
232 233 234 |
# File 'lib/admin_assistant/index.rb', line 232 def edit_link(record) @action_view.link_to 'Edit', :action => 'edit', :id => record.id end |
#header ⇒ Object
240 241 242 243 244 245 246 |
# File 'lib/admin_assistant/index.rb', line 240 def header if block = @index.settings.header block.call @action_view.params else @admin_assistant.model_class_name.pluralize.capitalize end end |
#multi_form? ⇒ Boolean
248 249 250 |
# File 'lib/admin_assistant/index.rb', line 248 def multi_form? @admin_assistant.form_settings.multi? end |
#new? ⇒ Boolean
236 237 238 |
# File 'lib/admin_assistant/index.rb', line 236 def new? @new ||= @admin_assistant.new? end |
#new_link ⇒ Object
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/admin_assistant/index.rb', line 252 def new_link new_link_name = if multi_form? "New #{@admin_assistant.model_class_name.pluralize}" else "New #{@admin_assistant.model_class_name}" end @action_view.link_to( new_link_name, @admin_assistant.url_params(:new) ) end |
#render_after_index_header ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/admin_assistant/index.rb', line 192 def render_after_index_header slug = "_after_index_header.html.erb" abs_template_file = File.join( Rails.root, 'app/views', @admin_assistant.controller_class.controller_path, slug ) if File.exist?(abs_template_file) @action_view.render :file => abs_template_file end end |
#render_delete_link?(record) ⇒ Boolean
316 317 318 319 |
# File 'lib/admin_assistant/index.rb', line 316 def render_delete_link?(record) return false if @action_view.respond_to?(:link_to_delete_in_index?) && !@action_view.link_to_delete_in_index?(record) destroy? end |
#render_edit_link?(record) ⇒ Boolean
311 312 313 314 |
# File 'lib/admin_assistant/index.rb', line 311 def render_edit_link?(record) return false if @action_view.respond_to?(:link_to_edit_in_index?) && !@action_view.link_to_edit_in_index?(record) edit? end |
#render_new_link? ⇒ Boolean
301 302 303 304 |
# File 'lib/admin_assistant/index.rb', line 301 def render_new_link? return false if @action_view.respond_to?(:link_to_new_in_index?) && !@action_view.link_to_new_in_index? new? end |
#render_search_link? ⇒ Boolean
306 307 308 309 |
# File 'lib/admin_assistant/index.rb', line 306 def render_search_link? return false if @action_view.respond_to?(:link_to_search_in_index?) && !@action_view.link_to_search_in_index? true end |
#render_show_link?(record) ⇒ Boolean
321 322 323 324 |
# File 'lib/admin_assistant/index.rb', line 321 def render_show_link?(record) return false if @action_view.respond_to?(:link_to_show_in_index?) && !@action_view.link_to_show_in_index?(record) show? end |
#right_column? ⇒ Boolean
263 264 265 |
# File 'lib/admin_assistant/index.rb', line 263 def right_column? edit? or destroy? or show? or !right_column_lambdas.empty? or @action_view.respond_to?(:extra_right_column_links_for_index) end |
#right_column_lambdas ⇒ Object
267 268 269 270 |
# File 'lib/admin_assistant/index.rb', line 267 def right_column_lambdas @right_column_lambdas ||= @admin_assistant.index_settings.right_column_links end |
#right_column_links(record) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/admin_assistant/index.rb', line 272 def right_column_links(record) links = [] links << edit_link(record) if render_edit_link?(record) links << delete_link(record) if render_delete_link?(record) if render_show_link?(record) links << @action_view.link_to( 'Show', :action => 'show', :id => record.id ) end right_column_lambdas.each do |lambda| link_args = lambda.call record links << @action_view.link_to(*link_args) end if @action_view.respond_to?(:extra_right_column_links_for_index) links << @action_view.extra_right_column_links_for_index( record ) end links.join(" ") end |
#show? ⇒ Boolean
326 327 328 |
# File 'lib/admin_assistant/index.rb', line 326 def show? @show ||= @admin_assistant.show? end |
#show_link(record) ⇒ Object
330 331 332 |
# File 'lib/admin_assistant/index.rb', line 330 def show_link(record) @action_view.link_to 'Show', :action => 'show', :id => record.id end |
#tr_css_classes(record) ⇒ Object
293 294 295 296 297 298 299 |
# File 'lib/admin_assistant/index.rb', line 293 def tr_css_classes(record) css_classes = [@action_view.cycle('odd', 'even')] if @action_view.respond_to?(:css_class_for_index_tr) css_classes << @action_view.css_class_for_index_tr(record) end css_classes.join(' ') end |