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