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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var Page = cr.ui.pageManager.Page; |
7 var PageManager = cr.ui.pageManager.PageManager; | |
7 | 8 |
8 /** | 9 /** |
9 * AlertOverlay class | 10 * AlertOverlay class |
10 * Encapsulated handling of a generic alert. | 11 * Encapsulated handling of a generic alert. |
11 * @class | 12 * @class |
12 */ | 13 */ |
13 function AlertOverlay() { | 14 function AlertOverlay() { |
14 OptionsPage.call(this, 'alertOverlay', '', 'alertOverlay'); | 15 // AlertOverlay is special in that it is not tied to one page or overlay. |
16 // Set the nesting level arbitrarily high so as to always be recognized as | |
17 // the top-most visible page. | |
18 Page.call(this, 'alertOverlay', '', 'alertOverlay', 99); | |
15 } | 19 } |
16 | 20 |
17 cr.addSingletonGetter(AlertOverlay); | 21 cr.addSingletonGetter(AlertOverlay); |
18 | 22 |
19 AlertOverlay.prototype = { | 23 AlertOverlay.prototype = { |
20 // Inherit AlertOverlay from OptionsPage. | 24 // Inherit AlertOverlay from Page. |
21 __proto__: OptionsPage.prototype, | 25 __proto__: Page.prototype, |
22 | 26 |
23 /** | 27 /** |
24 * Whether the page can be shown. Used to make sure the page is only | 28 * Whether the page can be shown. Used to make sure the page is only |
25 * shown via AlertOverlay.Show(), and not via the address bar. | 29 * shown via AlertOverlay.Show(), and not via the address bar. |
26 * @private | 30 * @private |
27 */ | 31 */ |
28 canShow_: false, | 32 canShow_: false, |
29 | 33 |
30 /** | 34 /** |
31 * Initialize the page. | 35 * Initialize the page. |
32 */ | 36 */ |
33 initializePage: function() { | 37 initializePage: function() { |
34 // Call base class implementation to start preference initialization. | 38 Page.prototype.initializePage.call(this); |
35 OptionsPage.prototype.initializePage.call(this); | |
36 | 39 |
37 var self = this; | 40 var self = this; |
38 $('alertOverlayOk').onclick = function(event) { | 41 $('alertOverlayOk').onclick = function(event) { |
39 self.handleOK_(); | 42 self.handleOK_(); |
40 }; | 43 }; |
41 | 44 |
42 $('alertOverlayCancel').onclick = function(event) { | 45 $('alertOverlayCancel').onclick = function(event) { |
43 self.handleCancel_(); | 46 self.handleCancel_(); |
44 }; | 47 }; |
45 }, | 48 }, |
46 | 49 |
47 /** @override */ | |
48 get nestingLevel() { | |
49 // AlertOverlay is special in that it is not tied to one page or overlay. | |
50 // Set the nesting level arbitrarily high so as to always be recognized as | |
51 // the top-most visible page. | |
52 return 99; | |
53 }, | |
54 | |
55 /** | 50 /** |
56 * Handle the 'ok' button. Clear the overlay and call the ok callback if | 51 * Handle the 'ok' button. Clear the overlay and call the ok callback if |
57 * available. | 52 * available. |
58 * @private | 53 * @private |
59 */ | 54 */ |
60 handleOK_: function() { | 55 handleOK_: function() { |
61 OptionsPage.closeOverlay(); | 56 PageManager.closeOverlay(); |
62 if (this.okCallback != undefined) { | 57 if (this.okCallback != undefined) { |
Dan Beam
2014/07/30 01:00:01
opt nit: no curlies, no comparison to undefined
michaelpg
2014/07/30 21:42:19
would rather not touch this, the CL is big enough
| |
63 this.okCallback.call(); | 58 this.okCallback.call(); |
64 } | 59 } |
65 }, | 60 }, |
66 | 61 |
67 /** | 62 /** |
68 * Handle the 'cancel' button. Clear the overlay and call the cancel | 63 * Handle the 'cancel' button. Clear the overlay and call the cancel |
69 * callback if available. | 64 * callback if available. |
70 * @private | 65 * @private |
71 */ | 66 */ |
72 handleCancel_: function() { | 67 handleCancel_: function() { |
73 OptionsPage.closeOverlay(); | 68 PageManager.closeOverlay(); |
74 if (this.cancelCallback != undefined) { | 69 if (this.cancelCallback != undefined) { |
75 this.cancelCallback.call(); | 70 this.cancelCallback.call(); |
76 } | 71 } |
77 }, | 72 }, |
78 | 73 |
79 /** | 74 /** |
80 * The page is getting hidden. Don't let it be shown again. | 75 * The page is getting hidden. Don't let it be shown again. |
81 */ | 76 */ |
82 willHidePage: function() { | 77 willHidePage: function() { |
83 canShow_ = false; | 78 canShow_ = false; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 $('alertOverlayCancel').style.display = 'none'; | 130 $('alertOverlayCancel').style.display = 'none'; |
136 } | 131 } |
137 | 132 |
138 var alertOverlay = AlertOverlay.getInstance(); | 133 var alertOverlay = AlertOverlay.getInstance(); |
139 alertOverlay.okCallback = okCallback; | 134 alertOverlay.okCallback = okCallback; |
140 alertOverlay.cancelCallback = cancelCallback; | 135 alertOverlay.cancelCallback = cancelCallback; |
141 alertOverlay.canShow_ = true; | 136 alertOverlay.canShow_ = true; |
142 | 137 |
143 // Intentionally don't show the URL in the location bar as we don't want | 138 // Intentionally don't show the URL in the location bar as we don't want |
144 // people trying to navigate here by hand. | 139 // people trying to navigate here by hand. |
145 OptionsPage.showPageByName('alertOverlay', false); | 140 PageManager.showPageByName('alertOverlay', false); |
146 }; | 141 }; |
147 | 142 |
148 // Export | 143 // Export |
149 return { | 144 return { |
150 AlertOverlay: AlertOverlay | 145 AlertOverlay: AlertOverlay |
151 }; | 146 }; |
152 }); | 147 }); |
OLD | NEW |