Simplify indentation, add blocking modals. Fixes #412

This commit is contained in:
Tom MacWright
2013-01-23 12:30:22 -05:00
parent 5c65af512d
commit eefa22531c
4 changed files with 57 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
iD.ui.loading = function(message) {
var modal = iD.ui.modal();
iD.ui.loading = function(message, blocking) {
var modal = iD.ui.modal(blocking);
var loadertext = modal.select('.content')
.classed('loading-modal', true)

View File

@@ -1,4 +1,4 @@
iD.ui.modal = function() {
iD.ui.modal = function(blocking) {
var animate = d3.select('div.modal').empty();
d3.select('div.modal').transition()
@@ -9,7 +9,7 @@ iD.ui.modal = function() {
.attr('class', 'shaded')
.style('opacity', 0)
.on('click.remove-modal', function() {
if (d3.event.target == this) d3.select(this).remove();
if (d3.event.target == this && !blocking) d3.select(this).remove();
});
var modal = shaded.append('div')
@@ -18,7 +18,7 @@ iD.ui.modal = function() {
modal.append('button')
.attr('class', 'icon remove close-modal')
.on('click', function() {
shaded.remove();
if (!blocking) shaded.remove();
});
modal.append('div')

View File

@@ -14,60 +14,61 @@ iD.ui.save = function() {
.placement('bottom'))
.on('click', function() {
function commit(e) {
d3.select('.shaded').remove();
var l = iD.ui.loading('Uploading changes to OpenStreetMap.');
connection.putChangeset(history.changes(), e.comment, history.imagery_used(), function(err, changeset_id) {
l.remove();
history.reset();
map.flush().redraw();
if (err) {
var desc = iD.ui.confirm()
.select('.description');
desc.append('h2')
.text('An error occurred while trying to save');
desc.append('p').text(err.responseText);
} else {
var modal = iD.ui.modal();
modal.select('.content')
.classed('success-modal', true)
.datum({
id: changeset_id,
comment: e.comment
})
.call(iD.ui.success()
.on('cancel', function() {
modal.remove();
}));
}
});
}
if (history.hasChanges()) {
connection.authenticate(function(err) {
function commit(e) {
d3.select('.shaded').remove();
var l = iD.ui.loading('Uploading changes to OpenStreetMap.', true);
connection.putChangeset(history.changes(), e.comment, history.imagery_used(), function(err, changeset_id) {
l.remove();
history.reset();
map.flush().redraw();
if (err) {
var desc = iD.ui.confirm()
.select('.description');
desc.append('h2')
.text('An error occurred while trying to save');
desc.append('p').text(err.responseText);
} else {
var modal = iD.ui.modal();
var changes = history.changes();
changes.connection = connection;
modal.select('.content')
.classed('commit-modal', true)
.datum(changes)
.call(iD.ui.commit()
.classed('success-modal', true)
.datum({
id: changeset_id,
comment: e.comment
})
.call(iD.ui.success()
.on('cancel', function() {
modal.remove();
})
.on('fix', function(d) {
map.extent(d.entity.extent(map.history().graph()));
if (map.zoom() > 19) map.zoom(19);
controller.enter(iD.modes.Select(d.entity));
modal.remove();
})
.on('save', commit));
});
} else {
iD.ui.confirm().select('.description')
.append('h3').text('You don\'t have any changes to save.');
}
});
}));
}
});
}
if (history.hasChanges()) {
connection.authenticate(function(err) {
var modal = iD.ui.modal();
var changes = history.changes();
changes.connection = connection;
modal.select('.content')
.classed('commit-modal', true)
.datum(changes)
.call(iD.ui.commit()
.on('cancel', function() {
modal.remove();
})
.on('fix', function(d) {
map.extent(d.entity.extent(map.history().graph()));
if (map.zoom() > 19) map.zoom(19);
controller.enter(iD.modes.Select(d.entity));
modal.remove();
})
.on('save', commit));
});
} else {
iD.ui.confirm().select('.description')
.append('h3').text('You don\'t have any changes to save.');
}
});
selection.append('span')
.attr('class', 'count');

View File

@@ -66,7 +66,7 @@ describe('iD.Map', function() {
expect(map.center()[0]).to.be.closeTo(20, 0.5);
expect(map.center()[1]).to.be.closeTo(20, 0.5);
done();
}, 500);
}, 1000);
});
});