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 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 }, | 1527 }, |
1528 | 1528 |
1529 /** | 1529 /** |
1530 * Shows remove user warning. Used for legacy supervised users | 1530 * Shows remove user warning. Used for legacy supervised users |
1531 * and non-device-owner on CrOS, and for all users on desktop. | 1531 * and non-device-owner on CrOS, and for all users on desktop. |
1532 */ | 1532 */ |
1533 showRemoveWarning_: function() { | 1533 showRemoveWarning_: function() { |
1534 this.actionBoxMenuRemoveElement.hidden = true; | 1534 this.actionBoxMenuRemoveElement.hidden = true; |
1535 this.actionBoxRemoveUserWarningElement.hidden = false; | 1535 this.actionBoxRemoveUserWarningElement.hidden = false; |
1536 | 1536 |
1537 // Show extra statistics information for desktop users | |
1538 var message; | |
1539 if (!this.user.isDesktopUser) { | 1537 if (!this.user.isDesktopUser) { |
1540 this.moveActionMenuUpIfNeeded_(); | 1538 this.moveActionMenuUpIfNeeded_(); |
1541 if (!this.user.legacySupervisedUser) { | 1539 if (!this.user.legacySupervisedUser) { |
1542 this.querySelector( | 1540 this.querySelector( |
1543 '.action-box-remove-user-warning-text').style.display = 'none'; | 1541 '.action-box-remove-user-warning-text').style.display = 'none'; |
1544 this.querySelector( | 1542 this.querySelector( |
1545 '.action-box-remove-user-warning-table-nonsync').style.display | 1543 '.action-box-remove-user-warning-table-nonsync').style.display |
1546 = 'none'; | 1544 = 'none'; |
1547 var message = loadTimeData.getString('removeNonOwnerUserWarningText'); | 1545 var message = loadTimeData.getString('removeNonOwnerUserWarningText'); |
1548 var element_id = '.action-box-remove-non-owner-user-warning-text'; | 1546 this.updateRemoveNonOwnerUserWarningMessage_(this.user.profilePath, |
1549 this.updateRemoveWarningDialogSetMessage_(element_id, | 1547 message); |
1550 this.user.profilePath, | |
1551 message); | |
1552 } | 1548 } |
1553 } else { | 1549 } else { |
| 1550 // Show extra statistics information for desktop users |
1554 this.querySelector( | 1551 this.querySelector( |
1555 '.action-box-remove-non-owner-user-warning-text').hidden = true; | 1552 '.action-box-remove-non-owner-user-warning-text').hidden = true; |
1556 this.RemoveWarningDialogSetMessage_(true, false); | 1553 this.RemoveWarningDialogSetMessage_(true, false); |
1557 // set a global handler for the callback | 1554 // set a global handler for the callback |
1558 window.updateRemoveWarningDialog = | 1555 window.updateRemoveWarningDialog = |
1559 this.updateRemoveWarningDialog_.bind(this); | 1556 this.updateRemoveWarningDialog_.bind(this); |
1560 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); | 1557 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); |
1561 } | 1558 } |
1562 chrome.send('logRemoveUserWarningShown'); | 1559 chrome.send('logRemoveUserWarningShown'); |
1563 }, | 1560 }, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 stats_elements[key].textContent = count; | 1603 stats_elements[key].textContent = count; |
1607 total_count += count; | 1604 total_count += count; |
1608 num_stats_loaded++; | 1605 num_stats_loaded++; |
1609 } | 1606 } |
1610 } | 1607 } |
1611 | 1608 |
1612 // this.classList is used for selecting the appropriate dialog. | 1609 // this.classList is used for selecting the appropriate dialog. |
1613 if (total_count) | 1610 if (total_count) |
1614 this.classList.remove('has-no-stats'); | 1611 this.classList.remove('has-no-stats'); |
1615 | 1612 |
1616 var elementSelector = '.action-box-remove-user-warning-text'; | |
1617 var is_synced_user = this.user.emailAddress !== ""; | 1613 var is_synced_user = this.user.emailAddress !== ""; |
1618 // Write total number if all statistics are loaded. | 1614 // Write total number if all statistics are loaded. |
1619 if (num_stats_loaded === Object.keys(stats_elements).length) { | 1615 if (num_stats_loaded === Object.keys(stats_elements).length) { |
1620 if (!total_count) { | 1616 if (!total_count) { |
1621 this.classList.add('has-no-stats'); | 1617 this.classList.add('has-no-stats'); |
1622 var message = loadTimeData.getString( | 1618 var message = loadTimeData.getString( |
1623 is_synced_user ? 'removeUserWarningTextSyncNoStats' : | 1619 is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
1624 'removeUserWarningTextNonSyncNoStats'); | 1620 'removeUserWarningTextNonSyncNoStats'); |
1625 this.updateRemoveWarningDialogSetMessage_(elementSelector, | 1621 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
1626 this.user.profilePath, | |
1627 message); | 1622 message); |
1628 } else { | 1623 } else { |
1629 window.updateRemoveWarningDialogSetMessage = | 1624 window.updateRemoveWarningDialogSetMessage = |
1630 this.updateRemoveWarningDialogSetMessage_.bind(this); | 1625 this.updateRemoveWarningDialogSetMessage_.bind(this); |
1631 chrome.send('getRemoveWarningDialogMessage',[{ | 1626 chrome.send('getRemoveWarningDialogMessage',[{ |
1632 profilePath: this.user.profilePath, | 1627 profilePath: this.user.profilePath, |
1633 isSyncedUser: is_synced_user, | 1628 isSyncedUser: is_synced_user, |
1634 hasErrors: hasErrors, | 1629 hasErrors: hasErrors, |
1635 totalCount: total_count | 1630 totalCount: total_count |
1636 }]); | 1631 }]); |
1637 } | 1632 } |
1638 } else if (isInitial) { | 1633 } else if (isInitial) { |
1639 if (!this.user.isProfileLoaded) { | 1634 if (!this.user.isProfileLoaded) { |
1640 message = loadTimeData.getString( | 1635 message = loadTimeData.getString( |
1641 is_synced_user ? 'removeUserWarningTextSyncNoStats' : | 1636 is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
1642 'removeUserWarningTextNonSyncNoStats'); | 1637 'removeUserWarningTextNonSyncNoStats'); |
1643 this.updateRemoveWarningDialogSetMessage_(elementSelector, | 1638 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
1644 this.user.profilePath, | |
1645 message); | 1639 message); |
1646 } else { | 1640 } else { |
1647 message = loadTimeData.getString( | 1641 message = loadTimeData.getString( |
1648 is_synced_user ? 'removeUserWarningTextSyncCalculating' : | 1642 is_synced_user ? 'removeUserWarningTextSyncCalculating' : |
1649 'removeUserWarningTextNonSyncCalculating'); | 1643 'removeUserWarningTextNonSyncCalculating'); |
1650 substitute = loadTimeData.getString( | 1644 substitute = loadTimeData.getString( |
1651 'removeUserWarningTextCalculating'); | 1645 'removeUserWarningTextCalculating'); |
1652 this.updateRemoveWarningDialogSetMessage_(elementSelector, | 1646 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
1653 this.user.profilePath, | |
1654 message, substitute); | 1647 message, substitute); |
1655 } | 1648 } |
1656 } | 1649 } |
1657 }, | 1650 }, |
1658 | 1651 |
1659 /** | 1652 /** |
1660 * Refresh the message in the remove user warning dialog. | 1653 * Refresh the message in the remove user warning dialog. |
1661 * @param {string} elementSelector The elementSelector of warning dialog. | |
1662 * @param {string} profilePath The filepath of the URL (must be verified). | 1654 * @param {string} profilePath The filepath of the URL (must be verified). |
1663 * @param {string} message The message to be written. | 1655 * @param {string} message The message to be written. |
1664 * @param {number|string=} count The number or string to replace $1 in | 1656 * @param {number|string=} count The number or string to replace $1 in |
1665 * |message|. Can be omitted if $1 is not present in |message|. | 1657 * |message|. Can be omitted if $1 is not present in |message|. |
1666 */ | 1658 */ |
1667 updateRemoveWarningDialogSetMessage_: function(elementSelector, | 1659 updateRemoveWarningDialogSetMessage_: function(profilePath, message, |
1668 profilePath, | |
1669 message, | |
1670 count) { | 1660 count) { |
1671 if (profilePath !== this.user.profilePath) | 1661 if (profilePath !== this.user.profilePath) |
1672 return; | 1662 return; |
1673 // Add localized messages where $1 will be replaced with | 1663 // Add localized messages where $1 will be replaced with |
1674 // <span class="total-count"></span> and $2 will be replaced with | 1664 // <span class="total-count"></span> and $2 will be replaced with |
1675 // <span class="email"></span>. | 1665 // <span class="email"></span>. |
1676 var element = this.querySelector(elementSelector); | 1666 var element = this.querySelector('.action-box-remove-user-warning-text'); |
1677 element.textContent = ''; | 1667 element.textContent = ''; |
1678 | 1668 |
1679 messageParts = message.split(/(\$[12])/); | 1669 messageParts = message.split(/(\$[12])/); |
1680 var numParts = messageParts.length; | 1670 var numParts = messageParts.length; |
1681 for (var j = 0; j < numParts; j++) { | 1671 for (var j = 0; j < numParts; j++) { |
1682 if (messageParts[j] === '$1') { | 1672 if (messageParts[j] === '$1') { |
1683 var elementToAdd = document.createElement('span'); | 1673 var elementToAdd = document.createElement('span'); |
1684 elementToAdd.classList.add('total-count'); | 1674 elementToAdd.classList.add('total-count'); |
1685 elementToAdd.textContent = count; | 1675 elementToAdd.textContent = count; |
1686 element.appendChild(elementToAdd); | 1676 element.appendChild(elementToAdd); |
1687 } else if (messageParts[j] === '$2') { | 1677 } else if (messageParts[j] === '$2') { |
1688 var elementToAdd = document.createElement('span'); | 1678 var elementToAdd = document.createElement('span'); |
1689 elementToAdd.classList.add('email'); | 1679 elementToAdd.classList.add('email'); |
1690 elementToAdd.textContent = this.user.emailAddress; | 1680 elementToAdd.textContent = this.user.emailAddress; |
1691 element.appendChild(elementToAdd); | 1681 element.appendChild(elementToAdd); |
1692 } else { | 1682 } else { |
1693 element.appendChild(document.createTextNode(messageParts[j])); | 1683 element.appendChild(document.createTextNode(messageParts[j])); |
1694 } | 1684 } |
1695 } | 1685 } |
1696 this.moveActionMenuUpIfNeeded_(); | 1686 this.moveActionMenuUpIfNeeded_(); |
1697 }, | 1687 }, |
1698 | 1688 |
1699 /** | 1689 /** |
| 1690 * Update the message in the "remove non-owner user warning" dialog on CrOS. |
| 1691 * @param {string} profilePath The filepath of the URL (must be verified). |
| 1692 * @param (string) message The message to be written. |
| 1693 */ |
| 1694 updateRemoveNonOwnerUserWarningMessage_: function(profilePath, message) { |
| 1695 if (profilePath !== this.user.profilePath) |
| 1696 return; |
| 1697 // Add localized messages where $1 will be replaced with |
| 1698 // <span class="email"></span>. |
| 1699 var element = this.querySelector( |
| 1700 '.action-box-remove-non-owner-user-warning-text'); |
| 1701 element.textContent = ''; |
| 1702 |
| 1703 messageParts = message.split(/(\$[1])/); |
| 1704 var numParts = messageParts.length; |
| 1705 for (var j = 0; j < numParts; j++) { |
| 1706 if (messageParts[j] == '$1') { |
| 1707 var elementToAdd = document.createElement('span'); |
| 1708 elementToAdd.classList.add('email'); |
| 1709 elementToAdd.textContent = this.user.emailAddress; |
| 1710 element.appendChild(elementToAdd); |
| 1711 } else { |
| 1712 element.appendChild(document.createTextNode(messageParts[j])); |
| 1713 } |
| 1714 } |
| 1715 this.moveActionMenuUpIfNeeded_(); |
| 1716 }, |
| 1717 |
| 1718 /** |
1700 * Handles a click event on remove user confirmation button. | 1719 * Handles a click event on remove user confirmation button. |
1701 * @param {Event} e Click event. | 1720 * @param {Event} e Click event. |
1702 */ | 1721 */ |
1703 handleRemoveUserConfirmationClick_: function(e) { | 1722 handleRemoveUserConfirmationClick_: function(e) { |
1704 if (this.isActionBoxMenuActive) { | 1723 if (this.isActionBoxMenuActive) { |
1705 this.isActionBoxMenuActive = false; | 1724 this.isActionBoxMenuActive = false; |
1706 this.removeUser(this.user); | 1725 this.removeUser(this.user); |
1707 e.stopPropagation(); | 1726 e.stopPropagation(); |
1708 } | 1727 } |
1709 }, | 1728 }, |
(...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3544 if (pod && pod.multiProfilesPolicyApplied) { | 3563 if (pod && pod.multiProfilesPolicyApplied) { |
3545 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 3564 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
3546 } | 3565 } |
3547 } | 3566 } |
3548 }; | 3567 }; |
3549 | 3568 |
3550 return { | 3569 return { |
3551 PodRow: PodRow | 3570 PodRow: PodRow |
3552 }; | 3571 }; |
3553 }); | 3572 }); |
OLD | NEW |