mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
WIP: Using directive for EnterpriseFee index select elements, to properly bind data to the model
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
angular.module('admin.enterpriseFees').controller 'enterpriseFeesCtrl', ($scope, $http, $window) ->
|
||||
angular.module('admin.enterpriseFees').controller 'enterpriseFeesCtrl', ($scope, $http, $window, enterprises, tax_categories, calculators) ->
|
||||
$scope.enterprises = enterprises
|
||||
$scope.tax_categories = tax_categories
|
||||
$scope.calculators = calculators
|
||||
|
||||
$scope.enterpriseFeesUrl = ->
|
||||
url = '/admin/enterprise_fees.json?include_calculators=1'
|
||||
match = $window.location.search.match(/enterprise_id=(\d+)/)
|
||||
@@ -8,10 +12,3 @@ angular.module('admin.enterpriseFees').controller 'enterpriseFeesCtrl', ($scope,
|
||||
|
||||
$http.get($scope.enterpriseFeesUrl()).success (data) ->
|
||||
$scope.enterprise_fees = data
|
||||
# TODO: Angular 1.1.0 will have a means to reset a form to its pristine state, which
|
||||
# would avoid the need to save off original calculator types for comparison.
|
||||
for i of $scope.enterprise_fees
|
||||
$scope.enterprise_fees[i].orig_calculator_type = $scope.enterprise_fees[i].calculator_type
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
@@ -2,16 +2,12 @@ angular.module("admin.enterpriseFees").directive 'spreeEnsureCalculatorPreferenc
|
||||
# Hide calculator preference fields when calculator type changed
|
||||
# Fixes 'Enterprise fee is not found' error when changing calculator type
|
||||
# See spree/core/app/assets/javascripts/admin/calculator.js
|
||||
# Note: For some reason, DOM --> model bindings aren't working here, so
|
||||
# we use element.val() instead of querying the model itself.
|
||||
(scope, element, attrs) ->
|
||||
scope.$watch ((scope) ->
|
||||
#return scope.enterprise_fee.calculator_type;
|
||||
element.val()
|
||||
), (value) ->
|
||||
orig_calculator_type = scope.enterprise_fee.calculator_type
|
||||
|
||||
scope.$watch "enterprise_fee.calculator_type", (value) ->
|
||||
settings = element.parent().parent().find('div.calculator-settings')
|
||||
# scope.enterprise_fee.calculator_type == scope.enterprise_fee.orig_calculator_type
|
||||
if element.val() == scope.enterprise_fee.orig_calculator_type
|
||||
if value == orig_calculator_type
|
||||
settings.show()
|
||||
settings.find('input').prop 'disabled', false
|
||||
else
|
||||
|
||||
@@ -1 +1 @@
|
||||
angular.module("admin.enterpriseFees", [])
|
||||
angular.module("admin.enterpriseFees", ['admin.indexUtils'])
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# Mainly useful for adding a blank option that works with AngularJS
|
||||
# Angular doesn't seem to understand the blank option generated by rails
|
||||
# using the include_blank flag on select helper.
|
||||
angular.module("admin.indexUtils").directive "ofnSelect", ->
|
||||
restrict: 'E'
|
||||
scope:
|
||||
data: "="
|
||||
replace: true
|
||||
template: (element, attrs) ->
|
||||
valueAttr = attrs.valueAttr || 'id'
|
||||
textAttr = attrs.textAttr || 'name'
|
||||
blank = if attrs.includeBlank? then "<option value=''>#{attrs.includeBlank}</option>" else ""
|
||||
return "<select ng-options='e.#{valueAttr} as e.#{textAttr} for e in data'>#{blank}</select>"
|
||||
Reference in New Issue
Block a user