diff options
Diffstat (limited to 'public')
| -rw-r--r-- | public/javascripts/admin_interface.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index cbfa4dc6..b7cb1964 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -86,6 +86,10 @@ $(document).ready(function () { | |||
| 86 | cccms.preview.initialize(); | 86 | cccms.preview.initialize(); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | if (document.getElementById('revisions')) { | ||
| 90 | initialize_revision_diff_picker.initialize(); | ||
| 91 | } | ||
| 92 | |||
| 89 | var metadata_details = document.getElementById('metadata_details'); | 93 | var metadata_details = document.getElementById('metadata_details'); |
| 90 | if (metadata_details) { | 94 | if (metadata_details) { |
| 91 | var desktop_mq = window.matchMedia('(min-width: 1016px)'); | 95 | var desktop_mq = window.matchMedia('(min-width: 1016px)'); |
| @@ -559,3 +563,69 @@ rrule_builder = { | |||
| 559 | } | 563 | } |
| 560 | } | 564 | } |
| 561 | }; | 565 | }; |
| 566 | |||
| 567 | initialize_revision_diff_picker = { | ||
| 568 | initialize : function() { | ||
| 569 | let table = document.getElementById('revisions'); | ||
| 570 | let rows = table.querySelectorAll('tbody tr'); | ||
| 571 | let form = document.getElementById('diff_form'); | ||
| 572 | let from_field = form.querySelector('input[name="start_revision"]'); | ||
| 573 | let to_field = form.querySelector('input[name="end_revision"]'); | ||
| 574 | |||
| 575 | // Two-slot FIFO: the newest pick becomes the target and the previous | ||
| 576 | // target becomes the source, so two taps anywhere give any pair. | ||
| 577 | // Picking the current target is a no-op, picking the current source | ||
| 578 | // swaps them. | ||
| 579 | this.stack = [from_field.value, to_field.value].filter(function (v) { return v !== ''; }); | ||
| 580 | |||
| 581 | rows.forEach(function (row) { | ||
| 582 | row.addEventListener('click', function (e) { | ||
| 583 | if (e.target.closest('a, button, input, label')) { return; } | ||
| 584 | initialize_revision_diff_picker.pick(row.dataset.revision); | ||
| 585 | }); | ||
| 586 | row.addEventListener('keydown', function (e) { | ||
| 587 | if (e.key === 'Enter' || e.key === ' ') { | ||
| 588 | e.preventDefault(); | ||
| 589 | initialize_revision_diff_picker.pick(row.dataset.revision); | ||
| 590 | } | ||
| 591 | }); | ||
| 592 | }); | ||
| 593 | |||
| 594 | this.render(); | ||
| 595 | }, | ||
| 596 | |||
| 597 | render : function() { | ||
| 598 | let table = document.getElementById('revisions'); | ||
| 599 | let rows = table.querySelectorAll('tbody tr'); | ||
| 600 | let form = document.getElementById('diff_form'); | ||
| 601 | let from_field = form.querySelector('input[name="start_revision"]'); | ||
| 602 | let to_field = form.querySelector('input[name="end_revision"]'); | ||
| 603 | let submit = form.querySelector('input[type="submit"]'); | ||
| 604 | let readout = document.getElementById('diff_selection_label'); | ||
| 605 | let from_label = document.getElementById('diff_from'); | ||
| 606 | let to_label = document.getElementById('diff_to'); | ||
| 607 | |||
| 608 | let from = this.stack[0] || ''; | ||
| 609 | let to = this.stack[1] || ''; | ||
| 610 | from_field.value = from; | ||
| 611 | from_label.textContent = from; | ||
| 612 | to_field.value = to; | ||
| 613 | to_label.textContent = to; | ||
| 614 | readout.hidden = !(from && to); | ||
| 615 | submit.disabled = !(from && to && from !== to); | ||
| 616 | |||
| 617 | rows.forEach(function (row) { | ||
| 618 | var rev = row.dataset.revision; | ||
| 619 | row.classList.toggle('diff_source', rev === from); | ||
| 620 | row.classList.toggle('diff_target', rev === to); | ||
| 621 | row.setAttribute('aria-pressed', (rev === from || rev === to) ? 'true' : 'false'); | ||
| 622 | }); | ||
| 623 | }, | ||
| 624 | |||
| 625 | pick : function(rev) { | ||
| 626 | if (rev === this.stack[1]) { return; } | ||
| 627 | this.stack.push(rev); | ||
| 628 | if (this.stack.length > 2) { this.stack.shift(); } | ||
| 629 | this.render(); | ||
| 630 | } | ||
| 631 | }; | ||
