0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/client/app/components/gh-upload-modal.js

83 lines
2.2 KiB
JavaScript
Raw Normal View History

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