GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.37k stars 4.05k forks source link

Image removal from AssetManager fired twice #280

Closed g41n closed 7 years ago

g41n commented 7 years ago

I assign a listener on AssetManager removal in this way

var assets = editor.AssetManager.getAll() // <- Backbone collection
assets.on('remove', function(asset) {
  console.log(asset.get('src'));
})

as suggested in #86

It worked like a charm for me with 0.9.8 version. Now I've upgraded to 0.9.32 and results in firing the function twice... That's a problem for me: the second time my app raise an error because the image was deleted the first time.

Any hint about that?

Thanks in advance for the support.

artf commented 7 years ago

Hi @g41n honestly, I've done some refactoring work on Assets so some bug might appear, but testing your snippet in the demo (editor var is exposed to window globally so you can play with APIs) I can't reproduce it. By the way, in the last release, I've introduced new "official" events for Assets

Let me know

g41n commented 7 years ago

Hi, I've tried to implement it in this manner

this.templateEditor = grapesjs.init({
    container : '#HtmlTemplateEditorGjs:not(.gjs-editor-cont)',
    storageManager: {
        type: 'none'
    },
    plugins: ['gjs-preset-newsletter'],
    assetManager: {
        upload: '/asset'
    }
});

this.templateEditor.on('asset:remove', (asset) => {
    var filename = asset.get('src').split('/').reverse()[0];
    this.http.DELETE(`/assets/${filename}`, (response) => {
        console.log('asset remove', response);
    });
});

but seems that the second time I open the AssetManager the upload is not fired anymore...

Maybe I use the editor in the wrong way? Every time I run that code I have a new item in grapesjs.editors array and that seems not so good to me. Any hint on how to initialize and reuse it in a complex application?

Thanks for the support.

artf commented 7 years ago

Every time I run that code I have a new item in grapesjs.editors array and that seems not so good to me.

Why do you care about grapesjs.editors? It just contains the initialized editor, nothing more.

Your configuration seems good, so can you explain more about the issue with the uploader, because I'm not able to reproduce it. The ajax is not firing?!? you're not able to select files?!?

g41n commented 6 years ago

With version 0.12.8 my previous implementation seems working. Thanks for the support :smile:

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.