Add image to product

This commit is contained in:
2014-08-27 17:14:56 +02:00
parent 22ebf9e376
commit 2ed16351da
15 changed files with 55 additions and 23 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

@@ -82,6 +82,7 @@ App.ApplicationController = Ember.Controller.extend
if list.get('join_requests').toArray().length
@transitionToRoute 'join_requests'
callback.call(@) if callback
@transitionToRoute 'active_list' if @currentRouteName is 'index'
error = @ajaxError (emberError)=>
# if jqXHR.status == 404 officially, now assume close list on error
#@redirect_to 'index', message: 'the_list_has_been_closed'
@@ -0,0 +1,5 @@
App.ModalProductInfoController = Ember.ObjectController.extend
actions:
close: ->
@get('model.cancel').call(@) if @get('model.cancel')
@send 'closeModal'
@@ -29,6 +29,4 @@ App.TableController = Ember.ObjectController.extend
toggleProductCategory: (product_category)->
product_category.set 'collapsed', not product_category.get('collapsed')
showProductDescription: (product)->
@send 'openModal', 'modal_info', Ember.Object.create
title: product.get('name')
body: textile(product.get('description'))
@send 'openModal', 'modal_product_info', product
@@ -3,5 +3,6 @@ App.Product = DS.Model.extend
name: attr 'string'
price: attr 'number'
description: attr 'string'
image: attr()
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
@@ -0,0 +1,7 @@
modal-dialog action="close"
h3.flush--top= name
if image
.right: img src=image.small alt=""
p==description
hr
button{action "close"}= t 'modal.info.close'
@@ -1,3 +1,5 @@
.display-panel
//TODO: something smart
.display-row
+grid-row
.display-label
@@ -95,7 +95,7 @@ module Suppliers
private
def product_params
params.require(:product).permit(:name, :code, :price, :description, product_category_ids: [])
params.require(:product).permit(:name, :code, :price, :description, :image, product_category_ids: [])
end
end
end
+12
View File
@@ -1,6 +1,7 @@
class Product
include SimplyStored::Couch
include ActiveModel::SerializerSupport
include Paperclip::Glue
property :name
property :code
@@ -26,6 +27,17 @@ class Product
is_dirty
end
property :image_file_name
property :image_content_type
property :image_file_size, :type => Fixnum
property :image_updated_at, :type => Time
has_attached_file :image,
url: '/system/product/:id/images/:style.:extension',
styles: {medium: '512x512>', thumb: '128x128>', large: '896x896>', small: '320x320>'},
default_url: '/assets/user/blank-pixel.png'
validates_attachment :image, content_type: {content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]}
private
def persist_product_category_ids
+9 -1
View File
@@ -1,4 +1,12 @@
class ProductSerializer < Qwaiter::Serializer
embed :ids, include: true
attributes :name, :price, :description
attributes :name, :price, :description, :image
def image
if object.image.present?
{small: object.image.url(:small)}
else
nil
end
end
end
+11 -16
View File
@@ -1,25 +1,20 @@
= form_for [:suppliers, @product] do |f|
= render 'error_messages', target: @product
.form-row class=(f.object.errors[:name].any? ? 'error' : nil)
.form-label
= f.label :name, data: {t: 'attributes.product.name'}
.form-field
= f.text_field :name
.form-label= f.label :name, data: {t: 'attributes.product.name'}
.form-field= f.text_field :name
.form-row class=(f.object.errors[:code].any? ? 'error' : nil)
.form-label
= f.label :code, data: {t: 'attributes.product.code'}
.form-field
= f.text_field :code
.form-label= f.label :code, data: {t: 'attributes.product.code'}
.form-field= f.text_field :code
.form-row class=(f.object.errors[:price].any? ? 'error' : nil)
.form-label
= f.label :price, data: {t: 'attributes.product.price'}
.form-field
= f.text_field :price
.form-label= f.label :price, data: {t: 'attributes.product.price'}
.form-field= f.text_field :price
.form-row class=(f.object.errors[:image].any? ? 'error' : nil)
.form-label= f.label :image, data: {t: 'attributes.product.image'}
.form-field= f.file_field :image
.form-row class=(f.object.errors[:description].any? ? 'error' : nil)
.form-label
= f.label :description, data: {t: 'attributes.product.description'}
.form-field
= f.text_area :description
.form-label= f.label :description, data: {t: 'attributes.product.description'}
.form-field= f.text_area :description
/= f.input :name
/= f.input :code
/= f.input :price
@@ -1,6 +1,8 @@
- model_class = Product
.page-header= title :show, @product
- if @product.image.present?
.display-panel= image_tag @product.image.url(:medium)
.display-row
.display-label
span data-t='attributes.product.name'