mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-21 00:47:26 +00:00
Add display as to new product page
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown"]).config ($httpProvider) ->
|
||||
angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown", "admin.products"]).config ($httpProvider) ->
|
||||
$httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"
|
||||
@@ -17,7 +17,7 @@ angular.module("ofn.admin").directive "ofnDisplayAs", (optionValueNamer) ->
|
||||
variant_unit_scale: variant_unit_scale
|
||||
variant_unit: variant_unit
|
||||
variant_unit_name: scope.product.variant_unit_name
|
||||
|
||||
|
||||
scope.placeholder_text = new optionValueNamer(variant_object).name()
|
||||
|
||||
productUnitProperties = ->
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
angular.module("admin.products")
|
||||
.controller "unitsCtrl", ($scope) ->
|
||||
.controller "unitsCtrl", ($scope, optionValueNamer) ->
|
||||
$scope.product = { master: {} }
|
||||
$scope.product.master.product = $scope.product
|
||||
$scope.placeholder_text = ""
|
||||
|
||||
$scope.$watch ->
|
||||
$scope.product.variant_unit_with_scale
|
||||
, ->
|
||||
$scope.$watchCollection '[product.variant_unit_with_scale, product.master.unit_value_with_description]', ->
|
||||
if $scope.product.variant_unit_with_scale
|
||||
match = $scope.product.variant_unit_with_scale.match(/^([^_]+)_([\d\.]+)$/)
|
||||
if match
|
||||
@@ -16,9 +16,6 @@ angular.module("admin.products")
|
||||
else
|
||||
$scope.product.variant_unit = $scope.product.variant_unit_scale = null
|
||||
|
||||
$scope.$watch ->
|
||||
$scope.product.master.unit_value_with_description
|
||||
, ->
|
||||
if $scope.product.master.hasOwnProperty("unit_value_with_description")
|
||||
match = $scope.product.master.unit_value_with_description.match(/^([\d\.]+(?= |$)|)( |)(.*)$/)
|
||||
if match
|
||||
@@ -27,6 +24,8 @@ angular.module("admin.products")
|
||||
$scope.product.master.unit_value *= $scope.product.variant_unit_scale if $scope.product.master.unit_value && $scope.product.variant_unit_scale
|
||||
$scope.product.master.unit_description = match[3]
|
||||
|
||||
$scope.placeholder_text = new optionValueNamer($scope.product.master).name()
|
||||
|
||||
$scope.variant_unit_options = [
|
||||
["Weight (g)", "weight_1"],
|
||||
["Weight (kg)", "weight_1000"],
|
||||
@@ -41,6 +40,4 @@ angular.module("admin.products")
|
||||
Object.keys(product.variants).length > 0
|
||||
|
||||
$scope.hasUnit = (product) ->
|
||||
product.variant_unit_with_scale?
|
||||
|
||||
|
||||
product.variant_unit_with_scale?
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("ofn.admin").factory "optionValueNamer", ($resource) ->
|
||||
angular.module("admin.products").factory "optionValueNamer", ->
|
||||
class OptionValueNamer
|
||||
constructor: (@variant) ->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user