OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview User pod row implementation. | 6 * @fileoverview User pod row implementation. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('login', function() { | 9 cr.define('login', function() { |
10 /** | 10 /** |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 | 947 |
948 /** | 948 /** |
949 * Gets action box menu, remove user command item div. | 949 * Gets action box menu, remove user command item div. |
950 * @type {!HTMLInputElement} | 950 * @type {!HTMLInputElement} |
951 */ | 951 */ |
952 get actionBoxMenuRemoveElement() { | 952 get actionBoxMenuRemoveElement() { |
953 return this.querySelector('.action-box-menu-remove'); | 953 return this.querySelector('.action-box-menu-remove'); |
954 }, | 954 }, |
955 | 955 |
956 /** | 956 /** |
957 * Gets action box menu, remove user warning text div. | |
958 * @type {!HTMLInputElement} | |
959 */ | |
960 get actionBoxRemoveUserWarningTextElement() { | |
961 return this.querySelector('.action-box-remove-user-warning-text'); | |
962 }, | |
963 | |
964 /** | |
965 * Gets action box menu, remove legacy supervised user warning text div. | |
966 * @type {!HTMLInputElement} | |
967 */ | |
968 get actionBoxRemoveLegacySupervisedUserWarningTextElement() { | |
969 return this.querySelector( | |
970 '.action-box-remove-legacy-supervised-user-warning-text'); | |
971 }, | |
972 | |
973 /** | |
974 * Gets action box menu, remove user command item div. | 957 * Gets action box menu, remove user command item div. |
975 * @type {!HTMLInputElement} | 958 * @type {!HTMLInputElement} |
976 */ | 959 */ |
977 get actionBoxRemoveUserWarningElement() { | 960 get actionBoxRemoveUserWarningElement() { |
978 return this.querySelector('.action-box-remove-user-warning'); | 961 return this.querySelector('.action-box-remove-user-warning'); |
979 }, | 962 }, |
980 | 963 |
981 /** | 964 /** |
982 * Gets action box menu, remove user command item div. | 965 * Gets action box menu, remove user command item div. |
983 * @type {!HTMLInputElement} | 966 * @type {!HTMLInputElement} |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 // Move up the menu if it overlaps shelf. | 1401 // Move up the menu if it overlaps shelf. |
1419 var maxHeight = cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping( | 1402 var maxHeight = cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping( |
1420 this.actionBoxMenu); | 1403 this.actionBoxMenu); |
1421 var actualHeight = parseInt( | 1404 var actualHeight = parseInt( |
1422 window.getComputedStyle(this.actionBoxMenu).height); | 1405 window.getComputedStyle(this.actionBoxMenu).height); |
1423 if (maxHeight < actualHeight) { | 1406 if (maxHeight < actualHeight) { |
1424 this.actionBoxMenu.classList.add('menu-moved-up'); | 1407 this.actionBoxMenu.classList.add('menu-moved-up'); |
1425 this.actionBoxAreaElement.classList.add('menu-moved-up'); | 1408 this.actionBoxAreaElement.classList.add('menu-moved-up'); |
1426 } | 1409 } |
1427 chrome.send('logRemoveUserWarningShown'); | 1410 chrome.send('logRemoveUserWarningShown'); |
| 1411 |
| 1412 // Show extra statistics information for desktop users |
| 1413 var message; |
| 1414 if (this.user.isDesktopUser) { |
| 1415 this.classList.remove('has-errors'); |
| 1416 var isSyncedUser = this.user.emailAddress !== ""; |
| 1417 if (!this.user.isProfileLoaded) { |
| 1418 message = loadTimeData.getString( |
| 1419 isSyncedUser ? 'removeUserWarningTextSyncNoStats' : |
| 1420 'removeUserWarningTextNonSyncNoStats'); |
| 1421 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1422 message); |
| 1423 } else { |
| 1424 message = loadTimeData.getString( |
| 1425 isSyncedUser ? 'removeUserWarningTextSyncCalculating' : |
| 1426 'removeUserWarningTextNonSyncCalculating'); |
| 1427 substitute = loadTimeData.getString( |
| 1428 'removeUserWarningTextCalculating'); |
| 1429 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1430 message, substitute); |
| 1431 } |
| 1432 |
| 1433 // set a global handler for the callback |
| 1434 window.updateRemoveWarningDialog = |
| 1435 this.updateRemoveWarningDialog_.bind(this); |
| 1436 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); |
| 1437 } |
1428 }, | 1438 }, |
1429 | 1439 |
1430 /** | 1440 /** |
| 1441 * Refresh the statistics in the remove user warning dialog. |
| 1442 * @param {string} profilePath The filepath of the URL (must be verified). |
| 1443 * @param {Object} profileStats Statistics associated with profileURL. |
| 1444 */ |
| 1445 updateRemoveWarningDialog_: function(profilePath, profileStats) { |
| 1446 if (profilePath !== this.user.profilePath) |
| 1447 return; |
| 1448 // Converting profileStats into id attribute by an object. |
| 1449 var stats_id_map = { |
| 1450 'BrowsingHistory': 'action-box-remove-user-warning-history', |
| 1451 'Passwords': 'action-box-remove-user-warning-passwords', |
| 1452 'Bookmarks': 'action-box-remove-user-warning-bookmarks', |
| 1453 'Settings': 'action-box-remove-user-warning-settings', |
| 1454 } |
| 1455 // Load individual statistics |
| 1456 var num_stats_loaded = 0; |
| 1457 var total_count = 0; |
| 1458 var failed = false; |
| 1459 for (var key in profileStats) { |
| 1460 if (stats_id_map.hasOwnProperty(key)) { |
| 1461 if (profileStats[key].success) { |
| 1462 var count = profileStats[key].count; |
| 1463 this.querySelector("." + stats_id_map[key]).textContent = count; |
| 1464 total_count += count; |
| 1465 } else { |
| 1466 failed = true; |
| 1467 this.querySelector("." + stats_id_map[key]).textContent = ''; |
| 1468 } |
| 1469 num_stats_loaded++; |
| 1470 } |
| 1471 } |
| 1472 |
| 1473 // this.classList is used for selecting the appropriate dialog. |
| 1474 this.classList.toggle('has-errors', failed); |
| 1475 if (total_count > 0) { |
| 1476 this.classList.remove('has-no-stats'); |
| 1477 } |
| 1478 |
| 1479 // Write total number if all statistics are loaded. |
| 1480 if (num_stats_loaded === Object.keys(stats_id_map).length) { |
| 1481 if (total_count === 0) { |
| 1482 this.classList.add('has-no-stats'); |
| 1483 var isSyncedUser = this.user.emailAddress !== ""; |
| 1484 var message = loadTimeData.getString( |
| 1485 isSyncedUser ? 'removeUserWarningTextSyncNoStats' : |
| 1486 'removeUserWarningTextNonSyncNoStats'); |
| 1487 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1488 message); |
| 1489 } else { |
| 1490 window.updateRemoveWarningDialogSetMessage = |
| 1491 this.updateRemoveWarningDialogSetMessage_.bind(this); |
| 1492 chrome.send('getRemoveWarningDialogMessage',[{ |
| 1493 profilePath: this.user.profilePath, |
| 1494 isSyncedUser: this.user.emailAddress !== "", |
| 1495 hasErrors: failed, |
| 1496 totalCount: total_count |
| 1497 }]); |
| 1498 } |
| 1499 } |
| 1500 }, |
| 1501 |
| 1502 /** |
| 1503 * Refresh the message in the remove user warning dialog. |
| 1504 * @param {string} profilePath The filepath of the URL (must be verified). |
| 1505 * @param {string} message The message to be written. |
| 1506 * @param {number|string=} count The number or string to replace $1 in |
| 1507 * |message|. Can be omitted if $1 is not present in |message|. |
| 1508 */ |
| 1509 updateRemoveWarningDialogSetMessage_: function(profilePath, message, |
| 1510 count) { |
| 1511 if (profilePath !== this.user.profilePath) |
| 1512 return; |
| 1513 // Add localized messages where $1 will be replaced with |
| 1514 // <span class="total-count"></span>. |
| 1515 var element = this.querySelector('.action-box-remove-user-warning-text'); |
| 1516 while (element.firstChild) |
| 1517 element.removeChild(element.firstChild); |
| 1518 |
| 1519 messageParts = message.split('$1'); |
| 1520 var numParts = messageParts.length; |
| 1521 for (var j = 0; j < numParts; j++) { |
| 1522 element.appendChild(document.createTextNode(messageParts[j])); |
| 1523 if (j < numParts - 1) { |
| 1524 var elementToAdd = document.createElement('span'); |
| 1525 elementToAdd.classList.add('total-count'); |
| 1526 elementToAdd.textContent = count; |
| 1527 element.appendChild(elementToAdd); |
| 1528 } |
| 1529 } |
| 1530 }, |
| 1531 |
| 1532 /** |
1431 * Handles a click event on remove user confirmation button. | 1533 * Handles a click event on remove user confirmation button. |
1432 * @param {Event} e Click event. | 1534 * @param {Event} e Click event. |
1433 */ | 1535 */ |
1434 handleRemoveUserConfirmationClick_: function(e) { | 1536 handleRemoveUserConfirmationClick_: function(e) { |
1435 if (this.isActionBoxMenuActive) { | 1537 if (this.isActionBoxMenuActive) { |
1436 this.isActionBoxMenuActive = false; | 1538 this.isActionBoxMenuActive = false; |
1437 this.removeUser(this.user); | 1539 this.removeUser(this.user); |
1438 e.stopPropagation(); | 1540 e.stopPropagation(); |
1439 } | 1541 } |
1440 }, | 1542 }, |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1951 | 2053 |
1952 /** @override */ | 2054 /** @override */ |
1953 update: function() { | 2055 update: function() { |
1954 this.imageElement.src = this.user.userImage; | 2056 this.imageElement.src = this.user.userImage; |
1955 this.nameElement.textContent = this.user.displayName; | 2057 this.nameElement.textContent = this.user.displayName; |
1956 this.reauthNameHintElement.textContent = this.user.displayName; | 2058 this.reauthNameHintElement.textContent = this.user.displayName; |
1957 | 2059 |
1958 var isLockedUser = this.user.needsSignin; | 2060 var isLockedUser = this.user.needsSignin; |
1959 var isLegacySupervisedUser = this.user.legacySupervisedUser; | 2061 var isLegacySupervisedUser = this.user.legacySupervisedUser; |
1960 var isChildUser = this.user.childUser; | 2062 var isChildUser = this.user.childUser; |
| 2063 var isSyncedUser = this.user.emailAddress !== ""; |
| 2064 var isProfileLoaded = this.user.isProfileLoaded; |
1961 this.classList.toggle('locked', isLockedUser); | 2065 this.classList.toggle('locked', isLockedUser); |
1962 this.classList.toggle('legacy-supervised', isLegacySupervisedUser); | 2066 this.classList.toggle('legacy-supervised', isLegacySupervisedUser); |
1963 this.classList.toggle('child', isChildUser); | 2067 this.classList.toggle('child', isChildUser); |
| 2068 this.classList.toggle('synced', isSyncedUser); |
| 2069 this.classList.toggle('has-no-stats', !isProfileLoaded); |
1964 | 2070 |
1965 if (this.isAuthTypeUserClick) | 2071 if (this.isAuthTypeUserClick) |
1966 this.passwordLabelElement.textContent = this.authValue; | 2072 this.passwordLabelElement.textContent = this.authValue; |
1967 | 2073 |
1968 this.actionBoxRemoveUserWarningTextElement.hidden = | |
1969 isLegacySupervisedUser; | |
1970 this.actionBoxRemoveLegacySupervisedUserWarningTextElement.hidden = | |
1971 !isLegacySupervisedUser; | |
1972 | |
1973 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( | 2074 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( |
1974 'passwordFieldAccessibleName', this.user_.emailAddress)); | 2075 'passwordFieldAccessibleName', this.user_.emailAddress)); |
1975 | 2076 |
1976 UserPod.prototype.updateActionBoxArea.call(this); | 2077 UserPod.prototype.updateActionBoxArea.call(this); |
1977 }, | 2078 }, |
1978 | 2079 |
1979 /** @override */ | 2080 /** @override */ |
1980 activate: function(e) { | 2081 activate: function(e) { |
1981 if (!this.user.needsSignin) { | 2082 if (!this.user.needsSignin) { |
1982 Oobe.launchUser(this.user.profilePath); | 2083 Oobe.launchUser(this.user.profilePath); |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3181 if (pod && pod.multiProfilesPolicyApplied) { | 3282 if (pod && pod.multiProfilesPolicyApplied) { |
3182 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 3283 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
3183 } | 3284 } |
3184 } | 3285 } |
3185 }; | 3286 }; |
3186 | 3287 |
3187 return { | 3288 return { |
3188 PodRow: PodRow | 3289 PodRow: PodRow |
3189 }; | 3290 }; |
3190 }); | 3291 }); |
OLD | NEW |