BOM: Add factory to monitor changes made to line_items

This commit is contained in:
Rob H
2014-01-30 14:12:28 +08:00
parent 3bf36f0e55
commit 224d91083d
2 changed files with 133 additions and 4 deletions

View File

@@ -9,12 +9,39 @@ orderManagementModule.config [
orderManagementModule.value "blankEnterprise", ->
{ id: "", name: "All" }
orderManagementModule.factory "pendingChanges",[
"dataSubmitter"
(dataSubmitter) ->
pendingChanges: {}
add: (id, attrName, changeObj) ->
this.pendingChanges["#{id}"] = {} unless this.pendingChanges.hasOwnProperty("#{id}")
this.pendingChanges["#{id}"]["#{attrName}"] = changeObj
remove: (id, attrName) ->
if this.pendingChanges.hasOwnProperty("#{id}")
delete this.pendingChanges["#{id}"]["#{attrName}"]
delete this.pendingChanges["#{id}"] if this.changeCount( this.pendingChanges["#{id}"] ) < 1
submitAll: ->
for id,lineItem of this.pendingChanges
for attrName,changeObj of lineItem
this.submit id, attrName, changeObj
submit: (id, attrName, change) ->
factory = this
dataSubmitter(change).then (data) ->
factory.remove id, attrName
change.element.dbValue = data["#{attrName}"]
changeCount: (lineItem) ->
Object.keys(lineItem).length
]
orderManagementModule.controller "AdminOrderMgmtCtrl", [
"$scope", "$http", "dataFetcher", "blankEnterprise"
($scope, $http, dataFetcher, blankEnterprise) ->
$scope.updateStatusMessage =
text: ""
style: {}
$scope.lineItems = []
$scope.confirmDelete = true