OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <include src="../uber/uber_utils.js"> | 5 <include src="../uber/uber_utils.js"> |
6 | 6 |
7 /////////////////////////////////////////////////////////////////////////////// | 7 /////////////////////////////////////////////////////////////////////////////// |
8 // Globals: | 8 // Globals: |
9 /** @const */ var RESULTS_PER_PAGE = 150; | 9 /** @const */ var RESULTS_PER_PAGE = 150; |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 var isSearchResult = propertyBag.isSearchResult || false; | 120 var isSearchResult = propertyBag.isSearchResult || false; |
121 var addTitleFavicon = propertyBag.addTitleFavicon || false; | 121 var addTitleFavicon = propertyBag.addTitleFavicon || false; |
122 var useMonthDate = propertyBag.useMonthDate || false; | 122 var useMonthDate = propertyBag.useMonthDate || false; |
123 var node = createElementWithClassName('li', 'entry'); | 123 var node = createElementWithClassName('li', 'entry'); |
124 var time = createElementWithClassName('div', 'time'); | 124 var time = createElementWithClassName('div', 'time'); |
125 var entryBox = createElementWithClassName('label', 'entry-box'); | 125 var entryBox = createElementWithClassName('label', 'entry-box'); |
126 var domain = createElementWithClassName('div', 'domain'); | 126 var domain = createElementWithClassName('div', 'domain'); |
127 | 127 |
128 this.id_ = this.model_.nextVisitId_++; | 128 this.id_ = this.model_.nextVisitId_++; |
129 | 129 |
130 // Checkbox is always created, but only visible on hover & when checked. | 130 // Only create the checkbox if it can be used either to delete an entry or to |
131 var checkbox = document.createElement('input'); | 131 // block/allow it. |
132 checkbox.type = 'checkbox'; | 132 if (this.model_.editingEntriesAllowed) { |
133 checkbox.id = 'checkbox-' + this.id_; | 133 var checkbox = document.createElement('input'); |
134 checkbox.time = this.date.getTime(); | 134 checkbox.type = 'checkbox'; |
135 checkbox.addEventListener('click', checkboxClicked); | 135 checkbox.id = 'checkbox-' + this.id_; |
136 time.appendChild(checkbox); | 136 checkbox.time = this.date.getTime(); |
| 137 checkbox.addEventListener('click', checkboxClicked); |
| 138 time.appendChild(checkbox); |
| 139 |
| 140 // Clicking anywhere in the entryBox will check/uncheck the checkbox. |
| 141 entryBox.setAttribute('for', checkbox.id); |
| 142 entryBox.addEventListener('mousedown', entryBoxMousedown); |
| 143 } |
137 | 144 |
138 // Keep track of the drop down that triggered the menu, so we know | 145 // Keep track of the drop down that triggered the menu, so we know |
139 // which element to apply the command to. | 146 // which element to apply the command to. |
140 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. | 147 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. |
141 var self = this; | 148 var self = this; |
142 var setActiveVisit = function(e) { | 149 var setActiveVisit = function(e) { |
143 activeVisit = self; | 150 activeVisit = self; |
144 var menu = $('action-menu'); | 151 var menu = $('action-menu'); |
145 menu.dataset.devicename = self.deviceName; | 152 menu.dataset.devicename = self.deviceName; |
146 menu.dataset.devicetype = self.deviceType; | 153 menu.dataset.devicetype = self.deviceType; |
147 }; | 154 }; |
148 domain.textContent = this.getDomainFromURL_(this.url_); | 155 domain.textContent = this.getDomainFromURL_(this.url_); |
149 | 156 |
150 // Clicking anywhere in the entryBox will check/uncheck the checkbox. | |
151 entryBox.setAttribute('for', checkbox.id); | |
152 entryBox.addEventListener('mousedown', entryBoxMousedown); | |
153 | |
154 entryBox.appendChild(time); | 157 entryBox.appendChild(time); |
155 var titleAndDomainWrapper = entryBox.appendChild( | 158 var titleAndDomainWrapper = entryBox.appendChild( |
156 createElementWithClassName('div', 'title-and-domain')); | 159 createElementWithClassName('div', 'title-and-domain')); |
157 titleAndDomainWrapper.appendChild(this.getTitleDOM_()); | 160 titleAndDomainWrapper.appendChild(this.getTitleDOM_()); |
158 titleAndDomainWrapper.appendChild(domain); | 161 titleAndDomainWrapper.appendChild(domain); |
159 if (addTitleFavicon) | 162 if (addTitleFavicon) |
160 this.addFaviconToElement_(titleAndDomainWrapper); | 163 this.addFaviconToElement_(titleAndDomainWrapper); |
161 | 164 |
162 if (isMobileVersion()) { | 165 if (isMobileVersion()) { |
163 var removeButton = createElementWithClassName('button', 'remove-entry'); | 166 var removeButton = createElementWithClassName('button', 'remove-entry'); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 559 |
557 /** | 560 /** |
558 * Clear the history model. | 561 * Clear the history model. |
559 * @private | 562 * @private |
560 */ | 563 */ |
561 HistoryModel.prototype.clearModel_ = function() { | 564 HistoryModel.prototype.clearModel_ = function() { |
562 this.inFlight_ = false; // Whether a query is inflight. | 565 this.inFlight_ = false; // Whether a query is inflight. |
563 this.searchText_ = ''; | 566 this.searchText_ = ''; |
564 // Whether this user is a managed user. | 567 // Whether this user is a managed user. |
565 this.isManagedProfile = loadTimeData.getBoolean('isManagedProfile'); | 568 this.isManagedProfile = loadTimeData.getBoolean('isManagedProfile'); |
| 569 this.deletingHistoryAllowed = loadTimeData.getBoolean('allowDeletingHistory'); |
| 570 |
| 571 // Only create checkboxes for editing entries if they can be used either to |
| 572 // delete an entry or to block/allow it. |
| 573 this.editingEntriesAllowed = this.deletingHistoryAllowed || |
| 574 this.isManagedProfile; |
566 | 575 |
567 // Flag to show that the results are grouped by domain or not. | 576 // Flag to show that the results are grouped by domain or not. |
568 this.groupByDomain_ = false; | 577 this.groupByDomain_ = false; |
569 // Group domains by default for managed users. | 578 // Group domains by default for managed users. |
570 if (this.isManagedProfile) | 579 if (this.isManagedProfile) |
571 this.groupByDomain_ = true; | 580 this.groupByDomain_ = true; |
572 | 581 |
573 this.visits_ = []; // Date-sorted list of visits (most recent first). | 582 this.visits_ = []; // Date-sorted list of visits (most recent first). |
574 this.nextVisitId_ = 0; | 583 this.nextVisitId_ = 0; |
575 selectionAnchor = -1; | 584 selectionAnchor = -1; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 document.body.classList.remove('has-results'); | 899 document.body.classList.remove('has-results'); |
891 | 900 |
892 this.updateNavBar_(); | 901 this.updateNavBar_(); |
893 }; | 902 }; |
894 | 903 |
895 /** | 904 /** |
896 * Enables or disables the buttons that control editing entries depending on | 905 * Enables or disables the buttons that control editing entries depending on |
897 * whether there are any checked boxes. | 906 * whether there are any checked boxes. |
898 */ | 907 */ |
899 HistoryView.prototype.updateSelectionEditButtons = function() { | 908 HistoryView.prototype.updateSelectionEditButtons = function() { |
900 var anyChecked = document.querySelector('.entry input:checked') != null; | 909 if (loadTimeData.getBoolean('allowDeletingHistory')) { |
901 $('remove-selected').disabled = !anyChecked; | 910 var anyChecked = document.querySelector('.entry input:checked') != null; |
| 911 $('remove-selected').disabled = !anyChecked; |
| 912 } else { |
| 913 $('remove-selected').disabled = true; |
| 914 } |
902 $('allow-selected').disabled = !anyChecked; | 915 $('allow-selected').disabled = !anyChecked; |
903 $('block-selected').disabled = !anyChecked; | 916 $('block-selected').disabled = !anyChecked; |
904 }; | 917 }; |
905 | 918 |
906 /** | 919 /** |
907 * Callback triggered by the backend after the manual allow or block changes | 920 * Callback triggered by the backend after the manual allow or block changes |
908 * have been commited. Once the changes are commited the backend builds an | 921 * have been commited. Once the changes are commited the backend builds an |
909 * updated set of data which contains the new managed mode status and passes | 922 * updated set of data which contains the new managed mode status and passes |
910 * it through this function to the client. The function takes that data and | 923 * it through this function to the client. The function takes that data and |
911 * updates the individiual host/URL elements with their new managed mode status. | 924 * updates the individiual host/URL elements with their new managed mode status. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 * @param {Element} results DOM object to which to add the elements. | 1026 * @param {Element} results DOM object to which to add the elements. |
1014 * @param {string} domain Current domain name. | 1027 * @param {string} domain Current domain name. |
1015 * @param {Array} domainVisits Array of visits for this domain. | 1028 * @param {Array} domainVisits Array of visits for this domain. |
1016 * @private | 1029 * @private |
1017 */ | 1030 */ |
1018 HistoryView.prototype.getGroupedVisitsDOM_ = function( | 1031 HistoryView.prototype.getGroupedVisitsDOM_ = function( |
1019 results, domain, domainVisits) { | 1032 results, domain, domainVisits) { |
1020 // Add a new domain entry. | 1033 // Add a new domain entry. |
1021 var siteResults = results.appendChild( | 1034 var siteResults = results.appendChild( |
1022 createElementWithClassName('li', 'site-entry')); | 1035 createElementWithClassName('li', 'site-entry')); |
1023 var siteDomainCheckbox = | 1036 |
1024 createElementWithClassName('input', 'domain-checkbox'); | |
1025 siteDomainCheckbox.type = 'checkbox'; | |
1026 siteDomainCheckbox.addEventListener('click', domainCheckboxClicked); | |
1027 siteDomainCheckbox.domain_ = domain; | |
1028 // Make a wrapper that will contain the arrow, the favicon and the domain. | 1037 // Make a wrapper that will contain the arrow, the favicon and the domain. |
1029 var siteDomainWrapper = siteResults.appendChild( | 1038 var siteDomainWrapper = siteResults.appendChild( |
1030 createElementWithClassName('div', 'site-domain-wrapper')); | 1039 createElementWithClassName('div', 'site-domain-wrapper')); |
1031 siteDomainWrapper.appendChild(siteDomainCheckbox); | 1040 |
| 1041 if (this.model_.editingEntriesAllowed) { |
| 1042 var siteDomainCheckbox = |
| 1043 createElementWithClassName('input', 'domain-checkbox'); |
| 1044 |
| 1045 siteDomainCheckbox.type = 'checkbox'; |
| 1046 siteDomainCheckbox.addEventListener('click', domainCheckboxClicked); |
| 1047 siteDomainCheckbox.domain_ = domain; |
| 1048 |
| 1049 siteDomainWrapper.appendChild(siteDomainCheckbox); |
| 1050 } |
| 1051 |
1032 var siteArrow = siteDomainWrapper.appendChild( | 1052 var siteArrow = siteDomainWrapper.appendChild( |
1033 createElementWithClassName('div', 'site-domain-arrow collapse')); | 1053 createElementWithClassName('div', 'site-domain-arrow collapse')); |
1034 var siteDomain = siteDomainWrapper.appendChild( | 1054 var siteDomain = siteDomainWrapper.appendChild( |
1035 createElementWithClassName('div', 'site-domain')); | 1055 createElementWithClassName('div', 'site-domain')); |
1036 var siteDomainLink = siteDomain.appendChild( | 1056 var siteDomainLink = siteDomain.appendChild( |
1037 createElementWithClassName('button', 'link-button')); | 1057 createElementWithClassName('button', 'link-button')); |
1038 siteDomainLink.addEventListener('click', function(e) { e.preventDefault(); }); | 1058 siteDomainLink.addEventListener('click', function(e) { e.preventDefault(); }); |
1039 siteDomainLink.textContent = domain; | 1059 siteDomainLink.textContent = domain; |
1040 var numberOfVisits = createElementWithClassName('span', 'number-visits'); | 1060 var numberOfVisits = createElementWithClassName('span', 'number-visits'); |
1041 var domainElement = document.createElement('span'); | 1061 var domainElement = document.createElement('span'); |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 | 1472 |
1453 var doSearch = function(e) { | 1473 var doSearch = function(e) { |
1454 // Disable the group by domain control when a search is active. | 1474 // Disable the group by domain control when a search is active. |
1455 $('group-by-domain').disabled = (searchField.value != ''); | 1475 $('group-by-domain').disabled = (searchField.value != ''); |
1456 historyView.setSearch(searchField.value); | 1476 historyView.setSearch(searchField.value); |
1457 | 1477 |
1458 if (isMobileVersion()) | 1478 if (isMobileVersion()) |
1459 searchField.blur(); // Dismiss the keyboard. | 1479 searchField.blur(); // Dismiss the keyboard. |
1460 }; | 1480 }; |
1461 | 1481 |
| 1482 var mayRemoveVisits = loadTimeData.getBoolean('allowDeletingHistory'); |
| 1483 $('remove-visit').disabled = !mayRemoveVisits; |
| 1484 |
| 1485 if (mayRemoveVisits) { |
| 1486 $('remove-visit').addEventListener('activate', function(e) { |
| 1487 activeVisit.removeFromHistory_(); |
| 1488 activeVisit = null; |
| 1489 }); |
| 1490 } |
| 1491 |
1462 searchField.addEventListener('search', doSearch); | 1492 searchField.addEventListener('search', doSearch); |
1463 $('search-button').addEventListener('click', doSearch); | 1493 $('search-button').addEventListener('click', doSearch); |
1464 | 1494 |
1465 $('remove-visit').addEventListener('activate', function(e) { | |
1466 activeVisit.removeFromHistory(); | |
1467 activeVisit = null; | |
1468 }); | |
1469 $('more-from-site').addEventListener('activate', function(e) { | 1495 $('more-from-site').addEventListener('activate', function(e) { |
1470 activeVisit.showMoreFromSite_(); | 1496 activeVisit.showMoreFromSite_(); |
1471 activeVisit = null; | 1497 activeVisit = null; |
1472 }); | 1498 }); |
1473 | 1499 |
1474 // Only show the controls if the command line switch is activated. | 1500 // Only show the controls if the command line switch is activated. |
1475 if (loadTimeData.getBoolean('groupByDomain') || | 1501 if (loadTimeData.getBoolean('groupByDomain') || |
1476 loadTimeData.getBoolean('isManagedProfile')) { | 1502 loadTimeData.getBoolean('isManagedProfile')) { |
1477 $('filter-controls').hidden = false; | 1503 $('filter-controls').hidden = false; |
1478 } | 1504 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 cancelCallback, | 1665 cancelCallback, |
1640 okCallback); | 1666 okCallback); |
1641 showConfirmationOverlay(); | 1667 showConfirmationOverlay(); |
1642 } | 1668 } |
1643 | 1669 |
1644 /** | 1670 /** |
1645 * Click handler for the 'Remove selected items' button. | 1671 * Click handler for the 'Remove selected items' button. |
1646 * Confirms the deletion with the user, and then deletes the selected visits. | 1672 * Confirms the deletion with the user, and then deletes the selected visits. |
1647 */ | 1673 */ |
1648 function removeItems() { | 1674 function removeItems() { |
| 1675 if (!loadTimeData.getBoolean('allowDeletingHistory')) |
| 1676 return; |
| 1677 |
1649 var checked = $('results-display').querySelectorAll( | 1678 var checked = $('results-display').querySelectorAll( |
1650 '.entry-box input[type=checkbox]:checked:not([disabled])'); | 1679 '.entry-box input[type=checkbox]:checked:not([disabled])'); |
1651 var disabledItems = []; | 1680 var disabledItems = []; |
1652 var toBeRemoved = []; | 1681 var toBeRemoved = []; |
1653 | 1682 |
1654 for (var i = 0; i < checked.length; i++) { | 1683 for (var i = 0; i < checked.length; i++) { |
1655 var checkbox = checked[i]; | 1684 var checkbox = checked[i]; |
1656 var entry = findAncestorByClass(checkbox, 'entry'); | 1685 var entry = findAncestorByClass(checkbox, 'entry'); |
1657 toBeRemoved.push(entry.visit); | 1686 toBeRemoved.push(entry.visit); |
1658 | 1687 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 } | 1944 } |
1916 } | 1945 } |
1917 | 1946 |
1918 // Add handlers to HTML elements. | 1947 // Add handlers to HTML elements. |
1919 document.addEventListener('DOMContentLoaded', load); | 1948 document.addEventListener('DOMContentLoaded', load); |
1920 | 1949 |
1921 // This event lets us enable and disable menu items before the menu is shown. | 1950 // This event lets us enable and disable menu items before the menu is shown. |
1922 document.addEventListener('canExecute', function(e) { | 1951 document.addEventListener('canExecute', function(e) { |
1923 e.canExecute = true; | 1952 e.canExecute = true; |
1924 }); | 1953 }); |
OLD | NEW |