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:
Ursprung
0460f9342d
Commit
c058340c84
3 geänderte Dateien mit 34 neuen und 18 gelöschten Zeilen
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{{tag-chooser value=field.value maximum=field.limit}}
|
||||
{{tag-chooser tags=field.value maximum=field.limit}}
|
||||
|
|
|
@ -339,15 +339,16 @@ 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']
|
||||
|
@ -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
|
||||
|
|
Laden …
In neuem Issue referenzieren