diff --git a/js/id/actions/delete_node.js b/js/id/actions/delete_node.js index a93129ce3..48e704ac3 100644 --- a/js/id/actions/delete_node.js +++ b/js/id/actions/delete_node.js @@ -1,6 +1,6 @@ // https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteNodeAction.as iD.actions.DeleteNode = function(nodeId) { - return function(graph) { + var action = function(graph) { var node = graph.entity(nodeId); graph.parentWays(node) @@ -20,4 +20,10 @@ iD.actions.DeleteNode = function(nodeId) { return graph.remove(node); }; + + action.enabled = function(graph) { + return true; + }; + + return action; }; diff --git a/js/id/actions/delete_way.js b/js/id/actions/delete_way.js index 19e9e7c2a..224537c81 100644 --- a/js/id/actions/delete_way.js +++ b/js/id/actions/delete_way.js @@ -1,6 +1,6 @@ // https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as iD.actions.DeleteWay = function(wayId) { - return function(graph) { + var action = function(graph) { var way = graph.entity(wayId); graph.parentRelations(way) @@ -29,4 +29,10 @@ iD.actions.DeleteWay = function(wayId) { return graph.remove(way); }; + + action.enabled = function(graph) { + return true; + } + + return action; }; diff --git a/js/id/actions/reverse_way.js b/js/id/actions/reverse_way.js index 160017637..4a7d392b7 100644 --- a/js/id/actions/reverse_way.js +++ b/js/id/actions/reverse_way.js @@ -53,7 +53,7 @@ iD.actions.ReverseWay = function(wayId) { } } - return function(graph) { + var action = function(graph) { var way = graph.entity(wayId), nodes = way.nodes.slice().reverse(), tags = {}, key, role; @@ -73,4 +73,10 @@ iD.actions.ReverseWay = function(wayId) { return graph.replace(way.update({nodes: nodes, tags: tags})); }; + + action.enabled = function(graph) { + return true; + }; + + return action; }; diff --git a/js/id/actions/split_way.js b/js/id/actions/split_way.js index f6d502b97..6db8b57e0 100644 --- a/js/id/actions/split_way.js +++ b/js/id/actions/split_way.js @@ -19,7 +19,7 @@ iD.actions.SplitWay = function(nodeId, newWayId) { } var action = function(graph) { - if (!action.permitted(graph)) + if (!action.enabled(graph)) return graph; var way = candidateWays(graph)[0], @@ -60,7 +60,7 @@ iD.actions.SplitWay = function(nodeId, newWayId) { return graph; }; - action.permitted = function(graph) { + action.enabled = function(graph) { return candidateWays(graph).length === 1; }; diff --git a/js/id/actions/unjoin_node.js b/js/id/actions/unjoin_node.js index 037c56137..39e05a9cf 100644 --- a/js/id/actions/unjoin_node.js +++ b/js/id/actions/unjoin_node.js @@ -10,7 +10,7 @@ // iD.actions.UnjoinNode = function(nodeId, newNodeId) { var action = function(graph) { - if (!action.permitted(graph)) + if (!action.enabled(graph)) return graph; var node = graph.entity(nodeId); @@ -29,7 +29,7 @@ iD.actions.UnjoinNode = function(nodeId, newNodeId) { return graph; }; - action.permitted = function(graph) { + action.enabled = function(graph) { return graph.parentWays(graph.entity(nodeId)).length >= 2; }; diff --git a/test/spec/actions/split_way.js b/test/spec/actions/split_way.js index 09bacb82a..6074cbaa8 100644 --- a/test/spec/actions/split_way.js +++ b/test/spec/actions/split_way.js @@ -1,5 +1,5 @@ describe("iD.actions.SplitWay", function () { - describe("#permitted", function () { + describe("#enabled", function () { it("returns true for a non-end node of a single way", function () { var graph = iD.Graph({ 'a': iD.Node({id: 'a'}), @@ -8,7 +8,7 @@ describe("iD.actions.SplitWay", function () { '-': iD.Way({id: '-', nodes: ['a', 'b', 'c']}) }); - expect(iD.actions.SplitWay('b').permitted(graph)).to.be.true; + expect(iD.actions.SplitWay('b').enabled(graph)).to.be.true; }); it("returns false for the first node of a single way", function () { @@ -18,7 +18,7 @@ describe("iD.actions.SplitWay", function () { '-': iD.Way({id: '-', nodes: ['a', 'b']}) }); - expect(iD.actions.SplitWay('a').permitted(graph)).to.be.false; + expect(iD.actions.SplitWay('a').enabled(graph)).to.be.false; }); it("returns false for the last node of a single way", function () { @@ -28,7 +28,7 @@ describe("iD.actions.SplitWay", function () { '-': iD.Way({id: '-', nodes: ['a', 'b']}) }); - expect(iD.actions.SplitWay('b').permitted(graph)).to.be.false; + expect(iD.actions.SplitWay('b').enabled(graph)).to.be.false; }); }); diff --git a/test/spec/actions/unjoin_node.js b/test/spec/actions/unjoin_node.js index 247239f5c..5901e97da 100644 --- a/test/spec/actions/unjoin_node.js +++ b/test/spec/actions/unjoin_node.js @@ -1,9 +1,9 @@ describe("iD.actions.UnjoinNode", function () { - describe("#permitted", function () { + describe("#enabled", function () { it("returns false for a node shared by less than two ways", function () { var graph = iD.Graph({'a': iD.Node()}); - expect(iD.actions.UnjoinNode('a').permitted(graph)).to.equal(false); + expect(iD.actions.UnjoinNode('a').enabled(graph)).to.equal(false); }); it("returns true for a node shared by two or more ways", function () { @@ -19,7 +19,7 @@ describe("iD.actions.UnjoinNode", function () { '|': iD.Way({id: '|', nodes: ['d', 'b']}) }); - expect(iD.actions.UnjoinNode('b').permitted(graph)).to.equal(true); + expect(iD.actions.UnjoinNode('b').enabled(graph)).to.equal(true); }); });