1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<h2><%= t(".title", :path => @node.unique_name) %></h2>
<p class="node_action_bar standalone_action_bar">
<%= link_to t(".back_to_node"), node_path(@node) %>
</p>
<% if Page.non_default_locales.any? %>
<p class="diff_locale_toggle">
<%= t("revisions.locale_label") %>
<% ([I18n.default_locale] + Page.non_default_locales).each_with_index do |locale, i| %>
<%= " · ".html_safe if i > 0 %>
<% if locale == @translation_locale %>
<strong><%= locale.to_s.upcase %></strong>
<% else %>
<%= link_to locale.to_s.upcase, node_revisions_path(@node, :translation_locale => locale) %>
<% end %>
<% end %>
</p>
<% end %>
<table id="revisions" class="revisions_table">
<thead>
<tr class="header">
<th><%= t(".first") %></th>
<th><%= t(".last") %></th>
<th><%= t("admin.columns.rev") %></th>
<th><%= t("admin.columns.title") %></th>
<th><%= t("admin.columns.editor") %></th>
<th><%= t("admin.columns.date") %></th>
<th></th>
<th></th>
</tr>
<tr class="no_hover diff_sticky_bar">
<td colspan="8">
<%= button_to t(".diff_revisions"), diff_node_revisions_path(@node),
method: :post,
params: { translation_locale: @translation_locale },
form: { id: 'diff_form', class: 'button_to computation' },
disabled: true %>
<span id="diff_selection_label" data-against="<%= t(".against_word") %>" data-selected="<%= t(".selected_word") %>"></span>
<label><%= radio_button_tag :view, 'inline', true %> <%= t("revisions.inline") %></label>
<label><%= radio_button_tag :view, 'side_by_side', false %> <%= t("revisions.side_by_side") %></label>
</td>
</tr>
</thead>
<tbody>
<% pages = (@pages || @node.pages.all).reverse %>
<% pages.each_with_index do |page, index| %>
<tr>
<td><%= radio_button_tag :start_revision, page.revision, index == 1 %></td>
<td><%= radio_button_tag :end_revision, page.revision, index == 0 %></td>
<td class="revision"><%= page.revision %></td>
<td class="title"><%= page.translations.find_by(:locale => @translation_locale)&.title || "—" %></td>
<td class="user"><%= page.editor.try(:login) %></td>
<td class="date"><%= page.updated_at %></td>
<td><%= link_to t(".show_link"), node_revision_path(@node, page, :translation_locale => @translation_locale) %></td>
<td>
<%= button_to t(".restore_link"), restore_node_revision_path(@node, page),
method: :put,
form: { data: { confirm: t(".confirm_restore") }, class: 'button_to state_changing' } %>
</td>
</tr>
<% end %>
</tbody>
</table>
<script>
function update_diff_button_state() {
var start = document.querySelector('input[name="start_revision"]:checked');
var end = document.querySelector('input[name="end_revision"]:checked');
var valid = start && end && start.value !== end.value;
document.querySelector('#diff_form button[type="submit"]').disabled = !valid;
var label = document.getElementById('diff_selection_label');
if (start && end) {
label.textContent = start.value + ' ' + label.dataset.against + ' ' + end.value;
} else if (start || end) {
label.textContent = (start || end).value + ' ' + label.dataset.selected;
} else {
label.textContent = '';
}
}
document.querySelectorAll('input[name="start_revision"], input[name="end_revision"]')
.forEach(function(radio) { radio.addEventListener('change', update_diff_button_state); });
update_diff_button_state();
document.getElementById('diff_form').addEventListener('submit', function(e) {
var start = document.querySelector('input[name="start_revision"]:checked');
var end = document.querySelector('input[name="end_revision"]:checked');
var view = document.querySelector('input[name="view"]:checked');
if (start) {
var s = document.createElement('input');
s.type = 'hidden'; s.name = 'start_revision'; s.value = start.value;
this.appendChild(s);
}
if (end) {
var en = document.createElement('input');
en.type = 'hidden'; en.name = 'end_revision'; en.value = end.value;
this.appendChild(en);
}
if (view) {
var v = document.createElement('input');
v.type = 'hidden'; v.name = 'view'; v.value = view.value;
this.appendChild(v);
}
});
</script>
|