Sha256: e47f4d921fca31b8f9e8ad4448bb0b6e8557f786106cc9e1006198b74ffb9148

Contents?: true

Size: 1.94 KB

Versions: 12

Compression:

Stored size: 1.94 KB

Contents

module Netzke
  module Basepack
    # An extension for {Grid} that allows specifying (multiple) action columns.
    # Example:
    #
    #     class Books < Netzke::Basepack::Grid
    #       include Netzke::Basepack::ActionColumn
    #
    #       def configure(c)
    #         c.model = "Book"
    #         super
    #       end
    #
    #       def columns
    #         super + [:basic_actions, :extra_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
    #
    #       js_configure do |c|
    #         # handler for column action 'delete_row'
    #         c.on_delete_row = <<-JS
    #           function(record){
    #             this.getSelectionModel().select(record);
    #             this.onDel();
    #           }
    #         JS
    #       end
    #     end
    module ActionColumn
      extend ActiveSupport::Concern

      included do |base|
        js_configure do |c|
          c.require :action_column
        end
      end

      # This can be optimized in order to generate less json in the column getter
      def augment_column_config(c)
        if c[:type] == :action
          c.xtype = :netzkeactioncolumn

          c[:getter] = lambda do |r|
            c.actions.map {|a| build_action_config(a)}.netzke_jsonify.to_json
          end
        end

        super
      end

    private

      def build_action_config(a)
        a = {name: a} if a.is_a?(Symbol)
        a.tap do |a|
          a[:tooltip] ||= a[:name].to_s.humanize
          a[:icon] ||= a[:name].to_sym
          a[:handler] ||= "on_#{a[:name]}"

          a[:icon] = "#{Netzke::Core.icons_uri}/#{a[:icon]}.png" if a[:icon].is_a?(Symbol)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
netzke-basepack-0.11.2 lib/netzke/basepack/action_column.rb
netzke-basepack-0.11.1 lib/netzke/basepack/action_column.rb
netzke-basepack-0.12.0.beta lib/netzke/basepack/action_column.rb
netzke-basepack-0.11.0 lib/netzke/basepack/action_column.rb
netzke-basepack-0.10.1 lib/netzke/basepack/action_column.rb
netzke-basepack-0.10.0 lib/netzke/basepack/action_column.rb
netzke-basepack-0.9.0 lib/netzke/basepack/action_column.rb
netzke-basepack-0.10.0.rc2 lib/netzke/basepack/action_column.rb
netzke-basepack-0.9.0.rc1 lib/netzke/basepack/action_column.rb
netzke-basepack-0.8.4 lib/netzke/basepack/action_column.rb
netzke-basepack-0.8.3 lib/netzke/basepack/action_column.rb
netzke-basepack-0.8.2 lib/netzke/basepack/action_column.rb