Calculator type change works, enterprise fee tests pass

This commit is contained in:
Rohan Mitchell
2012-11-26 09:45:06 +11:00
parent 59af447739
commit 6106f1b469
3 changed files with 33 additions and 32 deletions

View File

@@ -1,9 +1,16 @@
function AdminEnterpriseFeesCtrl($scope, $http) {
$http.get('/admin/enterprise_fees.json').success(function(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 in $scope.enterprise_fees) {
$scope.enterprise_fees[i].orig_calculator_type = $scope.enterprise_fees[i].calculator_type;
}
});
}
angular.module('enterprise_fees', [])
.directive('ngBindHtmlUnsafeCompiled', function($compile) {
return function(scope, element, attrs) {
@@ -20,36 +27,30 @@ angular.module('enterprise_fees', [])
element.append(html);
}
}
});
})
.directive('spreeEnsureCalculatorPreferencesMatchType', function() {
// 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.
return function(scope, element, attrs) {
scope.$watch(function(scope) {
//return scope.enterprise_fee.calculator_type;
return element.val();
}, function(value) {
var settings = element.parent().parent().find("div.calculator-settings");
/*
// 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
$(document).ready(function() {
// Store original value
$("select.calculator_type").each(function(i, ct) {
ct = $(ct);
ct.data('original-value', ct.attr('value'));
});
// Hide and disable calculator fields when calculator type is changed
$("select.calculator_type").change(function() {
var ct = $(this);
var cs = ct.parent().parent().find("div.calculator-settings");
if(ct.attr('value') == ct.data('original-value')) {
cs.show();
cs.find("input").prop("disabled", false);
} else {
cs.hide();
cs.find("input").prop("disabled", true);
// scope.enterprise_fee.calculator_type == scope.enterprise_fee.orig_calculator_type
if(element.val() == scope.enterprise_fee.orig_calculator_type) {
settings.show();
settings.find("input").prop("disabled", false);
} else {
settings.hide();
settings.find("input").prop("disabled", true);
}
});
}
});
});
*/