Element Menu Plugin

Plugin to add new items to vertex or edge context menu. Providing a shouldDisable handler will still show the item in the context menu, provide a canHandle function if you want to remove items completely based on the current selection and target element.

To add a divider:

registry.registerExtension('org.visallo.vertex.menu', 'DIVIDER');  // vertex menu
registry.registerExtension('org.visallo.edge.menu', 'DIVIDER');  //edge menu

Example

To register an item:

require(['public/v1/api'], function(visallo) {

    visallo.connect().then(function(api) {
        visallo.registry.registerExtension('org.visallo.vertex.menu', {
            label: i18n('org.visallo.examples.vertex.menu.google'),
            event: 'context-menu-search-google',
            selection: 1,
            shouldDisable: (selection, vertexId, DOMelement, vertex) => {
                return api.formatters.vertex.title(vertex) === i18n('vertex.property.title.not_available');
            },
            options: {
                insertIntoMenuItems: function(item, items) {
                    //add item under search submenu
                    var search = _.findWhere(items, { label: i18n('vertex.contextmenu.search') });
                    if (search && search.submenu) {
                        search.submenu.push(item);
                    } else {
                        items.push(item);
                    }
                }
            }
        });
    // 25 lines hidden…
});

Then add an event listener to handle when your menu item is clicked:

visallo.connect().then(function(api) {
    // 32 lines hidden…
    $(document).on('context-menu-search-google', function(e, data) {
        api.dataRequest('vertex', 'store', {vertexIds: [data.vertexId]}).then(result => {
            var title = api.formatters.vertex.title(result[0]);
            var url = 'http://www.google.com/#safe=on&q=' + title;
            window.open(url, '_blank');
        });
    });
    // 4 lines hidden…
});

results matching ""

    No results matching ""