2012-05-16 03:07:11 +00:00
|
|
|
class Admin::AssetsController < OrbitBackendController
|
2013-07-02 08:46:44 +00:00
|
|
|
|
2013-12-11 10:43:38 +00:00
|
|
|
open_for_user
|
|
|
|
open_for_admin
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
before_filter :setup_vars
|
2010-02-01 09:24:28 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
def index
|
2013-12-11 10:43:38 +00:00
|
|
|
|
|
|
|
if params[:filter]
|
|
|
|
@assets = current_user.assets.where(title: /#{params[:filter]}/i)
|
|
|
|
else
|
|
|
|
@assets = current_user.assets.desc(:created_at)
|
|
|
|
end
|
|
|
|
|
2013-12-11 06:37:46 +00:00
|
|
|
if params[:type] == "image"
|
2013-09-09 15:10:04 +00:00
|
|
|
@assets = @assets.where(:content_type => /^image/)
|
|
|
|
end
|
|
|
|
@tag = ModuleTag.new
|
|
|
|
|
|
|
|
@module_app = ModuleApp.find(params[:module_app_id]) rescue nil
|
|
|
|
raise ModuleAppError, 'Can not find ModuleApp' if @module_app.nil?
|
|
|
|
@module_app_id = @module_app.id rescue nil
|
2013-12-11 06:37:46 +00:00
|
|
|
|
|
|
|
@assets = @assets.page(params[:page]).per(10)
|
2013-09-09 15:10:04 +00:00
|
|
|
|
|
|
|
render :layout => "assets"
|
2010-02-01 09:24:28 +00:00
|
|
|
end
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
def show
|
|
|
|
#TODO
|
2010-02-01 09:24:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@asset = Asset.new
|
2012-05-16 03:07:11 +00:00
|
|
|
@asset_categories = AssetCategory.all
|
2013-05-03 02:01:26 +00:00
|
|
|
@tags = get_tags
|
2011-12-28 12:49:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {}
|
|
|
|
format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/new'} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@asset = Asset.find(params[:id])
|
2013-05-03 02:01:26 +00:00
|
|
|
@tags = get_tags
|
2013-09-10 04:45:10 +00:00
|
|
|
render layout: false
|
2010-02-01 09:24:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@asset = Asset.new(params[:asset])
|
2012-07-25 21:07:32 +00:00
|
|
|
@asset.filename = @asset.title rescue nil
|
2012-05-16 22:28:29 +00:00
|
|
|
if @asset.filename && @asset.save
|
2012-08-07 09:32:15 +00:00
|
|
|
# respond_to do |format|
|
|
|
|
# format.js {
|
|
|
|
# if params[:uploader]
|
|
|
|
# render 'create'
|
|
|
|
# else
|
|
|
|
# render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil}
|
|
|
|
# end
|
|
|
|
# }
|
|
|
|
# end
|
2012-08-07 12:55:18 +00:00
|
|
|
# render :json=>{"url"=>@asset.data.url,"title"=>"xxx","desc"=>"sss"}.to_json
|
|
|
|
render :layout=>false
|
2010-02-01 09:24:28 +00:00
|
|
|
else
|
2012-09-12 11:12:50 +00:00
|
|
|
flash[:error] = t('create.fail')
|
2013-05-03 02:01:26 +00:00
|
|
|
@tags = get_tags
|
2011-12-28 12:49:53 +00:00
|
|
|
respond_to do |format|
|
2012-05-16 22:28:29 +00:00
|
|
|
format.js {
|
|
|
|
if params[:uploader]
|
|
|
|
render 'file_upload'
|
|
|
|
else
|
|
|
|
render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/new', :locals => {:is_html => false}}
|
|
|
|
end
|
|
|
|
}
|
2011-12-28 12:49:53 +00:00
|
|
|
end
|
2010-02-01 09:24:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@asset = Asset.find(params[:id])
|
|
|
|
if @asset.update_attributes(params[:asset])
|
2013-09-10 04:45:10 +00:00
|
|
|
render layout: false
|
2010-02-01 09:24:28 +00:00
|
|
|
else
|
2012-09-12 11:12:50 +00:00
|
|
|
flash[:error] = t('update.fail')
|
2013-05-03 02:01:26 +00:00
|
|
|
@tags = get_tags
|
2011-12-28 12:49:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :action => :edit }
|
2011-12-29 06:09:06 +00:00
|
|
|
format.js { render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/edit', :locals => {:is_html => false}} }
|
2011-12-28 12:49:53 +00:00
|
|
|
end
|
2010-02-01 09:24:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@asset = Asset.find(params[:id])
|
|
|
|
@asset.destroy
|
2011-12-28 12:49:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js { render 'js/remove_element', :locals => {:id => "asset_#{@asset.id}"} }
|
|
|
|
end
|
2010-02-01 09:24:28 +00:00
|
|
|
end
|
2012-05-16 03:07:11 +00:00
|
|
|
|
|
|
|
def delete
|
2012-08-13 16:59:01 +00:00
|
|
|
if params[:ids]
|
2013-02-05 10:26:45 +00:00
|
|
|
asset = Asset.any_in(:_id => params[:ids]).destroy_all
|
2012-05-16 03:07:11 +00:00
|
|
|
end
|
|
|
|
redirect_to assets_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
|
|
|
|
end
|
2012-05-16 22:28:29 +00:00
|
|
|
|
2013-09-09 15:10:04 +00:00
|
|
|
def delete_files
|
|
|
|
@files = params[:files]
|
|
|
|
@files.each do |file|
|
|
|
|
asset = Asset.find(file)
|
|
|
|
asset.destroy
|
|
|
|
end
|
|
|
|
@assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.desc(:created_at).page(params[:page]).per(10)
|
|
|
|
if params[:type] == "images"
|
|
|
|
@assets = @assets.where(:content_type => /^image/)
|
|
|
|
end
|
|
|
|
# render :json =>{"success"=>true}.to_json
|
|
|
|
end
|
|
|
|
|
2012-05-16 22:28:29 +00:00
|
|
|
def file_upload
|
2013-09-09 15:10:04 +00:00
|
|
|
@files = params['files']
|
|
|
|
a = Array.new
|
|
|
|
@files.each do |file|
|
|
|
|
@asset = current_user.assets.new
|
|
|
|
@asset.data = file
|
|
|
|
@asset.title_translations = {:en => file.original_filename, :zh_tw => file.original_filename}
|
|
|
|
# @asset.title_translations[:zh_tw] = file.original_filename
|
|
|
|
@asset.save!
|
|
|
|
a << {"url"=>@asset.data.url}
|
|
|
|
end
|
|
|
|
render :json=>{"files"=>a}.to_json
|
2012-05-16 22:28:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def file_select
|
|
|
|
@assets = Asset.all
|
|
|
|
render :layout => false
|
|
|
|
end
|
2010-02-01 09:24:28 +00:00
|
|
|
|
2012-08-31 09:54:25 +00:00
|
|
|
def check_permission
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-02-01 09:24:28 +00:00
|
|
|
end
|