Remove the old signature of NotificationManager::closePersistent().
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / login / screen_password_changed.js
blobaadc459ff89b13fb5da8ecfabd3130e36f8533f8
1 // Copyright (c) 2012 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 /**
6 * @fileoverview Password changed screen implementation.
7 */
9 login.createScreen('PasswordChangedScreen', 'password-changed', function() {
10 return {
11 EXTERNAL_API: [
12 'show'
15 /** @override */
16 decorate: function() {
17 $('old-password').addEventListener(
18 'keydown', function(e) {
19 $('password-changed').classList.remove('password-error');
20 if (e.keyIdentifier == 'Enter') {
21 $('password-changed').migrate();
22 e.stopPropagation();
24 });
25 $('old-password').addEventListener(
26 'keyup', function(e) {
27 if ($('password-changed').disabled)
28 return;
29 $('password-changed-ok-button').disabled = this.value.length == 0;
30 });
31 $('password-changed-cant-remember-link').addEventListener(
32 'click', function(e) {
33 if (this.classList.contains('disabled'))
34 return;
35 var screen = $('password-changed');
36 if (screen.classList.contains('migrate')) {
37 screen.classList.remove('migrate');
38 screen.classList.add('resync');
39 $('password-changed-proceed-button').focus();
40 $('password-changed').classList.remove('password-error');
41 $('old-password').value = '';
42 $('password-changed-ok-button').disabled = true;
44 });
47 /**
48 * Screen controls.
49 * @type {array} Array of Buttons.
51 get buttons() {
52 var buttons = [];
54 var backButton = this.ownerDocument.createElement('button');
55 backButton.id = 'password-changed-back-button';
56 backButton.textContent =
57 loadTimeData.getString('passwordChangedBackButton');
58 backButton.addEventListener('click', function(e) {
59 var screen = $('password-changed');
60 if (screen.classList.contains('migrate')) {
61 screen.cancel();
62 } else {
63 // Resync all data UI step.
64 screen.classList.remove('resync');
65 screen.classList.add('migrate');
66 $('old-password').focus();
68 e.stopPropagation();
69 });
70 buttons.push(backButton);
72 var okButton = this.ownerDocument.createElement('button');
73 okButton.id = 'password-changed-ok-button';
74 okButton.textContent = loadTimeData.getString('passwordChangedsOkButton');
75 okButton.addEventListener('click', function(e) {
76 $('password-changed').migrate();
77 e.stopPropagation();
78 });
79 buttons.push(okButton);
81 var proceedAnywayButton = this.ownerDocument.createElement('button');
82 proceedAnywayButton.id = 'password-changed-proceed-button';
83 proceedAnywayButton.textContent =
84 loadTimeData.getString('proceedAnywayButton');
85 proceedAnywayButton.addEventListener('click', function(e) {
86 var screen = $('password-changed');
87 if (screen.classList.contains('resync'))
88 $('password-changed').resync();
89 e.stopPropagation();
90 });
91 buttons.push(proceedAnywayButton);
93 return buttons;
96 /**
97 * Returns a control which should receive an initial focus.
99 get defaultControl() {
100 return $('old-password');
104 * True if the the screen is disabled (handles no user interaction).
105 * @type {boolean}
107 disabled_: false,
108 get disabled() {
109 return this.disabled_;
111 set disabled(value) {
112 this.disabled_ = value;
113 var controls = this.querySelectorAll('button,input');
114 for (var i = 0, control; control = controls[i]; ++i) {
115 control.disabled = value;
117 $('login-header-bar').disabled = value;
118 $('password-changed-cant-remember-link').classList[
119 value ? 'add' : 'remove']('disabled');
123 * Cancels password migration and drops the user back to the login screen.
125 cancel: function() {
126 this.disabled = true;
127 chrome.send('cancelPasswordChangedFlow');
131 * Starts migration process using old password that user provided.
133 migrate: function() {
134 if (!$('old-password').value) {
135 $('old-password').focus();
136 return;
138 this.disabled = true;
139 chrome.send('migrateUserData', [$('old-password').value]);
143 * Event handler that is invoked just before the screen is hidden.
145 onBeforeHide: function() {
146 $('login-header-bar').disabled = false;
150 * Starts migration process by removing old cryptohome and re-syncing data.
152 resync: function() {
153 this.disabled = true;
154 chrome.send('resyncUserData');
158 * Show password changed screen.
159 * @param {boolean} showError Whether to show the incorrect password error.
161 show: function(showError) {
162 // We'll get here after the successful online authentication.
163 // It assumes session is about to start so hides login screen controls.
164 Oobe.getInstance().headerHidden = false;
165 var screen = $('password-changed');
166 screen.classList.toggle('password-error', showError);
167 screen.classList.add('migrate');
168 screen.classList.remove('resync');
169 $('old-password').value = '';
170 $('password-changed').disabled = false;
172 Oobe.showScreen({id: SCREEN_PASSWORD_CHANGED});
173 $('password-changed-ok-button').disabled = true;