Snippets

Piotr Szrajber Geospatial Portal SDK - remove workspaces with given name or id

Created by Piotr Szrajber
/**
 * Remove workspaces with given id or name
 * @param {String|RegExp} config.name name of the workspace
 * @param {String} config.id id of the workspace. id or name must be passed
 * @param {Funcion} callback success callback
 * @param {Function} errback error callback
 * @return {void}
 * 2017-01-05 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
 */
 function removeWorkspaces(config, callback, errback) {
    $GP.user.workspaces.find({
        predicate: function(obj) {
            console.log(obj);
            return obj.id === config.id || (config.name instanceof RegExp ? config.name.test(obj.name) : obj.name === config.name);
        }
    }, function(ret) {
        var w = ret.workspaces;
        if (w.length === 0) {
            if (typeof errback === "function")
                errback({
                    success: false,
                    message: "Error"
                });
            return;
        };
        for (var i = 0, l = w.length; i < l; i++) {
            w[i].remove();
        }
        if (typeof callback === "function")
            callback({
                success: true
            });

    });
}

// usage:
/*
removeWorkspaces({
    name: /workspace/i
}, function() {
    console.log("Workspaces removed")
})
*/

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.