Sha256: 8eecc8fb73a3b6a0e19d96887098ce0a505cb273cc11ce1593d4fe21f831b0e9

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

module Netzke
  module Basepack
    # When mixed into a component with resizable layout (e.g. border layout), this module enables persistence for regions size and collapsed/expanded state.
    module ItemPersistence
      extend ActiveSupport::Concern

      included do
        # this plugins does the job of assigning resize/collapse events for the component
        plugin :events_plugin do |c|
          c.klass = EventsPlugin
        end

        # Added endpoints
        endpoint :region_resized do |params|
          state[:"#{params[:item]}_width"] = params[:width].to_i if params[:width]
          state[:"#{params[:item]}_height"] = params[:height].to_i if params[:height]
        end

        endpoint :region_collapsed do |params|
          state[:"#{params[:item]}_collapsed"] = true
        end

        endpoint :region_expanded do |params|
          state[:"#{params[:item]}_collapsed"] = false
        end
      end

      def extend_item(item)
        item = super
        item_id = item[:netzke_component] || item[:item_id] # identify regions by item_id

        if item_id
          item[:width] = state[:"#{item_id}_width"] if state[:"#{item_id}_width"]
          item[:height] = state[:"#{item_id}_height"] if state[:"#{item_id}_height"]
          if state[:"#{item_id}_collapsed"].present?
            item[:collapsed] = state[:"#{item_id}_collapsed"]
          end
        end

        item
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
netzke-basepack-6.5.0.0.rc1 lib/netzke/basepack/item_persistence.rb
netzke-basepack-1.0.1.0 lib/netzke/basepack/item_persistence.rb
netzke-basepack-1.0.0.1 lib/netzke/basepack/item_persistence.rb
netzke-basepack-1.0.0.0 lib/netzke/basepack/item_persistence.rb
netzke-basepack-1.0.0.0.pre3 lib/netzke/basepack/item_persistence.rb
netzke-basepack-1.0.0.0.pre2 lib/netzke/basepack/item_persistence.rb
netzke-basepack-1.0.0.0.pre lib/netzke/basepack/item_persistence.rb