2010-05-11 21:38:52 +00:00
|
|
|
module Admin
|
|
|
|
class ThemeAssetsController < BaseController
|
|
|
|
|
2010-07-22 22:10:40 +00:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
2010-06-02 14:31:01 +00:00
|
|
|
include ActionView::Helpers::TextHelper
|
2010-10-11 14:26:46 +00:00
|
|
|
include ActionView::Helpers::NumberHelper
|
2010-06-02 14:31:01 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
sections 'settings', 'theme_assets'
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-07-13 20:01:40 +00:00
|
|
|
respond_to :json, :only => [:create, :update]
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2011-02-04 09:39:23 +00:00
|
|
|
before_filter :sanitize_params, :only => [:create, :update]
|
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
def index
|
2011-07-04 17:40:14 +00:00
|
|
|
@assets = ThemeAsset.all_grouped_by_folder(current_site)
|
2010-10-07 00:45:41 +00:00
|
|
|
@js_and_css_assets = (@assets[:javascripts] || []) + (@assets[:stylesheets] || [])
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-06-02 00:39:05 +00:00
|
|
|
if request.xhr?
|
2010-12-30 14:24:47 +00:00
|
|
|
@images = @assets[:images] || []
|
2010-07-13 00:46:17 +00:00
|
|
|
render :action => 'images', :layout => false and return
|
2010-09-22 12:50:01 +00:00
|
|
|
else
|
|
|
|
@snippets = current_site.snippets.order_by([[:name, :asc]]).all.to_a
|
2010-06-02 00:39:05 +00:00
|
|
|
end
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2011-02-04 10:18:34 +00:00
|
|
|
def edit
|
|
|
|
resource.performing_plain_text = true if resource.stylesheet_or_javascript?
|
|
|
|
edit!
|
|
|
|
end
|
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
def create
|
2010-07-13 00:46:17 +00:00
|
|
|
create! do |success, failure|
|
|
|
|
success.json do
|
2010-07-22 22:10:40 +00:00
|
|
|
render :json => {
|
|
|
|
:status => 'success',
|
2010-10-11 14:26:46 +00:00
|
|
|
:url => @theme_asset.source.url,
|
|
|
|
:local_path => @theme_asset.local_path(true),
|
|
|
|
:size => number_to_human_size(@theme_asset.size),
|
|
|
|
:date => l(@theme_asset.updated_at, :format => :short)
|
2010-07-13 00:46:17 +00:00
|
|
|
}
|
2010-06-02 14:31:01 +00:00
|
|
|
end
|
2010-07-13 00:46:17 +00:00
|
|
|
failure.json { render :json => { :status => 'error' } }
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2011-02-04 09:39:23 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def sanitize_params
|
|
|
|
params[:theme_asset] = { :source => params[:file] } if params[:file]
|
|
|
|
end
|
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|