Closed ideadx closed 8 years ago
you need to use jquery options, such as:
deleteScript: '/images/delete',
deleteMethod: 'POST',
fileDeleteOptions: {
headers: {
'X-CSRF-TOKEN': Cookies.get('X-CSRF-Token')
}
Did you read the wiki about that new configuration https://github.com/orthes/medium-editor-insert-plugin/wiki/v2.x-Configuration ?
@j0k3r @jackyzhai I have read the docs, and added the configuration as @jackyzhai mentioned, but request is not been called when I remove the image.
@ideadx it seems to work on my machine. can u post ur code here?
here is a code:
deleteScript: '/post/method',
deleteMethod: 'POST',
fileDeleteOptions: {
headers: {
'X-CSRF-TOKEN': "{!! Session::getToken() !!}"
}
},
Is there a way to log when method is running or response comes back?
similar to
uploadCompleted: function ($el, data) {
console.log(data.result)
}
@ideadx idk. I think j0k3r would have better info. just curious. what syntax is this? {!! Session::getToken() !!}
@jackyzhai Thats Laravel Blade (a php framework)
@j0k3r any idea to console log?
I'll have a look
Everything works great on my side. I've tested on the example files (from this repo) with that config:
$(function () {
$('.editable').mediumInsert({
editor: editor,
addons: {
images: {
deleteScript: 'delete.php',
deleteMethod: 'POST',
fileDeleteOptions: {
headers: {
'X-CSRF-TOKEN': "TOKEN"
}
},
styles: {
slideshow: {
label: '<span class="fa fa-play"></span>',
added: function ($el) {
$el
.data('cycle-center-vert', true)
.cycle({
slides: 'figure'
});
},
removed: function ($el) {
$el.cycle('destroy');
}
}
},
actions: false
}
}
});
});
When I delete an image the ajax request is well sent with the additional token header:
Since it's an ajax request you might be able to debug it from your browser.
@j0k3r
Here is my full code:
https://gist.github.com/ideadx/143b768d97ba4ef5f96d
Here is file upload request (which works fine):
But when I remove this files (using backspace or delete), image get removed from content but no requests (delete scripts) get fired. I cant see it in debug in browser since plugin does nothing.
I've no idea why this doesn't work for u. J0k3r may have better info. However, one thing you can do is to set up a br here and see what's wrong. It's basically just jquery ajax request. https://github.com/orthes/medium-editor-insert-plugin/blob/adb9e9d7e3a0d0af582c33a3f5e698c3e4f95198/dist/js/medium-editor-insert-plugin.js#L1923
@ideadx did you try to remove all option related to delete to use default one and see if the ajax request is launched?
sorry I double clicked on the wrong place
@j0k3r I have try removing all default options but the issue is still the same!
I tried 4 different requests
1. Set default options
fileDeleteOptions: {
headers: {
'X-CSRF-TOKEN': "TOKEN"
}
},
2. Remove token option
fileDeleteOptions: {
headers: {
// 'X-CSRF-TOKEN': "TOKEN"
}
},
3. Remove header
fileDeleteOptions: {
//headers: {
// 'X-CSRF-TOKEN': "TOKEN"
//}
},
4. Remove File delete option
//fileDeleteOptions: {
// headers: {
// 'X-CSRF-TOKEN': "TOKEN"
// }
//},
One last idea, what happen if you try to delete an image that is already in the dom? I mean an image that you didn't just uploaded.
Same issue. Let's say I upload images, save the content and try to remove it, nothing happens. On 22 Jan 2016 11:06 PM, "Jeremy Benoist" notifications@github.com wrote:
One last idea, what happen if you try to delete an image that is already in the dom? I mean an image that you didn't just uploaded.
— Reply to this email directly or view it on GitHub https://github.com/orthes/medium-editor-insert-plugin/issues/265#issuecomment-173909385 .
I'm out of idea. :wave: @orthes, we need your help
@j0k3r Which version of jQuery you are using? I am using: 2.1.4
@orthes
@ideadx When you say that you use backspace or delete, do you mean that you select image first and then press one of those two buttons? Or do you place caret after the image and then press backspace? Because it is a known issue that deleting image together with text doesn't trigger the plugin's delete function (#228).
But if you're selecting an image by clicking on it first, then it should work. I tried it myself and it also works for me.
The one last thing that remains here to do is to dive into the code and find out where it fails for you. Is keydown
event triggered? Is Images.removeImage()
called? Is Images.deleteFile()
called after that? And finally, why the hell is $.ajax()
not called?
OMG!
I was doing Second: place caret after the image and then press backspace to delete image which doesn't work.
but I just selected image and try to delete and event did trigger. Oh God....
@j0k3r @orthes
I think thats a critical issues (228). When you writing content after the image and then press backspace to delete image is a natural scenario.
@j0k3r @jackyzhai @orthes Thanks boys.
I updated the plugin and Delete Request is no longer been called when I remove the image?
deleteScript: '{!! action('XXX\JoyController@putSomeMethod') !!}', deleteMethod: 'PUT', fileDeleteOptions: { _token: "{!! Session::getToken() !!}", id : 1 },