Files
iD/js/id/actions/delete_relation.js
John Firebaugh da9602795c Don't allow deleting incomplete relations
This will fail with an "entity not found" error.
2013-05-16 16:43:41 -07:00

36 lines
1.2 KiB
JavaScript

// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteRelationAction.as
iD.actions.DeleteRelation = function(relationId) {
function deleteEntity(entity, graph) {
return !graph.parentWays(entity).length &&
!graph.parentRelations(entity).length &&
!entity.hasInterestingTags();
}
var action = function(graph) {
var relation = graph.entity(relationId);
graph.parentRelations(relation)
.forEach(function(parent) {
graph = graph.replace(parent.removeMember(relationId));
});
_.uniq(_.pluck(relation.members, 'id')).forEach(function(memberId) {
graph = graph.replace(relation.removeMember(memberId));
var entity = graph.entity(memberId);
if (deleteEntity(entity, graph)) {
graph = iD.actions.DeleteMultiple([memberId])(graph);
}
});
return graph.remove(relation);
};
action.disabled = function(graph) {
if (!graph.entity(relationId).isComplete(graph))
return 'incomplete_relation';
};
return action;
};