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

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

Issue 215423002: [Hotword] Make ConfirmDialog subclass from SettingsDialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some more cleanup Created 6 years, 8 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 | Annotate | Revision Log
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 OptionsPage = options.OptionsPage; 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 OptionsPage constructor. 14 * @param {string} name See OptionsPage constructor.
15 * @param {string} title See OptionsPage constructor. 15 * @param {string} title See OptionsPage constructor.
16 * @param {string} pageDivName See OptionsPage constructor. 16 * @param {string} pageDivName See OptionsPage constructor.
17 * @param {HTMLInputElement} okButton The confirmation button element. 17 * @param {HTMLInputElement} okButton The confirmation button element.
18 * @param {HTMLInputElement} cancelButton The cancellation button element. 18 * @param {HTMLInputElement} 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} confirmed_pref A pref used to remember whether the user has 21 * @param {string} confirmed_pref A pref used to remember whether the user has
22 * confirmed the dialog before. This ensures that the user is presented 22 * confirmed the dialog before. This ensures that the user is presented
23 * with the dialog only once. If left |undefined| or |null|, the dialog 23 * with the dialog only once. If left |undefined| or |null|, 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 * @extends {OptionsPage} 25 * @extends {SettingsDialog}
26 */ 26 */
27 function ConfirmDialog(name, title, pageDivName, okButton, cancelButton, pref, 27 function ConfirmDialog(name, title, pageDivName, okButton, cancelButton, pref,
28 metric, confirmed_pref) { 28 metric, confirmed_pref) {
29 OptionsPage.call(this, name, title, pageDivName); 29 SettingsDialog.call(this, name, title, pageDivName, okButton, cancelButton);
30 this.okButton = okButton;
31 this.cancelButton = cancelButton;
32 this.pref = pref; 30 this.pref = pref;
33 this.metric = metric; 31 this.metric = metric;
34 this.confirmed_pref = confirmed_pref; 32 this.confirmed_pref = confirmed_pref;
35 this.confirmed_ = false; 33 this.confirmed_ = false;
36 } 34 }
37 35
38 ConfirmDialog.prototype = { 36 ConfirmDialog.prototype = {
39 // Set up the prototype chain 37 // Set up the prototype chain
40 __proto__: OptionsPage.prototype, 38 __proto__: SettingsDialog.prototype,
41 39
42 /** 40 /**
43 * Handle changes to |pref|. Only uncommitted changes are relevant as these 41 * Handle changes to |pref|. Only uncommitted changes are relevant as these
44 * originate from user and need to be explicitly committed to take effect. 42 * originate from user and need to be explicitly committed to take effect.
45 * Pop up the dialog or commit the change, depending on whether confirmation 43 * Pop up the dialog or commit the change, depending on whether confirmation
46 * is needed. 44 * is needed.
47 * @param {Event} event Change event. 45 * @param {Event} event Change event.
48 * @private 46 * @private
49 */ 47 */
50 onPrefChanged_: function(event) { 48 onPrefChanged_: function(event) {
(...skipping 10 matching lines...) Expand all
61 * Handle changes to |confirmed_pref| by caching them. 59 * Handle changes to |confirmed_pref| by caching them.
62 * @param {Event} event Change event. 60 * @param {Event} event Change event.
63 * @private 61 * @private
64 */ 62 */
65 onConfirmedChanged_: function(event) { 63 onConfirmedChanged_: function(event) {
66 this.confirmed_ = event.value.value; 64 this.confirmed_ = event.value.value;
67 }, 65 },
68 66
69 /** @override */ 67 /** @override */
70 initializePage: function() { 68 initializePage: function() {
69 SettingsDialog.prototype.initializePage.call(this);
70
71 this.okButton.onclick = this.handleConfirm.bind(this); 71 this.okButton.onclick = this.handleConfirm.bind(this);
72 this.cancelButton.onclick = this.handleCancel.bind(this); 72 this.cancelButton.onclick = this.handleCancel.bind(this);
73 Preferences.getInstance().addEventListener( 73 Preferences.getInstance().addEventListener(
74 this.pref, this.onPrefChanged_.bind(this)); 74 this.pref, this.onPrefChanged_.bind(this));
75 if (this.confirmed_pref) { 75 if (this.confirmed_pref) {
76 Preferences.getInstance().addEventListener( 76 Preferences.getInstance().addEventListener(
77 this.confirmed_pref, this.onConfirmedChanged_.bind(this)); 77 this.confirmed_pref, this.onConfirmedChanged_.bind(this));
78 } 78 }
79 }, 79 },
80 80
81 /** 81 /**
82 * Handle the confirm button by committing the |pref| change. If 82 * Handle the confirm button by committing the |pref| change. If
83 * |confirmed_pref| has been specified, also remember that the dialog has 83 * |confirmed_pref| has been specified, also remember that the dialog has
84 * been confirmed to avoid bringing it up in the future. 84 * been confirmed to avoid bringing it up in the future.
85 * @override
85 */ 86 */
86 handleConfirm: function() { 87 handleConfirm: function() {
87 OptionsPage.closeOverlay();
88
89 Preferences.getInstance().commitPref(this.pref, this.metric); 88 Preferences.getInstance().commitPref(this.pref, this.metric);
90 if (this.confirmed_pref) 89 if (this.confirmed_pref)
91 Preferences.setBooleanPref(this.confirmed_pref, true, true); 90 Preferences.setBooleanPref(this.confirmed_pref, true, true);
91
92 SettingsDialog.prototype.handleConfirm.call(this);
Dan Beam 2014/03/27 21:06:43 ^ why is this at the bottom?
rpetterson 2014/03/27 21:26:00 Done. To answer your question, the thought was th
92 }, 93 },
93 94
94 /** 95 /**
95 * Handle the cancel button by rolling back the |pref| change without it 96 * Handle the cancel button by rolling back the |pref| change without it
96 * ever taking effect. 97 * ever taking effect.
98 * @override
97 */ 99 */
98 handleCancel: function() { 100 handleCancel: function() {
99 OptionsPage.closeOverlay();
100
101 Preferences.getInstance().rollbackPref(this.pref); 101 Preferences.getInstance().rollbackPref(this.pref);
102 SettingsDialog.prototype.handleCancel.call(this);
Dan Beam 2014/03/27 21:06:43 same
rpetterson 2014/03/27 21:26:00 Done.
102 }, 103 },
103 104
104 /** 105 /**
105 * When a user navigates away from a confirm dialog, treat as a cancel. 106 * When a user navigates away from a confirm dialog, treat as a cancel.
106 * @protected 107 * @protected
107 * @override 108 * @override
108 */ 109 */
109 willHidePage: function() { 110 willHidePage: function() {
110 if (this.visible) 111 if (this.visible)
111 Preferences.getInstance().rollbackPref(this.pref); 112 Preferences.getInstance().rollbackPref(this.pref);
112 }, 113 },
113 }; 114 };
114 115
115 return { 116 return {
116 ConfirmDialog: ConfirmDialog 117 ConfirmDialog: ConfirmDialog
117 }; 118 };
118 }); 119 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698