Sha256: b4fcf0ce835158eea4d067578f84e02b1f989677cf344d98561567d50835c526

Contents?: true

Size: 1.97 KB

Versions: 7

Compression:

Stored size: 1.97 KB

Contents

require_dependency "storytime/application_controller"

module Storytime
  module Dashboard
    class NavigationsController < DashboardController
      respond_to :json, only: :destroy

      def index
        authorize current_storytime_site, :manage?
        @navigations = Navigation.includes(:links)
      end

      def new
        authorize current_storytime_site, :manage?
        @navigation = Navigation.new
      end

      def create
        authorize current_storytime_site, :manage?
        @navigation = Navigation.new(navigation_params)

        respond_to do |format|
          if @navigation.save
            format.html { redirect_to [storytime, :edit, :dashboard, @navigation], notice: t('dashboard.navigations.create.success') }
          else
            format.html { render :new }
          end
        end
      end

      def edit
        authorize current_storytime_site, :manage?
        @navigation = Navigation.find(params[:id])
      end

      def update
        authorize current_storytime_site, :manage?
        @navigation = Navigation.find(params[:id])

        respond_to do |format|
          if @navigation.update(navigation_params)
            format.html { redirect_to [storytime, :edit, :dashboard, @navigation], notice: t('dashboard.navigations.update.success') }
          else
            format.html { render :edit }
          end
        end
      end

      def destroy
        authorize current_storytime_site, :manage?
        @navigation = Navigation.find(params[:id])
        @navigation.destroy
        flash[:notice] = I18n.t('flash.navigations.destroy.success') unless request.xhr?
        
        respond_with [:dashboard, @navigation] do |format|
          format.html{ redirect_to url_for([:dashboard, Storytime::Navigation]) }
        end
      end

    private
      def navigation_params
        params.require(:navigation).permit(:name, :handle, links_attributes: [:id, :text, :url, :linkable_type, :linkable_id, :_destroy])
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
storytime-2.1.6 app/controllers/storytime/dashboard/navigations_controller.rb
storytime-2.1.5 app/controllers/storytime/dashboard/navigations_controller.rb
storytime-2.1.4 app/controllers/storytime/dashboard/navigations_controller.rb
storytime-2.1.3 app/controllers/storytime/dashboard/navigations_controller.rb
storytime-2.1.2 app/controllers/storytime/dashboard/navigations_controller.rb
storytime-2.1.1 app/controllers/storytime/dashboard/navigations_controller.rb
storytime-2.1.0 app/controllers/storytime/dashboard/navigations_controller.rb