##// END OF EJS Templates
Lists can be reordered with drag and drop (#12909)....
Jean-Philippe Lang -
r14954:42b5c332b2c2
parent child
Show More
@@ -54,11 +54,19 class CustomFieldsController < ApplicationController
54
54
55 def update
55 def update
56 if @custom_field.update_attributes(params[:custom_field])
56 if @custom_field.update_attributes(params[:custom_field])
57 flash[:notice] = l(:notice_successful_update)
58 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
57 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
59 redirect_back_or_default edit_custom_field_path(@custom_field)
58 respond_to do |format|
59 format.html {
60 flash[:notice] = l(:notice_successful_update)
61 redirect_back_or_default edit_custom_field_path(@custom_field)
62 }
63 format.js { render :nothing => true }
64 end
60 else
65 else
61 render :action => 'edit'
66 respond_to do |format|
67 format.html { render :action => 'edit' }
68 format.js { render :nothing => true, :status => 422 }
69 end
62 end
70 end
63 end
71 end
64
72
@@ -57,10 +57,18 class EnumerationsController < ApplicationController
57
57
58 def update
58 def update
59 if @enumeration.update_attributes(params[:enumeration])
59 if @enumeration.update_attributes(params[:enumeration])
60 flash[:notice] = l(:notice_successful_update)
60 respond_to do |format|
61 redirect_to enumerations_path
61 format.html {
62 flash[:notice] = l(:notice_successful_update)
63 redirect_to enumerations_path
64 }
65 format.js { render :nothing => true }
66 end
62 else
67 else
63 render :action => 'edit'
68 respond_to do |format|
69 format.html { render :action => 'edit' }
70 format.js { render :nothing => true, :status => 422 }
71 end
64 end
72 end
65 end
73 end
66
74
@@ -51,10 +51,18 class IssueStatusesController < ApplicationController
51 def update
51 def update
52 @issue_status = IssueStatus.find(params[:id])
52 @issue_status = IssueStatus.find(params[:id])
53 if @issue_status.update_attributes(params[:issue_status])
53 if @issue_status.update_attributes(params[:issue_status])
54 flash[:notice] = l(:notice_successful_update)
54 respond_to do |format|
55 redirect_to issue_statuses_path(:page => params[:page])
55 format.html {
56 flash[:notice] = l(:notice_successful_update)
57 redirect_to issue_statuses_path(:page => params[:page])
58 }
59 format.js { render :nothing => true }
60 end
56 else
61 else
57 render :action => 'edit'
62 respond_to do |format|
63 format.html { render :action => 'edit' }
64 format.js { render :nothing => true, :status => 422 }
65 end
58 end
66 end
59 end
67 end
60
68
@@ -72,10 +72,18 class RolesController < ApplicationController
72
72
73 def update
73 def update
74 if @role.update_attributes(params[:role])
74 if @role.update_attributes(params[:role])
75 flash[:notice] = l(:notice_successful_update)
75 respond_to do |format|
76 redirect_to roles_path(:page => params[:page])
76 format.html {
77 flash[:notice] = l(:notice_successful_update)
78 redirect_to roles_path(:page => params[:page])
79 }
80 format.js { render :nothing => true }
81 end
77 else
82 else
78 render :action => 'edit'
83 respond_to do |format|
84 format.html { render :action => 'edit' }
85 format.js { render :nothing => true, :status => 422 }
86 end
79 end
87 end
80 end
88 end
81
89
@@ -59,12 +59,22 class TrackersController < ApplicationController
59 def update
59 def update
60 @tracker = Tracker.find(params[:id])
60 @tracker = Tracker.find(params[:id])
61 if @tracker.update_attributes(params[:tracker])
61 if @tracker.update_attributes(params[:tracker])
62 flash[:notice] = l(:notice_successful_update)
62 respond_to do |format|
63 redirect_to trackers_path(:page => params[:page])
63 format.html {
64 return
64 flash[:notice] = l(:notice_successful_update)
65 redirect_to trackers_path(:page => params[:page])
66 }
67 format.js { render :nothing => true }
68 end
69 else
70 respond_to do |format|
71 format.html {
72 edit
73 render :action => 'edit'
74 }
75 format.js { render :nothing => true, :status => 422 }
76 end
65 end
77 end
66 edit
67 render :action => 'edit'
68 end
78 end
69
79
70 def destroy
80 def destroy
@@ -468,6 +468,16 module ApplicationHelper
468 :title => l(:label_sort_lowest), :class => 'icon-only icon-move-bottom')
468 :title => l(:label_sort_lowest), :class => 'icon-only icon-move-bottom')
469 end
469 end
470
470
471 def reorder_handle(object, options={})
472 data = {
473 :reorder_url => options[:url] || url_for(object),
474 :reorder_param => options[:param] || object.class.name.underscore
475 }
476 content_tag('span', '',
477 :class => "sort-handle ui-icon ui-icon-arrowthick-2-n-s",
478 :data => data)
479 end
480
471 def breadcrumb(*args)
481 def breadcrumb(*args)
472 elements = args.flatten
482 elements = args.flatten
473 elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
483 elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
@@ -1,4 +1,4
1 <table class="list">
1 <table class="list custom_fields">
2 <thead><tr>
2 <thead><tr>
3 <th><%=l(:field_name)%></th>
3 <th><%=l(:field_name)%></th>
4 <th><%=l(:field_field_format)%></th>
4 <th><%=l(:field_field_format)%></th>
@@ -7,7 +7,6
7 <th><%=l(:field_is_for_all)%></th>
7 <th><%=l(:field_is_for_all)%></th>
8 <th><%=l(:label_used_by)%></th>
8 <th><%=l(:label_used_by)%></th>
9 <% end %>
9 <% end %>
10 <th><%=l(:button_sort)%></th>
11 <th></th>
10 <th></th>
12 </tr></thead>
11 </tr></thead>
13 <tbody>
12 <tbody>
@@ -21,8 +20,8
21 <td><%= checked_image custom_field.is_for_all? %></td>
20 <td><%= checked_image custom_field.is_for_all? %></td>
22 <td><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
21 <td><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
23 <% end %>
22 <% end %>
24 <td class="reorder"><%= reorder_links('custom_field', {:action => 'update', :id => custom_field, :back_url => back_url}, :put) %></td>
25 <td class="buttons">
23 <td class="buttons">
24 <%= reorder_handle(custom_field, :url => custom_field_path(custom_field), :param => 'custom_field') %>
26 <%= delete_link custom_field_path(custom_field) %>
25 <%= delete_link custom_field_path(custom_field) %>
27 </td>
26 </td>
28 </tr>
27 </tr>
@@ -9,3 +9,7
9 <% else %>
9 <% else %>
10 <p class="nodata"><%= l(:label_no_data) %></p>
10 <p class="nodata"><%= l(:label_no_data) %></p>
11 <% end %>
11 <% end %>
12
13 <%= javascript_tag do %>
14 $(function() { $("table.custom_fields tbody").positionedItems(); });
15 <% end %> No newline at end of file
@@ -5,12 +5,11
5
5
6 <% enumerations = klass.shared %>
6 <% enumerations = klass.shared %>
7 <% if enumerations.any? %>
7 <% if enumerations.any? %>
8 <table class="list"><thead>
8 <table class="list enumerations"><thead>
9 <tr>
9 <tr>
10 <th><%= l(:field_name) %></th>
10 <th><%= l(:field_name) %></th>
11 <th><%= l(:field_is_default) %></th>
11 <th><%= l(:field_is_default) %></th>
12 <th><%= l(:field_active) %></th>
12 <th><%= l(:field_active) %></th>
13 <th><%=l(:button_sort)%></th>
14 <th></th>
13 <th></th>
15 </tr></thead>
14 </tr></thead>
16 <% enumerations.each do |enumeration| %>
15 <% enumerations.each do |enumeration| %>
@@ -18,8 +17,10
18 <td class="name"><%= link_to enumeration, edit_enumeration_path(enumeration) %></td>
17 <td class="name"><%= link_to enumeration, edit_enumeration_path(enumeration) %></td>
19 <td class="tick"><%= checked_image enumeration.is_default? %></td>
18 <td class="tick"><%= checked_image enumeration.is_default? %></td>
20 <td class="tick"><%= checked_image enumeration.active? %></td>
19 <td class="tick"><%= checked_image enumeration.active? %></td>
21 <td class="reorder"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}, :put) %></td>
20 <td class="buttons">
22 <td class="buttons"><%= delete_link enumeration_path(enumeration) %></td>
21 <%= reorder_handle(enumeration, :url => enumeration_path(enumeration), :param => 'enumeration') %>
22 <%= delete_link enumeration_path(enumeration) %>
23 </td>
23 </tr>
24 </tr>
24 <% end %>
25 <% end %>
25 </table>
26 </table>
@@ -30,3 +31,7
30 <% end %>
31 <% end %>
31
32
32 <% html_title(l(:label_enumerations)) -%>
33 <% html_title(l(:label_enumerations)) -%>
34
35 <%= javascript_tag do %>
36 $(function() { $("table.enumerations tbody").positionedItems(); });
37 <% end %> No newline at end of file
@@ -5,14 +5,13
5
5
6 <h2><%=l(:label_issue_status_plural)%></h2>
6 <h2><%=l(:label_issue_status_plural)%></h2>
7
7
8 <table class="list">
8 <table class="list issue_statuses">
9 <thead><tr>
9 <thead><tr>
10 <th><%=l(:field_status)%></th>
10 <th><%=l(:field_status)%></th>
11 <% if Issue.use_status_for_done_ratio? %>
11 <% if Issue.use_status_for_done_ratio? %>
12 <th><%=l(:field_done_ratio)%></th>
12 <th><%=l(:field_done_ratio)%></th>
13 <% end %>
13 <% end %>
14 <th><%=l(:field_is_closed)%></th>
14 <th><%=l(:field_is_closed)%></th>
15 <th><%=l(:button_sort)%></th>
16 <th></th>
15 <th></th>
17 </tr></thead>
16 </tr></thead>
18 <tbody>
17 <tbody>
@@ -23,8 +22,8
23 <td><%= status.default_done_ratio %></td>
22 <td><%= status.default_done_ratio %></td>
24 <% end %>
23 <% end %>
25 <td><%= checked_image status.is_closed? %></td>
24 <td><%= checked_image status.is_closed? %></td>
26 <td class="reorder"><%= reorder_links('issue_status', {:action => 'update', :id => status, :page => params[:page]}, :put) %></td>
27 <td class="buttons">
25 <td class="buttons">
26 <%= reorder_handle(status) %>
28 <%= delete_link issue_status_path(status) %>
27 <%= delete_link issue_status_path(status) %>
29 </td>
28 </td>
30 </tr>
29 </tr>
@@ -33,3 +32,7
33 </table>
32 </table>
34
33
35 <% html_title(l(:label_issue_status_plural)) -%>
34 <% html_title(l(:label_issue_status_plural)) -%>
35
36 <%= javascript_tag do %>
37 $(function() { $("table.issue_statuses tbody").positionedItems(); });
38 <% end %>
@@ -5,22 +5,17
5
5
6 <h2><%=l(:label_role_plural)%></h2>
6 <h2><%=l(:label_role_plural)%></h2>
7
7
8 <table class="list">
8 <table class="list roles">
9 <thead><tr>
9 <thead><tr>
10 <th><%=l(:label_role)%></th>
10 <th><%=l(:label_role)%></th>
11 <th><%=l(:button_sort)%></th>
12 <th></th>
11 <th></th>
13 </tr></thead>
12 </tr></thead>
14 <tbody>
13 <tbody>
15 <% for role in @roles %>
14 <% for role in @roles %>
16 <tr class="<%= cycle("odd", "even") %>">
15 <tr class="<%= cycle("odd", "even") %> <%= role.builtin? ? "builtin" : "givable" %>">
17 <td class="name"><%= content_tag(role.builtin? ? 'em' : 'span', link_to(role.name, edit_role_path(role))) %></td>
16 <td class="name"><%= content_tag(role.builtin? ? 'em' : 'span', link_to(role.name, edit_role_path(role))) %></td>
18 <td class="reorder">
19 <% unless role.builtin? %>
20 <%= reorder_links('role', {:action => 'update', :id => role, :page => params[:page]}, :put) %>
21 <% end %>
22 </td>
23 <td class="buttons">
17 <td class="buttons">
18 <%= reorder_handle(role) unless role.builtin? %>
24 <%= link_to l(:button_copy), new_role_path(:copy => role), :class => 'icon icon-copy' %>
19 <%= link_to l(:button_copy), new_role_path(:copy => role), :class => 'icon icon-copy' %>
25 <%= delete_link role_path(role) unless role.builtin? %>
20 <%= delete_link role_path(role) unless role.builtin? %>
26 </td>
21 </td>
@@ -30,3 +25,7
30 </table>
25 </table>
31
26
32 <% html_title(l(:label_role_plural)) -%>
27 <% html_title(l(:label_role_plural)) -%>
28
29 <%= javascript_tag do %>
30 $(function() { $("table.roles tbody").positionedItems({items: ".givable"}); });
31 <% end %> No newline at end of file
@@ -5,11 +5,10
5
5
6 <h2><%=l(:label_tracker_plural)%></h2>
6 <h2><%=l(:label_tracker_plural)%></h2>
7
7
8 <table class="list">
8 <table class="list trackers">
9 <thead><tr>
9 <thead><tr>
10 <th><%=l(:label_tracker)%></th>
10 <th><%=l(:label_tracker)%></th>
11 <th></th>
11 <th></th>
12 <th><%=l(:button_sort)%></th>
13 <th></th>
12 <th></th>
14 </tr></thead>
13 </tr></thead>
15 <tbody>
14 <tbody>
@@ -23,10 +22,8
23 </span>
22 </span>
24 <% end %>
23 <% end %>
25 </td>
24 </td>
26 <td class="reorder">
27 <%= reorder_links('tracker', {:action => 'update', :id => tracker, :page => params[:page]}, :put) %>
28 </td>
29 <td class="buttons">
25 <td class="buttons">
26 <%= reorder_handle(tracker) %>
30 <%= delete_link tracker_path(tracker) %>
27 <%= delete_link tracker_path(tracker) %>
31 </td>
28 </td>
32 </tr>
29 </tr>
@@ -35,3 +32,7
35 </table>
32 </table>
36
33
37 <% html_title(l(:label_tracker_plural)) -%>
34 <% html_title(l(:label_tracker_plural)) -%>
35
36 <%= javascript_tag do %>
37 $(function() { $("table.trackers tbody").positionedItems(); });
38 <% end %>
@@ -590,6 +590,45 function beforeShowDatePicker(input, inst) {
590 $(input).datepicker("option", "defaultDate", default_date);
590 $(input).datepicker("option", "defaultDate", default_date);
591 }
591 }
592
592
593 (function($){
594 $.fn.positionedItems = function(sortableOptions, options){
595 var settings = $.extend({
596 firstPosition: 1
597 }, options );
598
599 return this.sortable($.extend({
600 handle: ".sort-handle",
601 helper: function(event, ui){
602 ui.children().each(function(){
603 $(this).width($(this).width());
604 });
605 return ui;
606 },
607 update: function(event, ui) {
608 var sortable = $(this);
609 var url = ui.item.find(".sort-handle").data("reorder-url");
610 var param = ui.item.find(".sort-handle").data("reorder-param");
611 var data = {};
612 data[param] = {position: ui.item.index() + settings['firstPosition']};
613 $.ajax({
614 url: url,
615 type: 'put',
616 dataType: 'script',
617 data: data,
618 success: function(data){
619 sortable.children(":even").removeClass("even").addClass("odd");
620 sortable.children(":odd").removeClass("odd").addClass("even");
621 },
622 error: function(jqXHR, textStatus, errorThrown){
623 alert(jqXHR.status);
624 sortable.sortable("cancel");
625 }
626 });
627 },
628 }, sortableOptions));
629 }
630 }( jQuery ));
631
593 function initMyPageSortable(list, url) {
632 function initMyPageSortable(list, url) {
594 $('#list-'+list).sortable({
633 $('#list-'+list).sortable({
595 connectWith: '.block-receiver',
634 connectWith: '.block-receiver',
@@ -152,7 +152,7 class TrackersControllerTest < ActionController::TestCase
152
152
153 def test_move_lower
153 def test_move_lower
154 tracker = Tracker.find_by_position(1)
154 tracker = Tracker.find_by_position(1)
155 put :update, :id => 1, :tracker => { :move_to => 'lower' }
155 put :update, :id => 1, :tracker => { :position => '2' }
156 assert_equal 2, tracker.reload.position
156 assert_equal 2, tracker.reload.position
157 end
157 end
158
158
General Comments 0
You need to be logged in to leave comments. Login now