OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 var OptionsPage = options.OptionsPage; | |
7 | |
8 /** | |
9 * Encapsulated handling of ChromeOS kiosk apps options page. | |
10 * @extends {options.OptionsPage} | |
11 * @constructor | |
12 */ | |
13 function KioskAppsOverlay() { | |
14 OptionsPage.call(this, | |
15 'kioskAppsOverlay', | |
16 loadTimeData.getString('kioskOverlayTitle'), | |
17 'kiosk-apps-page'); | |
18 } | |
19 | |
20 cr.addSingletonGetter(KioskAppsOverlay); | |
21 | |
22 KioskAppsOverlay.prototype = { | |
23 __proto__: OptionsPage.prototype, | |
24 | |
25 /** | |
26 * Clear error timer id. | |
27 * @type {?number} | |
28 */ | |
29 clearErrorTimer_: null, | |
30 | |
31 /** @override */ | |
32 initializePage: function() { | |
33 // Call base class implementation to starts preference initialization. | |
34 OptionsPage.prototype.initializePage.call(this); | |
35 | |
36 options.KioskAppList.decorate($('kiosk-app-list')); | |
37 | |
38 $('kiosk-options-overlay-confirm').onclick = | |
39 OptionsPage.closeOverlay.bind(OptionsPage); | |
40 $('kiosk-app-id-edit').addEventListener('keypress', | |
41 this.handleAppIdInputKeyPressed_); | |
42 | |
43 Preferences.getInstance().addEventListener( | |
44 'cros.accounts.deviceLocalAccounts', | |
45 this.loadAppsIfVisible_.bind(this)); | |
46 Preferences.getInstance().addEventListener( | |
47 'cros.accounts.deviceLocalAccountAutoLoginId', | |
48 this.loadAppsIfVisible_.bind(this)); | |
49 }, | |
50 | |
51 /** @override */ | |
52 didShowPage: function() { | |
53 this.loadAppsIfVisible_(); | |
54 $('kiosk-app-id-edit').focus(); | |
55 }, | |
56 | |
57 /** | |
58 * Loads the apps if the overlay page is visible. | |
59 * @private | |
60 */ | |
61 loadAppsIfVisible_: function() { | |
62 if (this.visible) | |
63 chrome.send('getKioskApps'); | |
64 }, | |
65 | |
66 /** | |
67 * Shows error for given app name/id and schedules it to cleared. | |
68 * @param {!string} appName App name/id to show in error banner. | |
69 */ | |
70 showError: function(appName) { | |
71 var errorBanner = $('kiosk-apps-error-banner'); | |
72 var appNameElement = errorBanner.querySelector('.kiosk-app-name'); | |
73 appNameElement.textContent = appName; | |
74 errorBanner.classList.add('visible'); | |
75 | |
76 if (this.clearErrorTimer_) | |
77 window.clearTimeout(this.clearErrorTimer_); | |
78 | |
79 // Sets a timer to clear out error banner after 5 seconds. | |
80 this.clearErrorTimer_ = window.setTimeout(function() { | |
81 errorBanner.classList.remove('visible'); | |
82 this.clearErrorTimer_ = null; | |
83 }.bind(this), 5000); | |
84 }, | |
85 | |
86 /** | |
87 * Handles keypressed event in the app id input element. | |
88 * @private | |
89 */ | |
90 handleAppIdInputKeyPressed_: function(e) { | |
91 if (e.keyIdentifier == 'Enter' && e.target.value) { | |
92 chrome.send('addKioskApp', [e.target.value]); | |
93 e.target.value = ''; | |
94 } | |
95 } | |
96 }; | |
97 | |
98 /** | |
99 * Sets apps to be displayed in kiosk-app-list. | |
100 * @param {!Array.<!Object>} apps An array of app info objects. | |
101 */ | |
102 KioskAppsOverlay.setApps = function(apps) { | |
103 $('kiosk-app-list').setApps(apps); | |
104 }; | |
105 | |
106 /** | |
107 * Update an app in kiosk-app-list. | |
108 * @param {!Object} app App info to be updated. | |
109 */ | |
110 KioskAppsOverlay.updateApp = function(app) { | |
111 $('kiosk-app-list').updateApp(app); | |
112 }; | |
113 | |
114 /** | |
115 * Shows error for given app name/id. | |
116 * @param {!string} appName App name/id to show in error banner. | |
117 */ | |
118 KioskAppsOverlay.showError = function(appName) { | |
119 KioskAppsOverlay.getInstance().showError(appName); | |
120 }; | |
121 | |
122 // Export | |
123 return { | |
124 KioskAppsOverlay: KioskAppsOverlay | |
125 }; | |
126 }); | |
127 | |
128 <include src="kiosk_app_list.js"></include> | |
129 <include src="kiosk_app_disable_bailout_confirm.js"></include> | |
OLD | NEW |