Sha256: 7e958180dddb7030565be07081ea18bb43260d25332c7f563b269156dfa18603

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

module Netzke
  module Basepack
    # An extension for {Grid} that allows specifying (multiple) action columns.
    # Example:
    #
    #     class Books < Netzke::Grid::Base
    #       include Netzke::Basepack::ActionColumn
    #
    #       def configure(c)
    #         c.model = "Book"
    #         super
    #       end
    #
    #       def columns
    #         super + [:actions]
    #       end
    #
    #       column :actions do |c|
    #         c.type = :action
    #         c.actions = [
    #           # default handler will be on_delete_row
    #           {name: :delete_row, tooltip: "Delete row", icon: :delete}
    #
    #           # feel free to define more actions in this column
    #         ]
    #       end
    #
    #       client_class do |c|
    #         # handler for column action 'delete_row'
    #         c.on_delete_row = l(<<-JS)
    #           function(record){
    #             this.getSelectionModel().select(record);
    #             this.onDel();
    #           }
    #         JS
    #       end
    #     end
    module ActionColumn
      extend ActiveSupport::Concern

      def augment_column_config(c)
        super
        if c.type == :action
          c.xtype = :actioncolumn
          c.items = c.actions.map {|a| build_action_config(a)}.netzke_jsonify
        end
      end

    private

      def build_action_config(a)
        a = {name: a} if a.is_a?(Symbol)
        a[:handler] ||= a[:name]
        a.tap do |a|
          a[:tooltip] ||= a[:name].to_s.humanize
          a[:icon] ||= a[:name].to_sym
          a[:passed_handler] = a[:handler].to_s.camelize
          a[:handler] = f(:netzke_on_column_action)
          a[:icon] = "#{Netzke::Core.icons_uri}/#{a[:icon]}.png" if a[:icon].is_a?(Symbol)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
netzke-basepack-6.5.0.0 lib/netzke/basepack/action_column.rb
netzke-basepack-6.5.0.0.rc2 lib/netzke/basepack/action_column.rb
netzke-basepack-6.5.0.0.rc1 lib/netzke/basepack/action_column.rb
netzke-basepack-1.0.1.0 lib/netzke/basepack/action_column.rb
netzke-basepack-1.0.0.1 lib/netzke/basepack/action_column.rb
netzke-basepack-1.0.0.0 lib/netzke/basepack/action_column.rb
netzke-basepack-1.0.0.0.pre3 lib/netzke/basepack/action_column.rb