nice css for form page files

Oleg committed Sep 28, 2011
commit 1845c7eac69d97d3d736a3989c312b56cd7266a9
Showing 8 changed files with 122 additions and 42 deletions
app/assets/stylesheets/comfortable_mexican_sofa/form.css +44 -1
@@ @@ -67,6 +67,46 @@
#cms_body #form_blocks .no_tags code {
color: #B85042;
}
+ #cms_body #form_blocks .files {
+ overflow: hidden;
+ margin-top: 5px;
+ background-color: #252525;
+ padding: 5px 5px 0px 10px;
+ border-radius: 5px;
+ color: #fff;
+ min-height: 20px;
+ }
+ #cms_body #form_blocks .files .file {
+ float: left;
+ overflow: hidden;
+ background-color: #484848;
+ border-radius: 3px;
+ color: #fff;
+ height: 9px;
+ padding: 3px 5px;
+ margin: 0px 5px 5px 0px;
+ }
+ #cms_body #form_blocks .files .file a {
+ float: left;
+ color: #a3a3a3;
+ font: 9px/9px Arial, serif;
+ text-transform: uppercase;
+ }
+ #cms_body #form_blocks .files .file a:hover {
+ color: #fff;
+ }
+ #cms_body #form_blocks .files .file a.delete {
+ float: right;
+ margin-left: 5px;
+ background-color: #b7b7b7;
+ color: #000;
+ font: bold 7px/7px Arial, sans-serif;
+ padding: 1px 3px;
+ border-radius: 4px;
+ }
+ #cms_body #form_blocks .files .file a.delete:hover {
+ background-color: #fff;
+ }
#cms_body .form_element.field_date_time .label,
#cms_body .form_element.field_integer .label,
#cms_body .form_element.field_string .label,
@@ @@ -77,7 +117,10 @@
#cms_body .form_element.page_integer .label,
#cms_body .form_element.page_string .label,
#cms_body .form_element.page_text .label,
- #cms_body .form_element.page_rich_text .label {
+ #cms_body .form_element.page_rich_text .label,
+ #cms_body .form_element.collection .label,
+ #cms_body .form_element.page_file .label,
+ #cms_body .form_element.page_files .label {
border-color: #3F7300;
}
#cms_body .form_error {
app/views/cms_admin/files/_file.html.erb +1 -1
@@ @@ -1,4 +1,4 @@
- <div class='file' id='<%= dom_id(file) %>'>
+ <div class='file <%= dom_id(file) %>'>
<% file_name = file.file_file_name
file_ext = file.file_file_name.split('.').last
if (file_name.size - file_ext.size) > 30
app/views/cms_admin/files/_page_form.html.erb +10 -1
@@ @@ -1,3 +1,12 @@
<% block ||= page_form %>
- <%= debug block.files %>
\ No newline at end of file
+ <% if (files = block.files).present? %>
+ <div class='files'>
+ <% files.each do |file| %>
+ <div class='file <%= dom_id(file) %>'>
+ <%= link_to file.file_file_name, file.file.url, :target => '_blank' %>
+ <%= link_to 'x', cms_admin_site_file_path(@site, file), :method => :delete, :remote => true, :confirm => t('.are_you_sure'), :class => 'delete' %>
+ </div>
+ <% end %>
+ </div>
+ <% end %>
\ No newline at end of file
app/views/cms_admin/files/destroy.js.erb +1 -1
@@ @@ -1,3 +1,3 @@
- $(".file#<%= dom_id(@file) %>").fadeOut('slow', function(){
+ $(".file.<%= dom_id(@file) %>").fadeOut('slow', function(){
$(this).remove()
})
\ No newline at end of file
config/locales/en.yml +2 -0
@@ @@ -197,6 +197,8 @@ en:
form:
create: Upload File
update: Update File
+ page_form:
+ are_you_sure: Are you sure?
categories:
index:
config/locales/es.yml +2 -0
@@ @@ -197,6 +197,8 @@ es:
form:
create: Subir Archivo
update: Actualizar Archivo
+ page_form:
+ are_you_sure: ¿Estás seguro?
categories:
index:
comfortable_mexican_sofa/form_builder.rb b/lib/comfortable_mexican_sofa/form_builder.rb +46 -38
@@ @@ -55,11 +55,13 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
end
# -- Tag Field Fields -----------------------------------------------------
- def default_tag_field(tag, i, options = {})
- label = options[:label] || tag.label.to_s.titleize
- css_class = options[:css_class] || tag.class.to_s.demodulize.underscore
+ def default_tag_field(tag, index, options = {})
+ method = options.delete(:method) || :text_field_tag
+ label = tag.label.to_s.titleize
+ css_class = tag.class.to_s.demodulize.underscore
+ content = ''
- field_css_class = case tag
+ input_class = case tag
when ComfortableMexicanSofa::Tag::PageDateTime, ComfortableMexicanSofa::Tag::FieldDateTime
'datetime'
when ComfortableMexicanSofa::Tag::PageText, ComfortableMexicanSofa::Tag::FieldText
@@ @@ -68,72 +70,78 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
'rich_text'
end
- options[:content_field_method] ||= :text_field_tag
- field =
- options[:field] ||
- case method = options[:content_field_method]
- when :file_field_tag
- @template.send(method, "page[blocks_attributes][#{i}][content]", :id => nil, :class => field_css_class) +
- @template.render(:partial => 'cms_admin/files/page_form', :object => tag.block)
- else
- @template.send(method, "page[blocks_attributes][#{i}][content]", tag.content, :id => nil, :class => field_css_class)
- end
- content = "#{field} #{@template.hidden_field_tag("page[blocks_attributes][#{i}][label]", tag.label, :id => nil)}"
+ case method
+ when :file_field_tag
+ input_params = {:id => nil, :class => input_class}
+ input_params.merge!(:multiple => true) if options[:multiple]
+ name = "page[blocks_attributes][#{index}][content]"
+ name << '[]' if options[:multiple]
+ content << @template.send(method, name, input_params)
+ content << @template.render(:partial => 'cms_admin/files/page_form', :object => tag.block)
+ else
+ content << @template.send(method, "page[blocks_attributes][#{index}][content]", tag.content, :id => nil, :class => input_class)
+ end
+ content << @template.hidden_field_tag("page[blocks_attributes][#{index}][label]", tag.label, :id => nil)
+
simple_field(label, content, :class => css_class)
end
- def field_date_time(tag, i)
- default_tag_field(tag, i)
+ def field_date_time(tag, index)
+ default_tag_field(tag, index)
+ end
+
+ def field_integer(tag, index)
+ default_tag_field(tag, index, :method => :number_field_tag)
end
- def field_integer(tag, i)
- default_tag_field(tag, i, :content_field_method => :number_field_tag)
+ def field_string(tag, index)
+ default_tag_field(tag, index)
end
- def field_string(tag, i)
- default_tag_field(tag, i)
+ def field_text(tag, index)
+ default_tag_field(tag, index, :method => :text_area_tag)
end
- def field_text(tag, i)
- default_tag_field(tag, i, :content_field_method => :text_area_tag)
+ def page_date_time(tag, index)
+ default_tag_field(tag, index)
end
- def page_date_time(tag, i)
- default_tag_field(tag, i)
+ def page_integer(tag, index)
+ default_tag_field(tag, index, :method => :number_field_tag)
end
- def page_integer(tag, i)
- default_tag_field(tag, i, :content_field_method => :number_field_tag)
+ def page_string(tag, index)
+ default_tag_field(tag, index)
end
- def page_string(tag, i)
- default_tag_field(tag, i)
+ def page_text(tag, index)
+ default_tag_field(tag, index, :method => :text_area_tag)
end
- def page_text(tag, i)
- default_tag_field(tag, i, :content_field_method => :text_area_tag)
+ def page_rich_text(tag, index)
+ default_tag_field(tag, index, :method => :text_area_tag)
end
- def page_rich_text(tag, i)
- default_tag_field(tag, i, :content_field_method => :text_area_tag)
+ def page_file(tag, index)
+ default_tag_field(tag, index, :method => :file_field_tag)
end
- def page_file(tag, i)
- default_tag_field(tag, i, :content_field_method => :file_field_tag)
+ def page_files(tag, index)
+ default_tag_field(tag, index, :method => :file_field_tag, :multiple => true)
end
- def collection(tag, i)
+ def collection(tag, index)
options = [["---- Select #{tag.collection_class.titleize} ----", nil]] +
tag.collection_objects.collect do |m|
[m.send(tag.collection_title), m.send(tag.collection_identifier)]
end
content = @template.select_tag(
- "page[blocks_attributes][#{i}][content]",
+ "page[blocks_attributes][#{index}][content]",
@template.options_for_select(options, :selected => tag.content),
:id => nil
)
- content << @template.hidden_field_tag("page[blocks_attributes][#{i}][label]", tag.label, :id => nil)
+ content << @template.hidden_field_tag("page[blocks_attributes][#{index}][label]", tag.label, :id => nil)
simple_field(tag.label, content, :class => tag.class.to_s.demodulize.underscore )
end
test/functional/cms_admin/pages_controller_test.rb +16 -0
@@ @@ -110,6 +110,22 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']"
end
+ def test_get_new_with_page_file
+ cms_layouts(:default).update_attribute(:content, '{{cms:page_file:test_label}}')
+ get :new, :site_id => cms_sites(:default)
+ assert_response :success
+ assert_select "input[type='file'][name='page[blocks_attributes][0][content]']"
+ assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']"
+ end
+
+ def test_get_new_with_page_files
+ cms_layouts(:default).update_attribute(:content, '{{cms:page_files:test_label}}')
+ get :new, :site_id => cms_sites(:default)
+ assert_response :success
+ assert_select "input[type='file'][name='page[blocks_attributes][0][content][]'][multiple=multiple]"
+ assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']"
+ end
+
def test_get_new_with_collection
snippet = cms_snippets(:default)
cms_layouts(:default).update_attribute(:content, '{{cms:collection:snippet:cms/snippet}}')