diff options
-rw-r--r-- | app/controllers/custom_fields_controller.rb | 14 | ||||
-rw-r--r-- | app/controllers/enumerations_controller.rb | 14 | ||||
-rw-r--r-- | app/controllers/issue_statuses_controller.rb | 14 | ||||
-rw-r--r-- | app/controllers/roles_controller.rb | 14 | ||||
-rw-r--r-- | app/controllers/trackers_controller.rb | 20 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 10 | ||||
-rw-r--r-- | app/views/custom_fields/_index.html.erb | 5 | ||||
-rw-r--r-- | app/views/custom_fields/index.html.erb | 4 | ||||
-rw-r--r-- | app/views/enumerations/index.html.erb | 13 | ||||
-rw-r--r-- | app/views/issue_statuses/index.html.erb | 9 | ||||
-rw-r--r-- | app/views/roles/index.html.erb | 15 | ||||
-rw-r--r-- | app/views/trackers/index.html.erb | 11 | ||||
-rw-r--r-- | public/javascripts/application.js | 39 | ||||
-rw-r--r-- | test/functional/trackers_controller_test.rb | 2 |
14 files changed, 143 insertions, 41 deletions
diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index 3c2cf7cfa..ab0d5019f 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -54,11 +54,19 @@ class CustomFieldsController < ApplicationController def update if @custom_field.update_attributes(params[:custom_field]) - flash[:notice] = l(:notice_successful_update) call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) - redirect_back_or_default edit_custom_field_path(@custom_field) + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_back_or_default edit_custom_field_path(@custom_field) + } + format.js { render :nothing => true } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.js { render :nothing => true, :status => 422 } + end end end diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb index 05ca5152a..feb360398 100644 --- a/app/controllers/enumerations_controller.rb +++ b/app/controllers/enumerations_controller.rb @@ -57,10 +57,18 @@ class EnumerationsController < ApplicationController def update if @enumeration.update_attributes(params[:enumeration]) - flash[:notice] = l(:notice_successful_update) - redirect_to enumerations_path + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to enumerations_path + } + format.js { render :nothing => true } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.js { render :nothing => true, :status => 422 } + end end end diff --git a/app/controllers/issue_statuses_controller.rb b/app/controllers/issue_statuses_controller.rb index 6d574fe87..e49878f1d 100644 --- a/app/controllers/issue_statuses_controller.rb +++ b/app/controllers/issue_statuses_controller.rb @@ -51,10 +51,18 @@ class IssueStatusesController < ApplicationController def update @issue_status = IssueStatus.find(params[:id]) if @issue_status.update_attributes(params[:issue_status]) - flash[:notice] = l(:notice_successful_update) - redirect_to issue_statuses_path(:page => params[:page]) + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to issue_statuses_path(:page => params[:page]) + } + format.js { render :nothing => true } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.js { render :nothing => true, :status => 422 } + end end end diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 2732a89a1..2de185b5b 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -72,10 +72,18 @@ class RolesController < ApplicationController def update if @role.update_attributes(params[:role]) - flash[:notice] = l(:notice_successful_update) - redirect_to roles_path(:page => params[:page]) + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to roles_path(:page => params[:page]) + } + format.js { render :nothing => true } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.js { render :nothing => true, :status => 422 } + end end end diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 91784d16e..2b93753d0 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -59,12 +59,22 @@ class TrackersController < ApplicationController def update @tracker = Tracker.find(params[:id]) if @tracker.update_attributes(params[:tracker]) - flash[:notice] = l(:notice_successful_update) - redirect_to trackers_path(:page => params[:page]) - return + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to trackers_path(:page => params[:page]) + } + format.js { render :nothing => true } + end + else + respond_to do |format| + format.html { + edit + render :action => 'edit' + } + format.js { render :nothing => true, :status => 422 } + end end - edit - render :action => 'edit' end def destroy diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f09103791..4d5934858 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -468,6 +468,16 @@ module ApplicationHelper :title => l(:label_sort_lowest), :class => 'icon-only icon-move-bottom') end + def reorder_handle(object, options={}) + data = { + :reorder_url => options[:url] || url_for(object), + :reorder_param => options[:param] || object.class.name.underscore + } + content_tag('span', '', + :class => "sort-handle ui-icon ui-icon-arrowthick-2-n-s", + :data => data) + end + def breadcrumb(*args) elements = args.flatten elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil diff --git a/app/views/custom_fields/_index.html.erb b/app/views/custom_fields/_index.html.erb index b0d3c277b..7a5d37283 100644 --- a/app/views/custom_fields/_index.html.erb +++ b/app/views/custom_fields/_index.html.erb @@ -1,4 +1,4 @@ -<table class="list"> +<table class="list custom_fields"> <thead><tr> <th><%=l(:field_name)%></th> <th><%=l(:field_field_format)%></th> @@ -7,7 +7,6 @@ <th><%=l(:field_is_for_all)%></th> <th><%=l(:label_used_by)%></th> <% end %> - <th><%=l(:button_sort)%></th> <th></th> </tr></thead> <tbody> @@ -21,8 +20,8 @@ <td><%= checked_image custom_field.is_for_all? %></td> <td><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td> <% end %> - <td class="reorder"><%= reorder_links('custom_field', {:action => 'update', :id => custom_field, :back_url => back_url}, :put) %></td> <td class="buttons"> + <%= reorder_handle(custom_field, :url => custom_field_path(custom_field), :param => 'custom_field') %> <%= delete_link custom_field_path(custom_field) %> </td> </tr> diff --git a/app/views/custom_fields/index.html.erb b/app/views/custom_fields/index.html.erb index e4464132f..cf2193db5 100644 --- a/app/views/custom_fields/index.html.erb +++ b/app/views/custom_fields/index.html.erb @@ -9,3 +9,7 @@ <% else %> <p class="nodata"><%= l(:label_no_data) %></p> <% end %> + +<%= javascript_tag do %> + $(function() { $("table.custom_fields tbody").positionedItems(); }); +<% end %>
\ No newline at end of file diff --git a/app/views/enumerations/index.html.erb b/app/views/enumerations/index.html.erb index d1fb91926..5f1d2eafb 100644 --- a/app/views/enumerations/index.html.erb +++ b/app/views/enumerations/index.html.erb @@ -5,12 +5,11 @@ <% enumerations = klass.shared %> <% if enumerations.any? %> -<table class="list"><thead> +<table class="list enumerations"><thead> <tr> <th><%= l(:field_name) %></th> <th><%= l(:field_is_default) %></th> <th><%= l(:field_active) %></th> - <th><%=l(:button_sort)%></th> <th></th> </tr></thead> <% enumerations.each do |enumeration| %> @@ -18,8 +17,10 @@ <td class="name"><%= link_to enumeration, edit_enumeration_path(enumeration) %></td> <td class="tick"><%= checked_image enumeration.is_default? %></td> <td class="tick"><%= checked_image enumeration.active? %></td> - <td class="reorder"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}, :put) %></td> - <td class="buttons"><%= delete_link enumeration_path(enumeration) %></td> + <td class="buttons"> + <%= reorder_handle(enumeration, :url => enumeration_path(enumeration), :param => 'enumeration') %> + <%= delete_link enumeration_path(enumeration) %> + </td> </tr> <% end %> </table> @@ -30,3 +31,7 @@ <% end %> <% html_title(l(:label_enumerations)) -%> + +<%= javascript_tag do %> + $(function() { $("table.enumerations tbody").positionedItems(); }); +<% end %>
\ No newline at end of file diff --git a/app/views/issue_statuses/index.html.erb b/app/views/issue_statuses/index.html.erb index 59d684691..8608402ca 100644 --- a/app/views/issue_statuses/index.html.erb +++ b/app/views/issue_statuses/index.html.erb @@ -5,14 +5,13 @@ <h2><%=l(:label_issue_status_plural)%></h2> -<table class="list"> +<table class="list issue_statuses"> <thead><tr> <th><%=l(:field_status)%></th> <% if Issue.use_status_for_done_ratio? %> <th><%=l(:field_done_ratio)%></th> <% end %> <th><%=l(:field_is_closed)%></th> - <th><%=l(:button_sort)%></th> <th></th> </tr></thead> <tbody> @@ -23,8 +22,8 @@ <td><%= status.default_done_ratio %></td> <% end %> <td><%= checked_image status.is_closed? %></td> - <td class="reorder"><%= reorder_links('issue_status', {:action => 'update', :id => status, :page => params[:page]}, :put) %></td> <td class="buttons"> + <%= reorder_handle(status) %> <%= delete_link issue_status_path(status) %> </td> </tr> @@ -33,3 +32,7 @@ </table> <% html_title(l(:label_issue_status_plural)) -%> + +<%= javascript_tag do %> + $(function() { $("table.issue_statuses tbody").positionedItems(); }); +<% end %> diff --git a/app/views/roles/index.html.erb b/app/views/roles/index.html.erb index f9855f181..8f059648b 100644 --- a/app/views/roles/index.html.erb +++ b/app/views/roles/index.html.erb @@ -5,22 +5,17 @@ <h2><%=l(:label_role_plural)%></h2> -<table class="list"> +<table class="list roles"> <thead><tr> <th><%=l(:label_role)%></th> - <th><%=l(:button_sort)%></th> <th></th> </tr></thead> <tbody> <% for role in @roles %> - <tr class="<%= cycle("odd", "even") %>"> + <tr class="<%= cycle("odd", "even") %> <%= role.builtin? ? "builtin" : "givable" %>"> <td class="name"><%= content_tag(role.builtin? ? 'em' : 'span', link_to(role.name, edit_role_path(role))) %></td> - <td class="reorder"> - <% unless role.builtin? %> - <%= reorder_links('role', {:action => 'update', :id => role, :page => params[:page]}, :put) %> - <% end %> - </td> <td class="buttons"> + <%= reorder_handle(role) unless role.builtin? %> <%= link_to l(:button_copy), new_role_path(:copy => role), :class => 'icon icon-copy' %> <%= delete_link role_path(role) unless role.builtin? %> </td> @@ -30,3 +25,7 @@ </table> <% html_title(l(:label_role_plural)) -%> + +<%= javascript_tag do %> + $(function() { $("table.roles tbody").positionedItems({items: ".givable"}); }); +<% end %>
\ No newline at end of file diff --git a/app/views/trackers/index.html.erb b/app/views/trackers/index.html.erb index 9dd253ecc..5f40cf0ee 100644 --- a/app/views/trackers/index.html.erb +++ b/app/views/trackers/index.html.erb @@ -5,11 +5,10 @@ <h2><%=l(:label_tracker_plural)%></h2> -<table class="list"> +<table class="list trackers"> <thead><tr> <th><%=l(:label_tracker)%></th> <th></th> - <th><%=l(:button_sort)%></th> <th></th> </tr></thead> <tbody> @@ -23,10 +22,8 @@ </span> <% end %> </td> - <td class="reorder"> - <%= reorder_links('tracker', {:action => 'update', :id => tracker, :page => params[:page]}, :put) %> - </td> <td class="buttons"> + <%= reorder_handle(tracker) %> <%= delete_link tracker_path(tracker) %> </td> </tr> @@ -35,3 +32,7 @@ </table> <% html_title(l(:label_tracker_plural)) -%> + +<%= javascript_tag do %> + $(function() { $("table.trackers tbody").positionedItems(); }); +<% end %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 3409bc64c..f791addab 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -590,6 +590,45 @@ function beforeShowDatePicker(input, inst) { $(input).datepicker("option", "defaultDate", default_date); } +(function($){ + $.fn.positionedItems = function(sortableOptions, options){ + var settings = $.extend({ + firstPosition: 1 + }, options ); + + return this.sortable($.extend({ + handle: ".sort-handle", + helper: function(event, ui){ + ui.children().each(function(){ + $(this).width($(this).width()); + }); + return ui; + }, + update: function(event, ui) { + var sortable = $(this); + var url = ui.item.find(".sort-handle").data("reorder-url"); + var param = ui.item.find(".sort-handle").data("reorder-param"); + var data = {}; + data[param] = {position: ui.item.index() + settings['firstPosition']}; + $.ajax({ + url: url, + type: 'put', + dataType: 'script', + data: data, + success: function(data){ + sortable.children(":even").removeClass("even").addClass("odd"); + sortable.children(":odd").removeClass("odd").addClass("even"); + }, + error: function(jqXHR, textStatus, errorThrown){ + alert(jqXHR.status); + sortable.sortable("cancel"); + } + }); + }, + }, sortableOptions)); + } +}( jQuery )); + function initMyPageSortable(list, url) { $('#list-'+list).sortable({ connectWith: '.block-receiver', diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb index f3d7a1c0f..a2664f295 100644 --- a/test/functional/trackers_controller_test.rb +++ b/test/functional/trackers_controller_test.rb @@ -152,7 +152,7 @@ class TrackersControllerTest < ActionController::TestCase def test_move_lower tracker = Tracker.find_by_position(1) - put :update, :id => 1, :tracker => { :move_to => 'lower' } + put :update, :id => 1, :tracker => { :position => '2' } assert_equal 2, tracker.reload.position end |