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
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
def index
|
2010-10-10 21:59:56 +00:00
|
|
|
@assets = current_site.theme_assets.visible(params[:all]).order_by([[:slug, :asc]])
|
|
|
|
@assets = @assets.group_by { |a| a.folder.split('/').first.to_sym }
|
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-10-11 14:26:46 +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
|
|
|
|
2010-10-10 14:37: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-06-02 14:31:01 +00:00
|
|
|
params[:theme_asset] = { :source => params[:file] } if params[:file]
|
2010-07-22 22:10:40 +00:00
|
|
|
|
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
|
|
|
|
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
|