BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / resources / options / supervised_user_create_confirm.js
blob3d0cb6f5489f8c9d844f3b68e246b27568adda46
1 // Copyright 2014 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.
5 cr.define('options', function() {
6   var Page = cr.ui.pageManager.Page;
7   var PageManager = cr.ui.pageManager.PageManager;
9   /**
10    * SupervisedUserCreateConfirm class.
11    * Encapsulated handling of the confirmation overlay page when creating a
12    * supervised user.
13    * @constructor
14    * @extends {cr.ui.pageManager.Page}
15    */
16   function SupervisedUserCreateConfirmOverlay() {
17     Page.call(this, 'supervisedUserCreateConfirm',
18               '',  // The title will be based on the new profile name.
19               'supervised-user-created');
20   };
22   cr.addSingletonGetter(SupervisedUserCreateConfirmOverlay);
24   SupervisedUserCreateConfirmOverlay.prototype = {
25     // Inherit from Page.
26     __proto__: Page.prototype,
28     // Info about the newly created profile.
29     profileInfo_: null,
31     /** @override */
32     initializePage: function() {
33       Page.prototype.initializePage.call(this);
35       $('supervised-user-created-done').onclick = function(event) {
36         PageManager.closeOverlay();
37       };
39       var self = this;
41       $('supervised-user-created-switch').onclick = function(event) {
42         PageManager.closeOverlay();
43         chrome.send('switchToProfile', [self.profileInfo_.filePath]);
44       };
45     },
47     /** @override */
48     didShowPage: function() {
49       $('supervised-user-created-switch').focus();
50     },
52     /**
53      * Sets the profile info used in the dialog and updates the profile name
54      * displayed. Called by the profile creation overlay when this overlay is
55      * opened.
56      * @param {Object} info An object of the form:
57      *     info = {
58      *       name: "Profile Name",
59      *       filePath: "/path/to/profile/data/on/disk",
60      *       isSupervised: (true|false)
61      *       custodianEmail: "example@gmail.com"
62      *     };
63      * @private
64      */
65     setProfileInfo_: function(info) {
66       this.profileInfo_ = info;
67       var MAX_LENGTH = 50;
68       var elidedName = elide(info.name, MAX_LENGTH);
69       $('supervised-user-created-title').textContent =
70           loadTimeData.getStringF('supervisedUserCreatedTitle', elidedName);
71       $('supervised-user-created-switch').textContent =
72           loadTimeData.getStringF('supervisedUserCreatedSwitch', elidedName);
74       // HTML-escape the user-supplied strings before putting them into
75       // innerHTML. This is probably excessive for the email address, but
76       // belt-and-suspenders is cheap here.
77       $('supervised-user-created-text').innerHTML =
78           loadTimeData.getStringF('supervisedUserCreatedText',
79                                   HTMLEscape(elidedName),
80                                   HTMLEscape(elide(info.custodianEmail,
81                                                    MAX_LENGTH)));
82     },
84     /** @override */
85     canShowPage: function() {
86       return this.profileInfo_ != null;
87     },
89     /**
90      * Updates the displayed profile name if it has changed. Called by the
91      * handler.
92      * @param {string} filePath The file path of the profile whose name
93      *     changed.
94      * @param {string} newName The changed profile's new name.
95      * @private
96      */
97     onUpdatedProfileName_: function(filePath, newName) {
98       if (filePath == this.profileInfo_.filePath) {
99         this.profileInfo_.name = newName;
100         this.setProfileInfo_(this.profileInfo_);
101       }
102     },
104     /**
105      * Closes this overlay if the new profile has been deleted. Called by the
106      * handler.
107      * @param {string} filePath The file path of the profile that was deleted.
108      * @private
109      */
110     onDeletedProfile_: function(filePath) {
111       if (filePath == this.profileInfo_.filePath) {
112         PageManager.closeOverlay();
113       }
114     },
115   };
117   // Forward public APIs to private implementations.
118   cr.makePublic(SupervisedUserCreateConfirmOverlay, [
119     'onDeletedProfile',
120     'onUpdatedProfileName',
121     'setProfileInfo',
122   ]);
124   // Export
125   return {
126     SupervisedUserCreateConfirmOverlay: SupervisedUserCreateConfirmOverlay,
127   };