Add support for user_fields
Dieser Commit ist enthalten in:
Ursprung
5b312eca07
Commit
2981c32ea5
10 geänderte Dateien mit 191 neuen und 72 gelöschten Zeilen
|
@ -1,19 +1,36 @@
|
||||||
|
import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
|
const fieldNotPresent = (f) => { return f == null || f === undefined };
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
|
classNames: 'custom-input',
|
||||||
noneKey: 'admin.wizard.select_field',
|
noneKey: 'admin.wizard.select_field',
|
||||||
noneValue: 'admin.wizard.none',
|
noneValue: 'admin.wizard.none',
|
||||||
inputKey: 'admin.wizard.key',
|
inputKey: 'admin.wizard.key',
|
||||||
inputValue: 'admin.wizard.value',
|
inputValue: 'admin.wizard.value',
|
||||||
|
customDisabled: Ember.computed.alias('input.user_field'),
|
||||||
|
|
||||||
actions: {
|
@computed('input.value_custom', 'input.user_field')
|
||||||
add() {
|
valueDisabled(custom, user) {
|
||||||
if (!this.get('inputs')) {
|
return Boolean(custom || user);
|
||||||
this.set('inputs', Ember.A());
|
},
|
||||||
}
|
|
||||||
this.get('inputs').pushObject(Ember.Object.create());
|
|
||||||
},
|
|
||||||
|
|
||||||
remove(input) {
|
@on('init')
|
||||||
this.get('inputs').removeObject(input);
|
setupUserFields() {
|
||||||
|
const allowUserField = this.get('allowUserField');
|
||||||
|
if (allowUserField) {
|
||||||
|
const store = getOwner(this).lookup('store:main');
|
||||||
|
store.findAll('user-field').then((result) => {
|
||||||
|
if (result && result.content && result.content.length) {
|
||||||
|
this.set('userFields', result.content.map((f) => {
|
||||||
|
return {
|
||||||
|
id: `user_field_${f.id}`,
|
||||||
|
name: f.name
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
14
assets/javascripts/discourse/components/wizard-custom-inputs.js.es6
Normale Datei
14
assets/javascripts/discourse/components/wizard-custom-inputs.js.es6
Normale Datei
|
@ -0,0 +1,14 @@
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
actions: {
|
||||||
|
add() {
|
||||||
|
if (!this.get('inputs')) {
|
||||||
|
this.set('inputs', Ember.A());
|
||||||
|
}
|
||||||
|
this.get('inputs').pushObject(Ember.Object.create());
|
||||||
|
},
|
||||||
|
|
||||||
|
remove(input) {
|
||||||
|
this.get('inputs').removeObject(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -104,11 +104,11 @@
|
||||||
|
|
||||||
<div class="setting full">
|
<div class="setting full">
|
||||||
<label>{{i18n 'admin.wizard.action.add_fields' type='Topic'}}</label>
|
<label>{{i18n 'admin.wizard.action.add_fields' type='Topic'}}</label>
|
||||||
{{wizard-custom-input inputs=action.add_fields
|
{{wizard-custom-inputs inputs=action.add_fields
|
||||||
valueContent=availableFields
|
valueContent=availableFields
|
||||||
inputKey='admin.wizard.action.topic_attr'
|
inputKey='admin.wizard.action.topic_attr'
|
||||||
noneValue='admin.wizard.select_field'
|
noneValue='admin.wizard.select_field'
|
||||||
optionalCustom=true}}
|
allowCustomField=true}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
@ -167,20 +167,20 @@
|
||||||
|
|
||||||
<div class="setting full">
|
<div class="setting full">
|
||||||
<label>{{i18n "admin.wizard.action.add_fields" type='Message'}}</label>
|
<label>{{i18n "admin.wizard.action.add_fields" type='Message'}}</label>
|
||||||
{{wizard-custom-input inputs=action.add_fields
|
{{wizard-custom-inputs inputs=action.add_fields
|
||||||
keyContent=availableFields
|
keyContent=availableFields
|
||||||
inputValue='admin.wizard.action.topic_attr'}}
|
valuePlaceholder='admin.wizard.action.topic_attr'}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if updateProfile}}
|
{{#if updateProfile}}
|
||||||
<div class="setting full">
|
<div class="setting full">
|
||||||
<label>{{i18n "admin.wizard.action.add_fields" type='Profile'}}</label>
|
<label>{{i18n "admin.wizard.action.add_fields" type='Profile'}}</label>
|
||||||
{{wizard-custom-input inputs=action.profile_updates
|
{{wizard-custom-inputs inputs=action.profile_updates
|
||||||
valueContent=profileFields
|
valueContent=profileFields
|
||||||
keyContent=availableFields
|
keyContent=availableFields
|
||||||
noneValue='admin.wizard.action.update_profile.profile_field'
|
noneValue='admin.wizard.action.update_profile.profile_field'
|
||||||
optionalCustom=true
|
allowCustomField=true
|
||||||
inputValue='admin.wizard.action.update_profile.custom_field'}}
|
allowUserField=true}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -96,14 +96,14 @@
|
||||||
<div class="wizard-header small">
|
<div class="wizard-header small">
|
||||||
{{i18n 'admin.wizard.field.choices_preset.filter'}}
|
{{i18n 'admin.wizard.field.choices_preset.filter'}}
|
||||||
</div>
|
</div>
|
||||||
{{wizard-custom-input inputs=field.choices_filters}}
|
{{wizard-custom-inputs inputs=field.choices_filters}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if choicesCustom}}
|
{{#if choicesCustom}}
|
||||||
<div class="wizard-header small">
|
<div class="wizard-header small">
|
||||||
{{i18n 'admin.wizard.field.choices_custom'}}
|
{{i18n 'admin.wizard.field.choices_custom'}}
|
||||||
</div>
|
</div>
|
||||||
{{wizard-custom-input inputs=field.choices}}
|
{{wizard-custom-inputs inputs=field.choices}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="wizard-header small">
|
<div class="wizard-header small">
|
||||||
|
|
|
@ -1,25 +1,44 @@
|
||||||
{{#each inputs as |in|}}
|
<div class="key">
|
||||||
<div class='custom-input'>
|
{{#if keyContent}}
|
||||||
{{#if keyContent}}
|
{{combo-box value=input.key content=keyContent nameProperty="label" none=noneKey}}
|
||||||
{{combo-box value=in.key content=keyContent nameProperty="label" none=noneKey}}
|
{{else}}
|
||||||
{{else}}
|
{{input type="text" value=input.key placeholder=(i18n inputKey)}}
|
||||||
{{input type="text" value=in.key placeholder=(i18n inputKey)}}
|
{{/if}}
|
||||||
{{/if}}
|
|
||||||
{{#if valueContent}}
|
|
||||||
{{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}}
|
|
||||||
{{d-button action='remove' actionParam=in icon='times'}}
|
|
||||||
</div>
|
|
||||||
{{/each}}
|
|
||||||
<div class="add-custom-input">
|
|
||||||
{{d-button action='add' label='admin.wizard.add' icon='plus'}}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{d-icon 'arrow-right'}}
|
||||||
|
|
||||||
|
<div class="value">
|
||||||
|
{{#if valueContent}}
|
||||||
|
{{combo-box value=input.value
|
||||||
|
content=valueContent
|
||||||
|
nameProperty="label"
|
||||||
|
none=noneValue
|
||||||
|
isDisabled=valueDisabled}}
|
||||||
|
{{else}}
|
||||||
|
{{input type="text" value=input.value placeholder=(i18n valuePlaceholder)}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if allowCustomField}}
|
||||||
|
<div class="text-divider">
|
||||||
|
<span>{{i18n 'admin.wizard.or'}}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{input type="text"
|
||||||
|
value=input.value_custom
|
||||||
|
placeholder=(i18n 'admin.wizard.custom_field_placeholder')
|
||||||
|
disabled=customDisabled}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if allowUserField}}
|
||||||
|
<div class="text-divider">
|
||||||
|
<span>{{i18n 'admin.wizard.or'}}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{combo-box value=input.user_field
|
||||||
|
content=userFields
|
||||||
|
none='admin.wizard.user_field_placeholder'}}
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{d-button action=remove actionParam=input icon='times' class='remove'}}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
{{#each inputs as |input|}}
|
||||||
|
{{wizard-custom-input input=input
|
||||||
|
valueContent=valueContent
|
||||||
|
keyContent=keyContent
|
||||||
|
noneValue=noneValue
|
||||||
|
valuePlaceholder=valuePlaceholder
|
||||||
|
allowCustomField=allowCustomField
|
||||||
|
allowUserField=allowUserField
|
||||||
|
remove=(action 'remove')}}
|
||||||
|
{{/each}}
|
||||||
|
<div class="add-custom-input">
|
||||||
|
{{d-button action='add' label='admin.wizard.add' icon='plus'}}
|
||||||
|
</div>
|
|
@ -66,13 +66,7 @@ export default {
|
||||||
bannerImage: function() {
|
bannerImage: function() {
|
||||||
const src = this.get('step.banner');
|
const src = this.get('step.banner');
|
||||||
if (!src) return;
|
if (!src) return;
|
||||||
|
return getUrl(src);
|
||||||
const localPaths = ['uploads', 'plugins', 'images'];
|
|
||||||
if (localPaths.indexOf(src.split('/')[1]) > -1) {
|
|
||||||
return getUrl(src);
|
|
||||||
} else {
|
|
||||||
return getUrl(`/images/wizard/${src}`);
|
|
||||||
};
|
|
||||||
}.property('step.banner'),
|
}.property('step.banner'),
|
||||||
|
|
||||||
handleMessage: function() {
|
handleMessage: function() {
|
||||||
|
@ -114,7 +108,13 @@ export default {
|
||||||
save() {
|
save() {
|
||||||
const wizardId = this.get('wizardId');
|
const wizardId = this.get('wizardId');
|
||||||
const fields = {};
|
const fields = {};
|
||||||
this.get('fields').forEach(f => fields[f.id] = f.value);
|
|
||||||
|
this.get('fields').forEach(f => {
|
||||||
|
if (f.type !== 'text-only') {
|
||||||
|
fields[f.id] = f.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return ajax({
|
return ajax({
|
||||||
url: `/w/${wizardId}/steps/${this.get('id')}`,
|
url: `/w/${wizardId}/steps/${this.get('id')}`,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
width: 49%;
|
width: 49%;
|
||||||
|
|
||||||
.setting-label {
|
.setting-label {
|
||||||
width: 90px;
|
width: 20%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.setting-value {
|
.setting-value {
|
||||||
|
@ -77,6 +77,10 @@
|
||||||
&.full {
|
&.full {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
.setting-label {
|
||||||
|
width: 10%;
|
||||||
|
}
|
||||||
|
|
||||||
.setting-value {
|
.setting-value {
|
||||||
width: initial;
|
width: initial;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -164,15 +168,26 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-input {
|
.custom-input {
|
||||||
|
display: flex;
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
|
|
||||||
> * {
|
.d-icon {
|
||||||
margin-bottom: 0 !important;
|
margin: 0 auto;
|
||||||
margin-right: 5px;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.select-box-kit {
|
input[disabled] {
|
||||||
width: 150px !important;
|
background-color: $primary-low;
|
||||||
|
border-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-kit {
|
||||||
|
width: 232px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove {
|
||||||
|
margin: 0 auto;
|
||||||
|
align-self: flex-start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,3 +264,36 @@
|
||||||
.post-builder-editor {
|
.post-builder-editor {
|
||||||
min-height: 220px;
|
min-height: 220px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-divider {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin: 5px 0;
|
||||||
|
|
||||||
|
> span {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
> span:before,
|
||||||
|
> span:after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
width: 9999px;
|
||||||
|
height: 1px;
|
||||||
|
background: $tertiary;
|
||||||
|
}
|
||||||
|
|
||||||
|
> span:before {
|
||||||
|
right: 100%;
|
||||||
|
margin-right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
> span:after {
|
||||||
|
left: 100%;
|
||||||
|
margin-left: 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ en:
|
||||||
js:
|
js:
|
||||||
wizard:
|
wizard:
|
||||||
complete_custom: "Welcome to %{site_name}! Get started with <a href='%{wizard_url}' data-auto-route='true'>the %{wizard_name} wizard</a> ✨"
|
complete_custom: "Welcome to %{site_name}! Get started with <a href='%{wizard_url}' data-auto-route='true'>the %{wizard_name} wizard</a> ✨"
|
||||||
|
|
||||||
admin_js:
|
admin_js:
|
||||||
admin:
|
admin:
|
||||||
wizard:
|
wizard:
|
||||||
|
@ -42,11 +43,14 @@ en:
|
||||||
add: "Add"
|
add: "Add"
|
||||||
url: "Url"
|
url: "Url"
|
||||||
key: "Key"
|
key: "Key"
|
||||||
|
or: "Or"
|
||||||
value: "Value"
|
value: "Value"
|
||||||
id: "Id"
|
id: "Id"
|
||||||
id_placeholder: "Underscored. Cannot be changed."
|
id_placeholder: "Underscored. Cannot be changed."
|
||||||
key_placeholder: "Translation key"
|
key_placeholder: "Translation key"
|
||||||
custom_text_placeholder: "Overrides translation"
|
custom_text_placeholder: "Overrides translation"
|
||||||
|
custom_field_placeholder: "Custom Field"
|
||||||
|
user_field_placeholder: "User Field"
|
||||||
type: "Type"
|
type: "Type"
|
||||||
none: "Make a selection"
|
none: "Make a selection"
|
||||||
select_field: "Select Field"
|
select_field: "Select Field"
|
||||||
|
@ -107,7 +111,6 @@ en:
|
||||||
update_profile:
|
update_profile:
|
||||||
label: "Update Profile"
|
label: "Update Profile"
|
||||||
profile_field: "Profile Field"
|
profile_field: "Profile Field"
|
||||||
custom_field: "User Custom Field"
|
|
||||||
post_builder:
|
post_builder:
|
||||||
checkbox: "Post Builder"
|
checkbox: "Post Builder"
|
||||||
label: "Builder"
|
label: "Builder"
|
||||||
|
@ -130,7 +133,10 @@ en:
|
||||||
desc: "e.g. 42 Wallaby Way"
|
desc: "e.g. 42 Wallaby Way"
|
||||||
postalcode:
|
postalcode:
|
||||||
title: "Postal Code (Zip)"
|
title: "Postal Code (Zip)"
|
||||||
desc: "e.g. 2548"
|
desc: "e.g. 2090"
|
||||||
|
neighbourhood:
|
||||||
|
title: "Neighbourhood"
|
||||||
|
desc: "e.g. Cremorne Point"
|
||||||
city:
|
city:
|
||||||
title: "City, Town or Village"
|
title: "City, Town or Village"
|
||||||
desc: "e.g. Sydney"
|
desc: "e.g. Sydney"
|
||||||
|
@ -148,6 +154,7 @@ en:
|
||||||
no_results: "No results. Please double check the spelling."
|
no_results: "No results. Please double check the spelling."
|
||||||
show_map: "Show Map"
|
show_map: "Show Map"
|
||||||
validation:
|
validation:
|
||||||
|
neighbourhood: "Please enter a neighbourhood."
|
||||||
city: "Please enter a city, town or village."
|
city: "Please enter a city, town or village."
|
||||||
countrycode: "Please select a country."
|
countrycode: "Please select a country."
|
||||||
geo_location: "Search and select a result."
|
geo_location: "Search and select a result."
|
||||||
|
|
|
@ -96,14 +96,13 @@ class CustomWizard::Builder
|
||||||
PluginStore.remove("#{@wizard.id}_submissions", @wizard.user.id)
|
PluginStore.remove("#{@wizard.id}_submissions", @wizard.user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @wizard.after_time && final_step
|
if final_step && @wizard.id === @wizard.user.custom_fields['redirect_to_wizard']
|
||||||
@wizard.user.custom_fields.delete('redirect_to_wizard');
|
@wizard.user.custom_fields.delete('redirect_to_wizard');
|
||||||
@wizard.user.save_custom_fields(true)
|
@wizard.user.save_custom_fields(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
if updater.errors.empty?
|
if updater.errors.empty?
|
||||||
user_redirect = user.custom_fields['redirect_to_wizard']
|
redirect_to = data['redirect_to']
|
||||||
redirect_to = user_redirect ? "/w/#{user_redirect}" : data['redirect_to']
|
|
||||||
updater.result = { redirect_to: redirect_to } if redirect_to
|
updater.result = { redirect_to: redirect_to } if redirect_to
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -155,9 +154,10 @@ class CustomWizard::Builder
|
||||||
def prefill_profile_field(update)
|
def prefill_profile_field(update)
|
||||||
attribute = update['value']
|
attribute = update['value']
|
||||||
custom_field = update['value_custom']
|
custom_field = update['value_custom']
|
||||||
|
user_field = update['user_field']
|
||||||
|
|
||||||
if custom_field
|
if user_field || custom_field
|
||||||
UserCustomField.where(user_id: @wizard.user.id, name: custom_field).pluck(:value)
|
UserCustomField.where(user_id: @wizard.user.id, name: user_field || custom_field).pluck(:value)
|
||||||
elsif UserProfile.column_names.include? attribute
|
elsif UserProfile.column_names.include? attribute
|
||||||
UserProfile.find_by(user_id: @wizard.user.id).send(attribute)
|
UserProfile.find_by(user_id: @wizard.user.id).send(attribute)
|
||||||
elsif User.column_names.include? attribute
|
elsif User.column_names.include? attribute
|
||||||
|
@ -336,10 +336,11 @@ class CustomWizard::Builder
|
||||||
action['profile_updates'].each do |pu|
|
action['profile_updates'].each do |pu|
|
||||||
value = pu['value']
|
value = pu['value']
|
||||||
custom_field = pu['value_custom']
|
custom_field = pu['value_custom']
|
||||||
|
user_field = pu['user_field']
|
||||||
key = pu['key']
|
key = pu['key']
|
||||||
|
|
||||||
if custom_field
|
if user_field || custom_field
|
||||||
custom_fields[custom_field] = data[key]
|
custom_fields[user_field || custom_field] = data[key]
|
||||||
else
|
else
|
||||||
attributes[value.to_sym] = data[key]
|
attributes[value.to_sym] = data[key]
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren