0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-09 20:02:54 +01:00

Add file types setting to upload field

Dieser Commit ist enthalten in:
Angus McLeod 2019-07-19 13:47:17 +10:00
Ursprung 0b90fdabcf
Commit 81d86bec7c
6 geänderte Dateien mit 34 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -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({ 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'),
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'),
@ -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');
}
}
}); });

Datei anzeigen

@ -112,3 +112,14 @@
{{input name="dropdown_none" value=field.dropdown_none placeholder=(i18n 'admin.wizard.field.dropdown_none_placeholder')}} {{input name="dropdown_none" value=field.dropdown_none placeholder=(i18n 'admin.wizard.field.dropdown_none_placeholder')}}
</div> </div>
{{/if}} {{/if}}
{{#if isUpload}}
<div class="setting">
<div class="setting-label">
<h3>{{i18n 'admin.wizard.field.file_types'}}</h3>
</div>
<div class="setting-value">
{{input value=field.file_types}}
</div>
</div>
{{/if}}

Datei anzeigen

@ -6,7 +6,7 @@
{{d-icon "upload"}} {{d-icon "upload"}}
{{/if}} {{/if}}
<input disabled={{uploading}} type="file" accept="image/*,application/pdf" style="visibility: hidden; position: absolute;" /> <input disabled={{uploading}} type="file" accept="{{field.file_types}}" style="visibility: hidden; position: absolute;" />
</label> </label>
{{#if field.value}} {{#if field.value}}

Datei anzeigen

@ -108,6 +108,7 @@ en:
required_label: "Field is Required" required_label: "Field is Required"
min_length: "Min Length" min_length: "Min Length"
min_length_placeholder: "Minimum length in characters" min_length_placeholder: "Minimum length in characters"
file_types: "File Types"
action: action:
header: "Actions<sup>*</sup>" header: "Actions<sup>*</sup>"
include: "Include Fields" include: "Include Fields"

Datei anzeigen

@ -203,6 +203,10 @@ class CustomWizard::Builder
params[:value] = standardise_boolean(params[:value]) params[:value] = standardise_boolean(params[:value])
end end
if field_template['type'] === 'upload'
params[:file_types] = field_template['file_types']
end
field = step.add_field(params) field = step.add_field(params)
if field_template['type'] === 'dropdown' if field_template['type'] === 'dropdown'

Datei anzeigen

@ -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 attr_reader :label, :description, :image, :key, :min_length, :file_types
attr_accessor :dropdown_none attr_accessor :dropdown_none
def initialize(attrs) def initialize(attrs)
@ -38,6 +38,7 @@ end
@value = attrs[:value] @value = attrs[:value]
@choices = [] @choices = []
@dropdown_none = attrs[:dropdown_none] @dropdown_none = attrs[:dropdown_none]
@file_types = attrs[:file_types]
end end
def label def label
@ -152,7 +153,7 @@ end
end end
::WizardFieldSerializer.class_eval do ::WizardFieldSerializer.class_eval do
attributes :dropdown_none, :image attributes :dropdown_none, :image, :file_types
def label def label
return object.label if object.label.present? return object.label if object.label.present?
@ -179,4 +180,8 @@ end
def dropdown_none def dropdown_none
object.dropdown_none object.dropdown_none
end end
def file_types
object.file_types
end
end end