Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var SettingsDialog = options.SettingsDialog; | 6 /** @const */ var SettingsDialog = options.SettingsDialog; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A dialog that will pop up when the user attempts to set the value of the | 9 * A dialog that will pop up when the user attempts to set the value of the |
| 10 * Boolean |pref| to |true|, asking for confirmation. If the user clicks OK, | 10 * Boolean |pref| to |true|, asking for confirmation. If the user clicks OK, |
| 11 * the new value is committed to Chrome. If the user clicks Cancel or leaves | 11 * the new value is committed to Chrome. If the user clicks Cancel or leaves |
| 12 * the settings page, the new value is discarded. | 12 * the settings page, the new value is discarded. |
| 13 * @constructor | 13 * @constructor |
| 14 * @param {string} name See Page constructor. | 14 * @param {string} name See Page constructor. |
| 15 * @param {string} title See Page constructor. | 15 * @param {string} title See Page constructor. |
| 16 * @param {string} pageDivName See Page constructor. | 16 * @param {string} pageDivName See Page constructor. |
| 17 * @param {HTMLButtonElement} okButton The confirmation button element. | 17 * @param {HTMLButtonElement} okButton The confirmation button element. |
| 18 * @param {HTMLButtonElement} cancelButton The cancellation button element. | 18 * @param {HTMLButtonElement} cancelButton The cancellation button element. |
| 19 * @param {string} pref The pref that requires confirmation. | 19 * @param {string} pref The pref that requires confirmation. |
| 20 * @param {string} metric User metrics identifier. | 20 * @param {string} metric User metrics identifier. |
| 21 * @param {string=} opt_confirmedPref A pref used to remember whether the | 21 * @param {string=} opt_confirmedPref A pref used to remember whether the |
| 22 * user has confirmed the dialog before. This ensures that the user is | 22 * user has confirmed the dialog before. This ensures that the user is |
| 23 * presented with the dialog only once. If left |undefined|, the dialog | 23 * presented with the dialog only once. If left |undefined|, the dialog |
| 24 * will pop up every time the user attempts to set |pref| to |true|. | 24 * will pop up every time the user attempts to set |pref| to |true|. |
| 25 * @param {boolean=} opt_confirmValue The value to which changing should | |
| 26 * trigger the confirmation dialog. Defaults to |true| if left | |
| 27 * |undefined|. | |
| 25 * @extends {options.SettingsDialog} | 28 * @extends {options.SettingsDialog} |
| 26 */ | 29 */ |
| 27 function ConfirmDialog(name, title, pageDivName, okButton, cancelButton, pref, | 30 function ConfirmDialog(name, title, pageDivName, okButton, cancelButton, pref, |
| 28 metric, opt_confirmedPref) { | 31 metric, opt_confirmedPref, opt_confirmValue) { |
| 29 SettingsDialog.call(this, name, title, pageDivName, okButton, cancelButton); | 32 SettingsDialog.call(this, name, title, pageDivName, okButton, cancelButton); |
| 30 | 33 |
| 31 /** @protected */ | 34 /** @protected */ |
| 32 this.pref = pref; | 35 this.pref = pref; |
| 33 | 36 |
| 34 /** @protected */ | 37 /** @protected */ |
| 35 this.metric = metric; | 38 this.metric = metric; |
| 36 | 39 |
| 37 /** @private */ | 40 /** @private */ |
| 38 this.confirmedPref_ = opt_confirmedPref; | 41 this.confirmedPref_ = opt_confirmedPref; |
| 39 | 42 |
| 40 /** @private */ | 43 /** @private */ |
| 41 this.confirmed_ = false; | 44 this.confirmed_ = false; |
| 45 | |
| 46 /** @private */ | |
| 47 this.confirmValue_ = opt_confirmValue == undefined || | |
|
dpapad
2016/05/17 17:37:12
"null == undefined" VS "null === undefined" behavi
| |
| 48 Boolean(opt_confirmValue); | |
| 42 } | 49 } |
| 43 | 50 |
| 44 ConfirmDialog.prototype = { | 51 ConfirmDialog.prototype = { |
| 45 // Set up the prototype chain | 52 // Set up the prototype chain |
| 46 __proto__: SettingsDialog.prototype, | 53 __proto__: SettingsDialog.prototype, |
| 47 | 54 |
| 48 /** | 55 /** |
| 49 * Handle changes to |pref|. Only uncommitted changes are relevant as these | 56 * Handle changes to |pref|. Only uncommitted changes are relevant as these |
| 50 * originate from user and need to be explicitly committed to take effect. | 57 * originate from user and need to be explicitly committed to take effect. |
| 51 * Pop up the dialog or commit the change, depending on whether confirmation | 58 * Pop up the dialog or commit the change, depending on whether confirmation |
| 52 * is needed. | 59 * is needed. |
| 53 * @param {Event} event Change event. | 60 * @param {Event} event Change event. |
| 54 * @private | 61 * @private |
| 55 */ | 62 */ |
| 56 onPrefChanged_: function(event) { | 63 onPrefChanged_: function(event) { |
| 57 if (!event.value.uncommitted) | 64 if (!event.value.uncommitted) |
| 58 return; | 65 return; |
| 59 | 66 |
| 60 if (event.value.value && !this.confirmed_) | 67 if (event.value.value == this.confirmValue_ && !this.confirmed_) |
| 61 PageManager.showPageByName(this.name, false); | 68 PageManager.showPageByName(this.name, false); |
| 62 else | 69 else |
| 63 Preferences.getInstance().commitPref(this.pref, this.metric); | 70 Preferences.getInstance().commitPref(this.pref, this.metric); |
| 64 }, | 71 }, |
| 65 | 72 |
| 66 /** | 73 /** |
| 67 * Handle changes to |confirmedPref_| by caching them. | 74 * Handle changes to |confirmedPref_| by caching them. |
| 68 * @param {Event} event Change event. | 75 * @param {Event} event Change event. |
| 69 * @private | 76 * @private |
| 70 */ | 77 */ |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 90 * Handle the confirm button by committing the |pref| change. If | 97 * Handle the confirm button by committing the |pref| change. If |
| 91 * |confirmedPref_| has been specified, also remember that the dialog has | 98 * |confirmedPref_| has been specified, also remember that the dialog has |
| 92 * been confirmed to avoid bringing it up in the future. | 99 * been confirmed to avoid bringing it up in the future. |
| 93 * @override | 100 * @override |
| 94 */ | 101 */ |
| 95 handleConfirm: function() { | 102 handleConfirm: function() { |
| 96 SettingsDialog.prototype.handleConfirm.call(this); | 103 SettingsDialog.prototype.handleConfirm.call(this); |
| 97 | 104 |
| 98 Preferences.getInstance().commitPref(this.pref, this.metric); | 105 Preferences.getInstance().commitPref(this.pref, this.metric); |
| 99 if (this.confirmedPref_) | 106 if (this.confirmedPref_) |
| 100 Preferences.setBooleanPref(this.confirmedPref_, true, true); | 107 Preferences.setBooleanPref( |
| 108 this.confirmedPref_, this.confirmValue_, true); | |
| 101 }, | 109 }, |
| 102 | 110 |
| 103 /** | 111 /** |
| 104 * Handle the cancel button by rolling back the |pref| change without it | 112 * Handle the cancel button by rolling back the |pref| change without it |
| 105 * ever taking effect. | 113 * ever taking effect. |
| 106 * @override | 114 * @override |
| 107 */ | 115 */ |
| 108 handleCancel: function() { | 116 handleCancel: function() { |
| 109 SettingsDialog.prototype.handleCancel.call(this); | 117 SettingsDialog.prototype.handleCancel.call(this); |
| 110 Preferences.getInstance().rollbackPref(this.pref); | 118 Preferences.getInstance().rollbackPref(this.pref); |
| 111 }, | 119 }, |
| 112 | 120 |
| 113 /** | 121 /** |
| 114 * When a user navigates away from a confirm dialog, treat as a cancel. | 122 * When a user navigates away from a confirm dialog, treat as a cancel. |
| 115 * @protected | 123 * @protected |
| 116 * @override | 124 * @override |
| 117 */ | 125 */ |
| 118 willHidePage: function() { | 126 willHidePage: function() { |
| 119 if (this.visible) | 127 if (this.visible) |
| 120 Preferences.getInstance().rollbackPref(this.pref); | 128 Preferences.getInstance().rollbackPref(this.pref); |
| 121 }, | 129 }, |
| 122 }; | 130 }; |
| 123 | 131 |
| 124 return { | 132 return { |
| 125 ConfirmDialog: ConfirmDialog | 133 ConfirmDialog: ConfirmDialog |
| 126 }; | 134 }; |
| 127 }); | 135 }); |
| OLD | NEW |