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

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

Issue 11232059: Clean up copy&paste in confirmation dialogs for prefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit addressed. Created 8 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6 /** @const */ var OptionsPage = options.OptionsPage;
7
8 /**
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,
11 * the new value is committed to Chrome. If the user clicks Cancel or leaves
12 * the settings page, the new value is discarded.
13 * @constructor
14 * @param {string} name See OptionsPage constructor.
15 * @param {string} title See OptionsPage constructor.
16 * @param {string} pageDivName See OptionsPage constructor.
17 * @param {HTMLInputElement} okButton The confirmation button element.
18 * @param {HTMLInputElement} cancelButton The cancellation button element.
19 * @param {string} pref The pref that requires confirmation.
20 * @param {string} metric User metrics identifier.
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
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|.
25 * @extends {OptionsPage}
26 */
27 function ConfirmDialog(name, title, pageDivName, okButton, cancelButton, pref,
28 metric, confirmed_pref) {
29 OptionsPage.call(this, name, title, pageDivName);
30 this.okButton = okButton;
31 this.cancelButton = cancelButton;
32 this.pref = pref;
33 this.metric = metric;
34 this.confirmed_pref = confirmed_pref;
35 this.confirmed_ = false;
36 }
37
38 ConfirmDialog.prototype = {
39 // Set up the prototype chain
40 __proto__: OptionsPage.prototype,
41
42 /**
43 * Handle changes to |pref|. Only uncommitted changes are relevant as these
44 * 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
46 * is needed.
47 * @param {Event} event Change event.
48 * @private
49 */
50 onPrefChanged_: function(event) {
51 if (!event.value.uncommitted)
52 return;
53
54 if (event.value.value && !this.confirmed_)
55 OptionsPage.showPageByName(this.name, false);
56 else
57 Preferences.getInstance().commitPref(this.pref, this.metric);
58 },
59
60 /**
61 * Handle changes to |confirmed_pref| by caching them.
62 * @param {Event} event Change event.
63 * @private
64 */
65 onConfirmedChanged_: function(event) {
66 this.confirmed_ = event.value.value;
67 },
68
69 /**
70 * @inheritDoc
71 */
72 initializePage: function() {
73 this.okButton.onclick = this.handleConfirm.bind(this);
74 this.cancelButton.onclick = this.handleCancel.bind(this);
75 Preferences.getInstance().addEventListener(
76 this.pref, this.onPrefChanged_.bind(this));
77 if (this.confirmed_pref) {
78 Preferences.getInstance().addEventListener(
79 this.confirmed_pref, this.onConfirmedChanged_.bind(this));
80 }
81 },
82
83 /**
84 * Handle the confirm button by committing the |pref| change. If
85 * |confirmed_pref| has been specified, also remember that the dialog has
86 * been confirmed to avoid bringing it up in the future.
87 */
88 handleConfirm: function() {
89 OptionsPage.closeOverlay();
90
91 Preferences.getInstance().commitPref(this.pref, this.metric);
92 if (this.confirmed_pref)
93 Preferences.setBooleanPref(this.confirmed_pref, true, true);
94 },
95
96 /**
97 * Handle the cancel button by rolling back the |pref| change without it
98 * ever taking effect.
99 */
100 handleCancel: function() {
101 OptionsPage.closeOverlay();
102
103 Preferences.getInstance().rollbackPref(this.pref);
104 },
105 };
106
107 return {
108 ConfirmDialog: ConfirmDialog
109 };
110 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/browser_options.js ('k') | chrome/browser/resources/options/do_not_track_confirm_overlay.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698