Changeset panel can now cancel and save comments.

This commit is contained in:
Tom MacWright
2012-11-26 17:33:50 -05:00
parent eee436be80
commit 0a7d5e8e78
5 changed files with 40 additions and 12 deletions

View File

@@ -247,9 +247,15 @@ button small {
.commit-pane ul {
border-bottom:1px solid #ccc;
background:#fff;
}
.commit-pane li {
border-top:1px solid #ccc;
padding:2px;
padding:2px 10px;
}
.commit-pane .changeset-comment {
width:630px;
font-size:100%;
}

View File

@@ -97,12 +97,12 @@ iD.Connection = function() {
return oauth.authenticated();
}
function createChangeset(changes) {
function putChangeset(changes, comment, callback) {
oauth.xhr({
method: 'PUT',
path: '/api/0.6/changeset/create',
options: { header: { 'Content-Type': 'text/xml' } },
content: iD.format.XML.changeset()
content: iD.format.XML.changeset(comment)
},
function (changeset_id) {
oauth.xhr({
@@ -115,7 +115,7 @@ iD.Connection = function() {
method: 'PUT',
path: '/api/0.6/changeset/' + changeset_id + '/close'
}, function () {
alert('saved! ' + apiURL.replace('/api/0.6', '/browse') + '/changeset/' + changeset_id);
callback(changeset_id);
});
});
});
@@ -155,7 +155,7 @@ iD.Connection = function() {
connection.userDetails = userDetails;
connection.authenticate = authenticate;
connection.authenticated = authenticated;
connection.createChangeset = createChangeset;
connection.putChangeset = putChangeset;
connection.objectData = objectData;
connection.apiURL = apiURL;

View File

@@ -69,13 +69,21 @@ var iD = function(container) {
.html("Save<small id='as-username'></small>")
.on('click', function() {
connection.authenticate(function() {
var commitpane = iD.Commit();
var shaded = d3.select(document.body)
.append('div').attr('class', 'shaded');
var modal = shaded.append('div')
.attr('class', 'modal commit-pane')
.datum(map.history.changes());
modal.call(iD.Commit());
// map.commit();
modal.call(commitpane);
commitpane.on('cancel', function() {
shaded.remove();
});
commitpane.on('save', function(e) {
connection.putChangeset(map.history.changes(), e.comment, function() {
shaded.remove();
});
});
});
});

View File

@@ -503,7 +503,7 @@ iD.Map = function(elem, connection) {
}
function commit() {
connection.createChangeset(history.changes());
connection.putChangeset(history.changes());
}
map.download = download;

View File

@@ -1,5 +1,5 @@
iD.Commit = function() {
var event = d3.dispatch();
var event = d3.dispatch('cancel', 'save');
function commit(selection) {
var changes = selection.datum();
@@ -9,7 +9,9 @@ iD.Commit = function() {
header.append('h2').text('Save Changes to OpenStreetMap');
var section = body.selectAll('div.section')
.data(['modify', 'delete', 'create'])
.data(['modify', 'delete', 'create'].filter(function(d) {
return changes[d].length;
}))
.enter()
.append('div').attr('class', 'section');
@@ -31,8 +33,20 @@ iD.Commit = function() {
return iD.Util.friendlyName(d);
});
body.append('button').text('Save');
body.append('button').text('Cancel');
body.append('textarea')
.attr('class', 'changeset-comment')
.attr('placeholder', 'Brief Description');
body.append('button').text('Save')
.on('click', function() {
event.save({
comment: d3.select('textarea.changeset-comment').node().value
});
});
body.append('button').text('Cancel')
.on('click', function() {
event.cancel();
});
}
return d3.rebind(commit, event, 'on');