Sha256: 67f51fd066bbd71629fac472f71611cf411054cb803628e11bf2aebce87d3d44

Contents?: true

Size: 1.42 KB

Versions: 14

Compression:

Stored size: 1.42 KB

Contents

module Locomotive
  module CustomFields
    class SelectOptionsController < BaseController

      account_required & within_site

      localized

      before_filter :load_content_type
      before_filter :load_custom_field

      def edit
        respond_with @custom_field
      end

      def update
        @options = service.update_select_options(options_params)
        respond_with @custom_field, location: -> { last_saved_location!(default_back_location) }
      end

      def new_option
        if params[:select_option].present?
          option = @custom_field.select_options.build(name: option_name_param)
          render partial: 'option', locals: { select_option: option }
        else
          head :unprocessable_entity
        end
      end

      private

      def load_content_type
        @content_type ||= current_site.content_types.where(slug: params[:slug]).first
      end

      def load_custom_field
        @custom_field = @content_type.entries_custom_fields.where(name: params[:name]).first
      end

      def service
        @service ||= Locomotive::CustomFieldService.new(@custom_field)
      end

      def options_params
        params.require(:select_options).map { |p| p.permit(:_id, :name, :_destroy) }
      end

      def option_name_param
        params.require(:select_option)
      end

      def default_back_location
        content_entries_path(current_site, @content_type.slug)
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
locomotivecms-3.3.0 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.3.0.rc3 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.3.0.rc2 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.1.2 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.2.1 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.3.0.rc1 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.2.0 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.2.0.rc2 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.2.0.rc1 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.1.1 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.1.0 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.1.0.rc3 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.1.0.rc2 app/controllers/locomotive/custom_fields/select_options_controller.rb
locomotivecms-3.1.0.rc1 app/controllers/locomotive/custom_fields/select_options_controller.rb