From 90a0128d8e2a750685a9966c335a30a777ee393d Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 5 Dec 2012 13:17:22 -0500 Subject: [PATCH] Do not create empty changesets #191 --- css/app.css | 6 +++--- js/id/id.js | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/css/app.css b/css/app.css index 3daa32ffa..fbb8de027 100644 --- a/css/app.css +++ b/css/app.css @@ -265,9 +265,9 @@ div.typeahead a.active { box-shadow:0 0 5px #000; } -.modal.loading-pane { - width:300px; - height:200px; +.modal.modal-alert { + width:320px; + height:100px; margin-left:-160px; } diff --git a/js/id/id.js b/js/id/id.js index fce441595..f857e7325 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -84,17 +84,36 @@ window.iD = function(container) { map.flush().redraw(); }); } - connection.authenticate(function() { + var changes = history.changes(); + var has_changes = d3.sum(d3.values(changes).map(function(c) { + return c.length; + })) > 0; + + if (has_changes) { + connection.authenticate(function() { + var modal = iD.modal(); + modal.select('.content') + .classed('commit-modal', true) + .datum(history.changes()) + .call(iD.commit() + .on('cancel', function() { + modal.remove(); + }) + .on('save', save)); + }); + } else { var modal = iD.modal(); + modal.select('.modal').classed('modal-alert', true); modal.select('.content') - .classed('commit-modal', true) - .datum(history.changes()) - .call(iD.commit() - .on('cancel', function() { - modal.remove(); - }) - .on('save', save)); - }); + .append('p') + .text('You don\'t have any changes to save.'); + modal.select('.content') + .append('button') + .text('OK') + .on('click', function() { + modal.remove(); + }); + } }); var zoom = bar.append('div')