Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
Allow selection of category property type
Dieser Commit ist enthalten in:
Ursprung
a1c8b53e64
Commit
0460f9342d
6 geänderte Dateien mit 31 neuen und 3 gelöschten Zeilen
|
@ -4,11 +4,13 @@ export default Ember.Component.extend({
|
|||
classNames: 'wizard-custom-field',
|
||||
isDropdown: Ember.computed.equal('field.type', 'dropdown'),
|
||||
isUpload: Ember.computed.equal('field.type', 'upload'),
|
||||
isCategory: Ember.computed.equal('field.type', 'category'),
|
||||
disableId: Ember.computed.not('field.isNew'),
|
||||
choicesTypes: ['translation', 'preset', 'custom'],
|
||||
choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'),
|
||||
choicesPreset: Ember.computed.equal('field.choices_type', 'preset'),
|
||||
choicesCustom: Ember.computed.equal('field.choices_type', 'custom'),
|
||||
categoryPropertyTypes: ['id', 'slug'],
|
||||
|
||||
@computed('field.type')
|
||||
isInput: (type) => type === 'text' || type === 'textarea',
|
||||
|
|
|
@ -134,3 +134,14 @@
|
|||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if isCategory}}
|
||||
<div class="setting">
|
||||
<div class="setting-label">
|
||||
<h3>{{i18n 'admin.wizard.field.property'}}</h3>
|
||||
</div>
|
||||
<div class="setting-value">
|
||||
{{combo-box content=categoryPropertyTypes value=field.property}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
|
@ -4,6 +4,11 @@ export default Ember.Component.extend({
|
|||
@observes('categories')
|
||||
setValue() {
|
||||
const categories = this.get('categories');
|
||||
this.set('field.value', categories.map(c => c.id));
|
||||
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]);
|
||||
this.set('field.value', value);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -112,6 +112,7 @@ en:
|
|||
tag: "Tag"
|
||||
category: "Category"
|
||||
limit: "Limit"
|
||||
property: "Property"
|
||||
action:
|
||||
header: "Actions<sup>*</sup>"
|
||||
include: "Include Fields"
|
||||
|
|
|
@ -210,6 +210,10 @@ class CustomWizard::Builder
|
|||
if field_template['type'] === 'category' || field_template['type'] === 'tag'
|
||||
params[:limit] = field_template['limit']
|
||||
end
|
||||
|
||||
if field_template['type'] === 'category'
|
||||
params[:property] = field_template['property']
|
||||
end
|
||||
|
||||
field = step.add_field(params)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ require_dependency 'wizard/step'
|
|||
end
|
||||
|
||||
::Wizard::Field.class_eval do
|
||||
attr_reader :label, :description, :image, :key, :min_length, :file_types, :limit
|
||||
attr_reader :label, :description, :image, :key, :min_length, :file_types, :limit, :property
|
||||
attr_accessor :dropdown_none
|
||||
|
||||
def initialize(attrs)
|
||||
|
@ -40,6 +40,7 @@ end
|
|||
@dropdown_none = attrs[:dropdown_none]
|
||||
@file_types = attrs[:file_types]
|
||||
@limit = attrs[:limit]
|
||||
@property = attrs[:property]
|
||||
end
|
||||
|
||||
def label
|
||||
|
@ -176,7 +177,7 @@ end
|
|||
end
|
||||
|
||||
::WizardFieldSerializer.class_eval do
|
||||
attributes :dropdown_none, :image, :file_types, :limit
|
||||
attributes :dropdown_none, :image, :file_types, :limit, :property
|
||||
|
||||
def label
|
||||
return object.label if object.label.present?
|
||||
|
@ -211,4 +212,8 @@ end
|
|||
def limit
|
||||
object.limit
|
||||
end
|
||||
|
||||
def property
|
||||
object.property
|
||||
end
|
||||
end
|
||||
|
|
Laden …
In neuem Issue referenzieren