0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00
Dieser Commit ist enthalten in:
Angus McLeod 2017-10-09 13:52:09 +08:00
Ursprung a43f4b1344
Commit dd26ac63af
16 geänderte Dateien mit 146 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -7,7 +7,7 @@ class CustomWizard::AdminController < ::ApplicationController
end end
def field_types def field_types
render json: { types: CustomWizard::FieldTypes.all } render json: { types: CustomWizard::Field.types }
end end
def save def save

Datei anzeigen

@ -2,15 +2,19 @@
<head> <head>
<link href="<%= Discourse.base_uri %>/plugins/discourse-custom-wizard/desktop.css" media="all" rel="stylesheet" data-target="desktop" type="text/css" /> <link href="<%= Discourse.base_uri %>/plugins/discourse-custom-wizard/desktop.css" media="all" rel="stylesheet" data-target="desktop" type="text/css" />
<%= discourse_stylesheet_link_tag :wizard, theme_key: nil %> <%= discourse_stylesheet_link_tag :wizard, theme_key: nil %>
<%= discourse_stylesheet_link_tag(mobile_view? ? :mobile : :desktop) %>
<%= preload_script "ember_jquery" %> <%= preload_script "ember_jquery" %>
<%= preload_script "wizard-vendor" %> <%= preload_script "wizard-vendor" %>
<%= preload_script "wizard-application" %> <%= preload_script "wizard-application" %>
<%= preload_script "wizard-custom" %> <%= preload_script "wizard-custom" %>
<%= preload_script "wizard-plugin" %>
<%= preload_script "locales/#{I18n.locale}" %> <%= preload_script "locales/#{I18n.locale}" %>
<%= render partial: "common/special_font_face" %> <%= render partial: "common/special_font_face" %>
<script src="<%= Discourse.base_uri %>/extra-locales/wizard"></script> <script src="<%= Discourse.base_uri %>/extra-locales/wizard"></script>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
<%= server_plugin_outlet "custom_wizard" %>
<meta name="discourse-base-uri" content="<%= Discourse.base_uri %>"> <meta name="discourse-base-uri" content="<%= Discourse.base_uri %>">
<%= render partial: "layouts/head" %> <%= render partial: "layouts/head" %>

Datei anzeigen

