Sha256: 5ce41567d96c0d4f56f298f9329356df76d4e2873e2e2eae16af67f0102e56b3

Contents?: true

Size: 1.55 KB

Versions: 88

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Alchemy
  module Admin
    class LanguagesController < ResourcesController
      before_action :load_current_site, only: %i[index new]

      def index
        @query = Language.on_site(@current_site).ransack(search_filter_params[:q])
        @query.sorts = default_sort_order if @query.sorts.empty?
        @languages = @query.result.page(params[:page] || 1).per(items_per_page)
      end

      def new
        @language = Language.new(
          site: @current_site,
          page_layout: Config.get(:default_language)["page_layout"],
        )
      end

      def create
        @language = Alchemy::Language.new(resource_params)
        if @language.save
          flash[:notice] = Alchemy.t("Language successfully created")
          redirect_to alchemy.admin_pages_path(language_id: @language)
        else
          render :new
        end
      end

      def destroy
        if @language.destroy
          flash[:notice] = Alchemy.t("Language successfully removed")
        else
          flash[:warning] = @language.errors.full_messages.to_sentence
        end
        do_redirect_to alchemy.admin_languages_path
      end

      def switch
        set_alchemy_language(params[:language_id])
        do_redirect_to request.referer || alchemy.admin_dashboard_path
      end

      private

      def load_current_site
        @current_site = Alchemy::Site.current
        if @current_site.nil?
          flash[:warning] = Alchemy.t("Please create a site first.")
          redirect_to admin_sites_path
        end
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
alchemy_cms-6.1.10 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.9 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.8 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.7 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.6 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.5 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.0.14 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.4 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-7.0.0.pre.a app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.0.13 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.3 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.2 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.1 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.1.0 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.0.12 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.0.11 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.0.10 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-5.3.8 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-6.0.9 app/controllers/alchemy/admin/languages_controller.rb
alchemy_cms-5.3.7 app/controllers/alchemy/admin/languages_controller.rb