Sha256: 7d929ce0464858cf8e3c099948bc08b2f3dbb82b67245a1558b893e3c5832492

Contents?: true

Size: 1.76 KB

Versions: 9

Compression:

Stored size: 1.76 KB

Contents

module Alchemy
  module Admin
    class TagsController < BaseController

      before_filter :load_tag, :only => [:edit, :update, :destroy]

      def index
        @tags = ActsAsTaggableOn::Tag.where(
          "name LIKE '%#{params[:query]}%'"
        ).page(params[:page] || 1).per(per_page_value_for_screen_size).order("name ASC")
      end

      def new
        @tag = ActsAsTaggableOn::Tag.new
        render :layout => false
      end

      def create
        @tag = ActsAsTaggableOn::Tag.create(params[:tag])
        render_errors_or_redirect @tag, admin_tags_path, _t('New Tag Created')
      end

      def edit
        @tags = ActsAsTaggableOn::Tag.order("name ASC").all - [@tag]
        render :layout => false
      end

      def update
        if params[:replace]
          @new_tag = ActsAsTaggableOn::Tag.find(params[:tag][:merge_to])
          Tag.replace(@tag, @new_tag)
          operation_text = _t('Replaced Tag %{old_tag} with %{new_tag}') % {:old_tag => @tag.name, :new_tag => @new_tag.name}
          @tag.destroy
        else
          @tag.update_attributes(params[:tag])
          @tag.save
          operation_text = _t(:successfully_updated_tag)
        end
        render_errors_or_redirect @tag, admin_tags_path, operation_text
      end

      def destroy
        if request.delete?
          @tag.destroy
          flash[:notice] = _t(:successfully_deleted_tag)
        end
        @redirect_url = admin_tags_path
        render :action => :redirect
      end

      def autocomplete
        items = ActsAsTaggableOn::Tag.where(['LOWER(name) LIKE ?', "#{params[:term].downcase}%"])
        render :json => json_for_autocomplete(items, :name)
      end

    private

      def load_tag
        @tag = ActsAsTaggableOn::Tag.find(params[:id])
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-2.5.3.1 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.3 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.2.2 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.2.1 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.2 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.1 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.0 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.0.rc3 app/controllers/alchemy/admin/tags_controller.rb
alchemy_cms-2.5.0.b9 app/controllers/alchemy/admin/tags_controller.rb