From a4875f22149369a107573d9a8a77c5ab191dd2d7 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sun, 17 Dec 2017 11:43:18 +0800 Subject: [PATCH] Add basic theme support to custom wizards --- .../discourse/models/custom-wizard.js.es6 | 3 ++- .../discourse/routes/admin-wizard.js.es6 | 13 +++++++++++++ .../discourse/templates/admin-wizard.hbs | 9 +++++++++ config/locales/client.en.yml | 2 ++ controllers/wizard.rb | 10 +++++++++- views/layouts/wizard.html.erb | 4 ++++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index 3bedce15..5c09ace1 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -10,7 +10,8 @@ const wizardProperties = [ 'after_time_scheduled', 'required', 'prompt_completion', - 'min_trust' + 'min_trust', + 'theme_key' ]; const CustomWizard = Discourse.Model.extend({ diff --git a/assets/javascripts/discourse/routes/admin-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizard.js.es6 index 31e84a7e..aeba38b0 100644 --- a/assets/javascripts/discourse/routes/admin-wizard.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizard.js.es6 @@ -31,10 +31,23 @@ export default Discourse.Route.extend({ }, afterModel(model) { + return Ember.RSVP.all([ + this._getFieldTypes(model), + this._getThemes(model) + ]); + }, + + _getFieldTypes(model) { return ajax('/admin/wizards/field-types') .then((result) => model.set('fieldTypes', result.types)); }, + _getThemes(model) { + return this.store.findAll('theme').then((result) => { + model.set('themes', result.content); + }); + }, + setupController(controller, model) { const newWizard = this.get('newWizard'); const steps = model.get('steps') || []; diff --git a/assets/javascripts/discourse/templates/admin-wizard.hbs b/assets/javascripts/discourse/templates/admin-wizard.hbs index 56da962e..c4de31a0 100644 --- a/assets/javascripts/discourse/templates/admin-wizard.hbs +++ b/assets/javascripts/discourse/templates/admin-wizard.hbs @@ -102,6 +102,15 @@ +
+
+

{{i18n 'admin.wizard.theme_key'}}

+
+
+ {{combo-box content=model.themes valueAttribute='key' value=model.theme_key none='admin.wizard.no_theme'}} +
+
+

{{i18n 'admin.wizard.url'}}

diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index b199ba95..dabb5c98 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -34,6 +34,8 @@ en: prompt_completion_label: "Prompt user to complete wizard." min_trust: "Trust" min_trust_label: "Trust level required to access wizard." + theme_key: "Theme" + no_theme: "Select a Theme (optional)" save: "Save Changes" remove: "Delete Wizard" header: "Wizard" diff --git a/controllers/wizard.rb b/controllers/wizard.rb index 7cd157ec..f236d772 100644 --- a/controllers/wizard.rb +++ b/controllers/wizard.rb @@ -4,12 +4,20 @@ class CustomWizard::WizardController < ::ApplicationController before_action :ensure_logged_in helper_method :wizard_page_title + helper_method :theme_key + + def wizard + PluginStore.get('custom_wizard', params[:wizard_id].underscore) + end def wizard_page_title - wizard = PluginStore.get('custom_wizard', params[:wizard_id].underscore) wizard ? (wizard['name'] || wizard['id']) : I18n.t('wizard.custom_title') end + def theme_key + wizard['theme_key'] + end + def index respond_to do |format| format.json do diff --git a/views/layouts/wizard.html.erb b/views/layouts/wizard.html.erb index 6a45e6bf..e3ba81f2 100644 --- a/views/layouts/wizard.html.erb +++ b/views/layouts/wizard.html.erb @@ -3,6 +3,9 @@ <%= discourse_stylesheet_link_tag :wizard, theme_key: nil %> <%= stylesheet_link_tag "wizard_custom", media: "all", "data-turbolinks-track" => "reload" %> <%= stylesheet_link_tag "wizard_custom_mobile", media: "all", "data-turbolinks-track" => "reload" if mobile_view?%> + <%- if theme_key %> + <%= discourse_stylesheet_link_tag (mobile_view? ? :mobile_theme : :desktop_theme) %> + <%- end %> <%= preload_script "ember_jquery" %> <%= preload_script "wizard-vendor" %> <%= preload_script "wizard-application" %> @@ -17,6 +20,7 @@ <%= server_plugin_outlet "custom_wizard" %> + <%= render partial: "layouts/head" %>