Integrate Harry's modifications to reload pop-up content

This commit is contained in:
chris2tof 2011-12-29 14:09:06 +08:00
parent b002c411ce
commit ea19f11fe2
5 changed files with 84 additions and 8 deletions

View File

@ -375,16 +375,24 @@ modalWindow : function(settings,callbackFn){
var tempheight = settings.height;
var tempwidth = settings.width;
var maxheight = (rgmaskHeight*85)/100;
var maxwidth = (rgmaskWidth*85)/100;
if(typeof tempheight!="undefined"){
if(tempheight.charAt(tempheight.length-1)=='%')
tempheight=(rgmaskHeight*parseInt(tempheight.substr(0,tempheight.length)))/100;
if(tempheight>maxheight)
tempheight=maxheight;
}else{tempheight="auto";}
if(typeof tempwidth!="undefined"){
if(tempwidth.charAt(tempwidth.length-1)=='%')
tempwidth=(rgmaskWidth*parseInt(tempwidth.substr(0,tempwidth.length)))/100;
if(tempwidth>maxwidth)
tempwidth=maxwidth;
}else{tempwidth="auto";}
$rss("body").append('<div class="rgmask" id="rgsheath" style="height:'+rgmaskHeight+'px"></div>');
$rss("#rgsheath").css({background: "#000", width: "100%", position: "fixed", top: 0, left: 0,opacity:0.9,'z-index':199});
$rss("body").append('<div id="rgWindow"></div>');
@ -410,14 +418,19 @@ modalWindow : function(settings,callbackFn){
rgWTop = (rgmaskHeight-tempheight)/2;
else{
tempheight=$rss("#rgWindow").height();
if(tempheight>maxheight)
tempheight=maxheight;
rgWTop=(rgmaskHeight-tempheight)/2;
}
if(tempwidth!="auto")
rgWLeft = (rgmaskWidth-tempwidth)/2;
else{
tempwidth=$rss("#rgWindow").width();
if(tempwidth>maxwidth)
tempwidth=maxwidth;
rgWLeft=(rgmaskWidth-tempwidth)/2;
}
tempwidth+=25;
$rss("#rgWindow").empty().show();
var closebtn = "";
if(closeBtn)
@ -443,6 +456,65 @@ modalWindow : function(settings,callbackFn){
});
}
},
modalWindowUpdate : function(settings,callbackFn){
var rgmaskHeight = $rss(window).height();
var rgmaskWidth = $rss(window).width();
var tempheight = settings.height;
var tempwidth = settings.width;
var dhtml = "";
var maxheight = (rgmaskHeight*85)/100;
var maxwidth = (rgmaskWidth*85)/100;
if(typeof tempheight!="undefined"){
if(tempheight.charAt(tempheight.length-1)=='%')
tempheight=(rgmaskHeight*parseInt(tempheight.substr(0,tempheight.length)))/100;
if(tempheight>maxheight)
tempheight=maxheight;
}else{tempheight="auto";}
if(typeof tempwidth!="undefined"){
if(tempwidth.charAt(tempwidth.length-1)=='%')
tempwidth=(rgmaskWidth*parseInt(tempwidth.substr(0,tempwidth.length)))/100;
if(tempwidth>maxwidth)
tempwidth=maxwidth;
}else{tempwidth="auto";};
$rss("body").append("<div id='rgwindow_temp_div'></div>");
if(typeof settings.loadDiv!="undefined"){
dhtml = $rss("#"+settings.loadDiv).html();
$rss("#rgwindow_temp_div").html(dhtml).hide();
prepareWindow();
}
if(typeof settings.loadHtml!="undefined"){
dhtml = settings.loadHtml;
$rss("#rgwindow_temp_div").html(dhtml).hide();
prepareWindow();
}
if(typeof settings.loadPage!="undefined"){
$rss("#rgwindow_temp_div").load(settings.loadPage,function(){$rss(this).hide();dhtml=$rss(this).html();prepareWindow();});
}
function prepareWindow(){
if(tempheight!="auto")
rgWTop = (rgmaskHeight-tempheight)/2;
else{
tempheight=$rss("#rgwindow_temp_div").height();
if(tempheight>maxheight)
tempheight=maxheight;
rgWTop=(rgmaskHeight-tempheight)/2;
}
if(tempwidth!="auto")
rgWLeft = (rgmaskWidth-tempwidth)/2;
else{
tempwidth=$rss("#rgwindow_temp_div").width();
if(tempwidth>maxwidth)
tempwidth=maxwidth;
rgWLeft=(rgmaskWidth-tempwidth)/2;
}
tempwidth+=25;
$rss("#rgContent").empty();
$rss("#rgWindow").animate({"width":tempwidth+"px","height":tempheight+"px",top:rgWTop+"px", left:rgWLeft+"px"},500,function(){$rss("#rgContent").css("height",tempheight+"px").html(dhtml)});
$rss("#rgwindow_temp_div").remove();
}
},
modalWindowClose : function(callbackFn){
if($rss("#rgWindow").length>0){
$rss("#rgWindow").empty();

View File

@ -38,7 +38,7 @@ class Admin::AssetsController < ApplicationController
else
respond_to do |format|
format.html { render :action => :new }
format.js { render 'js/reload_content', :locals => {:function => 'html', :id => 'pop_up_content', :value => @asset, :values => nil, :partial => 'admin/assets/new', :locals => {:is_html => false}} }
format.js { render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/new', :locals => {:is_html => false}} }
end
end
end
@ -53,7 +53,7 @@ class Admin::AssetsController < ApplicationController
else
respond_to do |format|
format.html { render :action => :edit }
format.js { render 'js/reload_content', :locals => {:function => 'html', :id => 'pop_up_content', :value => @asset, :values => nil, :partial => 'admin/assets/edit', :locals => {:is_html => false}} }
format.js { render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/edit', :locals => {:is_html => false}} }
end
end

View File

@ -0,0 +1,6 @@
var to_render = '';
<% if value %>
to_render = "<%= escape_javascript(render(:partial => partial, :object => value, :locals => locals)) %>"
<% elsif values %>
to_render = "<%= escape_javascript(render(:partial => partial, :collection => values, :locals => locals)) %>"
<% end %>

View File

@ -1,8 +1,3 @@
var to_render = '';
<% if value %>
to_render = "<%= escape_javascript(render(:partial => partial, :object => value, :locals => locals)) %>"
<% elsif values %>
to_render = "<%= escape_javascript(render(:partial => partial, :collection => values, :locals => locals)) %>"
<% end %>
<%= render :template => 'js/get_to_render', :locals => {:value => value, :values => values, :partial => partial, :locals => locals} %>
$("#<%= id %>").<%= function %>(to_render);

View File

@ -0,0 +1,3 @@
<%= render :template => 'js/get_to_render', :locals => {:value => value, :values => values, :partial => partial, :locals => locals} %>
rcom.modalWindowUpdate({loadHtml:to_render});