Class: ActiveList::Definition::ActionColumn
- Inherits:
-
AbstractColumn
- Object
- AbstractColumn
- ActiveList::Definition::ActionColumn
- Includes:
- Helpers
- Defined in:
- lib/active_list/definition/action_column.rb
Constant Summary collapse
- ID_PLACEHOLDER =
'##IDS##'.freeze
- USE_MODES =
i[none single many both].freeze
Instance Attribute Summary collapse
-
#use_mode ⇒ Object
readonly
Returns the value of attribute use_mode.
Attributes inherited from AbstractColumn
#condition, #id, #name, #options, #table
Instance Method Summary collapse
- #default_url(use_mode = :many) ⇒ Object
- #global? ⇒ Boolean
- #header_code ⇒ Object
-
#initialize(table, name, options = {}) ⇒ ActionColumn
constructor
A new instance of ActionColumn.
- #operation(record = 'record_of_the_death') ⇒ Object
- #use_many? ⇒ Boolean
- #use_none? ⇒ Boolean
- #use_single? ⇒ Boolean
Methods included from Helpers
#recordify, #recordify!, #urlify
Methods inherited from AbstractColumn
#check_options!, #computable?, #exportable?, #hidden?, #short_id, #sortable?, #unique_id
Constructor Details
#initialize(table, name, options = {}) ⇒ ActionColumn
Returns a new instance of ActionColumn.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_list/definition/action_column.rb', line 14 def initialize(table, name, = {}) super(table, name, ) @use_mode = (.delete(:on) || :single).to_sym unless USE_MODES.include?(@use_mode) raise "Invalid use mode: #{@use_mode.inspect}" end if @name.to_s == 'destroy' && !.key?(:method) [:method] = :delete end if @name.to_s == 'destroy' && !.key?(:confirm) [:confirm] ||= :are_you_sure_you_want_to_delete end [:if] ||= :destroyable? if @name.to_s == 'destroy' [:if] ||= :editable? if @name.to_s == 'edit' [:confirm] = :are_you_sure if [:confirm].is_a?(TrueClass) end |
Instance Attribute Details
#use_mode ⇒ Object (readonly)
Returns the value of attribute use_mode.
12 13 14 |
# File 'lib/active_list/definition/action_column.rb', line 12 def use_mode @use_mode end |
Instance Method Details
#default_url(use_mode = :many) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/active_list/definition/action_column.rb', line 51 def default_url(use_mode = :many) url = [:url] ||= {} url[:controller] ||= ([:controller] || table.model.name.tableize) url[:action] ||= @name.to_s url[:format] = [:format] if .key? :format url[:id] ||= ID_PLACEHOLDER if use_many? && use_mode == :many url end |
#global? ⇒ Boolean
43 44 45 |
# File 'lib/active_list/definition/action_column.rb', line 43 def global? use_none? || use_many? end |
#header_code ⇒ Object
47 48 49 |
# File 'lib/active_list/definition/action_column.rb', line 47 def header_code "''".c end |
#operation(record = 'record_of_the_death') ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_list/definition/action_column.rb', line 60 def operation(record = 'record_of_the_death') = '' if [:confirm] << ", 'data-confirm' => #{(@options[:confirm]).inspect}.t(scope: 'labels')" end if [:method] << ", method: :#{@options[:method].to_s.underscore}" end action = @name format = [:format] ? ", format: '#{@options[:format]}'" : '' if [:remote] raise StandardError, 'Sure to use :remote ?' # remote_options = @options.dup # remote_options['data-confirm'] = "#{@options[:confirm].inspect}.tl".c unless @options[:confirm].nil? # remote_options.delete :remote # remote_options.delete :image # remote_options = remote_options.inspect.to_s # remote_options = remote_options[1..-2] # code = "link_to_remote(#{image}" # code += ", {url: {action: "[email protected]_s+", id: "+record+".id"+format+"}" # code += ", "+remote_options+"}" # code += ", {title: #{action.inspect}.tl}" # code += ")" elsif [:actions] unless use_single? raise StandardError, 'Only compatible with single actions' end unless [:actions].is_a? Hash raise StandardError, ':actions parameter have to be a Hash.' end cases = [] for expected, url in [:actions] url[:id] ||= 'RECORD.id'.c url[:id] = 'RECORD.id'.c if url[:id] == ID_PLACEHOLDER url[:redirect] ||= 'params[:redirect]'.c url.delete_if { |_k, v| v.nil? } cases << "#{record}.#{@name} == #{expected.inspect}\nlink_to(content_tag(:i) + h(#{url[:action].inspect}.t(scope: 'rest.actions'))"\ ', {' + url.collect { |k, v| "#{k}: " + urlify(k, v, record) }.join(', ') + format + '}' \ ", {class: '#{@options[:icon_name] || @name}'" + + '}'\ ")\n" end code = 'if ' + cases.join('elsif ') + 'end' else url = [:url] ||= {} url[:controller] ||= ([:controller] || 'RECORD.class.name.tableize'.c) url[:action] ||= @name.to_s url[:id] ||= 'RECORD.id'.c url[:id] = 'RECORD.id'.c if url[:id] == ID_PLACEHOLDER url[:redirect] ||= 'params[:redirect]'.c url.delete_if { |_k, v| v.nil? } url = '{' + url.collect { |k, v| "#{k}: " + urlify(k, v, record) }.join(', ') + format + '}' code = "{class: '#{@options[:icon_name] || @name}'" + + '}' code = "link_to(content_tag(:i) + h(' ' + :#{action}.t(scope: 'rest.actions')), " + url + ', ' + code + ')' end if [:if] code = 'if ' + recordify!([:if], record) + "\n" + code.dig + 'end' end if [:unless] code = 'unless ' + recordify!([:unless], record) + "\n" + code.dig + 'end' end code.c end |
#use_many? ⇒ Boolean
35 36 37 |
# File 'lib/active_list/definition/action_column.rb', line 35 def use_many? @use_mode == :many || @use_mode == :both end |
#use_none? ⇒ Boolean
39 40 41 |
# File 'lib/active_list/definition/action_column.rb', line 39 def use_none? @use_mode == :none end |
#use_single? ⇒ Boolean
31 32 33 |
# File 'lib/active_list/definition/action_column.rb', line 31 def use_single? @use_mode == :single || @use_mode == :both end |