mirror of
https://github.com/redmine/redmine.git
synced 2025-11-07 22:05:56 +01:00
Don't reload the page when adding/removing a block.
git-svn-id: http://svn.redmine.org/redmine/trunk@16394 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -147,18 +147,29 @@ class MyController < ApplicationController
|
||||
# params[:block] : id of the block to add
|
||||
def add_block
|
||||
@user = User.current
|
||||
@user.pref.add_block params[:block]
|
||||
@block = params[:block]
|
||||
if @user.pref.add_block @block
|
||||
@user.pref.save
|
||||
redirect_to my_page_path
|
||||
respond_to do |format|
|
||||
format.html { redirect_to my_page_path }
|
||||
format.js
|
||||
end
|
||||
else
|
||||
render_error :status => 422
|
||||
end
|
||||
end
|
||||
|
||||
# Remove a block to user's page
|
||||
# params[:block] : id of the block to remove
|
||||
def remove_block
|
||||
@user = User.current
|
||||
@user.pref.remove_block params[:block]
|
||||
@block = params[:block]
|
||||
@user.pref.remove_block @block
|
||||
@user.pref.save
|
||||
redirect_to my_page_path
|
||||
respond_to do |format|
|
||||
format.html { redirect_to my_page_path }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# Change blocks order on user's page
|
||||
|
||||
@@ -35,7 +35,7 @@ module MyHelper
|
||||
content = render_block_content(block, user)
|
||||
if content.present?
|
||||
handle = content_tag('span', '', :class => 'sort-handle')
|
||||
close = link_to(l(:button_delete), {:action => "remove_block", :block => block}, :method => 'post', :class => "icon-only icon-close")
|
||||
close = link_to(l(:button_delete), {:action => "remove_block", :block => block}, :remote => true, :method => 'post', :class => "icon-only icon-close")
|
||||
content = content_tag('div', handle + close, :class => 'contextual') + content
|
||||
|
||||
content_tag('div', content, :class => "mypage-box", :id => "block-#{block}")
|
||||
@@ -64,7 +64,7 @@ module MyHelper
|
||||
Redmine::MyPage.block_options.each do |label, block|
|
||||
options << content_tag('option', label, :value => block, :disabled => disabled.include?(block))
|
||||
end
|
||||
select_tag('block', options, :id => "block-select", :onchange => "this.form.submit();")
|
||||
select_tag('block', options, :id => "block-select", :onchange => "$('#block-form').submit();")
|
||||
end
|
||||
|
||||
def calendar_items(startdt, enddt)
|
||||
|
||||
3
app/views/my/add_block.js.erb
Normal file
3
app/views/my/add_block.js.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
$("#block-<%= escape_javascript @block %>").remove();
|
||||
$("#list-top").prepend("<%= escape_javascript render_blocks([@block], @user) %>");
|
||||
$("#block-select").replaceWith("<%= escape_javascript block_select_tag(@user) %>");
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="contextual">
|
||||
<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
|
||||
<%= form_tag({:action => "add_block"}, :remote => true, :id => "block-form") do %>
|
||||
<%= label_tag('block-select', l(:button_add)) %>:
|
||||
<%= block_select_tag(@user) %>
|
||||
<% end %>
|
||||
|
||||
2
app/views/my/remove_block.js.erb
Normal file
2
app/views/my/remove_block.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
$("#block-<%= escape_javascript @block %>").remove();
|
||||
$("#block-select").replaceWith("<%= escape_javascript block_select_tag(@user) %>");
|
||||
@@ -227,7 +227,7 @@ class MyControllerTest < Redmine::ControllerTest
|
||||
|
||||
xhr :post, :update_page, :settings => {'timelog' => {'days' => '14'}}
|
||||
assert_response :success
|
||||
assert_include '$("#block-timelog").html(', response.body
|
||||
assert_include '$("#block-timelog").replaceWith(', response.body
|
||||
assert_include '14 days', response.body
|
||||
|
||||
assert_equal({:days => "14"}, user.reload.pref.my_page_settings('timelog'))
|
||||
@@ -239,9 +239,15 @@ class MyControllerTest < Redmine::ControllerTest
|
||||
assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
|
||||
end
|
||||
|
||||
def test_add_invalid_block_should_redirect
|
||||
def test_add_block_xhr
|
||||
xhr :post, :add_block, :block => 'issuesreportedbyme'
|
||||
assert_response :success
|
||||
assert_include 'issuesreportedbyme', User.find(2).pref[:my_page_layout]['top']
|
||||
end
|
||||
|
||||
def test_add_invalid_block_should_error
|
||||
post :add_block, :block => 'invalid'
|
||||
assert_redirected_to '/my/page'
|
||||
assert_response 422
|
||||
end
|
||||
|
||||
def test_remove_block
|
||||
@@ -250,6 +256,13 @@ class MyControllerTest < Redmine::ControllerTest
|
||||
assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
|
||||
end
|
||||
|
||||
def test_remove_block_xhr
|
||||
xhr :post, :remove_block, :block => 'issuesassignedtome'
|
||||
assert_response :success
|
||||
assert_include '$("#block-issuesassignedtome").remove();', response.body
|
||||
assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
|
||||
end
|
||||
|
||||
def test_order_blocks
|
||||
xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews']
|
||||
assert_response :success
|
||||
|
||||
Reference in New Issue
Block a user