2016-03-04 17:48:22 -05:00
|
|
|
// 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-diff-preferences',
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
prefs: {
|
|
|
|
type: Object,
|
|
|
|
notify: true,
|
|
|
|
},
|
2016-06-08 12:37:31 -07:00
|
|
|
localPrefs: {
|
|
|
|
type: Object,
|
|
|
|
notify: true,
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false,
|
|
|
|
reflectToAttribute: true,
|
|
|
|
},
|
2016-03-24 13:55:54 -04:00
|
|
|
|
2017-08-11 16:32:47 -07:00
|
|
|
/** @type {?} */
|
2016-03-24 13:55:54 -04:00
|
|
|
_newPrefs: Object,
|
2016-06-08 12:37:31 -07:00
|
|
|
_newLocalPrefs: Object,
|
2016-03-04 17:48:22 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
observers: [
|
|
|
|
'_prefsChanged(prefs.*)',
|
2016-06-08 12:37:31 -07:00
|
|
|
'_localPrefsChanged(localPrefs.*)',
|
2016-03-04 17:48:22 -05:00
|
|
|
],
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
getFocusStops() {
|
2016-09-16 10:44:37 -07:00
|
|
|
return {
|
|
|
|
start: this.$.contextSelect,
|
2017-11-20 14:01:39 -08:00
|
|
|
end: this.$.saveButton,
|
2016-09-16 10:44:37 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
resetFocus() {
|
2016-09-16 10:44:37 -07:00
|
|
|
this.$.contextSelect.focus();
|
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_prefsChanged(changeRecord) {
|
|
|
|
const prefs = changeRecord.base;
|
2016-03-24 13:55:54 -04:00
|
|
|
// NOTE: Object.assign is NOT automatically a deep copy. If prefs adds
|
|
|
|
// an object as a value, it must be marked enumerable.
|
|
|
|
this._newPrefs = Object.assign({}, prefs);
|
2016-03-04 17:48:22 -05:00
|
|
|
this.$.contextSelect.value = prefs.context;
|
|
|
|
this.$.showTabsInput.checked = prefs.show_tabs;
|
2016-11-17 12:03:51 -08:00
|
|
|
this.$.showTrailingWhitespaceInput.checked = prefs.show_whitespace_errors;
|
2016-10-31 14:35:35 -07:00
|
|
|
this.$.lineWrappingInput.checked = prefs.line_wrapping;
|
2016-07-27 10:32:44 -07:00
|
|
|
this.$.syntaxHighlightInput.checked = prefs.syntax_highlighting;
|
2018-02-09 10:55:27 -08:00
|
|
|
this.$.automaticReviewInput.checked = !prefs.manual_review;
|
2016-03-04 17:48:22 -05:00
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_localPrefsChanged(changeRecord) {
|
|
|
|
const localPrefs = changeRecord.base || {};
|
2016-06-08 12:37:31 -07:00
|
|
|
this._newLocalPrefs = Object.assign({}, localPrefs);
|
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handleContextSelectChange(e) {
|
|
|
|
const selectEl = Polymer.dom(e).rootTarget;
|
2016-03-24 13:55:54 -04:00
|
|
|
this.set('_newPrefs.context', parseInt(selectEl.value, 10));
|
2016-03-04 17:48:22 -05:00
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handleShowTabsTap(e) {
|
2016-03-24 13:55:54 -04:00
|
|
|
this.set('_newPrefs.show_tabs', Polymer.dom(e).rootTarget.checked);
|
2016-03-04 17:48:22 -05:00
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handleShowTrailingWhitespaceTap(e) {
|
2016-11-17 12:03:51 -08:00
|
|
|
this.set('_newPrefs.show_whitespace_errors',
|
|
|
|
Polymer.dom(e).rootTarget.checked);
|
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handleSyntaxHighlightTap(e) {
|
2016-07-27 10:32:44 -07:00
|
|
|
this.set('_newPrefs.syntax_highlighting',
|
|
|
|
Polymer.dom(e).rootTarget.checked);
|
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handlelineWrappingTap(e) {
|
2016-10-31 14:35:35 -07:00
|
|
|
this.set('_newPrefs.line_wrapping', Polymer.dom(e).rootTarget.checked);
|
2018-02-09 10:55:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_handleAutomaticReviewTap(e) {
|
|
|
|
this.set('_newPrefs.manual_review', !Polymer.dom(e).rootTarget.checked);
|
2016-10-31 14:35:35 -07:00
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handleSave(e) {
|
2017-04-19 12:06:43 -07:00
|
|
|
e.stopPropagation();
|
2016-03-24 13:55:54 -04:00
|
|
|
this.prefs = this._newPrefs;
|
2016-06-08 12:37:31 -07:00
|
|
|
this.localPrefs = this._newLocalPrefs;
|
2017-05-16 14:21:31 -07:00
|
|
|
const el = Polymer.dom(e).rootTarget;
|
2017-04-19 12:06:43 -07:00
|
|
|
el.disabled = true;
|
|
|
|
this.$.storage.savePreferences(this._localPrefs);
|
2017-05-16 14:21:31 -07:00
|
|
|
this._saveDiffPreferences().then(response => {
|
2017-04-19 12:06:43 -07:00
|
|
|
el.disabled = false;
|
|
|
|
if (!response.ok) { return response; }
|
|
|
|
|
|
|
|
this.$.prefsOverlay.close();
|
2017-05-16 14:21:31 -07:00
|
|
|
}).catch(err => {
|
2017-04-19 12:06:43 -07:00
|
|
|
el.disabled = false;
|
2017-05-16 14:21:31 -07:00
|
|
|
});
|
2017-04-19 12:06:43 -07:00
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handleCancel(e) {
|
2017-04-19 12:06:43 -07:00
|
|
|
e.stopPropagation();
|
|
|
|
this.$.prefsOverlay.close();
|
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_handlePrefsTap(e) {
|
2017-04-19 12:06:43 -07:00
|
|
|
e.preventDefault();
|
|
|
|
this._openPrefs();
|
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
open() {
|
|
|
|
this.$.prefsOverlay.open().then(() => {
|
|
|
|
const focusStops = this.getFocusStops();
|
2017-04-19 12:06:43 -07:00
|
|
|
this.$.prefsOverlay.setFocusStops(focusStops);
|
|
|
|
this.resetFocus();
|
2017-05-16 14:21:31 -07:00
|
|
|
});
|
2016-03-04 17:48:22 -05:00
|
|
|
},
|
|
|
|
|
2017-05-16 14:21:31 -07:00
|
|
|
_saveDiffPreferences() {
|
2017-04-19 12:06:43 -07:00
|
|
|
return this.$.restAPI.saveDiffPreferences(this.prefs);
|
2016-03-04 17:48:22 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
})();
|