Add some JS for design uploading

This commit is contained in:
Matthew Fu 2011-07-19 18:31:53 +08:00
parent c3ada90365
commit c48a11d9f5
10 changed files with 97 additions and 17 deletions

View File

@ -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

View File

@ -0,0 +1,25 @@
$(".r_snapshot").hover(
function(){
$(this).append($("<span></span>").html('<p class="z-preview"><img src="'+$(this).attr("path")+'"width="220" height="19" /></p>'));
}
,
function(){
$(this).find("span:last").remove();
}
);
$('input.multi_files').change(function(){
$(this).prev("ul").append("<li>"+$(this).val()+"</li>");
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;
});

View File

@ -0,0 +1,12 @@
.z-preview * {
width: 100%;
height: 100%;
}
.z-preview {
background: white;
border: solid;
position: absolute;
width: 200px;
float: right;
height: 200px;
}

View File

@ -1,6 +1,7 @@
class Admin::DesignsController < ApplicationController
layout "admin"
def index
@designs = Design.all.entries
end

View File

@ -1,2 +1,4 @@
module DesignHelper
end

View File

@ -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

View File

@ -4,5 +4,8 @@ class DesignFile
mount_uploader :file, AssetUploader
field :to_save, :type => Boolean
field :to_destroy, :type => Boolean
end

View File

@ -1,3 +1,4 @@
<%= stylesheet_link_tag "design_temp" %>
<p>
<%= f.label :title, t('admin.title') %>
<%= f.text_field :title, :class => 'text' %>
@ -24,22 +25,49 @@
<p>
<%= 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') %>
<ul>
<% @design.stylesheets.each do |t| %>
<li class="r_destroy r_edit" ><%= t.file_filename %>
<%= fields_for "design[stylesheets][]", t, :index => nil do |f| %>
<%= f.hidden_field :id %>
<%= f.hidden_field :to_destroy %>
<%end%>
<a class="remove_mark" href="#">Del</a></li>
<% end %>
</ul>
<%= fields_for "design[stylesheet][]", @design, :index => nil do |f| %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>"stylesheets"}%>
<% end %>
</p>
<p>
<%= f.label "javascript", t('admin.javascript') %>
<ul>
<% @design.javascripts.each do |t| %>
<li class="r_destroy r_edit" ><%= t.file_filename %>
<%=fields_for "design[javascripts][]",t,:index=>nil do |f| %>
<%= f.hidden_field :id %>
<%= f.hidden_field :to_destroy %>
<%end%>
<a class="remove_mark" href="#">Del</a></li>
<% end %>
</ul>
<%= fields_for "design[javascripts][]", @design, :index => nil do |f| %>
<%= f.file_field :file,{:class=>"multi_files",:rtype=>"javascripts"} %>
<% end %>
</p>
<p>
<%= f.label "javascript", t('admin.') %>
<%= fields_for "design[javascripts][]", @design, :index => nil do |f| %>
<%= f.file_field :file %>
<% end %>
</p>
<p>
<%= 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') %>
<ul>
<% @design.images.each do |t| %>
<li class="r_destroy r_snapshot" path="<%= t.file %>" item_id="<%=t.id %>"><%= t.file_filename %>
<a class="remove_mark" href="#">Del</a>
</li>
<% end %>
</ul>
<%= fields_for "design[images][]", @design, :index => nil do |f| %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>"images"}%>
<% end %>
</p>

View File

@ -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'