2015-02-19 18:15:19 +03:00
|
|
|
import Ember from 'ember';
|
2014-05-28 23:26:05 +04:00
|
|
|
import ModalDialog from 'ghost/components/gh-modal-dialog';
|
2014-06-06 18:44:09 +04:00
|
|
|
import upload from 'ghost/assets/lib/uploader';
|
2015-02-20 18:44:02 +03:00
|
|
|
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
|
2014-03-31 08:07:05 +04:00
|
|
|
|
|
|
|
var UploadModal = ModalDialog.extend({
|
2014-05-28 23:26:05 +04:00
|
|
|
layoutName: 'components/gh-modal-dialog',
|
2014-03-31 08:07:05 +04:00
|
|
|
|
|
|
|
didInsertElement: function () {
|
|
|
|
this._super();
|
2014-06-24 01:12:22 +04:00
|
|
|
upload.call(this.$('.js-drop-zone'), {fileStorage: this.get('config.fileStorage')});
|
2014-06-06 18:44:09 +04:00
|
|
|
},
|
2015-02-20 18:44:02 +03:00
|
|
|
keyDown: function () {
|
|
|
|
this.setErrorState(false);
|
|
|
|
},
|
|
|
|
setErrorState: function (state) {
|
|
|
|
if (state) {
|
|
|
|
this.$('.js-upload-url').addClass('error');
|
|
|
|
} else {
|
|
|
|
this.$('.js-upload-url').removeClass('error');
|
|
|
|
}
|
|
|
|
},
|
2014-06-06 18:44:09 +04:00
|
|
|
confirm: {
|
|
|
|
reject: {
|
|
|
|
func: function () { // The function called on rejection
|
|
|
|
return true;
|
|
|
|
},
|
2014-09-24 18:26:23 +04:00
|
|
|
buttonClass: 'btn btn-default',
|
2014-06-06 18:44:09 +04:00
|
|
|
text: 'Cancel' // The reject button text
|
|
|
|
},
|
|
|
|
accept: {
|
2014-08-06 15:34:08 +04:00
|
|
|
buttonClass: 'btn btn-blue right',
|
2015-02-20 18:44:02 +03:00
|
|
|
text: 'Save', // The accept button text: 'Save'
|
2014-06-06 18:44:09 +04:00
|
|
|
func: function () {
|
2015-02-20 18:44:02 +03:00
|
|
|
var imageType = 'model.' + this.get('imageType'),
|
|
|
|
value;
|
2014-03-31 08:07:05 +04:00
|
|
|
|
2014-06-06 18:44:09 +04:00
|
|
|
if (this.$('.js-upload-url').val()) {
|
2015-02-20 18:44:02 +03:00
|
|
|
value = this.$('.js-upload-url').val();
|
|
|
|
|
|
|
|
if (!Ember.isEmpty(value) && !cajaSanitizers.url(value)) {
|
|
|
|
this.setErrorState(true);
|
|
|
|
return {message: 'Image URI is not valid'};
|
|
|
|
}
|
2014-06-06 18:44:09 +04:00
|
|
|
} else {
|
2015-02-20 18:44:02 +03:00
|
|
|
value = this.$('.js-upload-target').attr('src');
|
2014-06-06 18:44:09 +04:00
|
|
|
}
|
2015-02-20 18:44:02 +03:00
|
|
|
|
|
|
|
this.set(imageType, value);
|
2014-06-06 18:44:09 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 08:07:05 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
closeModal: function () {
|
|
|
|
this.sendAction();
|
|
|
|
},
|
|
|
|
confirm: function (type) {
|
2015-02-20 18:44:02 +03:00
|
|
|
var result,
|
|
|
|
func = this.get('confirm.' + type + '.func');
|
|
|
|
|
2014-03-31 08:07:05 +04:00
|
|
|
if (typeof func === 'function') {
|
2015-02-20 18:44:02 +03:00
|
|
|
result = func.apply(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.message) {
|
|
|
|
this.sendAction();
|
|
|
|
this.sendAction('confirm' + type);
|
2014-03-31 08:07:05 +04:00
|
|
|
}
|
|
|
|
}
|
2014-06-06 18:44:09 +04:00
|
|
|
}
|
2014-03-31 08:07:05 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default UploadModal;
|