mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
Add fields for variant display name and display as to bpe
This commit is contained in:
@@ -196,6 +196,8 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [
|
||||
unit_value: null
|
||||
unit_description: null
|
||||
on_demand: false
|
||||
display_as: null
|
||||
display_name: null
|
||||
on_hand: null
|
||||
price: null
|
||||
$scope.displayProperties[product.id].showVariants = true
|
||||
@@ -425,6 +427,7 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
if product.hasOwnProperty("id")
|
||||
filteredProduct = {id: product.id}
|
||||
filteredVariants = []
|
||||
filteredMaster = null
|
||||
hasUpdatableProperty = false
|
||||
|
||||
if product.hasOwnProperty("variants")
|
||||
@@ -435,11 +438,14 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
filteredVariants.push filteredVariant if variantHasUpdatableProperty
|
||||
|
||||
if product.master?.hasOwnProperty("unit_value")
|
||||
filteredProduct.unit_value = product.master.unit_value
|
||||
hasUpdatableProperty = true
|
||||
filteredMaster ?= { id: product.master.id }
|
||||
filteredMaster.unit_value = product.master.unit_value
|
||||
if product.master?.hasOwnProperty("unit_description")
|
||||
filteredProduct.unit_description = product.master.unit_description
|
||||
hasUpdatableProperty = true
|
||||
filteredMaster ?= { id: product.master.id }
|
||||
filteredMaster.unit_description = product.master.unit_description
|
||||
if product.master?.hasOwnProperty("display_as")
|
||||
filteredMaster ?= { id: product.master.id }
|
||||
filteredMaster.display_as = product.master.display_as
|
||||
|
||||
if product.hasOwnProperty("name")
|
||||
filteredProduct.name = product.name
|
||||
@@ -466,6 +472,9 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
if product.hasOwnProperty("available_on")
|
||||
filteredProduct.available_on = product.available_on
|
||||
hasUpdatableProperty = true
|
||||
if filteredMaster?
|
||||
filteredProduct.master_attributes = filteredMaster
|
||||
hasUpdatableProperty = true
|
||||
if filteredVariants.length > 0 # Note that the name of the property changes to enable mass assignment of variants attributes with rails
|
||||
filteredProduct.variants_attributes = filteredVariants
|
||||
hasUpdatableProperty = true
|
||||
@@ -491,6 +500,12 @@ filterSubmitVariant = (variant) ->
|
||||
if variant.hasOwnProperty("unit_description")
|
||||
filteredVariant.unit_description = variant.unit_description
|
||||
hasUpdatableProperty = true
|
||||
if variant.hasOwnProperty("display_name")
|
||||
filteredVariant.display_name = variant.display_name
|
||||
hasUpdatableProperty = true
|
||||
if variant.hasOwnProperty("display_as")
|
||||
filteredVariant.display_as = variant.display_as
|
||||
hasUpdatableProperty = true
|
||||
{filteredVariant: filteredVariant, hasUpdatableProperty: hasUpdatableProperty}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
angular.module("ofn.admin").directive "ofnTrackMaster", ["DirtyProducts", (DirtyProducts) ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
ngModel.$parsers.push (viewValue) ->
|
||||
if ngModel.$dirty
|
||||
DirtyProducts.addMasterProperty scope.product.id, scope.product.master.id, attrs.ofnTrackMaster, viewValue
|
||||
scope.displayDirtyProducts()
|
||||
viewValue
|
||||
]
|
||||
@@ -12,6 +12,11 @@ angular.module("ofn.admin").factory "DirtyProducts", ($parse) ->
|
||||
|
||||
addProductProperty: (productID, propertyName, propertyValue) ->
|
||||
addDirtyProperty dirtyProducts, productID, propertyName, propertyValue
|
||||
|
||||
addMasterProperty: (productID, masterID, propertyName, propertyValue) ->
|
||||
if !dirtyProducts.hasOwnProperty(productID) or !dirtyProducts[productID].hasOwnProperty("master")
|
||||
addDirtyProperty dirtyProducts, productID, "master", { id: masterID }
|
||||
$parse(propertyName).assign(dirtyProducts[productID]["master"], propertyValue)
|
||||
|
||||
addVariantProperty: (productID, variantID, propertyName, propertyValue) ->
|
||||
if !dirtyProducts.hasOwnProperty(productID) or !dirtyProducts[productID].hasOwnProperty("variants")
|
||||
|
||||
Reference in New Issue
Block a user