From c48a11d9f57bb92882554938618cea009f96c550 Mon Sep 17 00:00:00 2001
From: Matthew Fu
Date: Tue, 19 Jul 2011 18:31:53 +0800
Subject: [PATCH] Add some JS for design uploading
---
app/assets/javascripts/application.js | 1 +
app/assets/javascripts/design_temp.js | 25 +++++++++
app/assets/stylesheets/design_temp.css | 12 +++++
app/controllers/admin/designs_controller.rb | 1 +
app/helpers/design_helper.rb | 2 +
app/models/design.rb | 7 ++-
app/models/design_file.rb | 3 ++
app/views/admin/designs/._form.html.erb.swp | Bin 12288 -> 12288 bytes
app/views/admin/designs/_form.html.erb | 56 +++++++++++++++-----
config/routes.rb | 7 ++-
10 files changed, 97 insertions(+), 17 deletions(-)
create mode 100644 app/assets/javascripts/design_temp.js
create mode 100644 app/assets/stylesheets/design_temp.css
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 7d51ec1ad..5a956f60d 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -4,6 +4,7 @@
// // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// // the compiled file.
// //
+// //= require design_temp
// //= require jquery
// //= require jquery_ujs
diff --git a/app/assets/javascripts/design_temp.js b/app/assets/javascripts/design_temp.js
new file mode 100644
index 000000000..a24a32bab
--- /dev/null
+++ b/app/assets/javascripts/design_temp.js
@@ -0,0 +1,25 @@
+$(".r_snapshot").hover(
+ function(){
+ $(this).append($("").html(''));
+ }
+ ,
+ function(){
+ $(this).find("span:last").remove();
+ }
+ );
+
+$('input.multi_files').change(function(){
+ $(this).prev("ul").append(""+$(this).val()+"");
+ new_node =$(this).clone();
+ new_node.css("display","none");
+ //new_node.val("asd");
+ $(this).parent().append(new_node);
+ $(this).val("");
+});
+
+$('a.remove_mark').live("click",function(){
+ $(this).prev("input").value("true");
+ $(this).parent().css("text-decoration","line-through")
+ $(this).remove();
+ return false;
+});
diff --git a/app/assets/stylesheets/design_temp.css b/app/assets/stylesheets/design_temp.css
new file mode 100644
index 000000000..27f874007
--- /dev/null
+++ b/app/assets/stylesheets/design_temp.css
@@ -0,0 +1,12 @@
+.z-preview * {
+ width: 100%;
+ height: 100%;
+}
+.z-preview {
+ background: white;
+ border: solid;
+ position: absolute;
+ width: 200px;
+ float: right;
+ height: 200px;
+}
diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb
index ba7af6a18..088245254 100644
--- a/app/controllers/admin/designs_controller.rb
+++ b/app/controllers/admin/designs_controller.rb
@@ -1,6 +1,7 @@
class Admin::DesignsController < ApplicationController
layout "admin"
+
def index
@designs = Design.all.entries
end
diff --git a/app/helpers/design_helper.rb b/app/helpers/design_helper.rb
index 6293f668b..c55eb2a09 100644
--- a/app/helpers/design_helper.rb
+++ b/app/helpers/design_helper.rb
@@ -1,2 +1,4 @@
module DesignHelper
+
+
end
diff --git a/app/models/design.rb b/app/models/design.rb
index c6fdac73b..b9e664bd0 100644
--- a/app/models/design.rb
+++ b/app/models/design.rb
@@ -17,7 +17,7 @@ class Design
embeds_many :javascripts
embeds_many :images
- after_save :save_embedded_objects
+ after_save :procs_embedded_objects
def javascripts=(*attrs)
self.files = (attrs << 'javascripts')
@@ -41,13 +41,16 @@ class Design
protected
- def save_embedded_objects
+ def procs_embedded_objects
[self.stylesheets, self.javascripts, self.images].each do |objects|
objects.each do |object|
if object.to_save
object.to_save = false
object.save
end
+ if object.to_destroy
+ object.destroy
+ end
end
end
end
diff --git a/app/models/design_file.rb b/app/models/design_file.rb
index 9871d74c5..07c09e14a 100644
--- a/app/models/design_file.rb
+++ b/app/models/design_file.rb
@@ -4,5 +4,8 @@ class DesignFile
mount_uploader :file, AssetUploader
field :to_save, :type => Boolean
+ field :to_destroy, :type => Boolean
+
+
end
diff --git a/app/views/admin/designs/._form.html.erb.swp b/app/views/admin/designs/._form.html.erb.swp
index aadcc0f18f045caffc517bb50b95a74b2476247e..2dbb06f611c3edf518c6d138af89225ed017a4a7 100644
GIT binary patch
literal 12288
zcmeI2zmFS56vrniLLeMLmo%p|lZ~uPB(od1g2b{75(&{2&_RkQT8(eVw}WSYWOvrd
zASAj_P@@!7^fVNJgy?|p%-G(IUtb{Pd+;sz2HXc90S+#Mi{LQ$dySAk!5`pv@EiCJd;vZL+u)z)
z3Hb$l4L$`KVBjiP0}qa29dI9f2|fp7kbpP9QSifagnR5Y1x|sVp2b?=HmHCC
zIk*h^U;})0l#mZV1$IFQHo!w@^dm4@9gz4tH=F`a0jGdd;Hg)j8{~aLX}3jr8qt>i
zj=ROJtsWivLm_!M6kJBMqrcPkoz9MAW!dX{NhOs)r{tyA?i6Y-=V%oP+eO1YGkI4}
zqDPndO+4z^_wue;o9oxEdu{r#n-QM)&<;7K;-VZw@$N8^GId)^tZe~HU(z^3+HDQ4y&Hld1aj}~E>vb>Bl<)o-eY4{?i39S9~Zj+eQMtiL<~Tu#%e!c=nQc3)^Q>
zqO6q)AA4D){Hl=W=(NyKE=xXnNNojd9yxY|DS9nR#c)gnR7&+MVq>JbAAOB0Ap8|XMMkXdRD18D^{3)YB*cK
uHY{I32_^Z01&rX$Bc?O4oULH)>jkuJ9sN*>bQCJKJ3YfgoP)V%X8jLTVaG`T
delta 468
zcmaLRF-yZh6bJBE9BoV#T&n1m8bU0lqDZNvap)ipic=SnHkwO~#I*K`R4CX_;9!@6
zgE}~ibQ1AfIEaHTj!r6wpx{5%t?0pzdvN#O`!|ctVr*kNzqHKK#w_6|M6X{XEAjpz
zT1{TYUgU`0k(77&z>E^TLHI+*^(hnG!a1D62^_;N&k$IK6F*2M#7N
z)*B~`*4+{Y4HJrjTdp$A;le8gYofOAbFsyFO{{CoDYJ=;phcy6y`+ztc4Gk#BLk
BY-9ic
diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb
index 19c3c6400..9743b9e1d 100644
--- a/app/views/admin/designs/_form.html.erb
+++ b/app/views/admin/designs/_form.html.erb
@@ -1,3 +1,4 @@
+<%= stylesheet_link_tag "design_temp" %>
<%= f.label :title, t('admin.title') %>
<%= f.text_field :title, :class => 'text' %>
@@ -24,22 +25,49 @@
-<%= f.label "stylesheet", t('admin.stylesheet') %>
-<%= fields_for "design[stylesheets][]", @design, :index => nil do |f| %>
- <%= f.file_field :file %>
+ <%= f.label "stylesheet", t('admin.stylesheet') %>
+
+ <% @design.stylesheets.each do |t| %>
+ - <%= t.file_filename %>
+ <%= fields_for "design[stylesheets][]", t, :index => nil do |f| %>
+ <%= f.hidden_field :id %>
+ <%= f.hidden_field :to_destroy %>
+ <%end%>
+ Del
+ <% end %>
+
+ <%= fields_for "design[stylesheet][]", @design, :index => nil do |f| %>
+ <%= f.file_field :file ,{:class=>"multi_files",:rtype=>"stylesheets"}%>
+ <% end %>
+
+
+
+ <%= f.label "javascript", t('admin.javascript') %>
+
+ <% @design.javascripts.each do |t| %>
+ - <%= t.file_filename %>
+ <%=fields_for "design[javascripts][]",t,:index=>nil do |f| %>
+ <%= f.hidden_field :id %>
+ <%= f.hidden_field :to_destroy %>
+ <%end%>
+ Del
+ <% end %>
+
+ <%= fields_for "design[javascripts][]", @design, :index => nil do |f| %>
+ <%= f.file_field :file,{:class=>"multi_files",:rtype=>"javascripts"} %>
<% end %>
-<%= f.label "javascript", t('admin.') %>
-<%= fields_for "design[javascripts][]", @design, :index => nil do |f| %>
- <%= f.file_field :file %>
-<% end %>
-
-
-
-<%= f.label "image", t('admin.') %>
-<%= fields_for "design[images][]", @design, :index => nil do |f| %>
- <%= f.file_field :file %>
-<% end %>
+ <%= f.label "image", t('admin.image') %>
+
+ <% @design.images.each do |t| %>
+ - <%= t.file_filename %>
+ Del
+
+ <% end %>
+
+ <%= fields_for "design[images][]", @design, :index => nil do |f| %>
+ <%= f.file_field :file ,{:class=>"multi_files",:rtype=>"images"}%>
+ <% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 23fb6053e..c518814c3 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -44,7 +44,12 @@ PrototypeR4::Application.routes.draw do
end
resources :layouts
- resources :designs
+ resources :designs do
+ member do
+ get 'delete'
+ end
+ end
+
resources :links do
member do
get 'delete'