@ -123,6 +123,7 @@ CustomWizard.reopenClass({
props['id'] = w.id; props['id'] = w.id;
props['name'] = w.name; props['name'] = w.name;
props['background'] = w.background; props['background'] = w.background;
props['save_submissions'] = w.save_submissions;
if (w.steps) { if (w.steps) {
w.steps.forEach((s) => { w.steps.forEach((s) => {

Datei anzeigen

@ -6,7 +6,7 @@ export default Discourse.Route.extend({
if (params.wizard_id === 'new') { if (params.wizard_id === 'new') {
this.set('newWizard', true); this.set('newWizard', true);
return CustomWizard.create(); return CustomWizard.create();
} };
this.set('newWizard', false); this.set('newWizard', false);
const wizard = this.modelFor('admin-wizards-custom').findBy('id', params.wizard_id.underscore()); const wizard = this.modelFor('admin-wizards-custom').findBy('id', params.wizard_id.underscore());

Datei anzeigen

@ -1,6 +1,13 @@
//= require ./wizard/custom-wizard //= require ./wizard/custom-wizard
//= require_tree ./wizard/components
//= require_tree ./wizard/controllers //= require_tree ./wizard/controllers
//= require_tree ./wizard/helpers
//= require_tree ./wizard/initializers //= require_tree ./wizard/initializers
//= require_tree ./wizard/models //= require_tree ./wizard/models
//= require_tree ./wizard/routes //= require_tree ./wizard/routes
//= require_tree ./wizard/templates //= require_tree ./wizard/templates
//= require lodash.js
window.Wizard = {};
Wizard.SiteSettings = {};

Datei anzeigen

@ -0,0 +1,17 @@
// loads files for plugins that have been added via CustomWizard::Field
<%
Discourse.unofficial_plugins.each do |plugin|
plugin_name = plugin.metadata.name
if require_plugin_assets = CustomWizard::Field.require_assets[plugin_name]
plugin.each_globbed_asset do |f, is_dir|
if require_plugin_assets.any? { |dir| f.include?(dir) }
if is_dir
depend_on(f)
else
require_asset(f)
end
end
end
end
end
%>

Datei anzeigen

@ -0,0 +1,28 @@
import { observes } from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNames: 'wizard-field-composer',
keyPress(e) {
e.stopPropagation();
},
@observes('field.value')
validate() {
const minLength = Wizard.SiteSettings.min_post_length;
const post = this.get('field.value');
const field = this.get('field');
field.set('customValidation', true);
if (!post) {
return field.setValid(false);
}
if (minLength && post.length < minLength) {
return field.setValid(false, I18n.t('wizard.validation.too_short', { min: minLength }));
}
field.setValid(true);
}
});

Datei anzeigen

@ -0,0 +1,15 @@
import { htmlHelper } from 'discourse-common/lib/helpers';
function renderSpinner(cssClass) {
var html = "<div class='spinner";
if (cssClass) { html += ' ' + cssClass; }
return html + "'></div>";
}
var spinnerHTML = renderSpinner();
export default htmlHelper(params => {
const hash = params.hash;
return renderSpinner((hash && hash.size) ? hash.size : undefined);
});
export { spinnerHTML, renderSpinner };

Datei anzeigen

@ -12,6 +12,7 @@ export default {
const StepModel = requirejs('wizard/models/step').default; const StepModel = requirejs('wizard/models/step').default;
const WizardStep = requirejs('wizard/components/wizard-step').default; const WizardStep = requirejs('wizard/components/wizard-step').default;
const getUrl = requirejs('discourse-common/lib/get-url').default; const getUrl = requirejs('discourse-common/lib/get-url').default;
const FieldModel = requirejs('wizard/models/wizard-field').default;
Router.map(function() { Router.map(function() {
this.route('custom', { path: '/custom/:id' }, function() { this.route('custom', { path: '/custom/:id' }, function() {
@ -26,16 +27,23 @@ export default {
}, },
afterModel(model) { afterModel(model) {
return ajax({ return Ember.RSVP.hash({
info: ajax({
url: `/site/basic-info`, url: `/site/basic-info`,
type: 'GET', type: 'GET',
}).then((result) => { }).then((result) => {
return model.set('siteInfo', result); return model.set('siteInfo', result);
}),
settings: ajax({
url: `/site/settings`,
type: 'GET',
}).then((result) => {
Object.assign(Wizard.SiteSettings, result);
})
}); });
}, },
setupController(controller, model) { setupController(controller, model) {
console.log(model)
Ember.run.scheduleOnce('afterRender', this, function(){ Ember.run.scheduleOnce('afterRender', this, function(){
$('body.custom-wizard').css('background', model.get('background')); $('body.custom-wizard').css('background', model.get('background'));
}); });
@ -106,5 +114,25 @@ export default {
} }
} }
}); });
FieldModel.reopen({
check() {
let valid = this.get('valid');
if (!this.get('required')) {
this.setValid(true);
return true;
}
if (!this.get('customValidation')) {
const val = this.get('value');
valid = val && val.length > 0;
this.setValid(valid);
}
return valid;
}
});
} }
}; };

Datei anzeigen

@ -0,0 +1 @@
{{textarea elementId=field.id value=field.value placeholder=field.placeholder tabindex="9"}}

Datei anzeigen

@ -81,3 +81,8 @@
display: inline-block; display: inline-block;
overflow: scroll; overflow: scroll;
} }
.wizard-field-composer textarea {
width: 100%;
min-height: 150px;
}

Datei anzeigen

@ -18,6 +18,7 @@ en:
add: "Add" add: "Add"
url: "Url" url: "Url"
translation: "Translation" translation: "Translation"
step: step:
header: "Steps" header: "Steps"
title: "Title" title: "Title"
@ -27,6 +28,7 @@ en:
description: "Description" description: "Description"
description_placeholder: "Overrides description translation" description_placeholder: "Overrides description translation"
translation_placeholder: "Translation key for step" translation_placeholder: "Translation key for step"
field: field:
header: "Fields" header: "Fields"
label: "Label" label: "Label"
@ -37,6 +39,7 @@ en:
required: "Required" required: "Required"
required_label: "Field is Required" required_label: "Field is Required"
translation_placeholder: "Translation key for field" translation_placeholder: "Translation key for field"
action: action:
header: "Actions" header: "Actions"
label: "Label" label: "Label"
@ -56,3 +59,8 @@ en:
field: "Profile Field" field: "Profile Field"
save_input: save_input:
label: "Save Input" label: "Save Input"
wizard_js:
wizard:
validation:
too_short: "Post must be at least {{min}} characters"

Datei anzeigen

@ -56,7 +56,7 @@ class CustomWizard::Builder
input = updater.fields input = updater.fields
user = @wizard.user user = @wizard.user
if @wizard.save_submissions if @wizard.save_submissions && input
store_key = @wizard.id store_key = @wizard.id
submissions = Array.wrap(PluginStore.get("custom_wizard_submissions", store_key)) submissions = Array.wrap(PluginStore.get("custom_wizard_submissions", store_key))
submission = {} submission = {}

19
lib/field.rb Normale Datei
Datei anzeigen

@ -0,0 +1,19 @@
class CustomWizard::Field
def self.types
@types ||= ['dropdown', 'image', 'radio', 'text', 'textarea', 'composer']
end
def self.require_assets
@require_assets ||= {}
end
def self.add_assets(type, plugin = nil, asset_paths = [])
if type
types.push(*type)
end
if plugin && asset_paths
require_assets[plugin] = asset_paths
end
end
end

Datei anzeigen

@ -1,11 +1,13 @@
class CustomWizard::Wizard class CustomWizard::Wizard
attr_reader :id, :name, :steps, :custom attr_reader :id, :name, :steps, :background, :save_submissions, :custom
def initialize(data) def initialize(data)
data = data.is_a?(String) ? ::JSON.parse(data) : data data = data.is_a?(String) ? ::JSON.parse(data) : data
@id = data['id'] @id = data['id']
@name = data['name'] @name = data['name']
@background = data['background']
@save_submissions = data['save_submissions']
@steps = data['steps'] @steps = data['steps']
@custom = true @custom = true
end end

Datei anzeigen

@ -18,6 +18,7 @@ after_initialize do
end end
load File.expand_path('../lib/builder.rb', __FILE__) load File.expand_path('../lib/builder.rb', __FILE__)
load File.expand_path('../lib/field.rb', __FILE__)
load File.expand_path('../lib/wizard.rb', __FILE__) load File.expand_path('../lib/wizard.rb', __FILE__)
load File.expand_path('../app/controllers/wizard.rb', __FILE__) load File.expand_path('../app/controllers/wizard.rb', __FILE__)
load File.expand_path('../app/controllers/steps.rb', __FILE__) load File.expand_path('../app/controllers/steps.rb', __FILE__)
@ -51,16 +52,6 @@ after_initialize do
end end
end end
class CustomWizard::FieldTypes
def self.all
@types ||= ['dropdown', 'image', 'radio', 'text', 'textarea']
end
def self.add(type)
all.push(*type)
end
end
class ::Wizard class ::Wizard
attr_accessor :id, :background, :save_submissions attr_accessor :id, :background, :save_submissions
end end