Add ng directive for setting on demand

This commit is contained in:
Hugo Daniel
2019-08-09 14:34:23 +02:00
parent 60bdde6349
commit bf2c1a0c1d
2 changed files with 32 additions and 48 deletions

View File

@@ -0,0 +1,21 @@
angular.module("admin.products").directive "setOnDemand", ->
link: (scope, element, attr) ->
onHand = element.context.querySelector("#variant_on_hand")
onDemand = element.context.querySelector("#variant_on_demand")
if onDemand.checked
onHand.disabled = 'disabled'
onHand.dataStock = onHand.value
onHand.value = t('admin.products.variants.infinity')
onDemand.addEventListener 'change', (event) ->
if onDemand.checked
onHand.disabled = 'disabled'
onHand.dataStock = onHand.value
onHand.value = t('admin.products.variants.infinity')
else
onHand.removeAttribute('disabled')
onHand.value = onHand.dataStock