Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix on_action when yielding a block

have to pass params to the control links.
Fix row control links
  • Loading branch information...
commit 4f1974d57624ce62c25d75a9cc01bd8d1b134654 1 parent 0db792d
Aaron Quint authored

Showing 2 changed files with 33 additions and 20 deletions. Show diff stats Hide diff stats

  1. +11 3 lib/qadmin/configuration.rb
  2. +22 17 lib/qadmin/helper.rb
14 lib/qadmin/configuration.rb
@@ -75,6 +75,10 @@ def model_column_names
75 75 []
76 76 end
77 77
  78 + def inspect
  79 + "#<#{self.class} #{super}>"
  80 + end
  81 +
78 82 protected
79 83 def extract_model_from_options(options = {})
80 84 self.controller_klass = options[:controller_klass]
@@ -149,9 +153,13 @@ class Resource < Base
149 153 ACTIONS.each do |action|
150 154 hash_accessor "on_#{action}"
151 155
152   - define_method("on_#{action}") do
153   - self["on_#{action}"] ||= "Qadmin::Configuration::Actions::#{action.to_s.classify}".constantize.new(self.dup.merge(:base => self))
154   - end
  156 + module_eval <<-EOV
  157 + def on_#{action}
  158 + value = self["on_#{action}"] ||= "Qadmin::Configuration::Actions::#{action.to_s.classify}".constantize.new(self.dup.merge(:base => self))
  159 + yield value if block_given?
  160 + value
  161 + end
  162 + EOV
155 163 end
156 164
157 165 end
39 lib/qadmin/helper.rb
... ... @@ -1,18 +1,18 @@
1 1 module Qadmin
2 2 module Helper
3 3
4   - def control_links(more_links={})
  4 + def control_links(more_links = {})
5 5 {
6   - :index => lambda { link_to(image_tag('qadmin/icon_list.png') + " Back to List", general_link_attributes.merge(:action => 'index')) },
7   - :new => lambda { link_to(image_tag('qadmin/icon_new.png') + " New", general_link_attributes.merge(:action => 'new')) },
8   - :edit => lambda { link_to(image_tag('qadmin/icon_edit.png') + " Edit", general_link_attributes.merge({:action => 'edit', :id => obj.id})) },
9   - :show => lambda { link_to(image_tag('qadmin/icon_show.png') + " View", general_link_attributes.merge({:action => 'show', :id => obj.id})) },
10   - :destroy => lambda { link_to(image_tag('qadmin/icon_destroy.png') + " Delete", general_link_attributes.merge({:action => 'destroy', :id => obj.id}), :confirm => 'Are you sure?', :method => :delete) },
11   - :ports => lambda { link_to(image_tag('qadmin/icon_export.png') + " Import/Export", general_link_attributes.merge(:action => 'ports')) },
12   - :export => lambda { link_to(image_tag('qadmin/icon_export.png') + " Export", general_link_attributes.merge(:action => 'export')) },
13   - :preview => lambda { link_to(image_tag('qadmin/icon_preview.png') + " Preview", general_link_attributes.merge({:action => 'preview', :id => obj.id})) },
14   - :sort => lambda { link_to(image_tag('qadmin/icon_sort.png') + " Sort", general_link_attributes.merge({:action => 'sort'})) }
15   - }.merge(more_links)
  6 + :index => lambda {|params| link_to(image_tag('qadmin/icon_list.png') + " Back to List", params.merge(:action => 'index')) },
  7 + :new => lambda {|params| link_to(image_tag('qadmin/icon_new.png') + " New", params.merge(:action => 'new')) },
  8 + :edit => lambda {|params| link_to(image_tag('qadmin/icon_edit.png') + " Edit", params.merge({:action => 'edit', :id => obj.id})) },
  9 + :show => lambda {|params| link_to(image_tag('qadmin/icon_show.png') + " View", params.merge({:action => 'show', :id => obj.id})) },
  10 + :destroy => lambda {|params| link_to(image_tag('qadmin/icon_destroy.png') + " Delete", params.merge({:action => 'destroy', :id => obj.id}), :confirm => 'Are you sure?', :method => :delete) },
  11 + :ports => lambda {|params| link_to(image_tag('qadmin/icon_export.png') + " Import/Export", params.merge(:action => 'ports')) },
  12 + :export => lambda {|params| link_to(image_tag('qadmin/icon_export.png') + " Export", params.merge(:action => 'export')) },
  13 + :preview => lambda {|params| link_to(image_tag('qadmin/icon_preview.png') + " Preview", params.merge({:action => 'preview', :id => obj.id})) },
  14 + :sort => lambda {|params| link_to(image_tag('qadmin/icon_sort.png') + " Sort", params.merge({:action => 'sort'})) }
  15 + }.merge(more_links || {})
16 16 end
17 17
18 18 def admin_controls(name, options = {}, &block)
@@ -23,8 +23,8 @@ def admin_controls(name, options = {}, &block)
23 23 obj = options[:object] || assumed_object || nil
24 24 parent = options[:parent] || false
25 25
26   - parent_link_attributes = parent ? {parent.class.to_s.foreign_key => parent.id} : {}
27   - general_link_attributes = {:controller => controller}.merge(parent_link_attributes)
  26 + parent_link_params = parent ? {parent.class.to_s.foreign_key => parent.id} : {}
  27 + general_link_params = {:controller => controller}.merge(parent_link_params)
28 28
29 29 control_sets = {
30 30 :index => [:new],
@@ -43,7 +43,7 @@ def admin_controls(name, options = {}, &block)
43 43 html = ""
44 44 html << %{<ul class="admin_controls">}
45 45 controls.each do |control|
46   - control_html = control.respond_to?(:call) ? control.call : control
  46 + control_html = control.respond_to?(:call) ? control.call(params) : control
47 47 html << li(control_html)
48 48 end
49 49 if block_given?
@@ -81,19 +81,24 @@ def model_restful_query_parser(options = {})
81 81 qadmin_configuration.model_klass.restful_query_parser(params[query_param], options)
82 82 end
83 83
84   - def row_control_links(more_links={})
  84 + def row_control_links(more_links = {})
85 85 {
86 86 :destroy => lambda { |obj| link_to(image_tag("qadmin/icon_destroy.png"), {:action => 'destroy', :id => obj.id}, :confirm => 'Are you sure?', :method => :delete)},
87 87 :edit => lambda { |obj| link_to(image_tag('qadmin/icon_edit.png'), {:action => 'edit', :id => obj.id}) },
88 88 :show => lambda { |obj| link_to(image_tag('qadmin/icon_show.png'), {:action => 'show', :id => obj.id}) },
89   - }.merge(more_links)
  89 + :preview => lambda { |obj| link_to(image_tag('qadmin/icon_preview.png'), {:action => 'preview', :id => obj.id}) }
  90 + }.merge(more_links || {})
90 91 end
91 92
92 93 def admin_table(collection, options = {})
93 94 config = self.qadmin_configuration.on_index
  95 +
94 96 controller = params[:controller] || options[:controller] || config.controller_name
95 97 attributes = options[:attributes] || config.columns
96   -
  98 +
  99 + logger.debug "columns: #{attributes.inspect}"
  100 +
  101 +
97 102 row_control_sets = {
98 103 :index => [:show,:edit,:destroy]
99 104 }

0 comments on commit 4f1974d

Please sign in to comment.
Something went wrong with that request. Please try again.