2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2014-09-15 15:46:40 -07:00
|
|
|
import uploader from 'ghost/assets/lib/uploader';
|
|
|
|
|
2015-06-13 09:34:09 -05:00
|
|
|
export default Ember.Component.extend({
|
2014-09-15 15:46:40 -07:00
|
|
|
classNames: ['image-uploader', 'js-post-image-upload'],
|
|
|
|
|
2015-05-25 21:10:50 -05:00
|
|
|
config: Ember.inject.service(),
|
|
|
|
|
2015-02-09 15:57:50 +00:00
|
|
|
imageSource: Ember.computed('image', function () {
|
|
|
|
return this.get('image') || '';
|
|
|
|
}),
|
|
|
|
|
2015-06-02 20:56:42 -06:00
|
|
|
/**
|
|
|
|
* Sets up the uploader on render
|
|
|
|
*/
|
2014-09-15 15:46:40 -07:00
|
|
|
setup: function () {
|
|
|
|
var $this = this.$(),
|
|
|
|
self = this;
|
|
|
|
|
2015-06-13 09:34:09 -05:00
|
|
|
// this.set('uploaderReference', uploader.call($this, {
|
|
|
|
// editor: true,
|
|
|
|
// fileStorage: this.get('config.fileStorage')
|
|
|
|
// }));
|
2014-09-15 15:46:40 -07:00
|
|
|
|
|
|
|
$this.on('uploadsuccess', function (event, result) {
|
|
|
|
if (result && result !== '' && result !== 'http://') {
|
|
|
|
self.sendAction('uploaded', result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-09 09:27:20 -08:00
|
|
|
$this.on('imagecleared', function () {
|
2014-09-15 15:46:40 -07:00
|
|
|
self.sendAction('canceled');
|
|
|
|
});
|
2015-06-02 20:56:42 -06:00
|
|
|
},
|
2014-09-15 15:46:40 -07:00
|
|
|
|
2015-06-02 20:56:42 -06:00
|
|
|
// removes event listeners from the uploader
|
2014-09-15 15:46:40 -07:00
|
|
|
removeListeners: function () {
|
|
|
|
var $this = this.$();
|
2014-10-24 21:09:50 +00:00
|
|
|
|
2014-09-15 15:46:40 -07:00
|
|
|
$this.off();
|
|
|
|
$this.find('.js-cancel').off();
|
2015-06-02 20:56:42 -06:00
|
|
|
},
|
|
|
|
|
2015-06-13 09:34:09 -05:00
|
|
|
// didInsertElement: function () {
|
|
|
|
// Ember.run.scheduleOnce('afterRender', this, this.setup());
|
|
|
|
// },
|
2015-06-02 20:56:42 -06:00
|
|
|
didInsertElement: function () {
|
2015-06-13 09:34:09 -05:00
|
|
|
this.send('initUploader');
|
2015-06-02 20:56:42 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement: function () {
|
|
|
|
this.removeListeners();
|
2015-06-13 09:34:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
initUploader: function () {
|
|
|
|
var ref,
|
|
|
|
el,
|
|
|
|
self = this;
|
|
|
|
|
|
|
|
el = this.$();
|
|
|
|
ref = uploader.call(el, {
|
|
|
|
editor: true,
|
|
|
|
fileStorage: this.get('config.fileStorage')
|
|
|
|
});
|
|
|
|
|
|
|
|
el.on('uploadsuccess', function (event, result) {
|
|
|
|
if (result && result !== '' && result !== 'http://') {
|
|
|
|
self.sendAction('uploaded', result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
el.on('imagecleared', function () {
|
|
|
|
self.sendAction('canceled');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.sendAction('initUploader', this.get('uploaderReference'));
|
|
|
|
}
|
2015-06-02 20:56:42 -06:00
|
|
|
}
|
2014-09-15 15:46:40 -07:00
|
|
|
});
|