0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

Add custom category and title for create_topic

Dieser Commit ist enthalten in:
Angus McLeod 2017-11-30 10:55:15 +08:00
Ursprung f7c1170e07
Commit aa1c30f1d3
6 geänderte Dateien mit 103 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
import { default as computed } from 'ember-addons/ember-computed-decorators';
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
const ACTION_TYPES = [
{ id: 'create_topic', name: 'Create Topic' },
@ -63,5 +63,17 @@ export default Ember.Component.extend({
const noThemeKey = PROFILE_FIELDS.filter((f) => f !== 'theme_key');
const fields = noThemeKey.concat(['email', 'username']);
return fields.map((f) => ` u{${f}}`);
},
@observes('action.custom_category_wizard_field')
toggleCustomCategoryUserField() {
const wizard = this.get('action.custom_category_wizard_field');
if (wizard) this.set('action.custom_category_user_field', false);
},
@observes('action.custom_category_user_field')
toggleCustomCategoryWizardField() {
const user = this.get('action.custom_category_user_field');
if (user) this.set('action.custom_category_wizard_field', false);
}
});

Datei anzeigen

@ -22,7 +22,32 @@
<h3>{{i18n "admin.wizard.action.create_topic.category"}}</h3>
</div>
<div class="setting-value">
{{category-chooser value=action.category_id}}
{{category-chooser value=action.category_id isDisabled=action.custom_category_enabled}}
<div class="setting-gutter">
{{input type='checkbox' checked=action.custom_category_enabled}}
<span>{{i18n 'admin.wizard.action.custom_category.label'}}</span>
{{#if action.custom_category_enabled}}
<div class="custom-category">
<div>
{{input type='checkbox' checked=action.custom_category_wizard_field}}
<span>{{i18n 'admin.wizard.action.custom_category.wizard_field'}}</span>
{{#if action.custom_category_wizard_field}}
{{combo-box value=action.category_id
content=availableFields
nameProperty="label"
none='admin.wizard.select_field'}}
{{/if}}
</div>
<div>
{{input type='checkbox' checked=action.custom_category_user_field}}
<span>{{i18n 'admin.wizard.action.custom_category.user_field'}}</span>
{{#if action.custom_category_user_field}}
{{input value=action.custom_category_user_field_key}}
{{/if}}
</div>
</div>
{{/if}}
</div>
</div>
</div>
@ -31,7 +56,18 @@
<h3>{{i18n "admin.wizard.action.title"}}</h3>
</div>
<div class="setting-value">
{{combo-box value=action.title content=availableFields nameProperty="label" none='admin.wizard.select_field'}}
{{combo-box value=action.title
content=availableFields
nameProperty="label"
none='admin.wizard.select_field'
isDisabled=action.custom_title_enabled}}
<div class="setting-gutter">
{{input type='checkbox' checked=action.custom_title_enabled}}
<span>{{i18n 'admin.wizard.action.custom_title'}}</span>
{{#if action.custom_title_enabled}}
{{input value=action.custom_title}}
{{/if}}
</div>
</div>
</div>
@ -44,7 +80,7 @@
nameProperty='label'
none='admin.wizard.select_field'
isDisabled=action.post_builder}}
<div>
<div class="setting-gutter">
{{input type='checkbox' checked=action.post_builder}}
<span>{{i18n 'admin.wizard.action.post_builder.checkbox'}}</span>
</div>
@ -71,7 +107,8 @@
{{wizard-custom-input inputs=action.add_fields
valueContent=availableFields
inputKey='admin.wizard.action.topic_attr'
noneValue='admin.wizard.select_field'}}
noneValue='admin.wizard.select_field'
optionalCustom=true}}
</div>
{{/if}}

Datei anzeigen

@ -6,7 +6,14 @@
{{input type="text" value=in.key placeholder=(i18n inputKey)}}
{{/if}}
{{#if valueContent}}
{{combo-box value=in.value content=valueContent nameProperty="label" none=noneValue}}
{{combo-box value=in.value
content=valueContent
nameProperty="label"
none=noneValue
isDisabled=(if in.value_custom true false)}}
{{#if optionalCustom}}
{{input type="text" value=in.value_custom placeholder=(i18n inputValue)}}
{{/if}}
{{else}}
{{input type="text" value=in.value placeholder=(i18n inputValue)}}
{{/if}}

Datei anzeigen

@ -87,6 +87,10 @@
label {
margin: 5px 0;
}
.setting-gutter {
margin-top: 5px;
}
}
.select-box-kit-header {
@ -104,6 +108,11 @@
.buttons .remove {
float: right;
}
.custom-category {
margin-top: 5px;
padding: 5px;
}
}
.wizard-links {

Datei anzeigen

@ -47,7 +47,7 @@ en:
custom_text_placeholder: "Overrides translation"
type: "Type"
none: "Make a selection"
select_field: "Wizard Field"
select_field: "Select Field"
error:
name_required: "Wizards must have a name."
steps_required: "Wizards must have at least one step."
@ -109,6 +109,11 @@ en:
user_fields: "User Fields: "
wizard_fields: "Wizard Fields: "
placeholder: "Insert wizard fields using the field_id in w{}. Insert user fields using field key in u{}."
custom_title: "Custom Title"
custom_category:
label: "Custom Category"
wizard_field: "Wizard Field"
user_field: "User Field"
wizard_js:
location:

Datei anzeigen

@ -174,7 +174,12 @@ class CustomWizard::Builder
if s['actions'] && s['actions'].length
s['actions'].each do |a|
if a['type'] === 'create_topic' && data
if a['custom_title']
title = a['custom_title']
else
title = data[a['title']]
end
if a['post_builder']
post = CustomWizard::Builder.build_post(a['post_template'], user, data)
@ -188,13 +193,31 @@ class CustomWizard::Builder
raw: post,
skip_validations: true
}
params[:category] = a['category_id'] if a['category_id']
if a['custom_category_enabled'] &&
!a['custom_category_wizard_field'] &&
a['custom_category_user_field_key']
if a['custom_category_user_field_key'].include?('custom_fields')
field = a['custom_category_user_field_key'].split('.').last
category_id = user.custom_fields[field]
else
category_id = user.send(a['custom_category_user_field_key'])
end
else
category_id = a['category_id']
end
params[:category] = category_id
topic_custom_fields = {}
if a['add_fields']
a['add_fields'].each do |f|
if f['value_custom']
value = f['value_custom']
else
value = data[f['value']]
end
key = f['key']
if key && key.include?('custom_fields')