openfoodfoundation/openfoodnetwork

View on GitHub
app/assets/javascripts/admin/directives/track_master.js.coffee

Summary

Maintainability
Test Coverage
angular.module("ofn.admin").directive "ofnTrackMaster", (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