Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: chrome/browser/resources/options/confirm_dialog.js

Issue 1984603002: Allow ConfirmDialog to confirm disabling options. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
dpapad 2016/05/16 17:09:53 The naming of this param suggests that it is optio
dspaid 2016/05/16 23:33:22 Done.
26 * trigger the confirmation dialog. Defaults to |true| if left |undefined|.
stevenjb 2016/05/16 16:19:48 indent
dspaid 2016/05/16 23:33:22 Done.
25 * @extends {options.SettingsDialog} 27 * @extends {options.SettingsDialog}
26 */ 28 */
27 function ConfirmDialog(name, title, pageDivName, okButton, cancelButton, pref, 29 function ConfirmDialog(name, title, pageDivName, okButton, cancelButton, pref,
28 metric, opt_confirmedPref) { 30 metric, opt_confirmedPref, opt_confirmValue) {
29 SettingsDialog.call(this, name, title, pageDivName, okButton, cancelButton); 31 SettingsDialog.call(this, name, title, pageDivName, okButton, cancelButton);
30 32
31 /** @protected */ 33 /** @protected */
32 this.pref = pref; 34 this.pref = pref;
33 35
34 /** @protected */ 36 /** @protected */
35 this.metric = metric; 37 this.metric = metric;
36 38
37 /** @private */ 39 /** @private */
38 this.confirmedPref_ = opt_confirmedPref; 40 this.confirmedPref_ = opt_confirmedPref;
39 41
40 /** @private */ 42 /** @private */
41 this.confirmed_ = false; 43 this.confirmed_ = false;
44
45 /** @private */
46 this.confirmValue_ = opt_confirmValue === undefined ||
dpapad 2016/05/16 17:09:53 This logic is fragile. In almost all JS APIs I hav
dspaid 2016/05/16 23:33:22 Good point. changing === to == should also do the
47 Boolean(opt_confirmValue);
42 } 48 }
43 49
44 ConfirmDialog.prototype = { 50 ConfirmDialog.prototype = {
45 // Set up the prototype chain 51 // Set up the prototype chain
46 __proto__: SettingsDialog.prototype, 52 __proto__: SettingsDialog.prototype,
47 53
48 /** 54 /**
49 * Handle changes to |pref|. Only uncommitted changes are relevant as these 55 * Handle changes to |pref|. Only uncommitted changes are relevant as these
50 * originate from user and need to be explicitly committed to take effect. 56 * 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 57 * Pop up the dialog or commit the change, depending on whether confirmation
52 * is needed. 58 * is needed.
53 * @param {Event} event Change event. 59 * @param {Event} event Change event.
54 * @private 60 * @private
55 */ 61 */
56 onPrefChanged_: function(event) { 62 onPrefChanged_: function(event) {
57 if (!event.value.uncommitted) 63 if (!event.value.uncommitted)
58 return; 64 return;
59 65
60 if (event.value.value && !this.confirmed_) 66 if (event.value.value == this.confirmValue_ && !this.confirmed_)
61 PageManager.showPageByName(this.name, false); 67 PageManager.showPageByName(this.name, false);
62 else 68 else
63 Preferences.getInstance().commitPref(this.pref, this.metric); 69 Preferences.getInstance().commitPref(this.pref, this.metric);
64 }, 70 },
65 71
66 /** 72 /**
67 * Handle changes to |confirmedPref_| by caching them. 73 * Handle changes to |confirmedPref_| by caching them.
68 * @param {Event} event Change event. 74 * @param {Event} event Change event.
69 * @private 75 * @private
70 */ 76 */
(...skipping 19 matching lines...) Expand all
90 * Handle the confirm button by committing the |pref| change. If 96 * Handle the confirm button by committing the |pref| change. If
91 * |confirmedPref_| has been specified, also remember that the dialog has 97 * |confirmedPref_| has been specified, also remember that the dialog has
92 * been confirmed to avoid bringing it up in the future. 98 * been confirmed to avoid bringing it up in the future.
93 * @override 99 * @override
94 */ 100 */
95 handleConfirm: function() { 101 handleConfirm: function() {
96 SettingsDialog.prototype.handleConfirm.call(this); 102 SettingsDialog.prototype.handleConfirm.call(this);
97 103
98 Preferences.getInstance().commitPref(this.pref, this.metric); 104 Preferences.getInstance().commitPref(this.pref, this.metric);
99 if (this.confirmedPref_) 105 if (this.confirmedPref_)
100 Preferences.setBooleanPref(this.confirmedPref_, true, true); 106 Preferences.setBooleanPref(
107 this.confirmedPref_, this.confirmValue, true);
dpapad 2016/05/16 17:09:53 Underscore missing! This is not referring to the m
dspaid 2016/05/16 23:33:22 Done. Oddly enough the compiler didn't seem to com
101 }, 108 },
102 109
103 /** 110 /**
104 * Handle the cancel button by rolling back the |pref| change without it 111 * Handle the cancel button by rolling back the |pref| change without it
105 * ever taking effect. 112 * ever taking effect.
106 * @override 113 * @override
107 */ 114 */
108 handleCancel: function() { 115 handleCancel: function() {
109 SettingsDialog.prototype.handleCancel.call(this); 116 SettingsDialog.prototype.handleCancel.call(this);
110 Preferences.getInstance().rollbackPref(this.pref); 117 Preferences.getInstance().rollbackPref(this.pref);
111 }, 118 },
112 119
113 /** 120 /**
114 * When a user navigates away from a confirm dialog, treat as a cancel. 121 * When a user navigates away from a confirm dialog, treat as a cancel.
115 * @protected 122 * @protected
116 * @override 123 * @override
117 */ 124 */
118 willHidePage: function() { 125 willHidePage: function() {
119 if (this.visible) 126 if (this.visible)
120 Preferences.getInstance().rollbackPref(this.pref); 127 Preferences.getInstance().rollbackPref(this.pref);
121 }, 128 },
122 }; 129 };
123 130
124 return { 131 return {
125 ConfirmDialog: ConfirmDialog 132 ConfirmDialog: ConfirmDialog
126 }; 133 };
127 }); 134 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698