88 lines
2.2 KiB
Ruby
88 lines
2.2 KiB
Ruby
class Admin::ImagesController < OrbitAdminController
|
|
before_filter :setup_vars
|
|
def show
|
|
@image = AlbumImage.find(params[:id])
|
|
@albumid = @image.album_id
|
|
@album = Album.find(@albumid)
|
|
@images = @album.album_images.asc(:order)
|
|
end
|
|
|
|
def changeorder
|
|
type = params[:type]
|
|
if type == "imgholder"
|
|
images = params[:imageids]
|
|
images.each_with_index do |image, i|
|
|
img = AlbumImage.find(image) rescue nil
|
|
if !img.nil?
|
|
img.order = i
|
|
img.save
|
|
end
|
|
end
|
|
elsif type == "orbit_gallery"
|
|
albums = params[:imageids]
|
|
albums.each_with_index do |albumid, i|
|
|
album = Album.find(albumid) rescue nil
|
|
if !album.nil?
|
|
album.order = i
|
|
album.save
|
|
end
|
|
end
|
|
end
|
|
render :json => {"success" => true}.to_json
|
|
end
|
|
|
|
def delete_photos
|
|
images = params['images']
|
|
images.each do |image|
|
|
img = AlbumImage.find(image)
|
|
img.delete
|
|
end
|
|
if params['delete_cover'] == "true"
|
|
album = Album.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 = AlbumImage.find(image)
|
|
img.tags = tags
|
|
img.save
|
|
i = img
|
|
end
|
|
@album = Album.find(i.album_id.to_s)
|
|
@images = @album.album_images
|
|
@image_content = []
|
|
@images.each do |image|
|
|
@image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}}
|
|
end
|
|
render :json=>{"galleries" => @image_content}.to_json
|
|
end
|
|
|
|
def update_image
|
|
image = AlbumImage.find(params[:image_id])
|
|
image.update_attributes(update_params)
|
|
image.save!
|
|
@album = Album.find(image.album_id.to_s)
|
|
@images = @album.album_images
|
|
@image_content = []
|
|
@images.each do |image|
|
|
@image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}}
|
|
end
|
|
render :json=>{"galleries" => @image_content}.to_json
|
|
end
|
|
|
|
private
|
|
|
|
def setup_vars
|
|
@module_app = ModuleApp.where(:key=>"gallery").first
|
|
end
|
|
|
|
def update_params
|
|
params.require(:album_image).permit!
|
|
end
|
|
end |