0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00

Fix tag and category fields

Dieser Commit ist enthalten in:
Angus McLeod 2019-07-27 16:10:26 +10:00
Ursprung 0460f9342d
Commit c058340c84
3 geänderte Dateien mit 34 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -1,13 +1,28 @@
import { observes } from 'ember-addons/ember-computed-decorators';
import Category from 'discourse/models/category';
export default Ember.Component.extend({
didInsertElement() {
const value = this.get('field.value');
if (value) {
const property = this.get('field.property') || 'id';
const categories = [...value].map(v => {
return property === 'id' ?
Category.findById(v) :
Category.findBySlug(v);
});
this.set('categories', categories);
}
},
@observes('categories')
setValue() {
const categories = this.get('categories');
if (categories.length) {
const limit = this.get('field.limit');
const property = this.get('field.property') || 'id';
let value = limit === 1 ? categories[0][property] : categories.map(c => c[property]);
let value = categories.length === 1 ?
categories[0][property] :
categories.map(c => c[property]);
this.set('field.value', value);
}
}

Datei anzeigen

@ -1 +1 @@
{{tag-chooser value=field.value maximum=field.limit}}
{{tag-chooser tags=field.value maximum=field.limit}}

Datei anzeigen

@ -107,13 +107,13 @@ class CustomWizard::Builder
step.on_update do |updater|
@updater = updater
user = @wizard.user
if step_template['fields'] && step_template['fields'].length
step_template['fields'].each do |field|
validate_field(field, updater, step_template) if field['type'] != 'text-only'
end
end
next if updater.errors.any?
CustomWizard::Builder.step_handlers.each do |handler|
@ -131,7 +131,7 @@ class CustomWizard::Builder
submission = @submissions.last
data = submission.merge(data)
end
if step_template['actions'] && step_template['actions'].length && data
step_template['actions'].each do |action|
self.send(action['type'].to_sym, user, action, data)
@ -331,7 +331,7 @@ class CustomWizard::Builder
else
post = data[action['post']]
end
if title
params = {
title: title,
@ -339,22 +339,23 @@ class CustomWizard::Builder
skip_validations: true
}
if action['custom_category_enabled'] &&
!action['custom_category_wizard_field'] &&
action['custom_category_user_field_key']
if action['custom_category_user_field_key'].include?('custom_fields')
field = action['custom_category_user_field_key'].split('.').last
category_id = user.custom_fields[field]
else
category_id = user.send(action['custom_category_user_field_key'])
if action['custom_category_enabled']
if action['custom_category_wizard_field']
category_id = data[action['category_id']]
elsif action['custom_category_user_field_key']
if action['custom_category_user_field_key'].include?('custom_fields')
field = action['custom_category_user_field_key'].split('.').last
category_id = user.custom_fields[field]
else
category_id = user.send(action['custom_category_user_field_key'])
end
end
else
category_id = action['category_id']
end
params[:category] = category_id
topic_custom_fields = {}
if action['add_fields']
@ -378,7 +379,7 @@ class CustomWizard::Builder
end
end
else
value = [value] if key === 'tags'
value = [*value] if key === 'tags'
params[key.to_sym] = value
end
end