From 9eb80d74245f40c568707df4246428e057ee3822 Mon Sep 17 00:00:00 2001 From: Kaito Date: Wed, 27 Jul 2011 17:23:01 +0800 Subject: [PATCH] Made r_editor into class style add functions --- app/assets/javascripts/design_temp.js | 41 ++++++++++++++++++- app/controllers/admin/designs_controller.rb | 4 +- app/views/admin/designs/_design_file.html.erb | 2 +- app/views/admin/designs/_form.html.erb | 2 - app/views/layouts/admin.html.erb | 1 + config/routes.rb | 1 + 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/design_temp.js b/app/assets/javascripts/design_temp.js index 7f9570cc..2f67aff8 100644 --- a/app/assets/javascripts/design_temp.js +++ b/app/assets/javascripts/design_temp.js @@ -1,7 +1,46 @@ +function r_editor(tgetUrl,tpostUrl,tfileid,toption){ + if(!toption){ toption =new Array();} + if(!toption['width']){toption['width']=400;} + if(!toption['height']){toption['height']=300;} + var editor = this; + editor.fileid = tfileid; + editor.getUrl = tgetUrl; + editor.postUrl = tpostUrl; + editor.width = toption['width']; + editor.height = toption['height']; + var html=''; + editor.init = function(){ + code = ""; + html = $(code); + html.children("textarea").load(editor.getUrl); + html.children("input.discard").click(function(){ + editor.reload(); + }); + html.children("input.send").click(function(){ + editor.send(); + }); + return html; + }; + editor.reload = function(){ + $.get(editor.getUrl,function(data){ + alert("reload!"); + html.children("textarea").text(data); + }); + }; + editor.send = function(){ + $.post(editor.postUrl,{fileid:editor.fileid,context:html.text()}); + }; + editor.destroy = function(){ + html.remove(); + }; +} + $(".r_edit").live("click",function(){ - $(this).after($("").load($(this).attr("path"))); + new_editor = new r_editor($(this).attr("path"),"edit_file",$(this).attr("fileid")); + $(this).after(new_editor.init()); }); + $(".r_snapshot").live({ mouseenter: function(){ diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index 9891ff2a..5bf47a20 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -23,9 +23,9 @@ class Admin::DesignsController < ApplicationController end end - def file_edit + def edit_file @design = Design.find(params[:id]) - debugger +# debugger end def edit diff --git a/app/views/admin/designs/_design_file.html.erb b/app/views/admin/designs/_design_file.html.erb index 498fc4f0..75a3e538 100644 --- a/app/views/admin/designs/_design_file.html.erb +++ b/app/views/admin/designs/_design_file.html.erb @@ -10,7 +10,7 @@ <% li_class += 'r_destroy ' if item_destroy %> <% li_class += 'r_snapshot ' if item_snapshot %> <% li_class += 'r_edit ' if item_editable %> -
  • > +
  • > <%= t.file_filename %> <% if item_destroy %> <%=fields_for "design["+fieldname_p+"][]",t,:index=>nil do |f| %> diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index c55363be..bc11e33b 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -23,8 +23,6 @@ <%= File.basename (Design.all.last.layout.url) %> <% end %>

    - -

    <%= render :partial => 'design_file' ,:locals => { :fieldname=>"stylesheet",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %>

    diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index b533f82b..3e448cf0 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -34,6 +34,7 @@
  • <%= link_to t('homepage'), root_path %>
  • <%= link_to t('admin.item'), admin_items_path %>
  • <%= link_to t('admin.layout'), admin_layouts_path %>
  • +
  • <%= link_to t('admin.design'), admin_designs_path %>
  • <%= link_to t('admin.asset'), admin_assets_path %>
  • <%= link_to t('admin.user_info'), admin_user_info_models_path %>
  • <%= link_to t('admin.user_role'), admin_user_role_models_path %>
  • diff --git a/config/routes.rb b/config/routes.rb index c518814c..04735928 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,7 @@ PrototypeR4::Application.routes.draw do resources :layouts resources :designs do member do + post 'edit_file' => 'designs#edit_file' get 'delete' end end