Removes most of the ajax stuff on my page layout.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10033 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
c9a46950de
commit
7e5bad993d
|
@ -135,7 +135,11 @@ class MyController < ApplicationController
|
||||||
@user = User.current
|
@user = User.current
|
||||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
||||||
@block_options = []
|
@block_options = []
|
||||||
BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
|
BLOCKS.each do |k, v|
|
||||||
|
unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)}
|
||||||
|
@block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a block to user's page
|
# Add a block to user's page
|
||||||
|
@ -152,7 +156,7 @@ class MyController < ApplicationController
|
||||||
layout['top'].unshift block
|
layout['top'].unshift block
|
||||||
@user.pref[:my_page_layout] = layout
|
@user.pref[:my_page_layout] = layout
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
render :partial => "block", :locals => {:user => @user, :block_name => block}
|
redirect_to :action => 'page_layout'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove a block to user's page
|
# Remove a block to user's page
|
||||||
|
@ -165,7 +169,7 @@ class MyController < ApplicationController
|
||||||
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||||
@user.pref[:my_page_layout] = layout
|
@user.pref[:my_page_layout] = layout
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
render :nothing => true
|
redirect_to :action => 'page_layout'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Change blocks order on user's page
|
# Change blocks order on user's page
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
<div id="block_<%= block_name.dasherize %>" class="mypage-box">
|
<div id="block_<%= block_name.dasherize %>" class="mypage-box">
|
||||||
|
|
||||||
<div style="float:right;margin-right:16px;z-index:500;">
|
<div style="float:right;margin-right:16px;z-index:500;">
|
||||||
<%= link_to_remote "", {
|
<%= link_to "", {:action => "remove_block", :block => block_name}, :method => 'post', :class => "close-icon" %>
|
||||||
:url => { :action => "remove_block", :block => block_name },
|
|
||||||
:complete => "removeBlock('block_#{block_name.dasherize}')" },
|
|
||||||
:class => "close-icon"
|
|
||||||
%>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="handle">
|
<div class="handle">
|
||||||
|
|
|
@ -1,53 +1,12 @@
|
||||||
<script language="JavaScript">
|
|
||||||
//<![CDATA[
|
|
||||||
function recreateSortables() {
|
|
||||||
Sortable.destroy('list-top');
|
|
||||||
Sortable.destroy('list-left');
|
|
||||||
Sortable.destroy('list-right');
|
|
||||||
|
|
||||||
Sortable.create("list-top", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('<%= url_for(:controller => 'my', :action => 'order_blocks', :group => 'top') %>', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-top")})}, only:'mypage-box', tag:'div'})
|
|
||||||
Sortable.create("list-left", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('<%= url_for(:controller => 'my', :action => 'order_blocks', :group => 'left') %>', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-left")})}, only:'mypage-box', tag:'div'})
|
|
||||||
Sortable.create("list-right", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('<%= url_for(:controller => 'my', :action => 'order_blocks', :group => 'right') %>', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-right")})}, only:'mypage-box', tag:'div'})
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateSelect() {
|
|
||||||
s = $('block-select')
|
|
||||||
for (var i = 0; i < s.options.length; i++) {
|
|
||||||
if ($('block_' + s.options[i].value)) {
|
|
||||||
s.options[i].disabled = true;
|
|
||||||
} else {
|
|
||||||
s.options[i].disabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.options[0].selected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function afterAddBlock() {
|
|
||||||
recreateSortables();
|
|
||||||
updateSelect();
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeBlock(block) {
|
|
||||||
Effect.DropOut(block);
|
|
||||||
updateSelect();
|
|
||||||
}
|
|
||||||
//]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
|
<% if @block_options.present? %>
|
||||||
<%= label_tag('block-select', l(:label_my_page_block)) %>:
|
<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
|
||||||
<%= select_tag 'block',
|
<%= label_tag('block-select', l(:label_my_page_block)) %>:
|
||||||
content_tag('option') + options_for_select(@block_options),
|
<%= select_tag 'block',
|
||||||
:id => "block-select" %>
|
content_tag('option') + options_for_select(@block_options),
|
||||||
<%= link_to_remote l(:button_add),
|
:id => "block-select" %>
|
||||||
{:url => { :action => "add_block" },
|
<%= link_to l(:button_add), '#', :onclick => '$("block-form").submit()', :class => 'icon icon-add' %>
|
||||||
:with => "Form.serialize('block-form')",
|
<% end %>
|
||||||
:update => "list-top",
|
|
||||||
:position => :top,
|
|
||||||
:complete => "afterAddBlock();"
|
|
||||||
}, :class => 'icon icon-add'
|
|
||||||
%>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %>
|
<%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -105,5 +64,4 @@ function removeBlock(block) {
|
||||||
:url => { :action => "order_blocks", :group => "right" }
|
:url => { :action => "order_blocks", :group => "right" }
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%= javascript_tag "updateSelect()" %>
|
|
||||||
<% html_title(l(:label_my_page)) -%>
|
<% html_title(l(:label_my_page)) -%>
|
||||||
|
|
|
@ -182,14 +182,14 @@ class MyControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add_block
|
def test_add_block
|
||||||
xhr :post, :add_block, :block => 'issuesreportedbyme'
|
post :add_block, :block => 'issuesreportedbyme'
|
||||||
assert_response :success
|
assert_redirected_to '/my/page_layout'
|
||||||
assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
|
assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_remove_block
|
def test_remove_block
|
||||||
xhr :post, :remove_block, :block => 'issuesassignedtome'
|
post :remove_block, :block => 'issuesassignedtome'
|
||||||
assert_response :success
|
assert_redirected_to '/my/page_layout'
|
||||||
assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
|
assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue