Sha256: 9922df2db3809ace87cbb389c74c9ce13a81348a311ed16ae9e70694ef8882be

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

# coding: utf-8
class Admin::SidebarController < Admin::BaseController
  def index
    @available = SidebarRegistry.available_sidebars
    @ordered_sidebars = Sidebar.ordered_sidebars
  end

  # Just update a single active Sidebar instance at once
  def update
    @sidebar = Sidebar.where(id: params[:id]).first
    @old_s_index = @sidebar.staged_position || @sidebar.active_position
    @sidebar.update_attributes params[:configure][@sidebar.id.to_s].permit!
    respond_to do |format|
      format.js
      format.html do
        return redirect_to(admin_sidebar_index_path)
      end
    end
  end

  def destroy
    @sidebar = Sidebar.where(id: params[:id]).first
    @sidebar && @sidebar.destroy
    respond_to do |format|
      format.html { return redirect_to(admin_sidebar_index_path) }
      format.js
    end
  end

  def publish
    Sidebar.apply_staging_on_active!
    redirect_to admin_sidebar_index_path
  end

  # Callback for admin sidebar sortable plugin
  def sortable
    sorted = params[:sidebar].map(&:to_i)

    Sidebar.transaction do
      sorted.each_with_index do |sidebar_id, staged_index|
        # DEV NOTE : Ok, that's a HUGE hack. Sidebar.available are Class, not
        # Sidebar instances. In order to use jQuery.sortable we need that hack:
        # Sidebar.available is an Array, so it's ordered. I arbitrary shift by?
        # IT'S OVER NINE THOUSAND! considering we'll never reach 9K Sidebar
        # instances or Sidebar specializations
        sidebar = if sidebar_id >= 9000
                    SidebarRegistry.available_sidebars[sidebar_id - 9000].new(blog: this_blog)
                  else
                    Sidebar.valid.find(sidebar_id)
                  end
        sidebar.update_attributes(staged_position: staged_index)
      end
    end

    @ordered_sidebars = Sidebar.ordered_sidebars
    @available = SidebarRegistry.available_sidebars

    respond_to do |format|
      format.js
      format.html do
        return redirect_to admin_sidebar_index_path
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
publify_core-9.0.0.pre6 app/controllers/admin/sidebar_controller.rb
publify_core-9.0.0.pre5 app/controllers/admin/sidebar_controller.rb
publify_core-9.0.0.pre4 app/controllers/admin/sidebar_controller.rb
publify_core-9.0.0.pre3 app/controllers/admin/sidebar_controller.rb