diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 8de6cb57..b8ae5fe4 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -1,8 +1,9 @@ -import { default as computed } from 'ember-addons/ember-computed-decorators'; +import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators'; export default Ember.Component.extend({ classNames: 'wizard-custom-field', isDropdown: Ember.computed.equal('field.type', 'dropdown'), + isUpload: Ember.computed.equal('field.type', 'upload'), disableId: Ember.computed.not('field.isNew'), choicesTypes: ['translation', 'preset', 'custom'], choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'), @@ -27,4 +28,12 @@ export default Ember.Component.extend({ } ]; }, + + @on('didInsertElement') + @observes('isUpload') + setupFileType() { + if (this.get('isUpload') && !this.get('field.file_types')) { + this.set('field.file_types', '.jpg,.png'); + } + } }); diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 692454f3..e292371e 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -112,3 +112,14 @@ {{input name="dropdown_none" value=field.dropdown_none placeholder=(i18n 'admin.wizard.field.dropdown_none_placeholder')}} {{/if}} + +{{#if isUpload}} +
+
+

{{i18n 'admin.wizard.field.file_types'}}

+
+
+ {{input value=field.file_types}} +
+
+{{/if}} diff --git a/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs b/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs index 4d984912..0e24849a 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs @@ -6,7 +6,7 @@ {{d-icon "upload"}} {{/if}} - + {{#if field.value}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index fdbe87b3..91c6ea75 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -108,6 +108,7 @@ en: required_label: "Field is Required" min_length: "Min Length" min_length_placeholder: "Minimum length in characters" + file_types: "File Types" action: header: "Actions*" include: "Include Fields" diff --git a/lib/builder.rb b/lib/builder.rb index 9d0bfda7..d4f779be 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -203,6 +203,10 @@ class CustomWizard::Builder params[:value] = standardise_boolean(params[:value]) end + if field_template['type'] === 'upload' + params[:file_types] = field_template['file_types'] + end + field = step.add_field(params) if field_template['type'] === 'dropdown' diff --git a/lib/wizard_edits.rb b/lib/wizard_edits.rb index dfab138a..dc6421ab 100644 --- a/lib/wizard_edits.rb +++ b/lib/wizard_edits.rb @@ -23,7 +23,7 @@ require_dependency 'wizard/step' end ::Wizard::Field.class_eval do - attr_reader :label, :description, :image, :key, :min_length + attr_reader :label, :description, :image, :key, :min_length, :file_types attr_accessor :dropdown_none def initialize(attrs) @@ -38,6 +38,7 @@ end @value = attrs[:value] @choices = [] @dropdown_none = attrs[:dropdown_none] + @file_types = attrs[:file_types] end def label @@ -152,7 +153,7 @@ end end ::WizardFieldSerializer.class_eval do - attributes :dropdown_none, :image + attributes :dropdown_none, :image, :file_types def label return object.label if object.label.present? @@ -179,4 +180,8 @@ end def dropdown_none object.dropdown_none end + + def file_types + object.file_types + end end