Commit 8c5fd95adb3729f1fec2d4b3da457b945701858a
1 parent
aa5adc62
Exists in
master
and in
29 other branches
ActionItem288: added change image thumbnail when edit product and link to change image
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1656 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
53 additions
and
4 deletions
Show diff stats
... | ... | @@ -0,0 +1,8 @@ |
1 | + <%= file_field_tag("product[image_builder][uploaded_data]") %> | |
2 | + | |
3 | + <br/> | |
4 | + | |
5 | + <%= link_to_function(_('Cancel'), nil, :id => 'cancel-change-image-link', :style => 'display: none') do |page| | |
6 | + page['change-image-link'].show | |
7 | + page['change-image'].replace_html '' | |
8 | + end %> | ... | ... |
app/views/manage_products/_form.rhtml
1 | 1 | <%= error_messages_for :product %> <br/> |
2 | 2 | |
3 | 3 | <% form_for :product, @product, :html => {:multipart => true }, :url => {:action => mode} do |f| %> |
4 | - <%= display_form_field( _('Name:'), f.text_field(:name) ) %> | |
5 | - <%= display_form_field( _('Price:'), f.text_field(:price) ) %> | |
6 | - <%= display_form_field( _('Description:'), f.text_area(:description) ) %> | |
7 | - <%= display_form_field( _('Image:'), file_field_tag( "product[image_builder][uploaded_data]" ) ) %> | |
4 | + <%= display_form_field( _('Name:'), f.text_field(:name) ) %> | |
5 | + <%= display_form_field( _('Price:'), f.text_field(:price) ) %> | |
6 | + <%= display_form_field( _('Description:'), f.text_area(:description) ) %> | |
7 | + <%= display_form_field( _('Image:'), (render :partial => @product.image && @product.image.valid? ? 'show_thumbnail' : 'change_image') ) %> | |
8 | 8 | |
9 | 9 | <div id='subcategories'> |
10 | 10 | <%= render :partial => 'subcategories' %> | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | + <%= image_tag(@product.image.public_filename(:thumb)) %> | |
2 | + | |
3 | + <br/> | |
4 | + | |
5 | + <%= link_to_function(_('Change image'), nil, :id => 'change-image-link') do |page| | |
6 | + page['change-image'].replace_html :partial => 'change_image' | |
7 | + page['change-image-link'].hide | |
8 | + page['cancel-change-image-link'].show | |
9 | + end %> | |
10 | + | |
11 | + <div id='change-image'> </div> | ... | ... |
test/functional/manage_products_controller_test.rb
... | ... | @@ -147,5 +147,26 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
147 | 147 | assert_equal category2, assigns(:product).product_category |
148 | 148 | end |
149 | 149 | end |
150 | + | |
151 | + should 'show thumbnail image when edit product' do | |
152 | + p = @enterprise.products.create!(:name => 'test product1', :image_builder => { | |
153 | + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
154 | + }) | |
155 | + get 'edit', :profile => @enterprise.identifier, :id => p.id | |
156 | + assert_tag :tag => 'img', :attributes => { :src => /#{p.image.public_filename(:thumb)}/ } | |
157 | + end | |
158 | + | |
159 | + should 'show change image link above thumbnail image' do | |
160 | + p = @enterprise.products.create!(:name => 'test product1', :image_builder => { | |
161 | + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
162 | + }) | |
163 | + get 'edit', :profile => @enterprise.identifier, :id => p.id | |
164 | + assert_tag :tag => 'a', :attributes => { :href => '#' }, :content => 'Change image' | |
165 | + end | |
150 | 166 | |
167 | + should 'show change image field when new product' do | |
168 | + get 'new', :profile => @enterprise.identifier | |
169 | + assert_tag :tag => 'input', :attributes => { :type => 'file', :name => 'product[image_builder][uploaded_data]' } | |
170 | + end | |
171 | + | |
151 | 172 | end | ... | ... |
test/unit/product_test.rb
... | ... | @@ -46,4 +46,13 @@ class ProductTest < Test::Unit::TestCase |
46 | 46 | assert_equal [p3, p2], Product.recent(2) |
47 | 47 | end |
48 | 48 | |
49 | + should 'save image on create product' do | |
50 | + assert_difference Product, :count do | |
51 | + p = Product.create!(:name => 'test product1', :image_builder => { | |
52 | + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
53 | + }) | |
54 | + assert_equal p.image(true).filename, 'rails.png' | |
55 | + end | |
56 | + end | |
57 | + | |
49 | 58 | end | ... | ... |