class Admin::AjaxController < ApplicationController
	skip_before_action :verify_authenticity_token
	
	layout "ajax"	

	def get_base_url
		@category = Category.where(:id => params[:id]).first
		render json:  { :get_base_url => @category.url  }, :status => 200
	end

	def save_image
		@image = Asset.new
		@image.image = params[:file]
		if @image.save
			render json:  { :link => @image.image.url  }
		else
			render json:  { :link => "/missing.png"  }
		end
	end

	def reorder_articles
		if !params[:article_ids].nil? && params[:article_ids].present?
			ActiveRecord::Base.transaction do
				params[:article_ids].each_with_index do |article_id,index|
					@article = Article.find(article_id)
					@article.priority = index + 1
					@article.save
				end
			end
		end
		render :reorder_articles
	end


end