Files
gerrit/polygerrit-ui/app/elements/settings/gr-menu-editor/gr-menu-editor.js
Becky Siegel 37636a6256 Update iron-input to 2.0
This version is compatible with Polymer 1 and Polymer 2, but required
for Polymer 2.

Elements that were formerly
<input is="iron-input>

are now
<iron-input>
  <input>
</iron-input>

There are a few scenarios in which inputs were not using two way data
binding, which is the reason for using iron-input, and those have been
modified back to a native input.

With the updated iron-input to access the native input, there is an
'inputElement' getter function, which is used heavily in this update.

Also of note, in many tests, it is required to wrap Polymer.Base.async,
which is necessary because the mutation observer is async:

https://github.com/PolymerElements/iron-input/blob/master/test/iron-input.html

Also modifies polylint_test to explicitly ignore bower_components.

Change-Id: I75f7fa1bb0c00837f631f6e1043e15a3270b9bce
2017-07-17 10:20:08 -07:00

72 lines
1.9 KiB
JavaScript

// 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';
Polymer({
is: 'gr-menu-editor',
properties: {
menuItems: Array,
_newName: String,
_newUrl: String,
},
_handleMoveUpButton(e) {
const index = e.target.dataIndex;
if (index === 0) { return; }
const row = this.menuItems[index];
const prev = this.menuItems[index - 1];
this.splice('menuItems', index - 1, 2, row, prev);
},
_handleMoveDownButton(e) {
const index = e.target.dataIndex;
if (index === this.menuItems.length - 1) { return; }
const row = this.menuItems[index];
const next = this.menuItems[index + 1];
this.splice('menuItems', index, 2, next, row);
},
_handleDeleteButton(e) {
const index = e.target.dataIndex;
this.splice('menuItems', index, 1);
},
_handleAddButton() {
if (this._computeAddDisabled(this._newName, this._newUrl)) { return; }
this.splice('menuItems', this.menuItems.length, 0, {
name: this._newName,
url: this._newUrl,
target: '_blank',
});
this._newName = '';
this._newUrl = '';
},
_computeAddDisabled(newName, newUrl) {
return !newName || !newUrl;
},
_handleInputKeydown(e) {
if (e.keyCode === 13) {
e.stopPropagation();
this._handleAddButton();
}
},
});
})();