107 lines
3.1 KiB
Ruby
107 lines
3.1 KiB
Ruby
class Admin::AssetsController < OrbitBackendController
|
|
|
|
def index
|
|
@assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.page(params[:page]).per(10)
|
|
end
|
|
|
|
def show
|
|
#TODO
|
|
end
|
|
|
|
def new
|
|
@asset = Asset.new
|
|
@asset_categories = AssetCategory.all
|
|
@tags = AssetTag.all
|
|
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])
|
|
@asset_categories = AssetCategory.all
|
|
@tags = AssetTag.all
|
|
respond_to do |format|
|
|
format.html {}
|
|
format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/edit'} }
|
|
end
|
|
end
|
|
|
|
def create
|
|
@asset = Asset.new(params[:asset])
|
|
@asset.filename = @asset.title[I18n.locale] rescue nil
|
|
if @asset.filename && @asset.save
|
|
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
|
|
else
|
|
flash[:error] = t(:create_fail)
|
|
@asset_categories = AssetCategory.all
|
|
@tags = AssetTag.all
|
|
respond_to do |format|
|
|
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
|
|
}
|
|
end
|
|
end
|
|
end
|
|
|
|
def update
|
|
@asset = Asset.find(params[:id])
|
|
if @asset.update_attributes(params[:asset])
|
|
respond_to do |format|
|
|
format.html { redirect_to admin_assets_url }
|
|
format.js { 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
|
|
else
|
|
flash[:error] = t(:update_fail)
|
|
@asset_categories = AssetCategory.all
|
|
@tags = AssetTag.all
|
|
respond_to do |format|
|
|
format.html { render :action => :edit }
|
|
format.js { render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/edit', :locals => {:is_html => false}} }
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
def destroy
|
|
@asset = Asset.find(params[:id])
|
|
@asset.destroy
|
|
respond_to do |format|
|
|
format.js { render 'js/remove_element', :locals => {:id => "asset_#{@asset.id}"} }
|
|
end
|
|
end
|
|
|
|
def delete
|
|
if params[:to_delete]
|
|
asset = Asset.any_in(:_id => params[:to_delete]).delete_all
|
|
end
|
|
redirect_to assets_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
|
|
end
|
|
|
|
def file_upload
|
|
@asset = Asset.new
|
|
@asset_categories = AssetCategory.all
|
|
@tags = AssetTag.all
|
|
render :layout => false
|
|
end
|
|
|
|
def file_select
|
|
@assets = Asset.all
|
|
render :layout => false
|
|
end
|
|
|
|
end
|