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
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
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
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
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
: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
-<table class="list">
+<table class="list custom_fields">
<thead><tr>
<th><%=l(:field_name)%></th>
<th><%=l(:field_field_format)%></th>
<th><%=l(:field_is_for_all)%></th>
<th><%=l(:label_used_by)%></th>
<% end %>
- <th><%=l(:button_sort)%></th>
<th></th>
</tr></thead>
<tbody>
<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>
<% 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
<% 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| %>
<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>
<% end %>
<% html_title(l(:label_enumerations)) -%>
+
+<%= javascript_tag do %>
+ $(function() { $("table.enumerations tbody").positionedItems(); });
+<% end %>
\ No newline at end of file
<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>
<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>
</table>
<% html_title(l(:label_issue_status_plural)) -%>
+
+<%= javascript_tag do %>
+ $(function() { $("table.issue_statuses tbody").positionedItems(); });
+<% end %>
<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>
</table>
<% html_title(l(:label_role_plural)) -%>
+
+<%= javascript_tag do %>
+ $(function() { $("table.roles tbody").positionedItems({items: ".givable"}); });
+<% end %>
\ No newline at end of file
<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>
</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>
</table>
<% html_title(l(:label_tracker_plural)) -%>
+
+<%= javascript_tag do %>
+ $(function() { $("table.trackers tbody").positionedItems(); });
+<% end %>
$(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',
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