From 8c5fd95adb3729f1fec2d4b3da457b945701858a Mon Sep 17 00:00:00 2001 From: JoenioCosta Date: Mon, 14 Apr 2008 02:53:56 +0000 Subject: [PATCH] ActionItem288: added change image thumbnail when edit product and link to change image --- app/views/manage_products/_change_image.rhtml | 8 ++++++++ app/views/manage_products/_form.rhtml | 8 ++++---- app/views/manage_products/_show_thumbnail.rhtml | 11 +++++++++++ test/functional/manage_products_controller_test.rb | 21 +++++++++++++++++++++ test/unit/product_test.rb | 9 +++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 app/views/manage_products/_change_image.rhtml create mode 100644 app/views/manage_products/_show_thumbnail.rhtml diff --git a/app/views/manage_products/_change_image.rhtml b/app/views/manage_products/_change_image.rhtml new file mode 100644 index 0000000..8bc88c6 --- /dev/null +++ b/app/views/manage_products/_change_image.rhtml @@ -0,0 +1,8 @@ + <%= file_field_tag("product[image_builder][uploaded_data]") %> + +
+ + <%= link_to_function(_('Cancel'), nil, :id => 'cancel-change-image-link', :style => 'display: none') do |page| + page['change-image-link'].show + page['change-image'].replace_html '' + end %> diff --git a/app/views/manage_products/_form.rhtml b/app/views/manage_products/_form.rhtml index e938fff..283e038 100644 --- a/app/views/manage_products/_form.rhtml +++ b/app/views/manage_products/_form.rhtml @@ -1,10 +1,10 @@ <%= error_messages_for :product %>
<% form_for :product, @product, :html => {:multipart => true }, :url => {:action => mode} do |f| %> - <%= display_form_field( _('Name:'), f.text_field(:name) ) %> - <%= display_form_field( _('Price:'), f.text_field(:price) ) %> - <%= display_form_field( _('Description:'), f.text_area(:description) ) %> - <%= display_form_field( _('Image:'), file_field_tag( "product[image_builder][uploaded_data]" ) ) %> + <%= display_form_field( _('Name:'), f.text_field(:name) ) %> + <%= display_form_field( _('Price:'), f.text_field(:price) ) %> + <%= display_form_field( _('Description:'), f.text_area(:description) ) %> + <%= display_form_field( _('Image:'), (render :partial => @product.image && @product.image.valid? ? 'show_thumbnail' : 'change_image') ) %>
<%= render :partial => 'subcategories' %> diff --git a/app/views/manage_products/_show_thumbnail.rhtml b/app/views/manage_products/_show_thumbnail.rhtml new file mode 100644 index 0000000..da06348 --- /dev/null +++ b/app/views/manage_products/_show_thumbnail.rhtml @@ -0,0 +1,11 @@ + <%= image_tag(@product.image.public_filename(:thumb)) %> + +
+ + <%= link_to_function(_('Change image'), nil, :id => 'change-image-link') do |page| + page['change-image'].replace_html :partial => 'change_image' + page['change-image-link'].hide + page['cancel-change-image-link'].show + end %> + +
diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 33ad6c3..1a954f4 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -147,5 +147,26 @@ class ManageProductsControllerTest < Test::Unit::TestCase assert_equal category2, assigns(:product).product_category end end + + should 'show thumbnail image when edit product' do + p = @enterprise.products.create!(:name => 'test product1', :image_builder => { + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') + }) + get 'edit', :profile => @enterprise.identifier, :id => p.id + assert_tag :tag => 'img', :attributes => { :src => /#{p.image.public_filename(:thumb)}/ } + end + + should 'show change image link above thumbnail image' do + p = @enterprise.products.create!(:name => 'test product1', :image_builder => { + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') + }) + get 'edit', :profile => @enterprise.identifier, :id => p.id + assert_tag :tag => 'a', :attributes => { :href => '#' }, :content => 'Change image' + end + should 'show change image field when new product' do + get 'new', :profile => @enterprise.identifier + assert_tag :tag => 'input', :attributes => { :type => 'file', :name => 'product[image_builder][uploaded_data]' } + end + end diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb index 8c0f9dc..e623223 100644 --- a/test/unit/product_test.rb +++ b/test/unit/product_test.rb @@ -46,4 +46,13 @@ class ProductTest < Test::Unit::TestCase assert_equal [p3, p2], Product.recent(2) end + should 'save image on create product' do + assert_difference Product, :count do + p = Product.create!(:name => 'test product1', :image_builder => { + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') + }) + assert_equal p.image(true).filename, 'rails.png' + end + end + end -- libgit2 0.21.2