2010-05-11 21:38:52 +00:00
|
|
|
module Admin
|
|
|
|
class ThemeAssetsController < BaseController
|
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
sections 'settings', 'theme_assets'
|
|
|
|
|
|
|
|
def index
|
|
|
|
assets = current_site.theme_assets.all
|
|
|
|
@non_image_assets = assets.find_all { |a| a.stylesheet? || a.javascript? }
|
|
|
|
@image_assets = assets.find_all { |a| a.image? }
|
2010-07-06 00:05:47 +00:00
|
|
|
@flash_assets = assets.find_all { |a| a.movie? }
|
2010-06-02 00:39:05 +00:00
|
|
|
|
|
|
|
if request.xhr?
|
|
|
|
render :action => 'images', :layout => false
|
|
|
|
end
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@asset = current_site.theme_assets.build
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@asset = current_site.theme_assets.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2010-06-02 14:31:01 +00:00
|
|
|
params[:theme_asset] = { :source => params[:file] } if params[:file]
|
2010-06-02 00:39:05 +00:00
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
@asset = current_site.theme_assets.build(params[:theme_asset])
|
2010-06-02 00:39:05 +00:00
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
respond_to do |format|
|
|
|
|
if @asset.save
|
|
|
|
format.html do
|
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_theme_asset_url(@asset)
|
|
|
|
end
|
|
|
|
format.json do
|
|
|
|
render :json => {
|
|
|
|
:status => 'success',
|
|
|
|
:name => truncate(@asset.slug, :length => 22),
|
|
|
|
:url => @asset.source.url,
|
|
|
|
:vignette_url => @asset.vignette_url
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
format.html do
|
|
|
|
flash_error!
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
format.json do
|
|
|
|
render :json => { :status => 'error' }
|
|
|
|
end
|
|
|
|
end
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@asset = current_site.theme_assets.find(params[:id])
|
|
|
|
|
|
|
|
if @asset.update_attributes(params[:theme_asset])
|
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_theme_asset_url(@asset)
|
|
|
|
else
|
|
|
|
flash_error!
|
|
|
|
render :action => 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@asset = current_site.theme_assets.find(params[:id])
|
|
|
|
@asset.destroy
|
|
|
|
|
|
|
|
flash_success!
|
|
|
|
redirect_to admin_theme_assets_url
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|