Sha256: 0ddb6c0dd7e0a0a2f83f4a12422362146c2b4601822db9606d2268673c7bf568

Contents?: true

Size: 1.24 KB

Versions: 28

Compression:

Stored size: 1.24 KB

Contents

module Avo
  module Concerns
    module HasResourceStimulusControllers
      extend ActiveSupport::Concern

      included do
        class_attribute :stimulus_controllers, default: ""
      end

      def get_stimulus_controllers
        return "" if @view.nil?

        controllers = []

        case @view.to_sym
        when :show
          controllers << "resource-show"
        when :new, :edit
          controllers << "resource-edit"
        when :index
          controllers << "resource-index record-selector"
        end

        controllers << self.class.stimulus_controllers

        controllers.reject(&:blank?).join " "
      end

      def stimulus_data_attributes
        attributes = {
          controller: get_stimulus_controllers,
        }

        get_stimulus_controllers.split(" ").each do |controller|
          attributes["#{controller}-view-value"] = @view
        end

        attributes
      end

      def add_stimulus_attributes_for(entity, attributes, target_name = nil)
        entity.get_stimulus_controllers.split(" ").each do |controller|
          attributes["#{controller}-target"] = target_name || "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
avo-3.18.1.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.18.1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.18.0.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.18.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.9.beta2 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.9.beta1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.9.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.9 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.8.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.8 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.7 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.6.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.6 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.5 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.3 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.5.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.4.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.3.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.17.2.tw4 lib/avo/concerns/has_resource_stimulus_controllers.rb