Ghost/core/client/app/components/gh-upload-modal.js
Jason Williams c3ad1ae9e2 Use Ember.inject instead of needs and initializers
No Issue
- Switches to the newer style of dependency injection.
- Instead of injection Controllers via "needs," use
  Ember.inject.controller().
- Get rid of initializers that were only injecting objects
  into various factories. Converts these objects into Ember.Service
  objects and declaratively inject them where needed via
  Ember.inject.service().  The added benefit to this is that it's no
  longer a mystery where these properties/methods come from and it's
  straightforward to inject them where needed.
2015-05-27 07:41:42 -05:00

78 lines
2.3 KiB
JavaScript

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