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 OptionsPage = options.OptionsPage;
14 * Base class for settings dialogs.
16 * @param {string} name See OptionsPage constructor.
17 * @param {string} title See OptionsPage constructor.
18 * @param {string} pageDivName See OptionsPage constructor.
19 * @param {HTMLInputElement} okButton The confirmation button element.
20 * @param {HTMLInputElement} cancelButton The cancellation button element.
21 * @extends {OptionsPage}
23 function SettingsDialog(name, title, pageDivName, okButton, cancelButton) {
24 OptionsPage.call(this, name, title, pageDivName);
25 this.okButton = okButton;
26 this.cancelButton = cancelButton;
29 SettingsDialog.prototype = {
30 __proto__: OptionsPage.prototype,
33 initializePage: function() {
34 this.okButton.onclick = this.handleConfirm.bind(this);
35 this.cancelButton.onclick = this.handleCancel.bind(this);
39 * Handles the confirm button by saving the dialog preferences.
41 handleConfirm: function() {
42 OptionsPage.closeOverlay();
44 var prefs = Preferences.getInstance();
45 var els = this.pageDiv.querySelectorAll('[dialog-pref]');
46 for (var i = 0; i < els.length; i++) {
48 prefs.commitPref(els[i].pref, els[i].metric);
53 * Handles the cancel button by closing the overlay.
55 handleCancel: function() {
56 OptionsPage.closeOverlay();
58 var prefs = Preferences.getInstance();
59 var els = this.pageDiv.querySelectorAll('[dialog-pref]');
60 for (var i = 0; i < els.length; i++) {
62 prefs.rollbackPref(els[i].pref);
68 SettingsDialog: SettingsDialog