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

Allow selection of category property type

Dieser Commit ist enthalten in:
Angus McLeod 2019-07-26 19:12:58 +10:00
Ursprung a1c8b53e64
Commit 0460f9342d
6 geänderte Dateien mit 31 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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',

Datei anzeigen

@ -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}}

Datei anzeigen

@ -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);
}
}
});

Datei anzeigen

@ -112,6 +112,7 @@ en:
tag: "Tag"
category: "Category"
limit: "Limit"
property: "Property"
action:
header: "Actions<sup>*</sup>"
include: "Include Fields"

Datei anzeigen

@ -211,6 +211,10 @@ class CustomWizard::Builder
params[:limit] = field_template['limit']
end
if field_template['type'] === 'category'
params[:property] = field_template['property']
end
field = step.add_field(params)
if field_template['type'] === 'dropdown'

Datei anzeigen

@ -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