add query parameter to temporarily disable customization

This commit is contained in:
Régis Hanol 2013-11-12 18:13:17 +01:00
parent e25cf580d6
commit e9f9d22482
7 changed files with 81 additions and 63 deletions

View file

@ -8,52 +8,56 @@
**/
Discourse.AdminCustomizeController = Ember.ArrayController.extend({
/**
Create a new customization style
actions: {
@method newCustomization
**/
newCustomization: function() {
var item = Discourse.SiteCustomization.create({name: I18n.t("admin.customize.new_style")});
this.pushObject(item);
this.set('selectedItem', item);
},
/**
Create a new customization style
/**
Select a given style
@method newCustomization
**/
newCustomization: function() {
var item = Discourse.SiteCustomization.create({name: I18n.t("admin.customize.new_style")});
this.pushObject(item);
this.set('selectedItem', item);
},
@method selectStyle
@param {Discourse.SiteCustomization} style The style we are selecting
**/
selectStyle: function(style) {
this.set('selectedItem', style);
},
/**
Select a given style
/**
Save the current customization
@method selectStyle
@param {Discourse.SiteCustomization} style The style we are selecting
**/
selectStyle: function(style) {
this.set('selectedItem', style);
},
@method save
**/
save: function() {
this.get('selectedItem').save();
},
/**
Save the current customization
/**
Destroy the current customization
@method save
**/
save: function() {
this.get('selectedItem').save();
},
/**
Destroy the current customization
@method destroy
**/
destroy: function() {
var _this = this;
return bootbox.confirm(I18n.t("admin.customize.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
var selected;
if (result) {
selected = _this.get('selectedItem');
selected.destroy();
_this.set('selectedItem', null);
return _this.removeObject(selected);
}
});
}
@method destroy
**/
destroy: function() {
var _this = this;
return bootbox.confirm(I18n.t("admin.customize.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
var selected;
if (result) {
selected = _this.get('selectedItem');
selected.destroy();
_this.set('selectedItem', null);
return _this.removeObject(selected);
}
});
}
});

View file

@ -1,5 +1,7 @@
class Admin::SiteCustomizationsController < Admin::AdminController
before_filter :enable_customization
def index
@site_customizations = SiteCustomization.all
@ -56,4 +58,8 @@ class Admin::SiteCustomizationsController < Admin::AdminController
StaffActionLogger.new(current_user).log_site_customization_change(old_record, new_params)
end
def enable_customization
session[:disable_customization] = false
end
end

View file

@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base
before_filter :set_mobile_view
before_filter :inject_preview_style
before_filter :disable_customization
before_filter :block_if_maintenance_mode
before_filter :authorize_mini_profiler
before_filter :store_incoming_links
@ -36,8 +37,10 @@ class ApplicationController < ActionController::Base
before_filter :redirect_to_login_if_required
rescue_from Exception do |exception|
unless [ ActiveRecord::RecordNotFound, ActionController::RoutingError,
ActionController::UnknownController, AbstractController::ActionNotFound].include? exception.class
unless [ActiveRecord::RecordNotFound,
ActionController::RoutingError,
ActionController::UnknownController,
AbstractController::ActionNotFound].include? exception.class
begin
ErrorLog.report_async!(exception, self, request, current_user)
rescue
@ -121,12 +124,15 @@ class ApplicationController < ActionController::Base
session[:mobile_view] = params[:mobile_view] if params.has_key?(:mobile_view)
end
def inject_preview_style
style = request['preview-style']
session[:preview_style] = style if style
end
def disable_customization
session[:disable_customization] = params[:customization] == "0" if params.has_key?(:customization)
end
def guardian
@guardian ||= Guardian.new(current_user)
end

View file

@ -22,9 +22,8 @@ class SiteCustomization < ActiveRecord::Base
error.gsub!("'", '\27 ')
self.send("#{stylesheet_attr}_baked=",
"#main {display: none;}
footer {white-space: pre; margin-left: 100px;}
footer:after{ content: '#{error}' }")
"footer { white-space: pre; }
footer:after { content: '#{error}' }")
end
end
end

View file

@ -10,4 +10,6 @@
<%= stylesheet_link_tag "admin"%>
<%-end%>
<%= SiteCustomization.custom_stylesheet(session[:preview_style], mobile_view? ? :mobile : :desktop) %>
<%- unless session[:disable_customization] %>
<%= SiteCustomization.custom_stylesheet(session[:preview_style], mobile_view? ? :mobile : :desktop) %>
<%- end %>

View file

@ -31,7 +31,10 @@
<body>
<!--[if IE 9]><script type="text/javascript">ie = "new";</script><![endif]-->
<%= SiteCustomization.custom_header(session[:preview_style], mobile_view? ? :mobile : :desktop) %>
<%- unless session[:disable_customization] %>
<%= SiteCustomization.custom_header(session[:preview_style], mobile_view? ? :mobile : :desktop) %>
<%- end %>
<section id='main'>
</section>
@ -57,6 +60,7 @@
<footer id='bottom'></footer>
<%= render :partial => "common/discourse_javascript" %>
<%= render_google_analytics_code %>
<noscript data-path="<%= request.env['PATH_INFO'] %>">

View file

@ -7,33 +7,30 @@
<meta content="" name="description">
<meta content="" name="author">
<link rel="icon" type="image/png" href=<%=SiteSetting.favicon_url%>>
<%= render :partial => "common/special_font_face" %>
<%= render :partial => "common/discourse_stylesheet" %>
<%= discourse_csrf_tags %>
</head>
<body>
<%=SiteCustomization.custom_header(session[:preview_style])%>
<%- unless session[:disable_customization] %>
<%= SiteCustomization.custom_header(session[:preview_style]) %>
<%- end %>
<section id='main'>
<header class="d-header">
<div class="container">
<div class="contents">
<div class="row">
<div class="title span13">
<a href="/"><img src="<%=SiteSetting.logo_url%>" alt="<%=SiteSetting.title%>" id="site-logo"></a>
<header class="d-header">
<div class="container">
<div class="contents">
<div class="row">
<div class="title span13">
<a href="/"><img src="<%=SiteSetting.logo_url%>" alt="<%=SiteSetting.title%>" id="site-logo"></a>
</div>
</div>
</div>
</div>
</header>
<div id="main-outlet" class="container">
<%= yield %>
</div>
</header>
<div id="main-outlet" class="container">
<%= yield %>
</div>
</section>
<footer id='bottom'>
</footer>
</body>