Making ofn-line-item-upd-attr work without ng-model

Conflicts:
	app/assets/javascripts/admin/directives/line_item_upd_attr.js.coffee
	app/views/spree/admin/orders/bulk_management.html.haml
This commit is contained in:
Rob Harrington
2015-04-15 10:25:20 +10:00
parent e8c8d8885c
commit 30bb948d35
2 changed files with 75 additions and 73 deletions

View File

@@ -1,23 +1,18 @@
angular.module("ofn.admin").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.add(scope.line_item.id, attrName, changeObj)
switchClass( element, "update-pending", ["update-error", "update-success"], false )
]
angular.module("ofn.admin").directive "ofnLineItemUpdAttr", (switchClass, pendingChanges) ->
scope:
lineItem: "&ofnLineItemUpdAttr"
attrName: "@"
link: (scope, element, attrs) ->
element.dbValue = scope.lineItem()[scope.attrName]
scope.$watch "lineItem().#{scope.attrName}", (value) ->
if value == element.dbValue
pendingChanges.remove(scope.lineItem().id, scope.attrName)
switchClass( element, "", ["update-pending", "update-error", "update-success"], false )
else
changeObj =
lineItem: scope.lineItem()
element: element
attrName: scope.attrName
url: "/api/orders/#{scope.lineItem().order.number}/line_items/#{scope.lineItem().id}?line_item[#{scope.attrName}]=#{value}"
pendingChanges.add(scope.lineItem().id, scope.attrName, changeObj)
switchClass( element, "update-pending", ["update-error", "update-success"], false )