diff options
Diffstat (limited to 'polygerrit-ui/app/elements/change/gr-account-entry/gr-account-entry.js')
-rw-r--r-- | polygerrit-ui/app/elements/change/gr-account-entry/gr-account-entry.js | 84 |
1 files changed, 64 insertions, 20 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-account-entry/gr-account-entry.js b/polygerrit-ui/app/elements/change/gr-account-entry/gr-account-entry.js index d3f2386744..715ddc05ea 100644 --- a/polygerrit-ui/app/elements/change/gr-account-entry/gr-account-entry.js +++ b/polygerrit-ui/app/elements/change/gr-account-entry/gr-account-entry.js @@ -1,16 +1,19 @@ -// Copyright (C) 2016 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/** + * @license + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ (function() { 'use strict'; @@ -22,10 +25,18 @@ * * @event add */ + + /** + * When allowAnyInput is true, account-text-changed is fired when input text + * changed. This is needed so that the reply dialog's save button can be + * enabled for arbitrary cc's, which don't need a 'commit'. + * + * @event account-text-changed + */ properties: { + allowAnyInput: Boolean, borderless: Boolean, change: Object, - _config: Object, filter: Function, placeholder: String, /** @@ -51,6 +62,15 @@ return this._getReviewerSuggestions.bind(this); }, }, + + _config: Object, + /** The value of the autocomplete entry. */ + _inputText: { + type: String, + observer: '_inputTextChanged', + }, + + _loggedIn: Boolean, }, behaviors: [ @@ -61,6 +81,9 @@ this.$.restAPI.getConfig().then(cfg => { this._config = cfg; }); + this.$.restAPI.getLoggedIn().then(loggedIn => { + this._loggedIn = loggedIn; + }); }, get focusStart() { @@ -92,17 +115,26 @@ return this.getUserName(this._config, reviewer, false); }, + _inputTextChanged(text) { + if (text.length && this.allowAnyInput) { + this.dispatchEvent(new CustomEvent('account-text-changed', + {bubbles: true})); + } + }, + _makeSuggestion(reviewer) { let name; let value; const generateStatusStr = function(account) { - return account.status ? ' (' + account.status + ')' : ''; + return account.status ? '(' + account.status + ')' : ''; }; if (reviewer.account) { // Reviewer is an account suggestion from getChangeSuggestedReviewers. const reviewerName = this._accountOrAnon(reviewer.account); - name = reviewerName + ' <' + reviewer.account.email + '>' + - generateStatusStr(reviewer.account); + const reviewerEmail = this._reviewerEmail(reviewer.account.email); + const reviewerStatus = generateStatusStr(reviewer.account); + name = [reviewerName, reviewerEmail, reviewerStatus] + .filter(p => p.length > 0).join(' '); value = reviewer; } else if (reviewer.group) { // Reviewer is a group suggestion from getChangeSuggestedReviewers. @@ -111,15 +143,19 @@ } else if (reviewer._account_id) { // Reviewer is an account suggestion from getSuggestedAccounts. const reviewerName = this._accountOrAnon(reviewer); - name = reviewerName + ' <' + reviewer.email + '>' + - generateStatusStr(reviewer); + const reviewerEmail = this._reviewerEmail(reviewer.email); + const reviewerStatus = generateStatusStr(reviewer); + name = [reviewerName, reviewerEmail, reviewerStatus] + .filter(p => p.length > 0).join(' '); value = {account: reviewer, count: 1}; } return {name, value}; }, _getReviewerSuggestions(input) { - if (!this.change || !this.change._number) { return Promise.resolve([]); } + if (!this.change || !this.change._number || !this._loggedIn) { + return Promise.resolve([]); + } const api = this.$.restAPI; const xhr = this.allowAnyUser ? @@ -136,5 +172,13 @@ .map(this._makeSuggestion.bind(this)); }); }, + + _reviewerEmail(email) { + if (typeof email !== 'undefined') { + return '<' + email + '>'; + } + + return ''; + }, }); })(); |