Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / user_manager / user_manager.js
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 <include src="../login/screen.js"></include>
5 <include src="../login/bubble.js"></include>
6 <include src="../login/display_manager.js"></include>
7 <include src="control_bar.js"></include>
8 <include src="../login/screen_account_picker.js"></include>
9 <include src="../login/user_pod_row.js"></include>
10 <include src="../login/resource_loader.js"></include>
11 <include src="user_manager_tutorial.js"></include>
12
13 cr.define('cr.ui', function() {
14   var DisplayManager = cr.ui.login.DisplayManager;
15   var UserManagerTutorial = cr.ui.login.UserManagerTutorial;
16
17   /**
18   * Constructs an Out of box controller. It manages initialization of screens,
19   * transitions, error messages display.
20   * @extends {DisplayManager}
21   * @constructor
22   */
23   function Oobe() {
24   }
25
26   cr.addSingletonGetter(Oobe);
27
28   Oobe.prototype = {
29     __proto__: DisplayManager.prototype,
30   };
31
32   /**
33    * Shows the given screen.
34    * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
35    */
36   Oobe.showUserManagerScreen = function() {
37     Oobe.getInstance().showScreen({id: 'account-picker',
38                                    data: {disableAddUser: false}});
39     // The ChromeOS account-picker will hide the AddUser button if a user is
40     // logged in and the screen is "locked", so we must re-enabled it
41     $('add-user-header-bar-item').hidden = false;
42
43     var hash = window.location.hash;
44     if (hash && hash == '#tutorial')
45       UserManagerTutorial.startTutorial();
46   };
47
48   /**
49    * Open a new browser for the given profile.
50    * @param {string} email The user's email, if signed in.
51    * @param {string} displayName The user's display name.
52    */
53   Oobe.launchUser = function(email, displayName) {
54     chrome.send('launchUser', [email, displayName]);
55   };
56
57   /**
58    * Disables signin UI.
59    */
60   Oobe.disableSigninUI = function() {
61     DisplayManager.disableSigninUI();
62   };
63
64   /**
65    * Shows signin UI.
66    * @param {string} opt_email An optional email for signin UI.
67    */
68   Oobe.showSigninUI = function(opt_email) {
69     DisplayManager.showSigninUI(opt_email);
70   };
71
72   /**
73    * Shows sign-in error bubble.
74    * @param {number} loginAttempts Number of login attemps tried.
75    * @param {string} message Error message to show.
76    * @param {string} link Text to use for help link.
77    * @param {number} helpId Help topic Id associated with help link.
78    */
79   Oobe.showSignInError = function(loginAttempts, message, link, helpId) {
80     DisplayManager.showSignInError(loginAttempts, message, link, helpId);
81   };
82
83   /**
84    * Clears error bubble as well as optional menus that could be open.
85    */
86   Oobe.clearErrors = function() {
87     DisplayManager.clearErrors();
88   };
89
90   /**
91    * Clears password field in user-pod.
92    */
93   Oobe.clearUserPodPassword = function() {
94     DisplayManager.clearUserPodPassword();
95   };
96
97   /**
98    * Restores input focus to currently selected pod.
99    */
100   Oobe.refocusCurrentPod = function() {
101     DisplayManager.refocusCurrentPod();
102   };
103
104   /**
105    * Show the user manager tutorial
106    * @param {string} email The user's email, if signed in.
107    * @param {string} displayName The user's display name.
108    */
109   Oobe.showUserManagerTutorial = function() {
110     UserManagerTutorial.startTutorial();
111   };
112
113   // Export
114   return {
115     Oobe: Oobe
116   };
117 });
118
119 cr.define('UserManager', function() {
120   'use strict';
121
122   function initialize() {
123     cr.ui.login.DisplayManager.initialize();
124     cr.ui.login.UserManagerTutorial.initialize();
125     login.AccountPickerScreen.register();
126     cr.ui.Bubble.decorate($('bubble'));
127     login.HeaderBar.decorate($('login-header-bar'));
128     chrome.send('userManagerInitialize');
129   }
130
131   // Return an object with all of the exports.
132   return {
133     initialize: initialize
134   };
135 });
136
137 var Oobe = cr.ui.Oobe;
138
139 // Allow selection events on components with editable text (password field)
140 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
141 disableTextSelectAndDrag(function(e) {
142   var src = e.target;
143   return src instanceof HTMLTextAreaElement ||
144          src instanceof HTMLInputElement &&
145          /text|password|search/.test(src.type);
146 });
147
148 document.addEventListener('DOMContentLoaded', UserManager.initialize);