diff --git a/app/assets/images/user/blank-pixel.png b/app/assets/images/user/blank-pixel.png new file mode 100644 index 00000000..9da19eac Binary files /dev/null and b/app/assets/images/user/blank-pixel.png differ diff --git a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee index a33475cf..bbac8b23 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -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' diff --git a/app/assets/javascripts/user/app/controllers/modal_product_info_controller.js.coffee b/app/assets/javascripts/user/app/controllers/modal_product_info_controller.js.coffee new file mode 100644 index 00000000..5b4951bd --- /dev/null +++ b/app/assets/javascripts/user/app/controllers/modal_product_info_controller.js.coffee @@ -0,0 +1,5 @@ +App.ModalProductInfoController = Ember.ObjectController.extend + actions: + close: -> + @get('model.cancel').call(@) if @get('model.cancel') + @send 'closeModal' diff --git a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee index b09bb81f..57bf4468 100644 --- a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee @@ -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 diff --git a/app/assets/javascripts/user/app/models/product.js.coffee b/app/assets/javascripts/user/app/models/product.js.coffee index ef2f667c..cd51e59b 100644 --- a/app/assets/javascripts/user/app/models/product.js.coffee +++ b/app/assets/javascripts/user/app/models/product.js.coffee @@ -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') diff --git a/app/assets/javascripts/user/app/templates/modal_product_info.emblem b/app/assets/javascripts/user/app/templates/modal_product_info.emblem new file mode 100644 index 00000000..70ebfcca --- /dev/null +++ b/app/assets/javascripts/user/app/templates/modal_product_info.emblem @@ -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' diff --git a/app/assets/stylesheets/user/foundation/_display_fields.css.sass b/app/assets/stylesheets/user/foundation/_display_fields.css.sass index d3167e0f..bf71ee89 100644 --- a/app/assets/stylesheets/user/foundation/_display_fields.css.sass +++ b/app/assets/stylesheets/user/foundation/_display_fields.css.sass @@ -1,3 +1,5 @@ +.display-panel + //TODO: something smart .display-row +grid-row .display-label diff --git a/app/controllers/suppliers/products_controller.rb b/app/controllers/suppliers/products_controller.rb index d892ebf2..69e8883f 100644 --- a/app/controllers/suppliers/products_controller.rb +++ b/app/controllers/suppliers/products_controller.rb @@ -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 diff --git a/app/models/product.rb b/app/models/product.rb index b0dfb2f4..914d40a8 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -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 diff --git a/app/serializers/product_serializer.rb b/app/serializers/product_serializer.rb index 5eb2bbaf..5c68a99f 100644 --- a/app/serializers/product_serializer.rb +++ b/app/serializers/product_serializer.rb @@ -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 diff --git a/app/views/suppliers/products/_form.html.slim b/app/views/suppliers/products/_form.html.slim index 8488374a..d8c3f03d 100644 --- a/app/views/suppliers/products/_form.html.slim +++ b/app/views/suppliers/products/_form.html.slim @@ -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 diff --git a/app/views/suppliers/products/show.html.slim b/app/views/suppliers/products/show.html.slim index 7649fef3..7dc46f48 100644 --- a/app/views/suppliers/products/show.html.slim +++ b/app/views/suppliers/products/show.html.slim @@ -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' diff --git a/config/locales/models.en.yml b/config/locales/models.en.yml index c2b36565..73c8fb17 100644 --- a/config/locales/models.en.yml +++ b/config/locales/models.en.yml @@ -14,7 +14,7 @@ en: user: Users supplier: Restaurants table: Tables - list: Lists + list: Lists product: Products order: Orders product_category: Product categories @@ -34,6 +34,7 @@ en: code: Code price: Price created_at: Created + image: Image list: created_at: Created state: Status diff --git a/config/locales/models.nl.yml b/config/locales/models.nl.yml index c2730b8b..f66952f8 100644 --- a/config/locales/models.nl.yml +++ b/config/locales/models.nl.yml @@ -34,6 +34,7 @@ nl: code: Code price: Prijs created_at: Aangemaakt + image: Afbeelding list: created_at: Aangemaakt state: Status diff --git a/wip.md b/wip.md index 337ea023..4cc91eb6 100644 --- a/wip.md +++ b/wip.md @@ -20,7 +20,6 @@ User - Cleanup UserController - test met veel producten - Change language -- redirect to list on open when active list present - Product image General