linkesch / medium-editor-insert-plugin

jQuery insert plugin for MediumEditor
http://orthes.github.io/medium-editor-insert-plugin
MIT License
1.22k stars 352 forks source link

Delete Request is no longer been called #265

Closed ideadx closed 8 years ago

ideadx commented 8 years ago

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 },

jackyzhai commented 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')
                    }
j0k3r commented 8 years ago

Did you read the wiki about that new configuration https://github.com/orthes/medium-editor-insert-plugin/wiki/v2.x-Configuration ?

ideadx commented 8 years ago

@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.

jackyzhai commented 8 years ago

@ideadx it seems to work on my machine. can u post ur code here?

ideadx commented 8 years ago

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)
 }
jackyzhai commented 8 years ago

@ideadx idk. I think j0k3r would have better info. just curious. what syntax is this? {!! Session::getToken() !!}

ideadx commented 8 years ago

@jackyzhai Thats Laravel Blade (a php framework)

ideadx commented 8 years ago

@j0k3r any idea to console log?

j0k3r commented 8 years ago

I'll have a look

j0k3r commented 8 years ago

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:

image

Since it's an ajax request you might be able to debug it from your browser.

ideadx commented 8 years ago

@j0k3r

Here is my full code:

https://gist.github.com/ideadx/143b768d97ba4ef5f96d

Here is file upload request (which works fine):

screen shot 2016-01-22 at 2 41 59 pm

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.

jackyzhai commented 8 years ago

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

j0k3r commented 8 years ago

@ideadx did you try to remove all option related to delete to use default one and see if the ajax request is launched?

j0k3r commented 8 years ago

sorry I double clicked on the wrong place

ideadx commented 8 years ago

@j0k3r I have try removing all default options but the issue is still the same!

ideadx commented 8 years ago

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"
  //  }
//},
j0k3r commented 8 years ago

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.

ideadx commented 8 years ago

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 .

j0k3r commented 8 years ago

I'm out of idea. :wave: @orthes, we need your help

ideadx commented 8 years ago

@j0k3r Which version of jQuery you are using? I am using: 2.1.4

ideadx commented 8 years ago

@orthes

linkesch commented 8 years ago

@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?

ideadx commented 8 years ago

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....

ideadx commented 8 years ago

@j0k3r @orthes

ideadx commented 8 years ago

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.

ideadx commented 8 years ago

@j0k3r @jackyzhai @orthes Thanks boys.