Sha256: 7f17972dfed9d1d435a661f39cbac9536bb67a8dec7d3e376db33fb514ccd171

Contents?: true

Size: 1.99 KB

Versions: 10

Compression:

Stored size: 1.99 KB

Contents

module CamaleonCms
  module Admin
    module Appearances
      module Widgets
        class SidebarController < CamaleonCms::AdminController
          before_action :check_permission_role
          before_action :set_sidebar, only: %i[edit update destroy]

          def new
            @sidebar ||= current_site.sidebars.new
            render 'form', layout: false
          end

          def create
            @sidebar = current_site.sidebars.new(params.require(:widget_sidebar).permit!)
            if @sidebar.save
              flash[:notice] = t('camaleon_cms.admin.widgets.sidebar.created')
            else
              flash[:error] = t('camaleon_cms.admin.widgets.sidebar.error_created')
            end
            redirect_to cama_admin_appearances_widgets_main_index_path
          end

          def edit
            new
          end

          def update
            if @sidebar.update(params.require(:widget_sidebar).permit!)
              flash[:notice] = t('camaleon_cms.admin.widgets.sidebar.updated')
            else
              flash[:error] = t('camaleon_cms.admin.widgets.sidebar.error_updated')
            end
            redirect_to cama_admin_appearances_widgets_main_index_path
          end

          def reorder
            params[:pos].each_with_index do |assigned_id, index|
              if assigned_id.present?
                current_site.sidebars.find(params[:sidebar_id]).assigned.find(assigned_id).update(item_order: index)
              end
            end
            render plain: ''
          end

          def destroy
            @sidebar = @sidebar.destroy
            flash[:notice] = t('camaleon_cms.admin.widgets.sidebar.error_deleted')
            redirect_to cama_admin_appearances_widgets_main_index_path
          end

          private

          def set_sidebar
            @sidebar = current_site.sidebars.find(params[:id])
          end

          def check_permission_role
            authorize! :manage, :widgets
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
camaleon_cms-2.8.3 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.8.2 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.8.1 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.8.0 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.7.5 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.7.4 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.7.3 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.7.2 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.7.1 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb
camaleon_cms-2.7.0 app/controllers/camaleon_cms/admin/appearances/widgets/sidebar_controller.rb