| OLD | NEW |
| 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 /** | 5 /** |
| 6 * @fileoverview Base class for dialogs that require saving preferences on | 6 * @fileoverview Base class for dialogs that require saving preferences on |
| 7 * confirm and resetting preference inputs on cancel. | 7 * confirm and resetting preference inputs on cancel. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 cr.define('options', function() { | 10 cr.define('options', function() { |
| 11 /** @const */ var OptionsPage = options.OptionsPage; | 11 /** @const */ var Page = cr.ui.pageManager.Page; |
| 12 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Base class for settings dialogs. | 15 * Base class for settings dialogs. |
| 15 * @constructor | 16 * @constructor |
| 16 * @param {string} name See OptionsPage constructor. | 17 * @param {string} name See Page constructor. |
| 17 * @param {string} title See OptionsPage constructor. | 18 * @param {string} title See Page constructor. |
| 18 * @param {string} pageDivName See OptionsPage constructor. | 19 * @param {string} pageDivName See Page constructor. |
| 19 * @param {HTMLInputElement} okButton The confirmation button element. | 20 * @param {HTMLInputElement} okButton The confirmation button element. |
| 20 * @param {HTMLInputElement} cancelButton The cancellation button element. | 21 * @param {HTMLInputElement} cancelButton The cancellation button element. |
| 21 * @extends {OptionsPage} | 22 * @extends {Page} |
| 22 */ | 23 */ |
| 23 function SettingsDialog(name, title, pageDivName, okButton, cancelButton) { | 24 function SettingsDialog(name, title, pageDivName, okButton, cancelButton) { |
| 24 OptionsPage.call(this, name, title, pageDivName); | 25 Page.call(this, name, title, pageDivName); |
| 25 this.okButton = okButton; | 26 this.okButton = okButton; |
| 26 this.cancelButton = cancelButton; | 27 this.cancelButton = cancelButton; |
| 27 } | 28 } |
| 28 | 29 |
| 29 SettingsDialog.prototype = { | 30 SettingsDialog.prototype = { |
| 30 __proto__: OptionsPage.prototype, | 31 __proto__: Page.prototype, |
| 31 | 32 |
| 32 /** @override */ | 33 /** @override */ |
| 33 initializePage: function() { | 34 initializePage: function() { |
| 34 this.okButton.onclick = this.handleConfirm.bind(this); | 35 this.okButton.onclick = this.handleConfirm.bind(this); |
| 35 this.cancelButton.onclick = this.handleCancel.bind(this); | 36 this.cancelButton.onclick = this.handleCancel.bind(this); |
| 36 }, | 37 }, |
| 37 | 38 |
| 38 /** | 39 /** |
| 39 * Handles the confirm button by saving the dialog preferences. | 40 * Handles the confirm button by saving the dialog preferences. |
| 40 */ | 41 */ |
| 41 handleConfirm: function() { | 42 handleConfirm: function() { |
| 42 OptionsPage.closeOverlay(); | 43 PageManager.closeOverlay(); |
| 43 | 44 |
| 44 var prefs = Preferences.getInstance(); | 45 var prefs = Preferences.getInstance(); |
| 45 var els = this.pageDiv.querySelectorAll('[dialog-pref]'); | 46 var els = this.pageDiv.querySelectorAll('[dialog-pref]'); |
| 46 for (var i = 0; i < els.length; i++) { | 47 for (var i = 0; i < els.length; i++) { |
| 47 if (els[i].pref) | 48 if (els[i].pref) |
| 48 prefs.commitPref(els[i].pref, els[i].metric); | 49 prefs.commitPref(els[i].pref, els[i].metric); |
| 49 } | 50 } |
| 50 }, | 51 }, |
| 51 | 52 |
| 52 /** | 53 /** |
| 53 * Handles the cancel button by closing the overlay. | 54 * Handles the cancel button by closing the overlay. |
| 54 */ | 55 */ |
| 55 handleCancel: function() { | 56 handleCancel: function() { |
| 56 OptionsPage.closeOverlay(); | 57 PageManager.closeOverlay(); |
| 57 | 58 |
| 58 var prefs = Preferences.getInstance(); | 59 var prefs = Preferences.getInstance(); |
| 59 var els = this.pageDiv.querySelectorAll('[dialog-pref]'); | 60 var els = this.pageDiv.querySelectorAll('[dialog-pref]'); |
| 60 for (var i = 0; i < els.length; i++) { | 61 for (var i = 0; i < els.length; i++) { |
| 61 if (els[i].pref) | 62 if (els[i].pref) |
| 62 prefs.rollbackPref(els[i].pref); | 63 prefs.rollbackPref(els[i].pref); |
| 63 } | 64 } |
| 64 }, | 65 }, |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 return { | 68 return { |
| 68 SettingsDialog: SettingsDialog | 69 SettingsDialog: SettingsDialog |
| 69 }; | 70 }; |
| 70 }); | 71 }); |
| OLD | NEW |