BOM: Add ofnLineItemUpdAttr directive to watch for changes in line_item attributes

This commit is contained in:
Rob H
2014-01-30 18:40:23 +08:00
parent 4fb06b76c7
commit 67db698a50

View File

@@ -9,6 +9,30 @@ orderManagementModule.config [
orderManagementModule.value "blankEnterprise", ->
{ id: "", name: "All" }
orderManagementModule.directive "ofnLineItemUpdAttr", [
"switchClass", "pendingChanges"
(switchClass, pendingChanges) ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
attrName = attrs.ofnLineItemUpdAttr
element.dbValue = scope.$eval(attrs.ngModel)
scope.$watch ->
scope.$eval(attrs.ngModel)
, (value) ->
if ngModel.$dirty
if value == element.dbValue
pendingChanges.remove(scope.line_item.id, attrName)
switchClass( element, "", ["update-pending", "update-error", "update-success"], false )
else
changeObj =
lineItem: scope.line_item
element: element
attrName: attrName
url: "/api/orders/#{scope.line_item.order.number}/line_items/#{scope.line_item.id}?line_item[#{attrName}]=#{value}"
pendingChanges.addItem(scope.line_item.id, attrName, changeObj)
switchClass( element, "update-pending", ["update-error", "update-success"], false )
]
orderManagementModule.factory "pendingChanges",[
"dataSubmitter"
(dataSubmitter) ->