/
_tools.html.erb
121 lines (116 loc) · 4.79 KB
/
_tools.html.erb
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
110
111
112
113
114
115
116
117
118
119
120
121
<%-
list ||= @list
-%>
<%- content_for(:extrajs) do -%>
<script type="text/javascript" charset="utf-8">
function confirmStartDelayed(msg, url, maxTries, eltId) {
var selector = '#'+eltId
if (confirm(msg)) {
window.refreshTries = 0
startDelayed(url, maxTries)
loadingClickForLink.apply($(selector).get(0))
}
}
function startDelayed(url, maxTries) {
if (refreshTries > maxTries) {
alert(I18n.t('reload_timed_out'))
} else {
$.ajax({
data:'tries='+refreshTries+'&authenticity_token=' + $('meta[name=csrf-token]').attr('content'),
dataType:'script',
type:'post',
url: url,
statusCode: {
// Processing
201: function() {
setTimeout('startDelayed("'+url+'", '+maxTries+')', 5000)
},
// OK
200: function() {
window.location.reload()
},
// Request Timeout
408: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText)
},
// Unprocessable Entity
422: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText)
}
}
});
refreshTries += 1
}
}
</script>
<%- end -%>
<div id="tools" class="clear buttonrow">
<% if list.editable_by?(current_user) %>
<%= link_to t(:edit), list.is_a?(CheckList) ? edit_check_list_path(list) : edit_list_url(list), :id => "edit_list_button", :class => "button" %>
<% end -%>
<% if list.listed_taxa_editable_by?(current_user) -%>
<%= link_to t(:edit_taxa), list_batch_edit_url(list), :id => "batch_edit_list_button", :class => "button" %>
<% end %>
<span class="toolset">
<label class="description"><%=t :view %></label>
<% for view in ListsController::LIST_VIEWS %>
<%= link_to(t("list_views.#{view}", :default=>view).capitalize, url_for(params.merge(:view => view)),
:id => "#{view}_view_link",
:class => "inter modal_link#{' selected' if @view == view}") %>
<% end %>
</span>
<% if logged_in? && ( ( list.is_a?(LifeList) && list.editable_by?(current_user) ) || ( list.is_a?(CheckList) && (current_user.admin? || !list.is_default?) ) ) -%>
<% link_to_toggle_menu t(:tools), :id => "tools_button", :class => "minor button",
:wrapper => {:class => "inter toggle_menu_list", :style => "padding: 0"} do %>
<% if list.is_a?(LifeList) && list.editable_by?(current_user) -%>
<ul>
<li>
<%- msg = t(:this_will_add_listed_taxa) -%>
<%= link_to_function t(:reload_from_observations),
"confirmStartDelayed('#{msg}', '#{list_reload_from_observations_path(@list.id)}', #{LifeList::MAX_RELOAD_TRIES}, 'reloadlink')",
:id => "reloadlink" %>
</li>
<li>
<%- msg = t(:this_will_re_apply_all_list_rules).gsub(/\s+/m, " ") -%>
<%= link_to_function t(:re_apply_list_rules),
"confirmStartDelayed('#{escape_javascript(msg)}', '#{list_refresh_path(@list.id)}', #{LifeList::MAX_RELOAD_TRIES}, 'refreshlink')",
:id => "refreshlink" %>
</li>
</ul>
<% elsif list.is_a?(CheckList) %>
<% if logged_in? && current_user.is_admin? -%>
<div class="admin">
<ul>
<li> </li>
<% if list.is_default? %>
<li>
<%- msg = t(:this_will_add_listed_taxa) -%>
<%= link_to_function t(:reload_from_observations),
"confirmStartDelayed('#{msg}', '#{list_add_from_observations_now_path(@list.id)}', #{CheckList::MAX_RELOAD_TRIES}, 'add_from_observations_nowlink')",
:id => "add_from_observations_nowlink" %>
</li>
<% end %>
<li>
<%- msg = t(:this_will_refresh_listed_taxa).gsub(/\s+/m, " ") -%>
<%= link_to_function t(:refresh),
"confirmStartDelayed('#{escape_javascript(msg)}', '#{list_refresh_now_path(@list.id)}', #{CheckList::MAX_RELOAD_TRIES}, 'refresh_nowlink')",
:id => "refresh_nowlink" %>
</li>
</ul>
<div class="alert">
These tools can be very slow, even debilitatingly slow for large
lists, so please only use them for small places and small lists.
</div>
</div>
<% end -%>
<% unless list.is_default? -%>
<ul>
<li>
<%= link_to t(:find_missing_listings), {find_missing_listings: true, missing_filter_taxon: @list.taxon_id} %>
</li>
</ul>
<% end -%>
<% end %>
<% end %>
<% end -%>
</div>