diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 7d8770776..66bd965ba 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -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] - @user.pref.save - redirect_to my_page_path + @block = params[:block] + if @user.pref.add_block @block + @user.pref.save + 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 diff --git a/app/helpers/my_helper.rb b/app/helpers/my_helper.rb index 3c0313f90..042209cac 100644 --- a/app/helpers/my_helper.rb +++ b/app/helpers/my_helper.rb @@ -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) diff --git a/app/views/my/add_block.js.erb b/app/views/my/add_block.js.erb new file mode 100644 index 000000000..c2382ee7a --- /dev/null +++ b/app/views/my/add_block.js.erb @@ -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) %>"); diff --git a/app/views/my/page.html.erb b/app/views/my/page.html.erb index 9fe143516..1210c471a 100644 --- a/app/views/my/page.html.erb +++ b/app/views/my/page.html.erb @@ -1,5 +1,5 @@