1
0
Fork 0

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

Datei anzeigen

@ -112,3 +112,14 @@
{{input name="dropdown_none" value=field.dropdown_none placeholder=(i18n 'admin.wizard.field.dropdown_none_placeholder')}}
</div>
{{/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"}}
{{/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>
{{#if field.value}}

Datei anzeigen

@ -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<sup>*</sup>"
include: "Include Fields"

Datei anzeigen

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

Datei anzeigen

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