Submit note comments with cmd+enter

(closes #5193)
This commit is contained in:
Bryan Housel
2018-08-07 10:05:12 -04:00
parent 12f402c48b
commit ff9e60d205
2 changed files with 90 additions and 45 deletions

View File

@@ -129,6 +129,7 @@ export function modeSelectNote(context, selectedNoteID) {
context.ui().sidebar
.hide();
context.selectedNoteID(null);
};

View File

@@ -160,8 +160,9 @@ export function uiNoteEditor(context) {
.attr('maxlength', 1000)
.property('value', function(d) { return d.newComment; })
.call(utilNoAuto)
.on('input', changeInput)
.on('blur', changeInput);
.on('keydown.note-input', keydown)
.on('input.note-input', changeInput)
.on('blur.note-input', changeInput);
// update
noteSave = noteSaveEnter
@@ -170,6 +171,36 @@ export function uiNoteEditor(context) {
.call(noteSaveButtons);
// fast submit if user presses cmd+enter
function keydown() {
if (!(d3_event.keyCode === 13 && d3_event.metaKey)) return;
var osm = services.osm;
if (!osm) return;
var hasAuth = osm.authenticated();
if (!hasAuth) return;
if (!_note.newComment) return;
d3_event.preventDefault();
d3_select(this)
.on('keydown.note-input', null);
// focus on button and submit
window.setTimeout(function() {
if (_note.isNew()) {
noteSave.selectAll('.save-button').node().focus();
clickSave(_note);
} else {
noteSave.selectAll('.comment-button').node().focus();
clickComment(_note);
}
}, 10);
}
function changeInput() {
var input = d3_select(this);
var val = input.property('value').trim() || undefined;
@@ -323,29 +354,11 @@ export function uiNoteEditor(context) {
.merge(buttonEnter);
buttonSection.select('.cancel-button') // select and propagate data
.on('click.cancel', function(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
osm.removeNote(d);
}
context.enter(modeBrowse(context));
dispatch.call('change');
});
.on('click.cancel', clickCancel);
buttonSection.select('.save-button') // select and propagate data
.attr('disabled', function(d) {
return (hasAuth && d.status === 'open' && d.newComment) ? null : true;
})
.on('click.save', function(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
osm.postNoteCreate(d, function(err, note) {
dispatch.call('change', note);
});
}
});
buttonSection.select('.save-button') // select and propagate data
.attr('disabled', isSaveDisabled)
.on('click.save', clickSave);
buttonSection.select('.status-button') // select and propagate data
.attr('disabled', (hasAuth ? null : true))
@@ -354,30 +367,61 @@ export function uiNoteEditor(context) {
var andComment = (d.newComment ? '_comment' : '');
return t('note.' + action + andComment);
})
.on('click.status', function(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
var setStatus = (d.status === 'open' ? 'closed' : 'open');
osm.postNoteUpdate(d, setStatus, function(err, note) {
dispatch.call('change', note);
});
}
});
.on('click.status', clickStatus);
buttonSection.select('.comment-button') // select and propagate data
.attr('disabled', function(d) {
return (hasAuth && d.status === 'open' && d.newComment) ? null : true;
})
.on('click.comment', function(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
osm.postNoteUpdate(d, d.status, function(err, note) {
dispatch.call('change', note);
});
}
.attr('disabled', isSaveDisabled)
.on('click.comment', clickComment);
function isSaveDisabled(d) {
return (hasAuth && d.status === 'open' && d.newComment) ? null : true;
}
}
function clickCancel(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
osm.removeNote(d);
}
context.enter(modeBrowse(context));
dispatch.call('change');
}
function clickSave(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
osm.postNoteCreate(d, function(err, note) {
dispatch.call('change', note);
});
}
}
function clickStatus(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
var setStatus = (d.status === 'open' ? 'closed' : 'open');
osm.postNoteUpdate(d, setStatus, function(err, note) {
dispatch.call('change', note);
});
}
}
function clickComment(d) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
osm.postNoteUpdate(d, d.status, function(err, note) {
dispatch.call('change', note);
});
}
}