diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html index 545f8946a6..859b653ff7 100644 --- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html +++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html @@ -15,8 +15,10 @@ limitations under the License. --> + + diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js index 044eb4653c..fb711d4fa4 100644 --- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js +++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js @@ -30,8 +30,16 @@ type: Boolean, value: true, }, + _prefsChanged: { + type: Boolean, + value: false, + }, }, + observers: [ + '_handlePrefsChanged(prefs.*)', + ], + attached: function() { var promises = []; @@ -52,5 +60,16 @@ if (!registered) { return ''; } return util.parseDate(registered).toGMTString(); }, + + _handlePrefsChanged: function() { + if (this._loading || this._loading === undefined) { return; } + this._prefsChanged = true; + }, + + _handleSavePreferences: function() { + this.$.restAPI.savePreferences(this.prefs).then(function() { + this._prefsChanged = false; + }.bind(this)); + }, }); })(); diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js index 298daf7a13..396ae9016a 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js @@ -198,6 +198,11 @@ }.bind(this)); }, + savePreferences: function(prefs, opt_errFn, opt_ctx) { + return this.send('PUT', '/accounts/self/preferences', prefs, opt_errFn, + opt_ctx); + }, + saveDiffPreferences: function(prefs, opt_errFn, opt_ctx) { return this.send('PUT', '/accounts/self/preferences.diff', prefs, opt_errFn, opt_ctx); diff --git a/polygerrit-ui/app/elements/shared/gr-select/gr-select.html b/polygerrit-ui/app/elements/shared/gr-select/gr-select.html new file mode 100644 index 0000000000..fed81bbd2e --- /dev/null +++ b/polygerrit-ui/app/elements/shared/gr-select/gr-select.html @@ -0,0 +1,20 @@ + + + + + + diff --git a/polygerrit-ui/app/elements/shared/gr-select/gr-select.js b/polygerrit-ui/app/elements/shared/gr-select/gr-select.js new file mode 100644 index 0000000000..9e14f08114 --- /dev/null +++ b/polygerrit-ui/app/elements/shared/gr-select/gr-select.js @@ -0,0 +1,55 @@ +// 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-select', + + extends: 'select', + + properties: { + bindValue: { + type: String, + notify: true, + }, + }, + + observers: [ + '_valueChanged(bindValue)', + ], + + attached: function() { + this.addEventListener('change', function() { + this.bindValue = this.value; + }); + }, + + ready: function() { + // If not set via the property, set bind-value to the element value. + if (!this.bindValue) { this.bindValue = this.value; } + }, + + _valueChanged: function(bindValue) { + var options = Polymer.dom(this.root).querySelectorAll('option'); + for (var i = 0; i < options.length; i++) { + if (options[i].getAttribute('value') === bindValue + '') { + options[i].setAttribute('selected', true); + this.value = bindValue; + break; + } + } + }, + }); +})(); diff --git a/polygerrit-ui/app/elements/shared/gr-select/gr-select_test.html b/polygerrit-ui/app/elements/shared/gr-select/gr-select_test.html new file mode 100644 index 0000000000..abdff64445 --- /dev/null +++ b/polygerrit-ui/app/elements/shared/gr-select/gr-select_test.html @@ -0,0 +1,81 @@ + + + + +gr-select + + + + + + + + + + + diff --git a/polygerrit-ui/app/test/index.html b/polygerrit-ui/app/test/index.html index a1f60bb5bc..78eefde91a 100644 --- a/polygerrit-ui/app/test/index.html +++ b/polygerrit-ui/app/test/index.html @@ -65,6 +65,7 @@ limitations under the License. 'shared/gr-editable-label/gr-editable-label_test.html', 'shared/gr-js-api-interface/gr-js-api-interface_test.html', 'shared/gr-linked-text/gr-linked-text_test.html', + 'shared/gr-select/gr-select_test.html', 'shared/gr-rest-api-interface/gr-rest-api-interface_test.html', 'shared/gr-storage/gr-storage_test.html', ].forEach(function(file) {