Sha256: 13491767681eb48146ed6aebf40f1502126eaa60739b89400e27175a087e6457

Contents?: true

Size: 1.51 KB

Versions: 10

Compression:

Stored size: 1.51 KB

Contents

module Kuhsaft
  module Cms
    class BricksController < AdminController
      respond_to :html, :js

      def create
        @brick = params[:brick][:type].constantize.create(brick_params)
        @brick.image_size = ImageSize.all.first.name.to_s

        if @brick.valid?
          respond_with @brick do |format|
            format.js
            format.html { redirect_to edit_cms_page_path(@brick.parents.first) }
          end
        else
          render 'new'
        end
      end

      def new
        @brick = Kuhsaft::Brick.new(brick_params)
      end

      def update
        @brick = Kuhsaft::Brick.find(params[:id])
        @brick.update_attributes(brick_params)

        #
        # rails will fall back to html if ajax can't be used
        # this is the case with the image brick, because ajax does not
        # support image uploads
        #
        respond_with @brick do |format|
          format.js
          format.html { redirect_to edit_cms_page_path(@brick.parents.first) }
        end
      end

      def destroy
        @brick = Kuhsaft::Brick.find(params[:id])
        @parent_brick = @brick.brick_list
        @brick.destroy
      end

      def sort
        if params[:bricks].present?
          params[:bricks][:ids].split(',').each_with_index do |id, idx|
            Kuhsaft::Brick.find(id).update_attribute(:position, idx.to_i + 1)
          end
        end
        render nothing: true
      end

      private

      def brick_params
        params.require(:brick).permit!
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kuhsaft-2.4.2 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.4.1 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.4.0 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.3.6 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.3.5 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.3.4 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.3.3 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.3.2 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.3.1 app/controllers/kuhsaft/cms/bricks_controller.rb
kuhsaft-2.3.0 app/controllers/kuhsaft/cms/bricks_controller.rb