Class: ActiveList::Definition::ActionColumn
- Inherits:
-
AbstractColumn
- Object
- AbstractColumn
- ActiveList::Definition::ActionColumn
- Includes:
- Helpers
- Defined in:
- lib/active_list/definition/action_column.rb
Instance Attribute Summary
Attributes inherited from AbstractColumn
Instance Method Summary collapse
Methods included from Helpers
#recordify, #recordify!, #urlify
Methods inherited from AbstractColumn
#check_options!, #exportable?, #hidden?, #initialize, #short_id, #sortable?, #unique_id
Constructor Details
This class inherits a constructor from ActiveList::Definition::AbstractColumn
Instance Method Details
#header_code ⇒ Object
9 10 11 |
# File 'lib/active_list/definition/action_column.rb', line 9 def header_code "''".c end |
#operation(record = 'record_of_the_death') ⇒ Object
13 14 15 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/active_list/definition/action_column.rb', line 13 def operation(record = 'record_of_the_death') @options[:method] = :delete if @name.to_s == "destroy" and !@options.has_key?(:method) @options[:confirm] ||= :are_you_sure_you_want_to_delete if @name.to_s == "destroy" and !@options.has_key?(:confirm) @options[:if] ||= :destroyable? if @name.to_s == "destroy" @options[:if] ||= :editable? if @name.to_s == "edit" @options[:confirm] = :are_you_sure if @options[:confirm].is_a?(TrueClass) = "" if @options[:confirm] << ", 'data-confirm' => #{(@options[:confirm]).inspect}.t(scope: 'labels')" end if @options['data-method'] or @options[:method] << ", :method => h('#{(@options['data-method']||@options[:method])}')" end action = @name format = @options[:format] ? ", :format => '#{@options[:format]}'" : "" if @options[: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 @options[:actions] unless @options[:actions].is_a? Hash raise StandardError, "options[:actions] have to be a Hash." end cases = [] for expected, url in @options[:actions] cases << record+"."+@name.to_s+" == " + expected.inspect + "\nlink_to(content_tag(:i) + h(#{url[:action].inspect}.t(scope: 'labels'))"+ ", {"+(url[:controller] ? 'controller: :'+url[:controller].to_s+', ' : '')+"action: '"+url[:action].to_s+"', id: "+record+".id"+format+"}"+ ", {:class => '#{@name}'"++"}"+ ")\n" end code = "if "+cases.join("elsif ")+"end" else url = @options[:url] ||= {} url[:controller] ||= (@options[:controller] || "RECORD.class.name.tableize".c) # self.table.model.name.underscore.pluralize.to_s url[:action] ||= @name.to_s url[:id] ||= "RECORD.id".c url.delete_if{|k, v| v.nil?} url = "{" + url.collect{|k, v| "#{k}: " + urlify(v, record)}.join(", ")+format+"}" code = "{class: '#{@name}'"++"}" code = "link_to(content_tag(:i) + h('#{action}'.t(scope: 'labels')), "+url+", "+code+")" end if @options[:if] code = "if " + recordify!(@options[:if], record) + "\n" + code.dig + "end" end if @options[:unless] code = "unless " + recordify!(@options[:unless], record) + "\n" + code.dig + "end" end code.c end |