mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 16:33:44 +08:00
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
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();
|
|
|
|
const $upload = this.$();
|
|
|
|
const id = this.get('field.id');
|
|
|
|
$upload.fileupload({
|
|
url: "/uploads.json",
|
|
formData: { synchronous: true,
|
|
type: `wizard_${id}`,
|
|
authenticity_token: getToken() },
|
|
dataType: 'json',
|
|
dropZone: $upload,
|
|
});
|
|
|
|
$upload.on("fileuploadsubmit", () => this.set('uploading', true));
|
|
|
|
$upload.on('fileuploaddone', (e, response) => {
|
|
this.set('field.value', response.result.url);
|
|
this.set('uploading', false);
|
|
});
|
|
},
|
|
});
|