| 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 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 '.action-box-remove-user-warning-table-nonsync').style.display | 1773 '.action-box-remove-user-warning-table-nonsync').style.display |
| 1774 = 'none'; | 1774 = 'none'; |
| 1775 var message = loadTimeData.getString('removeNonOwnerUserWarningText'); | 1775 var message = loadTimeData.getString('removeNonOwnerUserWarningText'); |
| 1776 this.updateRemoveNonOwnerUserWarningMessage_(this.user.profilePath, | 1776 this.updateRemoveNonOwnerUserWarningMessage_(this.user.profilePath, |
| 1777 message); | 1777 message); |
| 1778 } | 1778 } |
| 1779 } else { | 1779 } else { |
| 1780 // Show extra statistics information for desktop users | 1780 // Show extra statistics information for desktop users |
| 1781 this.querySelector( | 1781 this.querySelector( |
| 1782 '.action-box-remove-non-owner-user-warning-text').hidden = true; | 1782 '.action-box-remove-non-owner-user-warning-text').hidden = true; |
| 1783 this.RemoveWarningDialogSetMessage_(true, false); | 1783 this.RemoveWarningDialogSetMessage_(); |
| 1784 // set a global handler for the callback | 1784 // set a global handler for the callback |
| 1785 window.updateRemoveWarningDialog = | 1785 window.updateRemoveWarningDialog = |
| 1786 this.updateRemoveWarningDialog_.bind(this); | 1786 this.updateRemoveWarningDialog_.bind(this); |
| 1787 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); | 1787 var is_synced_user = this.user.emailAddress !== ""; |
| 1788 if (!is_synced_user) { |
| 1789 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); |
| 1790 } |
| 1788 } | 1791 } |
| 1789 chrome.send('logRemoveUserWarningShown'); | 1792 chrome.send('logRemoveUserWarningShown'); |
| 1790 }, | 1793 }, |
| 1791 | 1794 |
| 1792 /** | 1795 /** |
| 1793 * Refresh the statistics in the remove user warning dialog. | 1796 * Refresh the statistics in the remove user warning dialog. |
| 1794 * @param {string} profilePath The filepath of the URL (must be verified). | 1797 * @param {string} profilePath The filepath of the URL (must be verified). |
| 1795 * @param {Object} profileStats Statistics associated with profileURL. | 1798 * @param {Object} profileStats Statistics associated with profileURL. |
| 1796 */ | 1799 */ |
| 1797 updateRemoveWarningDialog_: function(profilePath, profileStats) { | 1800 updateRemoveWarningDialog_: function(profilePath, profileStats) { |
| 1798 if (profilePath !== this.user.profilePath) | 1801 if (profilePath !== this.user.profilePath) |
| 1799 return; | 1802 return; |
| 1800 | 1803 |
| 1801 var stats_elements = this.statsMapElements; | 1804 var stats_elements = this.statsMapElements; |
| 1802 // Update individual statistics | 1805 // Update individual statistics |
| 1803 var hasErrors = false; | |
| 1804 for (var key in profileStats) { | 1806 for (var key in profileStats) { |
| 1805 if (stats_elements.hasOwnProperty(key)) { | 1807 if (stats_elements.hasOwnProperty(key)) { |
| 1806 if (profileStats[key].success) { | 1808 stats_elements[key].textContent = profileStats[key].count; |
| 1807 this.user.statistics[key] = profileStats[key]; | |
| 1808 } else if (!this.user.statistics[key].success) { | |
| 1809 hasErrors = true; | |
| 1810 stats_elements[key].textContent = ''; | |
| 1811 } | |
| 1812 } | |
| 1813 } | |
| 1814 | |
| 1815 this.RemoveWarningDialogSetMessage_(false, hasErrors); | |
| 1816 }, | |
| 1817 | |
| 1818 /** | |
| 1819 * Set the new message in the dialog. | |
| 1820 * @param {boolean} Whether this is the first output, that requires setting | |
| 1821 * a in-progress message. | |
| 1822 * @param {boolean} Whether any actual query to the statistics have failed. | |
| 1823 * Should be true only if there is an error and the corresponding statistic | |
| 1824 * is also unavailable in ProfileAttributesStorage. | |
| 1825 */ | |
| 1826 RemoveWarningDialogSetMessage_: function(isInitial, hasErrors) { | |
| 1827 var stats_elements = this.statsMapElements; | |
| 1828 var total_count = 0; | |
| 1829 var num_stats_loaded = 0; | |
| 1830 for (var key in stats_elements) { | |
| 1831 if (this.user.statistics[key].success) { | |
| 1832 var count = this.user.statistics[key].count; | |
| 1833 stats_elements[key].textContent = count; | |
| 1834 total_count += count; | |
| 1835 num_stats_loaded++; | |
| 1836 } | |
| 1837 } | |
| 1838 | |
| 1839 var is_synced_user = this.user.emailAddress !== ""; | |
| 1840 // Write total number if all statistics are loaded. | |
| 1841 if (num_stats_loaded === Object.keys(stats_elements).length) { | |
| 1842 if (!total_count) { | |
| 1843 var message = loadTimeData.getString( | |
| 1844 is_synced_user ? 'removeUserWarningTextSyncNoStats' : | |
| 1845 'removeUserWarningTextNonSyncNoStats'); | |
| 1846 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | |
| 1847 message); | |
| 1848 } else { | |
| 1849 window.updateRemoveWarningDialogSetMessage = | |
| 1850 this.updateRemoveWarningDialogSetMessage_.bind(this); | |
| 1851 chrome.send('getRemoveWarningDialogMessage',[{ | |
| 1852 profilePath: this.user.profilePath, | |
| 1853 isSyncedUser: is_synced_user, | |
| 1854 hasErrors: hasErrors, | |
| 1855 totalCount: total_count | |
| 1856 }]); | |
| 1857 } | |
| 1858 } else if (isInitial) { | |
| 1859 if (!this.user.isProfileLoaded) { | |
| 1860 message = loadTimeData.getString( | |
| 1861 is_synced_user ? 'removeUserWarningTextSyncNoStats' : | |
| 1862 'removeUserWarningTextNonSyncNoStats'); | |
| 1863 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | |
| 1864 message); | |
| 1865 } else { | |
| 1866 message = loadTimeData.getString( | |
| 1867 is_synced_user ? 'removeUserWarningTextSyncCalculating' : | |
| 1868 'removeUserWarningTextNonSyncCalculating'); | |
| 1869 substitute = loadTimeData.getString( | |
| 1870 'removeUserWarningTextCalculating'); | |
| 1871 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | |
| 1872 message, substitute); | |
| 1873 } | 1809 } |
| 1874 } | 1810 } |
| 1875 }, | 1811 }, |
| 1876 | 1812 |
| 1877 /** | 1813 /** |
| 1814 * Set the new message in the dialog. |
| 1815 */ |
| 1816 RemoveWarningDialogSetMessage_: function() { |
| 1817 var is_synced_user = this.user.emailAddress !== ""; |
| 1818 message = loadTimeData.getString( |
| 1819 is_synced_user ? 'removeUserWarningTextSync' : |
| 1820 'removeUserWarningTextNonSync'); |
| 1821 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1822 message); |
| 1823 }, |
| 1824 |
| 1825 /** |
| 1878 * Refresh the message in the remove user warning dialog. | 1826 * Refresh the message in the remove user warning dialog. |
| 1879 * @param {string} profilePath The filepath of the URL (must be verified). | 1827 * @param {string} profilePath The filepath of the URL (must be verified). |
| 1880 * @param {string} message The message to be written. | 1828 * @param {string} message The message to be written. |
| 1881 * @param {number|string=} count The number or string to replace $1 in | 1829 * @param {number|string=} count The number or string to replace $1 in |
| 1882 * |message|. Can be omitted if $1 is not present in |message|. | 1830 * |message|. Can be omitted if $1 is not present in |message|. |
| 1883 */ | 1831 */ |
| 1884 updateRemoveWarningDialogSetMessage_: function( | 1832 updateRemoveWarningDialogSetMessage_: function( |
| 1885 profilePath, message, count) { | 1833 profilePath, message, count) { |
| 1886 if (profilePath !== this.user.profilePath) | 1834 if (profilePath !== this.user.profilePath) |
| 1887 return; | 1835 return; |
| (...skipping 2794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4682 if (pod && pod.multiProfilesPolicyApplied) { | 4630 if (pod && pod.multiProfilesPolicyApplied) { |
| 4683 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 4631 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
| 4684 } | 4632 } |
| 4685 } | 4633 } |
| 4686 }; | 4634 }; |
| 4687 | 4635 |
| 4688 return { | 4636 return { |
| 4689 PodRow: PodRow | 4637 PodRow: PodRow |
| 4690 }; | 4638 }; |
| 4691 }); | 4639 }); |
| OLD | NEW |