mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
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:
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user