Product error handling

This commit is contained in:
2014-11-27 14:48:33 +01:00
parent 60f014811c
commit 5453837880
20 changed files with 96 additions and 39 deletions
@@ -1,9 +1,24 @@
App.MenuProductComponent = Ember.Component.extend
editMode: false
code_filter: ''
showProduct: (-> !@get('code_filter') or (@get('product.code') || "").match(@get('code_filter'))).property('code_filter')
code_filter_display: (->
return new Ember.Handlebars.SafeString(' ') unless code = @get('product.code')
return code unless filter = @get('code_filter')
index = code.indexOf(filter)
if index >= 0
pre_code = code.substring(0,index)
highlight = code.substring(index,index + filter.length)
post_code = code.substring(index + filter.length)
new Ember.Handlebars.SafeString("#{pre_code}<span class='highlight'>#{highlight}</span>#{post_code}")
else
code
).property('code_filter')
actions:
makeEditable: -> @set('editMode', true)
save: ->
@get('product').save() if @get('product.isDirty')
if @get('product.isDirty')
@get('product').save().then((-> true), (-> true))
@set 'editMode', false
destroyProduct: (product)->
if product.get('isNew')
@@ -1,7 +1,9 @@
App.MenuController = Ember.ObjectController.extend
needs: ['application']
product_code_filter: ''
product_categories: (-> @store.all('product_category')).property()
sorted_product_categories: (-> @get('product_categories').sortBy('position')).property('product_categories.@each', 'product_categories.@each.position')
product_code_filter_placeholder: t('product.code_filter.placeholder')
actions:
editProductCategory: (product_category)->
@modal 'product_category_edit',
@@ -0,0 +1,12 @@
Ember.Handlebars.helper 'errors', (errors, params..., options)->
return "" unless errors and errors.length
result = ""
model_name = options.hash.includeAttribute
for error in errors
if model_name
attribute = ttry("attributes.#{model_name}.#{error.attribute}")
message = "#{attribute} #{error.message}"
else
message = error.message
result += "<div class='error'>#{message}</div>"
new Ember.Handlebars.SafeString(result)
@@ -1,8 +1,8 @@
App.ApplicationSerializer = DS.ActiveModelSerializer
App.ApplicationStore = DS.Store.extend
adapter: DS.RESTAdapter.extend
adapter: DS.ActiveModelAdapter.extend
namespace: 'supplier'
# user underscored paths
pathForType: (type)->
Ember.String.pluralize(Ember.String.decamelize(type))
## user underscored paths
#pathForType: (type)->
#Ember.String.pluralize(Ember.String.decamelize(type))
@@ -1,13 +1,22 @@
.row.menu-product-container
if editMode
.small-3.columns= input value=product.name
.small-3.columns= edit-currency value=product.price validatePresence=true
.small-3.columns
= input value=product.name
= errors product.errors.name
.small-3.columns
= edit-currency value=product.price validatePresence=true
= errors product.errors.price
.small-3.columns= input value=product.code
.small-3.columns
a.destroy-product-action{action "destroyProduct" product}: span
a.save-product-action{action "save"}: span
else
.small-3.columns: span= product.name
.small-3.columns= currency product.price
.small-3.columns: span= product.code_or_empty
.small-3.columns: span.fa.fa-edit{action "makeEditable"}
if showProduct
.small-3.columns
span= product.name
= errors product.errors.name includeAttribute="product"
.small-3.columns
= currency product.price
= errors product.errors.price includeAttribute="product"
.small-3.columns: span= code_filter_display
.small-3.columns: span.fa.fa-edit{action "makeEditable"}
@@ -1,3 +1,5 @@
.products-menu-filters-container
= input value=product_code_filter type="search" placeholder=product_code_filter_placeholder
h2 Menu
each product_category in sorted_product_categories
.row.product_category-container: .small-12.columns
@@ -8,7 +10,7 @@ each product_category in sorted_product_categories
a.edit-product-category-button{action "editProductCategory" product_category} href="#"
a.add-product-product-category-button{action "addProduct" product_category} href="#": span
each product in product_category.sorted_products
= menu-product product=product
= menu-product product=product code_filter=product_code_filter
.row
.small-12.columns
a.button{action "newProductCategory"} href="#" = t 'product_category.new_button'
@@ -2,7 +2,7 @@
.form-label.half=t 'attributes.product_category.name'
.form-field.half= input valueBinding="model.name"
.row
.small-6.columns
.small-12.medium-6.columns
unless model.supplier.week_starts_on_monday
.form-row
.form-label.half= t 'date.day_name.sunday'
@@ -29,7 +29,7 @@
.form-row
.form-label.half= t 'date.day_name.sunday'
.form-field.half= view "boolean-switch" valueBinding=model.active_on_sunday
.small-6.columns
.small-12.medium-6.columns
.row
.small-12.columns.text-center= view 'boolean-button' value=model.full_day reverse=true text_path="product_category.modal.active_between.top"
unless model.full_day
@@ -9,13 +9,14 @@ each product_category in product_categories
a{action "moveBelow" product_category} href="#"
span.title= product_category.name
span.availability= product_category.availability_text
hr
h4=t 'product_category.modal.move.products.title'
hr
ul.sortable
each product in model.sorted_products
li.sortable-item-container data-sortable-id=product.id
span.handle
span= product.name
if model.products
hr
h4=t 'product_category.modal.move.products.title'
hr
ul.sortable
each product in model.sorted_products
li.sortable-item-container data-sortable-id=product.id
span.handle
span= product.name
hr
button.modal-close{action "close"}=t 'section.add_tables.modal.close_button'
@@ -18,6 +18,7 @@
//= require_self
var Qstorage = localStorage;
$.extend($translations.en, <%= I18n.t('supplier', locale: :en).to_json %>);
$.extend($translations.nl, <%= I18n.t('supplier', locale: :nl).to_json %>);
@@ -1,6 +1,6 @@
jQuery ->
$('#product-category-list').sortable
axis: 'y'
handle: '.handle'
update: ->
$.post($(this).data('update-url'), $(this).sortable('serialize'))
#jQuery ->
#$('#product-category-list').sortable
#axis: 'y'
#handle: '.handle'
#update: ->
#$.post($(this).data('update-url'), $(this).sortable('serialize'))
@@ -32,9 +32,10 @@
#translatable = undefined
#isafety = undefined
#replacable = undefined
locale = Qstorage.getItem('locale') || 'en'
parts = path.split(".")
#accessor = "$translations.#{$locale}[\"#{parts.join("\"][\"")}\"]"
result = $translations[$locale]
result = $translations[locale]
try
result = result[part] for part in parts
catch err