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.
6 * @fileoverview Base class for dialogs that require saving preferences on
7 * confirm and resetting preference inputs on cancel.
10 cr.define('options', function() {
11 /** @const */ var Page = cr.ui.pageManager.Page;
12 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
15 * Base class for settings dialogs.
17 * @param {string} name See Page constructor.
18 * @param {string} title See Page constructor.
19 * @param {string} pageDivName See Page constructor.
20 * @param {HTMLButtonElement} okButton The confirmation button element.
21 * @param {HTMLButtonElement} cancelButton The cancellation button element.
22 * @extends {cr.ui.pageManager.Page}
24 function SettingsDialog(name, title, pageDivName, okButton, cancelButton) {
25 Page.call(this, name, title, pageDivName);
26 this.okButton = okButton;
27 this.cancelButton = cancelButton;
30 SettingsDialog.prototype = {
31 __proto__: Page.prototype,
34 initializePage: function() {
35 this.okButton.onclick = this.handleConfirm.bind(this);
36 this.cancelButton.onclick = this.handleCancel.bind(this);
40 * Handles the confirm button by saving the dialog preferences.
42 handleConfirm: function() {
43 PageManager.closeOverlay();
45 var prefs = Preferences.getInstance();
46 var els = this.pageDiv.querySelectorAll('[dialog-pref]');
47 for (var i = 0; i < els.length; i++) {
49 prefs.commitPref(els[i].pref, els[i].metric);
54 * Handles the cancel button by closing the overlay.
56 handleCancel: function() {
57 PageManager.closeOverlay();
59 var prefs = Preferences.getInstance();
60 var els = this.pageDiv.querySelectorAll('[dialog-pref]');
61 for (var i = 0; i < els.length; i++) {
63 prefs.rollbackPref(els[i].pref);
69 SettingsDialog: SettingsDialog