Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +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',
|
classNames: 'wizard-custom-field',
|
||||||
isDropdown: Ember.computed.equal('field.type', 'dropdown'),
|
isDropdown: Ember.computed.equal('field.type', 'dropdown'),
|
||||||
isUpload: Ember.computed.equal('field.type', 'upload'),
|
isUpload: Ember.computed.equal('field.type', 'upload'),
|
||||||
|
isCategory: Ember.computed.equal('field.type', 'category'),
|
||||||
disableId: Ember.computed.not('field.isNew'),
|
disableId: Ember.computed.not('field.isNew'),
|
||||||
choicesTypes: ['translation', 'preset', 'custom'],
|
choicesTypes: ['translation', 'preset', 'custom'],
|
||||||
choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'),
|
choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'),
|
||||||
choicesPreset: Ember.computed.equal('field.choices_type', 'preset'),
|
choicesPreset: Ember.computed.equal('field.choices_type', 'preset'),
|
||||||
choicesCustom: Ember.computed.equal('field.choices_type', 'custom'),
|
choicesCustom: Ember.computed.equal('field.choices_type', 'custom'),
|
||||||
|
categoryPropertyTypes: ['id', 'slug'],
|
||||||
|
|
||||||
@computed('field.type')
|
@computed('field.type')
|
||||||
isInput: (type) => type === 'text' || type === 'textarea',
|
isInput: (type) => type === 'text' || type === 'textarea',
|
||||||
|
|
|
@ -134,3 +134,14 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/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')
|
@observes('categories')
|
||||||
setValue() {
|
setValue() {
|
||||||
const categories = this.get('categories');
|
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"
|
tag: "Tag"
|
||||||
category: "Category"
|
category: "Category"
|
||||||
limit: "Limit"
|
limit: "Limit"
|
||||||
|
property: "Property"
|
||||||
action:
|
action:
|
||||||
header: "Actions<sup>*</sup>"
|
header: "Actions<sup>*</sup>"
|
||||||
include: "Include Fields"
|
include: "Include Fields"
|
||||||
|
|
|
@ -210,6 +210,10 @@ class CustomWizard::Builder
|
||||||
if field_template['type'] === 'category' || field_template['type'] === 'tag'
|
if field_template['type'] === 'category' || field_template['type'] === 'tag'
|
||||||
params[:limit] = field_template['limit']
|
params[:limit] = field_template['limit']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if field_template['type'] === 'category'
|
||||||
|
params[:property] = field_template['property']
|
||||||
|
end
|
||||||
|
|
||||||
field = step.add_field(params)
|
field = step.add_field(params)
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ require_dependency 'wizard/step'
|
||||||
end
|
end
|
||||||
|
|
||||||
::Wizard::Field.class_eval do
|
::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
|
attr_accessor :dropdown_none
|
||||||
|
|
||||||
def initialize(attrs)
|
def initialize(attrs)
|
||||||
|
@ -40,6 +40,7 @@ end
|
||||||
@dropdown_none = attrs[:dropdown_none]
|
@dropdown_none = attrs[:dropdown_none]
|
||||||
@file_types = attrs[:file_types]
|
@file_types = attrs[:file_types]
|
||||||
@limit = attrs[:limit]
|
@limit = attrs[:limit]
|
||||||
|
@property = attrs[:property]
|
||||||
end
|
end
|
||||||
|
|
||||||
def label
|
def label
|
||||||
|
@ -176,7 +177,7 @@ end
|
||||||
end
|
end
|
||||||
|
|
||||||
::WizardFieldSerializer.class_eval do
|
::WizardFieldSerializer.class_eval do
|
||||||
attributes :dropdown_none, :image, :file_types, :limit
|
attributes :dropdown_none, :image, :file_types, :limit, :property
|
||||||
|
|
||||||
def label
|
def label
|
||||||
return object.label if object.label.present?
|
return object.label if object.label.present?
|
||||||
|
@ -211,4 +212,8 @@ end
|
||||||
def limit
|
def limit
|
||||||
object.limit
|
object.limit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def property
|
||||||
|
object.property
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren