mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Merge pull request #4965 from ErisDS/validate-image-url
Validate urls in modal
This commit is contained in:
commit
a6f0264bf1
1 changed files with 32 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
import ModalDialog from 'ghost/components/gh-modal-dialog';
|
import ModalDialog from 'ghost/components/gh-modal-dialog';
|
||||||
import upload from 'ghost/assets/lib/uploader';
|
import upload from 'ghost/assets/lib/uploader';
|
||||||
|
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
|
||||||
|
|
||||||
var UploadModal = ModalDialog.extend({
|
var UploadModal = ModalDialog.extend({
|
||||||
layoutName: 'components/gh-modal-dialog',
|
layoutName: 'components/gh-modal-dialog',
|
||||||
|
@ -8,6 +9,16 @@ var UploadModal = ModalDialog.extend({
|
||||||
this._super();
|
this._super();
|
||||||
upload.call(this.$('.js-drop-zone'), {fileStorage: this.get('config.fileStorage')});
|
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: {
|
confirm: {
|
||||||
reject: {
|
reject: {
|
||||||
func: function () { // The function called on rejection
|
func: function () { // The function called on rejection
|
||||||
|
@ -18,15 +29,23 @@ var UploadModal = ModalDialog.extend({
|
||||||
},
|
},
|
||||||
accept: {
|
accept: {
|
||||||
buttonClass: 'btn btn-blue right',
|
buttonClass: 'btn btn-blue right',
|
||||||
text: 'Save', // The accept button texttext: 'Save'
|
text: 'Save', // The accept button text: 'Save'
|
||||||
func: function () {
|
func: function () {
|
||||||
var imageType = 'model.' + this.get('imageType');
|
var imageType = 'model.' + this.get('imageType'),
|
||||||
|
value;
|
||||||
|
|
||||||
if (this.$('.js-upload-url').val()) {
|
if (this.$('.js-upload-url').val()) {
|
||||||
this.set(imageType, 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 {
|
} else {
|
||||||
this.set(imageType, this.$('.js-upload-target').attr('src'));
|
value = this.$('.js-upload-target').attr('src');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.set(imageType, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,12 +56,17 @@ var UploadModal = ModalDialog.extend({
|
||||||
this.sendAction();
|
this.sendAction();
|
||||||
},
|
},
|
||||||
confirm: function (type) {
|
confirm: function (type) {
|
||||||
var func = this.get('confirm.' + type + '.func');
|
var result,
|
||||||
|
func = this.get('confirm.' + type + '.func');
|
||||||
|
|
||||||
if (typeof func === 'function') {
|
if (typeof func === 'function') {
|
||||||
func.apply(this);
|
result = func.apply(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.message) {
|
||||||
|
this.sendAction();
|
||||||
|
this.sendAction('confirm' + type);
|
||||||
}
|
}
|
||||||
this.sendAction();
|
|
||||||
this.sendAction('confirm' + type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue