summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/managed_user_create_confirm.js
blob: 0f4e51fad99859697c4cb9105b87cf3801fcf09f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

cr.define('options', function() {
  var OptionsPage = options.OptionsPage;

  /**
   * ManagedUserCreateConfirm class.
   * Encapsulated handling of the confirmation overlay page when creating a
   * managed user.
   * @constructor
   * @class
   */
  function ManagedUserCreateConfirmOverlay() {
    OptionsPage.call(this, 'managedUserCreateConfirm',
                     '',  // The title will be based on the new profile name.
                     'managed-user-create-confirm');
  };

  cr.addSingletonGetter(ManagedUserCreateConfirmOverlay);

  ManagedUserCreateConfirmOverlay.prototype = {
    // Inherit from OptionsPage.
    __proto__: OptionsPage.prototype,

    // Info about the newly created profile.
    profileInfo_: null,

    /**
     * Initialize the page.
     */
    initializePage: function() {
      OptionsPage.prototype.initializePage.call(this);

      $('managed-user-create-confirm-done').onclick = function(event) {
        OptionsPage.closeOverlay();
      };

      $('managed-user-create-confirm-switch').onclick = function(event) {
        OptionsPage.closeOverlay();
        chrome.send('switchToProfile', [self.profileInfo_.filePath]);
      };
    },

    /**
     * Sets the profile info used in the dialog and updates the profile name
     * displayed. Called by the profile creation overlay when this overlay is
     * opened.
     * @param {Object} profileInfo An object of the form:
     *     profileInfo = {
     *       name: "Profile Name",
     *       filePath: "/path/to/profile/data/on/disk"
     *       isManaged: (true|false),
     *     };
     * @private
     */
    setProfileInfo_: function(info) {
      self.profileInfo_ = info;
      $('managed-user-create-confirm-title').textContent =
          loadTimeData.getStringF('managedUserCreateConfirmTitle', info.name);
      $('managed-user-create-confirm-switch').textContent =
          loadTimeData.getStringF('managedUserCreateConfirmSwitch', info.name);
    },
  };

  // Forward public APIs to private implementations.
  [
    'setProfileInfo',
  ].forEach(function(name) {
    ManagedUserCreateConfirmOverlay[name] = function() {
      var instance = ManagedUserCreateConfirmOverlay.getInstance();
      return instance[name + '_'].apply(instance, arguments);
    };
  });

  // Export
  return {
    ManagedUserCreateConfirmOverlay: ManagedUserCreateConfirmOverlay,
  };
});