Clean code and workaround mongoid embedded with carrierwave
This commit is contained in:
parent
a1391493a3
commit
a571d1dcff
|
@ -80,7 +80,7 @@ GEM
|
||||||
subexec (~> 0.1.0)
|
subexec (~> 0.1.0)
|
||||||
mongo (1.3.1)
|
mongo (1.3.1)
|
||||||
bson (>= 1.3.1)
|
bson (>= 1.3.1)
|
||||||
mongoid (2.1.9)
|
mongoid (2.2.0)
|
||||||
activemodel (~> 3.0)
|
activemodel (~> 3.0)
|
||||||
mongo (~> 1.3)
|
mongo (~> 1.3)
|
||||||
tzinfo (~> 0.3.22)
|
tzinfo (~> 0.3.22)
|
||||||
|
|
|
@ -59,9 +59,9 @@ $(".r_snapshot").live({
|
||||||
);
|
);
|
||||||
|
|
||||||
$('input.multi_files').live("change", function(){
|
$('input.multi_files').live("change", function(){
|
||||||
$(this).parent().prev("ul").append("<li>"+$(this).val()+"</li>");
|
$(this).parent().prev("ul").append("<li>" + $(this).val() + "</li>");
|
||||||
new_node =$(this).parent().clone();
|
new_node = $(this).parent().clone();
|
||||||
$(this).css("display","none");
|
$(this).parent().css("display","none");
|
||||||
new_node.children('input.multi_files').val("");
|
new_node.children('input.multi_files').val("");
|
||||||
$(this).parent().before(new_node);
|
$(this).parent().before(new_node);
|
||||||
});
|
});
|
||||||
|
@ -69,8 +69,8 @@ $('input.multi_files').live("change", function(){
|
||||||
$('a.remove_mark').live("click",function(){
|
$('a.remove_mark').live("click",function(){
|
||||||
$(this).prev("input").val("true");
|
$(this).prev("input").val("true");
|
||||||
$(this).parent().css("text-decoration","line-through")
|
$(this).parent().css("text-decoration","line-through")
|
||||||
$(this).parent("li").removeClass("r_snapshot");
|
$(this).parent().removeClass("r_snapshot");
|
||||||
$(this).next("span").remove();
|
$(this).next().remove();
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,7 +32,6 @@ class Admin::DesignsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
params[:design][:existing_task_attributes] ||= {}
|
|
||||||
@design = Design.find(params[:id])
|
@design = Design.find(params[:id])
|
||||||
if @design.update_attributes(params[:design])
|
if @design.update_attributes(params[:design])
|
||||||
flash[:notice] = "Successfully updated design and tasks."
|
flash[:notice] = "Successfully updated design and tasks."
|
||||||
|
|
|
@ -44,10 +44,8 @@ class Design
|
||||||
files = eval(attrs.last)
|
files = eval(attrs.last)
|
||||||
end
|
end
|
||||||
attrs[0].each do |a|
|
attrs[0].each do |a|
|
||||||
if(a[:id]=='' && !a[:file].nil? )
|
if a[:id].blank? && !a[:file].blank?
|
||||||
if(a[:file]!='')
|
|
||||||
files.build(:file => a[:file], :to_save => true)
|
files.build(:file => a[:file], :to_save => true)
|
||||||
end
|
|
||||||
else
|
else
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
if file.id.to_s == a[:id]
|
if file.id.to_s == a[:id]
|
||||||
|
@ -75,6 +73,7 @@ class Design
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if self.layout.to_save
|
if self.layout.to_save
|
||||||
|
self.layout.to_save = false
|
||||||
self.layout.save
|
self.layout.save
|
||||||
self.layout.parse_urls
|
self.layout.parse_urls
|
||||||
end
|
end
|
||||||
|
@ -86,12 +85,11 @@ class Design
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_object(object)
|
def process_object(object)
|
||||||
if object.file.blank?
|
|
||||||
object.to_save = false
|
|
||||||
end
|
|
||||||
if object.to_save
|
if object.to_save
|
||||||
object.to_save = false
|
new_object = self.send(object._type.downcase.pluralize).build
|
||||||
object.save
|
new_object.file = object.file
|
||||||
|
object.destroy
|
||||||
|
new_object.save
|
||||||
end
|
end
|
||||||
if object.to_destroy
|
if object.to_destroy
|
||||||
object.destroy
|
object.destroy
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Layout < DesignFile
|
||||||
names << [html_name, file_name]
|
names << [html_name, file_name]
|
||||||
}
|
}
|
||||||
names.each do |name|
|
names.each do |name|
|
||||||
content.gsub!(name[0], name[1])
|
content.gsub!(name[0], name[1]) rescue nil
|
||||||
end
|
end
|
||||||
Dir.mktmpdir('f_path') { |dir|
|
Dir.mktmpdir('f_path') { |dir|
|
||||||
orig_file_name = self.file_filename
|
orig_file_name = self.file_filename
|
||||||
|
|
|
@ -1,34 +1,24 @@
|
||||||
<% item_destroy ||= false %>
|
<%= f.label "field_name", t('admin.' + field_name) %>
|
||||||
<% item_snapshot ||= false %>
|
|
||||||
<% item_editable ||= false %>
|
|
||||||
<% li_class = ''%>
|
|
||||||
|
|
||||||
<% fieldname_p = fieldname.pluralize %>
|
|
||||||
<%= f.label "fieldname", t('admin.'+fieldname) %>
|
|
||||||
<ul>
|
<ul>
|
||||||
<% object.send(fieldname_p).each do |t| %>
|
<% object.send(field_name).each do |t| %>
|
||||||
<% li_class += 'r_destroy ' if item_destroy %>
|
<li class="<%= classes %>" <%="path='#{t.file.url}' filename='#{t.file_filename}'" %> >
|
||||||
<% li_class += 'r_snapshot ' if item_snapshot %>
|
|
||||||
<% li_class += 'r_edit ' if item_editable %>
|
|
||||||
<li class="<%= li_class %>" <%= "path='#{t.file.url}' filename='#{t.file_filename}'" if (item_snapshot || item_editable) %> >
|
|
||||||
<%= t.file_filename %>
|
<%= t.file_filename %>
|
||||||
<% if item_destroy %>
|
<% if classes.include?('r_destroy') %>
|
||||||
<%=fields_for "design["+fieldname_p+"][]",t,:index=>nil do |f| %>
|
<%= fields_for "design[" + field_name + "][]", t, :index => nil do |f| %>
|
||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
|
<%= f.hidden_field :file %>
|
||||||
<%= f.hidden_field :to_destroy %>
|
<%= f.hidden_field :to_destroy %>
|
||||||
<%end%>
|
<% end %>
|
||||||
<a class="remove_mark" href="#"><%= t('Delete') %></a>
|
<a class="remove_mark" href="#"><%= t('Delete') %></a>
|
||||||
<%end%>
|
<% end %>
|
||||||
|
<% if classes.include?('r_editable') %>
|
||||||
<% if item_editable %>
|
|
||||||
<a class="edit_mark" href="#"><%= t('Edit') %></a>
|
<a class="edit_mark" href="#"><%= t('Edit') %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="new_file">
|
<p class="new_file">
|
||||||
<%= fields_for "design["+fieldname_p+"][]", object, :index => nil do |f| %>
|
<%= fields_for "design[" + field_name + "][]", object.send(field_name).build, :index => nil do |f| %>
|
||||||
<%= f.hidden_field :id,{:value=>''} %>
|
<%= f.file_field :file, :class => "multi_files" %>
|
||||||
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%>
|
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
|
@ -1,46 +1,48 @@
|
||||||
<%= stylesheet_link_tag "design_temp" %>
|
<% content_for :page_specific_css do %>
|
||||||
<%= javascript_include_tag "design_temp" %>
|
<%= stylesheet_link_tag "design_temp" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :title, t('admin.title') %>
|
<%= f.label :title, t('admin.title') %>
|
||||||
<%= f.text_field :title, :class => 'text' %>
|
<%= f.text_field :title, :class => 'text' %>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :author, t('admin.author') %>
|
<%= f.label :author, t('admin.author') %>
|
||||||
<%= f.text_field :author, :class => 'text' %>
|
<%= f.text_field :author, :class => 'text' %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :intro, t('admin.intro') %>
|
<%= f.label :intro, t('admin.intro') %>
|
||||||
<%= f.text_field :intro, :class => 'text' %>
|
<%= f.text_field :intro, :class => 'text' %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label "layout", t('admin.layout') %>
|
<%= f.label "layout", t('admin.layout') %>
|
||||||
<% if @design.layout.blank? %>
|
<% if @design.layout.blank? %>
|
||||||
<%= fields_for 'design[layout]' do |f| %>
|
<%= fields_for 'design[layout]' do |f| %>
|
||||||
<%= f.file_field :file %>
|
<%= f.file_field :file %>
|
||||||
<%= f.hidden_field :to_save, :value => true %>
|
<%= f.hidden_field :to_save, :value => true %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else%>
|
<% else %>
|
||||||
<%= File.basename (@design.layout.file.url) %>
|
<%= File.basename (@design.layout.file.url) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= f.label "default_css", t('admin.default_css') %>
|
<%= f.label "default_css", t('admin.default_css') %>
|
||||||
<% if @design.default_css.blank? %>
|
<% if @design.default_css.blank? %>
|
||||||
<%= f.file_field :default_css %>
|
<%= f.file_field :default_css %>
|
||||||
<% else%>
|
<% else %>
|
||||||
<%= File.basename (@design.default_css.url) %>
|
<%= File.basename (@design.default_css.url) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"themes",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %>
|
<%= render :partial => 'design_file', :locals => { :object => @design, :field_name => "themes", :f => f, :classes => "r_destroy, r_editable" } %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' ,:item_destroy=>true,:item_editable=>true} %>
|
<%= render :partial => 'design_file', :locals => { :object => @design, :field_name => "javascripts", :f => f, :classes => "r_destroy, r_editable" } %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"image",:object=>@design ,:f=>f,:rtype=>'images' ,:item_destroy=>true,:item_snapshot=>true} %>
|
<%= render :partial => 'design_file', :locals => { :object => @design, :field_name => "images", :f => f, :classes => "r_destroy, r_snapshot" } %>
|
||||||
</p>
|
</p>
|
||||||
|
|
Reference in New Issue