in design,after online editing,return json url,callback not finish

This commit is contained in:
Kaito 2011-07-28 18:54:31 +08:00
parent 1839269581
commit c9e4d0f345
2 changed files with 12 additions and 6 deletions

View File

@ -6,6 +6,7 @@ function r_editor(tgetUrl,tpostUrl,tfilename,toption){
editor.filename = tfilename; editor.filename = tfilename;
editor.getUrl = tgetUrl; editor.getUrl = tgetUrl;
editor.postUrl = tpostUrl; editor.postUrl = tpostUrl;
editor.nodeToBeChanged=""
editor.width = toption['width']; editor.width = toption['width'];
editor.height = toption['height']; editor.height = toption['height'];
var html=''; var html='';
@ -27,7 +28,12 @@ function r_editor(tgetUrl,tpostUrl,tfilename,toption){
}); });
}; };
editor.send = function(){ editor.send = function(){
$.post(editor.postUrl,{filename:editor.filename,context:html.children("textarea").val(),authenticity_token:$('meta[name=csrf-token]').attr('content')}); callback_for_send = function(data){
editor.postUrl = data;
alert($(this).attr("path"));
};
$.post(editor.postUrl,{filename:editor.filename,context:html.children("textarea").val(),authenticity_token:$('meta[name=csrf-token]').attr('content')},callback_for_send,"json");
}; };
editor.destroy = function(){ editor.destroy = function(){
html.remove(); html.remove();

View File

@ -31,17 +31,17 @@ class Admin::DesignsController < ApplicationController
obj.file_filename == filename obj.file_filename == filename
} }
type = file_to_removed._type type = file_to_removed._type
new_file = ""
Dir.mktmpdir('design_temp'){ |dir| Dir.mktmpdir('design_temp'){ |dir|
temp_file = File.new(dir+'/'+filename,'w+') temp_file = File.new(dir+'/'+filename,'w+')
temp_file.write params[:context] temp_file.write params[:context]
replace_target = eval("@design.#{type.downcase.pluralize}") replace_target = eval("@design.#{type.downcase.pluralize}")
a = replace_target.build(:file => temp_file,:to_save=>true) new_file = replace_target.build(:file => temp_file,:to_save=>true)
debugger
file_to_removed.destroy file_to_removed.destroy
@design.save @design.save
debugger
temp_file.close temp_file.close
} }
render :json => new_file.file.url
end end