2014-07-31 09:12:57 +00:00
|
|
|
class Admin::ImagesController < OrbitAdminController
|
2014-05-05 06:07:18 +00:00
|
|
|
before_filter :setup_vars
|
2020-01-09 16:14:41 +00:00
|
|
|
def crop_process
|
|
|
|
end
|
2019-09-25 06:53:46 +00:00
|
|
|
def batch_crop
|
|
|
|
images = params['image_ids'].split(',')
|
|
|
|
@img = []
|
|
|
|
images.each do |image|
|
|
|
|
@img << AlbumImage.find(image)
|
|
|
|
end
|
|
|
|
render 'batch_crop'
|
|
|
|
end
|
|
|
|
def edit
|
|
|
|
@image = AlbumImage.find(params[:id])
|
|
|
|
render 'edit_image'
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
def show
|
|
|
|
@image = AlbumImage.find(params[:id])
|
|
|
|
@albumid = @image.album_id
|
|
|
|
@album = Album.find(@albumid)
|
2015-04-16 12:07:54 +00:00
|
|
|
@images = @album.album_images.asc(:order)
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
2015-04-16 12:07:54 +00:00
|
|
|
def changeorder
|
2015-04-16 15:10:25 +00:00
|
|
|
type = params[:type]
|
|
|
|
if type == "imgholder"
|
2022-12-03 16:26:47 +00:00
|
|
|
album = Album.find(params[:album_id]) rescue nil
|
2015-04-16 15:10:25 +00:00
|
|
|
images = params[:imageids]
|
2022-12-03 16:26:47 +00:00
|
|
|
images.each_with_index.reverse_each do |image, i|
|
2015-04-16 15:10:25 +00:00
|
|
|
img = AlbumImage.find(image) rescue nil
|
|
|
|
if !img.nil?
|
|
|
|
img.order = i
|
|
|
|
img.save
|
|
|
|
end
|
|
|
|
end
|
2022-12-03 16:26:47 +00:00
|
|
|
if album
|
|
|
|
album.update(:min_order=>-1)
|
|
|
|
end
|
2015-04-16 15:10:25 +00:00
|
|
|
elsif type == "orbit_gallery"
|
|
|
|
albums = params[:imageids]
|
2022-12-03 16:26:47 +00:00
|
|
|
albums.each_with_index.reverse_each do |albumid, i|
|
2015-04-16 15:10:25 +00:00
|
|
|
album = Album.find(albumid) rescue nil
|
|
|
|
if !album.nil?
|
|
|
|
album.order = i
|
|
|
|
album.save
|
|
|
|
end
|
2015-04-16 12:07:54 +00:00
|
|
|
end
|
2022-12-03 16:26:47 +00:00
|
|
|
AlbumSetting.update_all(:min_order=>-1)
|
2015-04-16 12:07:54 +00:00
|
|
|
end
|
|
|
|
render :json => {"success" => true}.to_json
|
|
|
|
end
|
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
def delete_photos
|
|
|
|
images = params['images']
|
|
|
|
images.each do |image|
|
|
|
|
img = AlbumImage.find(image)
|
2022-12-03 16:26:47 +00:00
|
|
|
img.destroy
|
2020-01-09 16:14:41 +00:00
|
|
|
begin
|
|
|
|
FileUtils.rm_rf(File.dirname(img.file.path))
|
|
|
|
rescue => e
|
|
|
|
puts ["can't delete",e]
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
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
|