From 4645c7654d854678dbcbf0123c597da30a251282 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Wed, 6 Mar 2019 16:27:10 -0500 Subject: [PATCH] Disable search field when editing is not allowed --- css/80_app.css | 5 ++++- modules/ui/search_add.js | 32 +++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/css/80_app.css b/css/80_app.css index d5a647638..dd7b7818c 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -607,7 +607,6 @@ button.add-note svg.icon { min-width: 200px; max-width: 250px; border-radius: 20px 0 0 20px; - background: #fff; } .search-add .search-wrap.focused .tooltip { display: none; @@ -626,6 +625,10 @@ button.add-note svg.icon { padding: 5px 10px; border-radius: inherit; } +.search-add input[type='search'][disabled] { + opacity: 0.25; + cursor: not-allowed; +} .search-add .search-icon { color: #333; display: block; diff --git a/modules/ui/search_add.js b/modules/ui/search_add.js index 24d45d503..01632665f 100644 --- a/modules/ui/search_add.js +++ b/modules/ui/search_add.js @@ -1,5 +1,6 @@ -import { dispatch as d3_dispatch } from 'd3-dispatch'; +import _debounce from 'lodash-es/debounce'; +import { dispatch as d3_dispatch } from 'd3-dispatch'; import { event as d3_event, select as d3_select, @@ -24,7 +25,10 @@ import { utilKeybinding, utilNoAuto, utilRebind } from '../util'; export function uiSearchAdd(context) { var dispatch = d3_dispatch('choose'); var presets; - var search = d3_select(null), popover = d3_select(null), list = d3_select(null); + var searchWrap = d3_select(null), + search = d3_select(null), + popover = d3_select(null), + list = d3_select(null); var shownGeometry = ['area', 'line', 'point', 'vertex']; @@ -34,7 +38,7 @@ export function uiSearchAdd(context) { var key = t('modes.add_feature.key'); - var searchWrap = selection + searchWrap = selection .append('div') .attr('class', 'search-wrap') .call(tooltip() @@ -103,6 +107,28 @@ export function uiSearchAdd(context) { d3_event.preventDefault(); d3_event.stopPropagation(); }); + + var debouncedUpdate = _debounce(updateEnabledState, 500, { leading: true, trailing: true }); + + context.map() + .on('move.search-add', debouncedUpdate) + .on('drawn.search-add', debouncedUpdate); + + updateEnabledState(); + } + + function osmEditable() { + var mode = context.mode(); + return context.editable() && mode && mode.id !== 'save'; + } + + function updateEnabledState() { + var isEnabled = osmEditable(); + searchWrap.classed('disabled', !isEnabled); + if (!isEnabled) { + search.node().blur(); + } + search.attr('disabled', isEnabled ? null : true); } function keypress() {