Sha256: a698fc83f4e9424667346e4a95f3ec39c59caf44766dd6daea0adf72a80c65a4

Contents?: true

Size: 1.62 KB

Versions: 45

Compression:

Stored size: 1.62 KB

Contents

class Backend::PagesController < Backend::BaseController
  include Concerns::Backend::TranslatableController

  before_action :find_model, except: [:index, :new, :create]
  before_action -> { breadcrumb.add t('b.pages'), backend_pages_path }

  def index
    @pages = Page.all

    respond_to do |format|
      format.html
      format.json {
        render json: Udongo::Pages::Tree.new(self).data
      }
    end
  end

  def new
    @model = Page.new.decorate
  end

  def create
    @model = Page.new(allowed_params).decorate

    if @model.save
      redirect_to edit_backend_page_path(@model), notice: translate_notice(:added, :page)
    else
      render :new
    end
  end

  def update
    if @model.update_attributes allowed_params
      redirect_to edit_backend_page_path(@model), notice: translate_notice(:edited, :page)
    else
      render :edit
    end
  end

  def toggle_visibility
    @model.visible? ? @model.hide! : @model.show!
    render json: { toggled: @model }
  end

  def tree_drag_and_drop
    # TODO (Dave) - check if this page is draggable.
    render json: { moved: @model.set_position(params[:position], params[:parent_id]) }
  end

  def destroy
    # TODO (Dave) - check if this page may be destroyed.
    render json: { trashed: @model.destroy }
  end

  private

  def find_model
    @model = Page.find(params[:id]).decorate
  end

  def allowed_params
    params[:page].permit(:description, :parent_id, :visible, :sitemap)
  end

  def translation_form
    Backend::PageTranslationForm.new(
      @model,
      @model.translation(params[:translation_locale]),
      @model.seo(params[:translation_locale])
    )
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
udongo-7.9.0 app/controllers/backend/pages_controller.rb
udongo-7.8.1 app/controllers/backend/pages_controller.rb
udongo-7.8.0 app/controllers/backend/pages_controller.rb
udongo-7.7.2 app/controllers/backend/pages_controller.rb
udongo-7.7.1 app/controllers/backend/pages_controller.rb
udongo-7.7.0 app/controllers/backend/pages_controller.rb
udongo-7.6.2 app/controllers/backend/pages_controller.rb
udongo-7.6.1 app/controllers/backend/pages_controller.rb
udongo-7.6.0 app/controllers/backend/pages_controller.rb
udongo-7.5.1 app/controllers/backend/pages_controller.rb
udongo-7.5.0 app/controllers/backend/pages_controller.rb
udongo-7.4.2 app/controllers/backend/pages_controller.rb
udongo-7.4.1 app/controllers/backend/pages_controller.rb
udongo-7.4.0 app/controllers/backend/pages_controller.rb
udongo-7.3.5 app/controllers/backend/pages_controller.rb
udongo-7.3.4 app/controllers/backend/pages_controller.rb
udongo-7.3.3 app/controllers/backend/pages_controller.rb
udongo-7.3.2 app/controllers/backend/pages_controller.rb
udongo-7.3.1 app/controllers/backend/pages_controller.rb
udongo-7.2.1 app/controllers/backend/pages_controller.rb