class Panel::Gallery::BackEnd::AlbumImagesController < OrbitBackendController
	include AdminHelper

	# before_filter :force_order_for_visitor,:only=>[:index]
	# before_filter :force_order_for_user#,:except => [:index]

	def show
		@tags = get_tags
		@image = GalleryImage.find(params[:id])
		@albumid = @image.gallery_album_id
		@album = GalleryAlbum.find(@albumid)
		@images = @album.gallery_images.all
	end


	def destroy
		images = params['images']
		images.each do |image|
			img = GalleryImage.find(image)
			img.delete
		end
		if params['delete_cover'] == "true"
			album = GalleryAlbum.find(params['id'])
			album.update_attributes(:cover=>"default",:cover_path => nil)
		end
		render :json =>{"success"=>true}.to_json
	end

	def update_image
		image = GalleryImage.find(params[:image_id])
		image.update_attributes(params[:gallery_image])
		image.save
		@album = GalleryAlbum.find(image.gallery_album_id.to_s)
		@images = @album.gallery_images
	    @image_content = []
	    @images.each do |image|
	      @image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tagged_ids}
	    end
	    render :json => @image_content.to_json
	end

	def delete_photos
		images = params['images']
		images.each do |image|
			img = GalleryImage.find(image)
			img.delete
		end
		if params['delete_cover'] == "true"
			album = GalleryAlbum.find(params['album_id'])
			album.update_attributes(:cover=>"default",:cover_path => nil)
		end
		render :json =>{"success"=>true}.to_json
	end

	def image_tagging
		images = params[:image_ids]
		tags = params[:tag_ids]
		i = nil
		images.each do |image|
			img = GalleryImage.find(image)
			img.tagged_ids = tags
			img.save
			i = img
		end
		@album = GalleryAlbum.find(i.gallery_album_id.to_s)
		@images = @album.gallery_images
	    @image_content = []
	    @images.each do |image|
	      @image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tagged_ids}
	    end
		render :json=>@image_content.to_json
	end

end