diff --git a/index.html b/index.html index 5cd8ff735..f94a11019 100644 --- a/index.html +++ b/index.html @@ -76,6 +76,7 @@ + diff --git a/js/id/actions/delete_multiple.js b/js/id/actions/delete_multiple.js new file mode 100644 index 000000000..839c1d780 --- /dev/null +++ b/js/id/actions/delete_multiple.js @@ -0,0 +1,15 @@ +iD.actions.DeleteMultiple = function(ids) { + return function(graph) { + var actions = { + way: iD.actions.DeleteWay, + node: iD.actions.DeleteNode, + relation: iD.actions.DeleteRelation + }; + + ids.forEach(function (id) { + graph = actions[graph.entity(id).type](id)(graph); + }); + + return graph; + }; +}; diff --git a/js/id/operations/delete.js b/js/id/operations/delete.js index 33c638ce0..2c9765b62 100644 --- a/js/id/operations/delete.js +++ b/js/id/operations/delete.js @@ -1,22 +1,20 @@ iD.operations.Delete = function(selection, context) { - var entityId = selection[0]; - var operation = function() { - var entity = context.entity(entityId), - action = { - way: iD.actions.DeleteWay, - node: iD.actions.DeleteNode, - relation: iD.actions.DeleteRelation - }[entity.type], - annotation = t('operations.delete.annotation.' + context.geometry(entityId)); + var annotation; + + if (selection.length === 1) { + annotation = t('operations.delete.annotation.' + context.geometry(selection[0])); + } else { + annotation = t('operations.delete.annotation.multiple', {n: selection.length}); + } context.perform( - action(entityId), + iD.actions.DeleteMultiple(selection), annotation); }; operation.available = function() { - return selection.length === 1; + return true; }; operation.enabled = function() { diff --git a/locale/en.js b/locale/en.js index d7fc3628f..b32149ee3 100644 --- a/locale/en.js +++ b/locale/en.js @@ -73,7 +73,8 @@ locale.en = { point: "Deleted a point.", vertex: "Deleted a node from a way.", line: "Deleted a line.", - area: "Deleted an area." + area: "Deleted an area.", + multiple: "Deleted {n} objects." } }, move: { diff --git a/test/index.html b/test/index.html index 120938b5f..1ed505174 100644 --- a/test/index.html +++ b/test/index.html @@ -73,6 +73,7 @@ + @@ -141,6 +142,7 @@ + diff --git a/test/index_packaged.html b/test/index_packaged.html index 1764e5a9e..4b44086c5 100644 --- a/test/index_packaged.html +++ b/test/index_packaged.html @@ -35,6 +35,7 @@ + diff --git a/test/spec/actions/delete_multiple.js b/test/spec/actions/delete_multiple.js new file mode 100644 index 000000000..3a70adc38 --- /dev/null +++ b/test/spec/actions/delete_multiple.js @@ -0,0 +1,12 @@ +describe("iD.actions.DeleteMultiple", function () { + it("deletes multiple entities of heterogeneous types", function () { + var n = iD.Node(), + w = iD.Way(), + r = iD.Relation(), + action = iD.actions.DeleteMultiple([n.id, w.id, r.id]), + graph = action(iD.Graph([n, w, r])); + expect(graph.entity(n.id)).to.be.undefined; + expect(graph.entity(w.id)).to.be.undefined; + expect(graph.entity(r.id)).to.be.undefined; + }); +});