This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/assets_controller.rb

76 lines
2.5 KiB
Ruby
Raw Normal View History

2012-05-16 03:07:11 +00:00
class Admin::AssetsController < OrbitBackendController
2010-02-01 09:24:28 +00:00
def index
2012-05-16 03:07:11 +00:00
@assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.page(params[:page]).per(10)
2010-02-01 09:24:28 +00:00
end
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
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])
2012-05-16 03:07:11 +00:00
@asset_categories = AssetCategory.all
respond_to do |format|
format.html {}
format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/edit'} }
end
2010-02-01 09:24:28 +00:00
end
def create
@asset = Asset.new(params[:asset])
if @asset.save
respond_to do |format|
format.html { redirect_to admin_assets_url }
2012-05-16 03:07:11 +00:00
format.js { render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'append', :id => 'tbody_assets', :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil} }
end
2010-02-01 09:24:28 +00:00
else
respond_to do |format|
format.html { render :action => :new }
format.js { render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/new', :locals => {:is_html => false}} }
end
2010-02-01 09:24:28 +00:00
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
2010-02-01 09:24:28 +00:00
else
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
2010-02-01 09:24:28 +00:00
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
2010-02-01 09:24:28 +00:00
end
2012-05-16 03:07:11 +00:00
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
2010-02-01 09:24:28 +00:00
end