From 07ccacb7d71367b2c3f5d58365df00f9c0b6ebd5 Mon Sep 17 00:00:00 2001 From: chris2tof Date: Fri, 9 Sep 2011 15:40:13 +0800 Subject: [PATCH] Modifications of the JS in Design --- app/assets/javascripts/design_temp.js | 9 ++------- app/controllers/admin/designs_controller.rb | 11 ++++++----- app/models/design/design.rb | 1 + app/views/admin/designs/edit_file.js.erb | 1 + 4 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 app/views/admin/designs/edit_file.js.erb diff --git a/app/assets/javascripts/design_temp.js b/app/assets/javascripts/design_temp.js index ff19da16..2c8ccb1c 100644 --- a/app/assets/javascripts/design_temp.js +++ b/app/assets/javascripts/design_temp.js @@ -11,7 +11,7 @@ function r_editor(tgetUrl,tpostUrl,tfilename,toption){ editor.height = toption['height']; var html=''; editor.init = function(){ - code = ""; + code = ""; html = $(code); html.children("textarea").load(editor.getUrl); html.children("input.discard").click(function(){ @@ -28,12 +28,7 @@ function r_editor(tgetUrl,tpostUrl,tfilename,toption){ }); }; editor.send = function(){ - 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"); - + $.post(editor.postUrl,{filename:editor.filename,context:html.children("textarea").val(),authenticity_token:$('meta[name=csrf-token]').attr('content')},null,"script"); }; editor.destroy = function(){ html.remove(); diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index 932c855b..c52d653b 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -44,7 +44,7 @@ class Admin::DesignsController < ApplicationController def edit_file @design = Design.find(params[:id]) filename = params[:filename] - files = @design.stylesheets + @design.javascripts + @design.images + files = @design.themes + @design.javascripts + @design.images file_to_removed = files.find{ |obj| obj.file_filename == filename } @@ -56,11 +56,12 @@ class Admin::DesignsController < ApplicationController replace_target = eval("@design.#{type.downcase.pluralize}") new_file = replace_target.build(:file => temp_file,:to_save=>true) file_to_removed.destroy - @design.save + new_file.save temp_file.close - } - render :json => new_file.file.url - + } + respond_to do |format| + format.js {} + end end def edit diff --git a/app/models/design/design.rb b/app/models/design/design.rb index 1d4a5284..4d695710 100644 --- a/app/models/design/design.rb +++ b/app/models/design/design.rb @@ -13,6 +13,7 @@ class Design has_many :pages embeds_one :layout + embeds_many :stylesheets embeds_many :themes embeds_many :javascripts embeds_many :images diff --git a/app/views/admin/designs/edit_file.js.erb b/app/views/admin/designs/edit_file.js.erb new file mode 100644 index 00000000..96746b39 --- /dev/null +++ b/app/views/admin/designs/edit_file.js.erb @@ -0,0 +1 @@ +$('#file_editor').remove(); \ No newline at end of file