a61dc625fb264f0c41a4e1ee0bb34a8e15f6cc3d
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / supervised_user_create_confirm.js
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.
4
5 cr.define('options', function() {
6   var Page = cr.ui.pageManager.Page;
7   var PageManager = cr.ui.pageManager.PageManager;
8
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   };
21
22   cr.addSingletonGetter(SupervisedUserCreateConfirmOverlay);
23
24   SupervisedUserCreateConfirmOverlay.prototype = {
25     // Inherit from Page.
26     __proto__: Page.prototype,
27
28     // Info about the newly created profile.
29     profileInfo_: null,
30
31     /** @override */
32     initializePage: function() {
33       Page.prototype.initializePage.call(this);
34
35       $('supervised-user-created-done').onclick = function(event) {
36         PageManager.closeOverlay();
37       };
38
39       var self = this;
40
41       $('supervised-user-created-switch').onclick = function(event) {
42         PageManager.closeOverlay();
43         chrome.send('switchToProfile', [self.profileInfo_.filePath]);
44       };
45     },
46
47     /** @override */
48     didShowPage: function() {
49       $('supervised-user-created-switch').focus();
50     },
51
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);
73
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     },
83
84     /** @override */
85     canShowPage: function() {
86       return this.profileInfo_ != null;
87     },
88   };
89
90   // Forward public APIs to private implementations.
91   cr.makePublic(SupervisedUserCreateConfirmOverlay, [
92     'setProfileInfo',
93   ]);
94
95   // Export
96   return {
97     SupervisedUserCreateConfirmOverlay: SupervisedUserCreateConfirmOverlay,
98   };
99 });