Chromium Code Reviews| 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 }; | 350 }; |
| 351 | 351 |
| 352 /** | 352 /** |
| 353 * Reload our model with the current parameters. | 353 * Reload our model with the current parameters. |
| 354 */ | 354 */ |
| 355 HistoryModel.prototype.reload = function() { | 355 HistoryModel.prototype.reload = function() { |
| 356 // Save user-visible state, clear the model, and restore the state. | 356 // Save user-visible state, clear the model, and restore the state. |
| 357 var search = this.searchText_; | 357 var search = this.searchText_; |
| 358 var page = this.requestedPage_; | 358 var page = this.requestedPage_; |
| 359 var range = this.rangeInDays_; | 359 var range = this.rangeInDays_; |
| 360 var offset = this.offset_; | |
| 360 var groupByDomain = this.groupByDomain_; | 361 var groupByDomain = this.groupByDomain_; |
| 361 | 362 |
| 362 this.clearModel_(); | 363 this.clearModel_(); |
| 363 this.searchText_ = search; | 364 this.searchText_ = search; |
| 364 this.requestedPage_ = page; | 365 this.requestedPage_ = page; |
| 365 this.rangeInDays_ = range; | 366 this.rangeInDays_ = range; |
| 367 this.offset_ = offset; | |
| 366 this.groupByDomain_ = groupByDomain; | 368 this.groupByDomain_ = groupByDomain; |
| 367 this.queryHistory_(); | 369 this.queryHistory_(); |
| 368 }; | 370 }; |
| 369 | 371 |
| 370 /** | 372 /** |
| 371 * @return {string} The current search text. | 373 * @return {string} The current search text. |
| 372 */ | 374 */ |
| 373 HistoryModel.prototype.getSearchText = function() { | 375 HistoryModel.prototype.getSearchText = function() { |
| 374 return this.searchText_; | 376 return this.searchText_; |
| 375 }; | 377 }; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 }; | 468 }; |
| 467 | 469 |
| 468 /** | 470 /** |
| 469 * Sets the range in days when using grouped results and updates the results. | 471 * Sets the range in days when using grouped results and updates the results. |
| 470 * @param {HistoryModel.Range} days The range to set. | 472 * @param {HistoryModel.Range} days The range to set. |
| 471 */ | 473 */ |
| 472 HistoryModel.prototype.setRangeInDays = function(days) { | 474 HistoryModel.prototype.setRangeInDays = function(days) { |
| 473 this.rangeInDays_ = days; | 475 this.rangeInDays_ = days; |
| 474 }; | 476 }; |
| 475 | 477 |
| 478 /** | |
| 479 * Returns the current offset. The offset moves the current query 'window' | |
| 480 * |range| days behind. As such for range set to WEEK an offset of 0 refers to | |
| 481 * the last 7 days, an offset of 1 refers to the 7 day period that ended 7 days | |
| 482 * ago, etc. For MONTH an offset of 0 refers to the current calendar month, | |
| 483 * 1 to the previous one, etc. | |
| 484 * @return {number} The current offset. | |
| 485 */ | |
| 486 HistoryModel.prototype.getOffset = function() { | |
|
Bernhard Bauer
2013/01/18 16:08:27
Use get/set accessors?
Sergiu
2013/01/21 14:05:24
Done.
| |
| 487 return this.offset_; | |
| 488 }; | |
| 489 | |
| 490 /** | |
| 491 * Sets the offset. | |
| 492 * @param {Number} value Either the new value or the relative change. | |
| 493 */ | |
| 494 HistoryModel.prototype.setOffset = function(value) { | |
| 495 this.offset_ = value; | |
| 496 }; | |
| 497 | |
| 476 // HistoryModel, Private: ----------------------------------------------------- | 498 // HistoryModel, Private: ----------------------------------------------------- |
| 477 | 499 |
| 478 /** | 500 /** |
| 479 * Clear the history model. | 501 * Clear the history model. |
| 480 * @private | 502 * @private |
| 481 */ | 503 */ |
| 482 HistoryModel.prototype.clearModel_ = function() { | 504 HistoryModel.prototype.clearModel_ = function() { |
| 483 this.inFlight_ = false; // Whether a query is inflight. | 505 this.inFlight_ = false; // Whether a query is inflight. |
| 484 this.searchText_ = ''; | 506 this.searchText_ = ''; |
| 485 // Flag to show that the results are grouped by domain or not. | 507 // Flag to show that the results are grouped by domain or not. |
| 486 this.groupByDomain_ = false; | 508 this.groupByDomain_ = false; |
| 487 | 509 |
| 488 this.visits_ = []; // Date-sorted list of visits (most recent first). | 510 this.visits_ = []; // Date-sorted list of visits (most recent first). |
| 489 this.last_id_ = 0; | 511 this.last_id_ = 0; |
| 490 selectionAnchor = -1; | 512 selectionAnchor = -1; |
| 491 | 513 |
| 492 // The page that the view wants to see - we only fetch slightly past this | 514 // The page that the view wants to see - we only fetch slightly past this |
| 493 // point. If the view requests a page that we don't have data for, we try | 515 // point. If the view requests a page that we don't have data for, we try |
| 494 // to fetch it and call back when we're done. | 516 // to fetch it and call back when we're done. |
| 495 this.requestedPage_ = 0; | 517 this.requestedPage_ = 0; |
| 496 | 518 |
| 519 // Skip |offset_| * weeks/months from the begining. | |
| 520 this.offset_ = 0; | |
| 521 | |
| 497 // The range of history to view or search over, WEEK by default. | 522 // The range of history to view or search over, WEEK by default. |
| 498 this.rangeInDays_ = HistoryModel.Range.WEEK; | 523 this.rangeInDays_ = HistoryModel.Range.WEEK; |
| 499 | 524 |
| 500 // Keeps track of whether or not there are more results available than are | 525 // Keeps track of whether or not there are more results available than are |
| 501 // currently held in |this.visits_|. | 526 // currently held in |this.visits_|. |
| 502 this.isQueryFinished_ = false; | 527 this.isQueryFinished_ = false; |
| 503 | 528 |
| 504 // An opaque value that is returned with the query results. This is used to | 529 // An opaque value that is returned with the query results. This is used to |
| 505 // fetch the next page of results for a query. | 530 // fetch the next page of results for a query. |
| 506 this.queryCursor_ = null; | 531 this.queryCursor_ = null; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 533 // Show the result or a message if no results were returned. | 558 // Show the result or a message if no results were returned. |
| 534 this.view_.onModelReady(); | 559 this.view_.onModelReady(); |
| 535 }; | 560 }; |
| 536 | 561 |
| 537 /** | 562 /** |
| 538 * Query for history, either for a search or time-based browsing. | 563 * Query for history, either for a search or time-based browsing. |
| 539 * @private | 564 * @private |
| 540 */ | 565 */ |
| 541 HistoryModel.prototype.queryHistory_ = function() { | 566 HistoryModel.prototype.queryHistory_ = function() { |
| 542 var endTime = 0; | 567 var endTime = 0; |
| 543 // Set the range to the values from the interface. | 568 // Set the range and offset to the values from the interface. |
| 569 var offset = this.offset_; | |
| 544 var range = this.rangeInDays_; | 570 var range = this.rangeInDays_; |
| 545 if (!this.getGroupByDomain()) { | 571 if (!this.getGroupByDomain()) { |
| 546 // Do the time-based search. | 572 // Do the time-based search. |
| 547 // If there are already some visits, pick up the previous query where it | 573 // If there are already some visits, pick up the previous query where it |
| 548 // left off. | 574 // left off. |
| 549 if (this.visits_.length > 0) { | 575 if (this.visits_.length > 0) { |
| 550 var lastVisit = this.visits_.slice(-1)[0]; | 576 var lastVisit = this.visits_.slice(-1)[0]; |
| 551 endTime = lastVisit.date.getTime(); | 577 endTime = lastVisit.date.getTime(); |
| 552 cursor = this.queryCursor_; | 578 cursor = this.queryCursor_; |
| 553 } | 579 } |
| 554 range = HistoryModel.Range.NOT_GROUPED; | 580 range = HistoryModel.Range.NOT_GROUPED; |
| 555 } | 581 } |
| 556 $('loading-spinner').hidden = false; | 582 $('loading-spinner').hidden = false; |
| 557 this.inFlight_ = true; | 583 this.inFlight_ = true; |
| 558 chrome.send('queryHistory', | 584 chrome.send('queryHistory', |
| 559 [this.searchText_, range, endTime, this.queryCursor_, | 585 [this.searchText_, offset, range, endTime, this.queryCursor_, |
| 560 RESULTS_PER_PAGE]); | 586 RESULTS_PER_PAGE]); |
| 561 }; | 587 }; |
| 562 | 588 |
| 563 /** | 589 /** |
| 564 * Check to see if we have data for the given page. | 590 * Check to see if we have data for the given page. |
| 565 * @param {number} page The page number. | 591 * @param {number} page The page number. |
| 566 * @return {boolean} Whether we have any data for the given page. | 592 * @return {boolean} Whether we have any data for the given page. |
| 567 * @private | 593 * @private |
| 568 */ | 594 */ |
| 569 HistoryModel.prototype.haveDataForPage_ = function(page) { | 595 HistoryModel.prototype.haveDataForPage_ = function(page) { |
| 570 return (page * RESULTS_PER_PAGE < this.getSize()); | 596 return (page * RESULTS_PER_PAGE < this.getSize()); |
| 571 }; | 597 }; |
| 572 | 598 |
| 573 /** | 599 /** |
| 574 * Check to see if we have data to fill the given page. | 600 * Check to see if we have data to fill the given page. |
| 575 * @param {number} page The page number. | 601 * @param {number} page The page number. |
| 576 * @return {boolean} Whether we have data to fill the page. | 602 * @return {boolean} Whether we have data to fill the page. |
| 577 * @private | 603 * @private |
| 578 */ | 604 */ |
| 579 HistoryModel.prototype.canFillPage_ = function(page) { | 605 HistoryModel.prototype.canFillPage_ = function(page) { |
| 580 return ((page + 1) * RESULTS_PER_PAGE <= this.getSize()); | 606 return ((page + 1) * RESULTS_PER_PAGE <= this.getSize()); |
| 581 }; | 607 }; |
| 582 | 608 |
| 583 /** | 609 /** |
| 584 * Enables or disables grouping by domain. | 610 * Enables or disables grouping by domain. |
| 585 * @param {boolean} groupByDomain New groupByDomain_ value. | 611 * @param {boolean} groupByDomain New groupByDomain_ value. |
| 586 */ | 612 */ |
| 587 HistoryModel.prototype.setGroupByDomain = function(groupByDomain) { | 613 HistoryModel.prototype.setGroupByDomain = function(groupByDomain) { |
| 588 this.groupByDomain_ = groupByDomain; | 614 this.groupByDomain_ = groupByDomain; |
| 615 this.offset_ = 0; | |
| 589 }; | 616 }; |
| 590 | 617 |
| 591 /** | 618 /** |
| 592 * Gets whether we are grouped by domain. | 619 * Gets whether we are grouped by domain. |
| 593 * @return {boolean} Whether the results are grouped by domain. | 620 * @return {boolean} Whether the results are grouped by domain. |
| 594 */ | 621 */ |
| 595 HistoryModel.prototype.getGroupByDomain = function() { | 622 HistoryModel.prototype.getGroupByDomain = function() { |
| 596 return this.groupByDomain_; | 623 return this.groupByDomain_; |
| 597 }; | 624 }; |
| 598 | 625 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 }); | 663 }); |
| 637 | 664 |
| 638 // Add handlers for the range options. | 665 // Add handlers for the range options. |
| 639 $('timeframe-filter').addEventListener('change', function(e) { | 666 $('timeframe-filter').addEventListener('change', function(e) { |
| 640 self.setRangeInDays(parseInt(e.target.value, 10)); | 667 self.setRangeInDays(parseInt(e.target.value, 10)); |
| 641 }); | 668 }); |
| 642 | 669 |
| 643 $('display-filter-sites').addEventListener('click', function(e) { | 670 $('display-filter-sites').addEventListener('click', function(e) { |
| 644 self.setGroupByDomain($('display-filter-sites').checked); | 671 self.setGroupByDomain($('display-filter-sites').checked); |
| 645 }); | 672 }); |
| 673 | |
| 674 $('range-previous').addEventListener('click', function(e) { | |
| 675 self.setOffset(self.getOffset() + 1); | |
| 676 }); | |
| 677 $('range-next').addEventListener('click', function(e) { | |
| 678 self.setOffset(self.getOffset() - 1); | |
| 679 }); | |
| 680 $('range-today').addEventListener('click', function(e) { | |
| 681 self.setOffset(0); | |
| 682 }); | |
| 646 } | 683 } |
| 647 | 684 |
| 648 // HistoryView, public: ------------------------------------------------------- | 685 // HistoryView, public: ------------------------------------------------------- |
| 649 /** | 686 /** |
| 650 * Do a search and optionally view a certain page. | 687 * Do a search and optionally view a certain page. |
| 651 * @param {string} term The string to search for. | 688 * @param {string} term The string to search for. |
| 652 * @param {number} opt_page The page we wish to view, only use this for | 689 * @param {number} opt_page The page we wish to view, only use this for |
| 653 * setting up initial views, as this triggers a search. | 690 * setting up initial views, as this triggers a search. |
| 654 */ | 691 */ |
| 655 HistoryView.prototype.setSearch = function(term, opt_page) { | 692 HistoryView.prototype.setSearch = function(term, opt_page) { |
| 656 this.pageIndex_ = parseInt(opt_page || 0, 10); | 693 this.pageIndex_ = parseInt(opt_page || 0, 10); |
| 657 window.scrollTo(0, 0); | 694 window.scrollTo(0, 0); |
| 658 this.model_.setSearchText(term, this.pageIndex_); | 695 this.model_.setSearchText(term, this.pageIndex_); |
| 659 pageState.setUIState(term, this.pageIndex_, this.model_.getGroupByDomain(), | 696 pageState.setUIState(term, this.pageIndex_, this.model_.getGroupByDomain(), |
| 660 this.getRangeInDays()); | 697 this.getRangeInDays(), this.getOffset()); |
| 661 }; | 698 }; |
| 662 | 699 |
| 663 /** | 700 /** |
| 664 * Enable or disable results as being grouped by domain. | 701 * Enable or disable results as being grouped by domain. |
| 665 * @param {boolean} groupedByDomain Whether to group by domain or not. | 702 * @param {boolean} groupedByDomain Whether to group by domain or not. |
| 666 */ | 703 */ |
| 667 HistoryView.prototype.setGroupByDomain = function(groupedByDomain) { | 704 HistoryView.prototype.setGroupByDomain = function(groupedByDomain) { |
| 668 // Group by domain is not currently supported for search results, so reset | 705 // Group by domain is not currently supported for search results, so reset |
| 669 // the search term if there was one. | 706 // the search term if there was one. |
| 670 this.model_.clearSearchText(); | 707 this.model_.clearSearchText(); |
| 671 this.model_.setGroupByDomain(groupedByDomain); | 708 this.model_.setGroupByDomain(groupedByDomain); |
| 672 $('timeframe-filter').disabled = !groupedByDomain; | 709 setRangeButtonsState(groupedByDomain, this); |
| 673 this.model_.reload(); | 710 this.model_.reload(); |
| 674 pageState.setUIState(this.model_.getSearchText(), | 711 pageState.setUIState(this.model_.getSearchText(), |
| 675 this.pageIndex_, | 712 this.pageIndex_, |
| 676 this.model_.getGroupByDomain(), | 713 this.model_.getGroupByDomain(), |
| 677 this.getRangeInDays()); | 714 this.getRangeInDays(), |
| 715 this.getOffset()); | |
| 678 }; | 716 }; |
| 679 | 717 |
| 680 /** | 718 /** |
| 681 * Reload the current view. | 719 * Reload the current view. |
| 682 */ | 720 */ |
| 683 HistoryView.prototype.reload = function() { | 721 HistoryView.prototype.reload = function() { |
| 684 this.model_.reload(); | 722 this.model_.reload(); |
| 685 this.updateRemoveButton(); | 723 this.updateRemoveButton(); |
| 686 }; | 724 }; |
| 687 | 725 |
| 688 /** | 726 /** |
| 689 * Switch to a specified page. | 727 * Switch to a specified page. |
| 690 * @param {number} page The page we wish to view. | 728 * @param {number} page The page we wish to view. |
| 691 */ | 729 */ |
| 692 HistoryView.prototype.setPage = function(page) { | 730 HistoryView.prototype.setPage = function(page) { |
| 693 this.clear_(); | 731 this.clear_(); |
| 694 this.pageIndex_ = parseInt(page, 10); | 732 this.pageIndex_ = parseInt(page, 10); |
| 695 window.scrollTo(0, 0); | 733 window.scrollTo(0, 0); |
| 696 this.model_.requestPage(page); | 734 this.model_.requestPage(page); |
| 697 pageState.setUIState(this.model_.getSearchText(), | 735 pageState.setUIState(this.model_.getSearchText(), |
| 698 this.pageIndex_, | 736 this.pageIndex_, |
| 699 this.model_.getGroupByDomain(), | 737 this.model_.getGroupByDomain(), |
| 700 this.getRangeInDays()); | 738 this.getRangeInDays(), |
| 739 this.getOffset()); | |
| 701 }; | 740 }; |
| 702 | 741 |
| 703 /** | 742 /** |
| 704 * @return {number} The page number being viewed. | 743 * @return {number} The page number being viewed. |
| 705 */ | 744 */ |
| 706 HistoryView.prototype.getPage = function() { | 745 HistoryView.prototype.getPage = function() { |
| 707 return this.pageIndex_; | 746 return this.pageIndex_; |
| 708 }; | 747 }; |
| 709 | 748 |
| 710 /** | 749 /** |
| 711 * Set the current range for grouped results. | 750 * Set the current range for grouped results. |
| 712 * @param {string} range The number of days to which the range should be set. | 751 * @param {string} range The number of days to which the range should be set. |
| 713 */ | 752 */ |
| 714 HistoryView.prototype.setRangeInDays = function(range) { | 753 HistoryView.prototype.setRangeInDays = function(range) { |
| 715 window.scrollTo(0, 0); | 754 window.scrollTo(0, 0); |
| 716 // Set the range and reset the offset. | 755 // Set the range and reset the offset. |
| 756 this.model_.setOffset(0); | |
| 717 this.model_.setRangeInDays(range); | 757 this.model_.setRangeInDays(range); |
| 718 this.model_.reload(); | 758 this.model_.reload(); |
| 719 pageState.setUIState(this.model_.getSearchText(), this.pageIndex_, | 759 pageState.setUIState(this.model_.getSearchText(), this.pageIndex_, |
| 720 this.model_.getGroupByDomain(), range); | 760 this.model_.getGroupByDomain(), range, this.getOffset()); |
| 721 }; | 761 }; |
| 722 | 762 |
| 723 /** | 763 /** |
| 724 * Get the current range in days. | 764 * Get the current range in days. |
| 725 * @return {number} Current range in days from the model. | 765 * @return {number} Current range in days from the model. |
| 726 */ | 766 */ |
| 727 HistoryView.prototype.getRangeInDays = function() { | 767 HistoryView.prototype.getRangeInDays = function() { |
| 728 return this.model_.getRangeInDays(); | 768 return this.model_.getRangeInDays(); |
| 729 }; | 769 }; |
| 730 | 770 |
| 731 /** | 771 /** |
| 772 * Set the current offset for grouped results. | |
| 773 * @param {number} offset Offset to set. | |
| 774 */ | |
| 775 HistoryView.prototype.setOffset = function(offset) { | |
| 776 window.scrollTo(0, 0); | |
| 777 this.model_.setOffset(offset); | |
| 778 this.model_.reload(); | |
| 779 setRangeButtonsState(true, this); | |
| 780 pageState.setUIState(this.model_.getSearchText(), | |
| 781 this.pageIndex_, | |
| 782 this.model_.getGroupByDomain(), | |
| 783 this.getRangeInDays(), | |
| 784 this.getOffset()); | |
| 785 }; | |
| 786 | |
| 787 /** | |
| 788 * Get the current offset. | |
| 789 * @return {number} Current offset from the model. | |
| 790 */ | |
| 791 HistoryView.prototype.getOffset = function() { | |
| 792 return this.model_.getOffset(); | |
| 793 }; | |
| 794 | |
| 795 /** | |
| 732 * Callback for the history model to let it know that it has data ready for us | 796 * Callback for the history model to let it know that it has data ready for us |
| 733 * to view. | 797 * to view. |
| 734 */ | 798 */ |
| 735 HistoryView.prototype.onModelReady = function() { | 799 HistoryView.prototype.onModelReady = function() { |
| 736 this.displayResults_(); | 800 this.displayResults_(); |
| 737 this.updateNavBar_(); | 801 this.updateNavBar_(); |
| 738 }; | 802 }; |
| 739 | 803 |
| 740 /** | 804 /** |
| 741 * Enables or disables the 'Remove selected items' button as appropriate. | 805 * Enables or disables the 'Remove selected items' button as appropriate. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1052 var hashData = state_obj.getHashData(); | 1116 var hashData = state_obj.getHashData(); |
| 1053 if (hashData.q != state_obj.model.getSearchText()) { | 1117 if (hashData.q != state_obj.model.getSearchText()) { |
| 1054 state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10)); | 1118 state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10)); |
| 1055 } else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) { | 1119 } else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) { |
| 1056 state_obj.view.setPage(hashData.p); | 1120 state_obj.view.setPage(hashData.p); |
| 1057 } else if ((hashData.g == 'true') != | 1121 } else if ((hashData.g == 'true') != |
| 1058 state_obj.view.model_.getGroupByDomain()) { | 1122 state_obj.view.model_.getGroupByDomain()) { |
| 1059 state_obj.view.setGroupByDomain(hashData.g); | 1123 state_obj.view.setGroupByDomain(hashData.g); |
| 1060 } else if (parseInt(hashData.r, 10) != state_obj.model.getRangeInDays()) { | 1124 } else if (parseInt(hashData.r, 10) != state_obj.model.getRangeInDays()) { |
| 1061 state_obj.view.setRangeInDays(parseInt(hashData.r, 10)); | 1125 state_obj.view.setRangeInDays(parseInt(hashData.r, 10)); |
| 1126 } else if (parseInt(hashData.o, 10) != state_obj.model.getOffset()) { | |
| 1127 state_obj.view.setOffset(parseInt(hashData.o, 10)); | |
| 1062 } | 1128 } |
| 1063 }), 50, this); | 1129 }), 50, this); |
| 1064 } | 1130 } |
| 1065 | 1131 |
| 1066 /** | 1132 /** |
| 1067 * Holds the singleton instance. | 1133 * Holds the singleton instance. |
| 1068 */ | 1134 */ |
| 1069 PageState.instance = null; | 1135 PageState.instance = null; |
| 1070 | 1136 |
| 1071 /** | 1137 /** |
| 1072 * @return {Object} An object containing parameters from our window hash. | 1138 * @return {Object} An object containing parameters from our window hash. |
| 1073 */ | 1139 */ |
| 1074 PageState.prototype.getHashData = function() { | 1140 PageState.prototype.getHashData = function() { |
| 1075 var result = { | 1141 var result = { |
| 1076 e: 0, | 1142 e: 0, |
| 1077 q: '', | 1143 q: '', |
| 1078 p: 0, | 1144 p: 0, |
| 1079 g: false, | 1145 g: false, |
| 1080 r: 0 | 1146 r: 0, |
| 1147 o: 0 | |
| 1081 }; | 1148 }; |
| 1082 | 1149 |
| 1083 if (!window.location.hash) | 1150 if (!window.location.hash) |
| 1084 return result; | 1151 return result; |
| 1085 | 1152 |
| 1086 var hashSplit = window.location.hash.substr(1).split('&'); | 1153 var hashSplit = window.location.hash.substr(1).split('&'); |
| 1087 for (var i = 0; i < hashSplit.length; i++) { | 1154 for (var i = 0; i < hashSplit.length; i++) { |
| 1088 var pair = hashSplit[i].split('='); | 1155 var pair = hashSplit[i].split('='); |
| 1089 if (pair.length > 1) { | 1156 if (pair.length > 1) { |
| 1090 result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' ')); | 1157 result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' ')); |
| 1091 } | 1158 } |
| 1092 } | 1159 } |
| 1093 | 1160 |
| 1094 return result; | 1161 return result; |
| 1095 }; | 1162 }; |
| 1096 | 1163 |
| 1097 /** | 1164 /** |
| 1098 * Set the hash to a specified state, this will create an entry in the | 1165 * Set the hash to a specified state, this will create an entry in the |
| 1099 * session history so the back button cycles through hash states, which | 1166 * session history so the back button cycles through hash states, which |
| 1100 * are then picked up by our listener. | 1167 * are then picked up by our listener. |
| 1101 * @param {string} term The current search string. | 1168 * @param {string} term The current search string. |
| 1102 * @param {number} page The page currently being viewed. | 1169 * @param {number} page The page currently being viewed. |
| 1103 * @param {boolean} grouped Whether the results are grouped or not. | 1170 * @param {boolean} grouped Whether the results are grouped or not. |
| 1104 * @param {number} range The range in days to view or search over. If 0, use | 1171 * @param {number} range The range in days to view or search over. If 0, use |
| 1105 * the entire history. | 1172 * the entire history. |
| 1173 * @param {number} offset Set the begining of the query to range * offset days. | |
| 1106 */ | 1174 */ |
| 1107 PageState.prototype.setUIState = function(term, page, grouped, range) { | 1175 PageState.prototype.setUIState = function(term, page, grouped, range, offset) { |
| 1108 // Make sure the form looks pretty. | 1176 // Make sure the form looks pretty. |
| 1109 $('search-field').value = term; | 1177 $('search-field').value = term; |
| 1110 if (grouped) { | 1178 if (grouped) { |
| 1111 $('timeframe-filter').value = range; | 1179 $('timeframe-filter').value = range; |
| 1112 $('display-filter-sites').checked = true; | 1180 $('display-filter-sites').checked = true; |
| 1113 } else { | 1181 } else { |
| 1114 $('timeframe-filter').disabled = true; | 1182 $('timeframe-filter').disabled = true; |
| 1115 $('display-filter-sites').checked = false; | 1183 $('display-filter-sites').checked = false; |
| 1116 } | 1184 } |
| 1117 var hash = this.getHashData(); | 1185 var hash = this.getHashData(); |
| 1118 if (hash.q != term || hash.p != page || hash.g != grouped || | 1186 if (hash.q != term || hash.p != page || hash.g != grouped || |
| 1119 hash.r != range) { | 1187 hash.r != range || hash.o != offset) { |
| 1120 window.location.hash = PageState.getHashString( | 1188 window.location.hash = PageState.getHashString( |
| 1121 term, page, grouped, range); | 1189 term, page, grouped, range, offset); |
| 1122 } | 1190 } |
| 1123 }; | 1191 }; |
| 1124 | 1192 |
| 1125 /** | 1193 /** |
| 1126 * Static method to get the hash string for a specified state | 1194 * Static method to get the hash string for a specified state |
| 1127 * @param {string} term The current search string. | 1195 * @param {string} term The current search string. |
| 1128 * @param {number} page The page currently being viewed. | 1196 * @param {number} page The page currently being viewed. |
| 1129 * @param {boolean} grouped Whether the results are grouped or not. | 1197 * @param {boolean} grouped Whether the results are grouped or not. |
| 1130 * @param {number} range The range in days to view or search over. | 1198 * @param {number} range The range in days to view or search over. |
| 1199 * @param {number} offset Set the begining of the query to range * offset days. | |
| 1131 * @return {string} The string to be used in a hash. | 1200 * @return {string} The string to be used in a hash. |
| 1132 */ | 1201 */ |
| 1133 PageState.getHashString = function(term, page, grouped, range) { | 1202 PageState.getHashString = function(term, page, grouped, range, offset) { |
| 1134 // Omit elements that are empty. | 1203 // Omit elements that are empty. |
| 1135 var newHash = []; | 1204 var newHash = []; |
| 1136 | 1205 |
| 1137 if (term) | 1206 if (term) |
| 1138 newHash.push('q=' + encodeURIComponent(term)); | 1207 newHash.push('q=' + encodeURIComponent(term)); |
| 1139 | 1208 |
| 1140 if (page) | 1209 if (page) |
| 1141 newHash.push('p=' + page); | 1210 newHash.push('p=' + page); |
| 1142 | 1211 |
| 1143 if (range > 0) | 1212 if (range > 0) |
| 1144 newHash.push('r=' + range); | 1213 newHash.push('r=' + range); |
| 1145 | 1214 |
| 1215 if (offset > 0) | |
| 1216 newHash.push('o=' + offset); | |
| 1217 | |
| 1146 if (grouped) | 1218 if (grouped) |
| 1147 newHash.push('g=' + grouped); | 1219 newHash.push('g=' + grouped); |
| 1148 | 1220 |
| 1149 return newHash.join('&'); | 1221 return newHash.join('&'); |
| 1150 }; | 1222 }; |
| 1151 | 1223 |
| 1152 /////////////////////////////////////////////////////////////////////////////// | 1224 /////////////////////////////////////////////////////////////////////////////// |
| 1153 // Document Functions: | 1225 // Document Functions: |
| 1154 /** | 1226 /** |
| 1155 * Window onload handler, sets up the page. | 1227 * Window onload handler, sets up the page. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1369 removeNode(previousEntry); | 1441 removeNode(previousEntry); |
| 1370 } | 1442 } |
| 1371 | 1443 |
| 1372 // if both the next and previous entries are gaps, remove one | 1444 // if both the next and previous entries are gaps, remove one |
| 1373 if (nextEntry && nextEntry.className == 'gap' && | 1445 if (nextEntry && nextEntry.className == 'gap' && |
| 1374 previousEntry && previousEntry.className == 'gap') { | 1446 previousEntry && previousEntry.className == 'gap') { |
| 1375 removeNode(nextEntry); | 1447 removeNode(nextEntry); |
| 1376 } | 1448 } |
| 1377 } | 1449 } |
| 1378 | 1450 |
| 1451 /** | |
| 1452 * Enables or disables the time range buttons. | |
| 1453 * @param {boolean} groupByDomain Whether grouping by domain is active | |
| 1454 * @param {HistoryView} view The current history view. | |
| 1455 */ | |
| 1456 function setRangeButtonsState(groupByDomain, view) { | |
| 1457 // The enabled state for the previous, today and next buttons. | |
| 1458 var buttonsState = [false, false, false]; | |
| 1459 var start = 0; | |
| 1460 var isQueryFinished = view.model_.isQueryFinished_; | |
| 1461 var offset = view.getOffset(); | |
| 1462 | |
| 1463 // Set today button. | |
| 1464 if (offset != start) { | |
| 1465 buttonsState[2] = true; | |
| 1466 buttonsState[1] = true; | |
| 1467 } | |
| 1468 | |
| 1469 // TODO(sergiu): isQueryFinished does not return the correct value now but | |
| 1470 // ideally it would return false when there are no older results available. | |
| 1471 // Until then allow to go back in time as much as the user wants. | |
| 1472 // See http://crbug.com/167363. | |
| 1473 buttonsState[0] = true; | |
| 1474 | |
| 1475 $('range-previous').disabled = !(groupByDomain && buttonsState[0]); | |
| 1476 $('range-today').disabled = !(groupByDomain && buttonsState[1]); | |
| 1477 $('range-next').disabled = !(groupByDomain && buttonsState[2]); | |
| 1478 $('timeframe-filter').disabled = !groupByDomain; | |
| 1479 } | |
| 1480 | |
| 1379 /////////////////////////////////////////////////////////////////////////////// | 1481 /////////////////////////////////////////////////////////////////////////////// |
| 1380 // Chrome callbacks: | 1482 // Chrome callbacks: |
| 1381 | 1483 |
| 1382 /** | 1484 /** |
| 1383 * Our history system calls this function with results from searches. | 1485 * Our history system calls this function with results from searches. |
| 1384 * @param {Object} info An object containing information about the query. | 1486 * @param {Object} info An object containing information about the query. |
| 1385 * @param {Array} results A list of results. | 1487 * @param {Array} results A list of results. |
| 1386 */ | 1488 */ |
| 1387 function historyResult(info, results) { | 1489 function historyResult(info, results) { |
| 1388 historyModel.addResults(info, results); | 1490 historyModel.addResults(info, results); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1426 historyView.reload(); | 1528 historyView.reload(); |
| 1427 } | 1529 } |
| 1428 | 1530 |
| 1429 // Add handlers to HTML elements. | 1531 // Add handlers to HTML elements. |
| 1430 document.addEventListener('DOMContentLoaded', load); | 1532 document.addEventListener('DOMContentLoaded', load); |
| 1431 | 1533 |
| 1432 // This event lets us enable and disable menu items before the menu is shown. | 1534 // This event lets us enable and disable menu items before the menu is shown. |
| 1433 document.addEventListener('canExecute', function(e) { | 1535 document.addEventListener('canExecute', function(e) { |
| 1434 e.canExecute = true; | 1536 e.canExecute = true; |
| 1435 }); | 1537 }); |
| OLD | NEW |