<%- if User.current.allowed_to?(:edit_product_backlog, project) &&
	  params[:filter_by_project].blank? -%>
	<%= javascript_tag do %>
		$(document).ready(function() {
			$('#pbis').sortable({
				update: function() {
					if ($.isFunction($.fn.setupAjaxIndicator)) {
						setupAjaxIndicator();
					}
					$.ajax({
						url: '<%= sort_product_backlog_path(product_backlog) %>',
						type: 'POST',
						data: $('#pbis').sortable('serialize'),
						dataType: 'script',
						error: function() {
							alert('<%= l(:error_changing_pbi_order) %>');
							location.reload(true);
						},
						complete: function() {
							if ($.isFunction($.fn.hideOnLoad)) {
								hideOnLoad();
							}
						},
						success: function(data) {
							var error_messages = JSON.parse(data);
							if (error_messages && error_messages.length > 0) {
								alert('<%= l(:error_changing_pbi_order) %>\n' +
											error_messages.join('\n'));
								location.reload(true);
							} else if ($.isFunction($.fn.hideOnLoad)) {
								hideOnLoad();
							}
						}
					});
				}
			});
		});
	<% end %>
<%- end -%>
