mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Calculator type change works, enterprise fee tests pass
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
*/
|
||||
@@ -24,7 +24,7 @@
|
||||
= f.angular_collection_select :enterprise_id, Enterprise.all, :id, :name, 'enterprise_fee.enterprise_id', :include_blank => true
|
||||
%td= f.angular_select :fee_type, enterprise_fee_type_options, 'enterprise_fee.fee_type'
|
||||
%td= f.angular_text_field :name
|
||||
%td= f.angular_collection_select :calculator_type, @calculators, :name, :description, 'enterprise_fee.calculator_type', {:class => 'calculator_type'}
|
||||
%td= f.angular_collection_select :calculator_type, @calculators, :name, :description, 'enterprise_fee.calculator_type', {'class' => 'calculator_type', 'ng-model' => 'calculatorType', 'spree-ensure-calculator-preferences-match-type' => "1"}
|
||||
%td{'ng-bind-html-unsafe-compiled' => 'enterprise_fee.calculator_settings'}
|
||||
%td{'spree-delete-resource' => "1"}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want to manage enterprise fees
|
||||
} do
|
||||
}, js: true do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
@@ -49,7 +49,7 @@ feature %q{
|
||||
page.should have_selector "#enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']"
|
||||
end
|
||||
|
||||
scenario "editing an enterprise fee", js: true do
|
||||
scenario "editing an enterprise fee" do
|
||||
# Given an enterprise fee
|
||||
fee = create(:enterprise_fee)
|
||||
create(:enterprise, name: 'Foo')
|
||||
@@ -73,7 +73,7 @@ feature %q{
|
||||
page.should have_selector "option[selected]", text: 'Flat Percent'
|
||||
end
|
||||
|
||||
scenario "deleting an enterprise fee", js: true do
|
||||
scenario "deleting an enterprise fee" do
|
||||
# Given an enterprise fee
|
||||
fee = create(:enterprise_fee)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user