Snippets

Piotr Szrajber Geospatial Portal - Remove Selected Features Confirmation

Created by Piotr Szrajber last modified
/**
 * Add confirmation before deleting selecting features. As it touches the internal removeSelectedFeatures implementation, it affects both UI controls and API calls.
 *
 * This runtime patch is intended to be appended to the MapConfig.js file of the portal instance
 * 
 * 2016-10-21 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
 * 2016-11-21 Added $event.notify calls to cancel the pending map operation
 */
Sys.Application.add_init(function() {
    Intergraph.WebSolutions.Core.WebClient.Platform.ClientScript.Edit.InsertFeature.prototype.removeSelectedFeatures = function() {
        var args = Array.prototype.slice.call(arguments);
        $GP.selectedFeatures.find({}, function(ret) {
            // ret.featureClassIds is array of feature class Ids
            // ret.featureIds and ret.features are multidimensional arrays with array of features for each featureClassId from ret.featureClassIds
            if (ret.featureClassIds.join(",").indexOf("UndeletableFeatureClass1") > -1) {
                $GP.ui.info("You cannot delete objects from this feature class!");
                $event.notify("cancelMapOperation", {mapStateId: "map"}, this);
                return;
            }
            // Examine feature classes and features using $GP.selectedFeatures methods and decide what to do
            var confirmation = window.confirm("Are you sure?");
            if (confirmation) {
                orig.call(this);
            } else {
                $GP.ui.info("Features saved");
                $event.notify("cancelMapOperation", {mapStateId: "map"}, this);
            }
        });

    };
});

Comments (0)