Grapesjs: Asset manager alert

Created on 20 Jan 2020  路  4Comments  路  Source: artf/grapesjs

Hi, thanks for the wonderful editor,
I Tried to integrate the editor and everything is Fine.
When the user selects an image from the asset manager there is no action if an alert is shown that image has been replaced or image selected successfully how can an alert be achieved is there any options for That.
Couldn't find a way to add an alert please let me know if there is a way to achieve this

Most helpful comment

Hi @pradeeshattlee place the below code inside a plugin:

        const am = editor.AssetManager;
        am.addType('image', {
            view: {
                onDblClick(){
                    alert('Selected Successfully!');
                    this.em.get('Modal').close();
                },
            }
        })

for more on extending asset manager, check out this link
cheers!

All 4 comments

Hi @pradeeshattlee place the below code inside a plugin:

        const am = editor.AssetManager;
        am.addType('image', {
            view: {
                onDblClick(){
                    alert('Selected Successfully!');
                    this.em.get('Modal').close();
                },
            }
        })

for more on extending asset manager, check out this link
cheers!

hi @pouyamiralayi @artf
I tried the code it's working perfectly.
but this Generates alert on double click
but the image gets replaced on a single click
I tried the bellow code the alert is shown on a single click but the image doesn't get replaced

Is there a way to change the image and get an alert on a single click or to only change the image on double click.

    const am = editor.AssetManager;
    am.addType('image', {
        view: {
            onclick(){
                alert('Selected Successfully!');
                this.em.get('Modal').close();
            },
        }
    })

I tried the bellow code the alert is shown on a single click but the image doesn't get replaced

This happens because you overwrite the original method, to extend it correctly you should do this:

const am = editor.AssetManager;
const tImageView = am.getType('image').view;

am.addType('image', {
        view: {
            onClick(){
                tImageView.prototype.onClick.apply(this);
                alert('Selected Successfully!');
                this.em.get('Modal').close();
            },
        }
})

Thanks @artf this works like a charm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tribulant picture tribulant  路  3Comments

kawika-connell picture kawika-connell  路  3Comments

ryandeba picture ryandeba  路  3Comments

Snarkly picture Snarkly  路  3Comments

YashPrince picture YashPrince  路  3Comments