From 379f49b9987c79a07bc38d34f7f06ef9129b6e00 Mon Sep 17 00:00:00 2001 From: Kohei Yoshino Date: Mon, 15 Jul 2019 18:31:43 -0400 Subject: [PATCH] =?utf8?q?Bug=201566079=20-=20User=20autocomplete=20doesn?= =?utf8?q?=E2=80=99t=20work=20for=20requestee=20for=20certain=20flags?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- js/field.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/js/field.js b/js/field.js index 639484ac1..5631e6cf9 100644 --- a/js/field.js +++ b/js/field.js @@ -738,28 +738,27 @@ $(function() { }, formatResult: function(suggestion) { const $input = this; - const user = suggestion.data; + const { email, real_name, requests, gravatar } = suggestion.data; const request_type = $input.getAttribute('data-request-type'); - const blocked = user.requests && request_type ? user.requests[request_type].blocked : false; - const pending = user.requests && request_type ? user.requests[request_type].pending : 0; - const image = user.gravatar ? `` : ''; + const { blocked, pending } = requests ? (requests[request_type] || {}) : {}; + const image = gravatar ? `` : ''; const description = blocked ? ' Requests blocked' : pending ? `${pending} pending ${request_type}${pending === 1 ? '' : 's'}` : ''; return `
${image} ` + - `${user.real_name.htmlEncode()} ` + - `${user.email.htmlEncode()} ` + + `${real_name.htmlEncode()} ` + + `${email.htmlEncode()} ` + `${description}
`; }, onSelect: function (suggestion) { const $input = this; - const user = suggestion.data; + const { real_name, requests } = suggestion.data; const is_multiple = !!$input.getAttribute('data-multiple'); const request_type = $input.getAttribute('data-request-type'); - const blocked = user.requests && request_type ? user.requests[request_type].blocked : false; + const { blocked } = requests ? (requests[request_type] || {}) : {}; if (blocked) { - window.alert(`${user.real_name} is not accepting ${request_type} requests at this time. ` + + window.alert(`${real_name} is not accepting ${request_type} requests at this time. ` + 'If you’re in a hurry, ask someone else for help.'); } else if (is_multiple) { const _values = $input.value.split(',').map(value => value.trim()); -- 2.47.3