Wizard: Support for custom image previews for uploads

This commit is contained in:
Robin Ward 2016-09-16 13:10:12 -04:00
parent 28cd49f02b
commit 69325fbe02
4 changed files with 16 additions and 7 deletions

View File

@ -1,10 +1,17 @@
import computed from 'ember-addons/ember-computed-decorators';
import { getToken } from 'wizard/lib/ajax';
export default Ember.Component.extend({
classNames: ['wizard-image-row'],
uploading: false,
@computed('field.id')
previewComponent(id) {
const componentName = `image-preview-${Ember.String.dasherize(id)}`;
const exists = this.container.lookup(`component:${componentName}`);
return exists ? componentName : 'wizard-image-preview';
},
didInsertElement() {
this._super();

View File

@ -0,0 +1,3 @@
export default Ember.Component.extend({
classNameBindings: [':wizard-image-preview', 'fieldClass']
});

View File

@ -1,3 +1,7 @@
{{#if field.value}}
{{component previewComponent field=field fieldClass=fieldClass}}
{{/if}}
<label class="wizard-btn wizard-btn-upload {{if uploading 'disabled'}}">
{{#if uploading}}
{{i18n "wizard.uploading"}}
@ -8,9 +12,3 @@
<input disabled={{uploading}} type="file" accept="image/*" style="visibility: hidden; position: absolute;" />
</label>
{{#if field.value}}
<div class='wizard-image-preview {{fieldClass}}'>
<img src={{field.value}} class={{fieldClass}}>
</div>
{{/if}}

View File

@ -0,0 +1 @@
<img src={{field.value}} class={{fieldClass}}>