diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index fa487a2f6..b5dc67982 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -24,4 +24,12 @@ module AdminHelper [l(:project_status_closed), '5'], [l(:project_status_archived), '9']], selected.to_s) end + + def plugin_data_for_updates(plugins) + data = {"v" => Redmine::VERSION.to_s, "p" => {}} + plugins.each do |plugin| + data["p"].merge! plugin.id => {"v" => plugin.version, "n" => plugin.name, "a" => plugin.author} + end + data + end end diff --git a/app/views/admin/plugins.html.erb b/app/views/admin/plugins.html.erb index 7cd4fe763..3c708544c 100644 --- a/app/views/admin/plugins.html.erb +++ b/app/views/admin/plugins.html.erb @@ -9,11 +9,55 @@ <%= content_tag('span', link_to(h(plugin.url), plugin.url), :class => 'url') unless plugin.url.blank? %> <%= plugin.author_url.blank? ? h(plugin.author) : link_to(h(plugin.author), plugin.author_url) %> - <%=h plugin.version %> + <%= plugin.version %> <%= link_to(l(:button_configure), plugin_settings_path(plugin)) if plugin.configurable? %> <% end %> +

Check for updates <% else %>

<%= l(:label_no_data) %>

<% end %> + +<%= javascript_tag do %> +$(document).ready(function(){ + $("#check-for-updates").click(function(e){ + e.preventDefault(); + $.ajax({ + dataType: "jsonp", + url: "http://www.redmine.org/plugins/check_updates", + data: <%= raw_json plugin_data_for_updates(@plugins) %>, + timeout: 3000, + beforeSend: function(){ + $('#ajax-indicator').show(); + }, + success: function(data){ + $('#ajax-indicator').hide(); + $("table.plugins td.version span").addClass("unknown"); + $.each(data, function(plugin_id, plugin_data){ + var s = $("tr#plugin-"+plugin_id+" td.version span"); + s.removeClass("icon-checked icon-warning unknown"); + if (plugin_data.url) { + if (s.parent("a").length>0) { + s.unwrap(); + } + s.addClass("found"); + s.wrap($("").attr("href", plugin_data.url).attr("target", "_blank")); + } + if (plugin_data.c == s.text()) { + s.addClass("icon-checked"); + } else if (plugin_data.c) { + s.addClass("icon-warning"); + s.attr("title", "Latest compatible version: "+plugin_data.c); + } + }); + $("table.plugins td.version span.unknown").addClass("icon-help").attr("title", "Unknown plugin"); + }, + error: function(){ + $('#ajax-indicator').hide(); + alert("Unable to retrieve plugin informations from www.redmine.org"); + } + }); + }); +}); +<% end if @plugins.any? %>