mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-10 03:30:22 +00:00
Enterprise Fees: Splitting ng controllers and directives into separate files, reanming module and coffee-ising
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
//= require ./customers/customers
|
||||
//= require ./dropdown/dropdown
|
||||
//= require ./enterprises/enterprises
|
||||
//= require ./enterprise_fees/enterprise_fees
|
||||
//= require ./enterprise_groups/enterprise_groups
|
||||
//= require ./index_utils/index_utils
|
||||
//= require ./line_items/line_items
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
angular.module('enterprise_fees', [])
|
||||
.controller('AdminEnterpriseFeesCtrl', ['$scope', '$http', '$window', function($scope, $http, $window) {
|
||||
$scope.enterpriseFeesUrl = function() {
|
||||
var url = '/admin/enterprise_fees.json?include_calculators=1';
|
||||
|
||||
var match = $window.location.search.match(/enterprise_id=(\d+)/);
|
||||
if(match) {
|
||||
url += "&"+match[0];
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
$http.get($scope.enterpriseFeesUrl()).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;
|
||||
}
|
||||
});
|
||||
}])
|
||||
|
||||
.directive('ngBindHtmlUnsafeCompiled', ['$compile', function($compile) {
|
||||
return function(scope, element, attrs) {
|
||||
scope.$watch(attrs.ngBindHtmlUnsafeCompiled, function(value) {
|
||||
element.html($compile(value)(scope));
|
||||
});
|
||||
}
|
||||
}])
|
||||
|
||||
.directive('spreeDeleteResource', function() {
|
||||
return function(scope, element, attrs) {
|
||||
if(scope.enterprise_fee.id) {
|
||||
var url = "/admin/enterprise_fees/" + scope.enterprise_fee.id
|
||||
var html = '<a href="'+url+'" class="delete-resource icon_link icon-trash no-text" data-action="remove" data-confirm="Are you sure?" url="'+url+'"></a>';
|
||||
//var html = '<a href="'+url+'" class="delete-resource" data-confirm="Are you sure?"><img alt="Delete" src="/assets/admin/icons/delete.png" /> Delete</a>';
|
||||
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");
|
||||
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
angular.module('admin.enterpriseFees').controller 'enterpriseFeesCtrl', ($scope, $http, $window) ->
|
||||
$scope.enterpriseFeesUrl = ->
|
||||
url = '/admin/enterprise_fees.json?include_calculators=1'
|
||||
match = $window.location.search.match(/enterprise_id=(\d+)/)
|
||||
if match
|
||||
url += '&' + match[0]
|
||||
url
|
||||
|
||||
$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
|
||||
@@ -0,0 +1,6 @@
|
||||
angular.module("admin.enterpriseFees").directive 'ngBindHtmlUnsafeCompiled', ($compile) ->
|
||||
(scope, element, attrs) ->
|
||||
scope.$watch attrs.ngBindHtmlUnsafeCompiled, (value) ->
|
||||
element.html $compile(value)(scope)
|
||||
return
|
||||
return
|
||||
@@ -0,0 +1,8 @@
|
||||
angular.module('admin.enterpriseFees').directive 'spreeDeleteResource', ->
|
||||
(scope, element, attrs) ->
|
||||
if scope.enterprise_fee.id
|
||||
url = '/admin/enterprise_fees/' + scope.enterprise_fee.id
|
||||
html = '<a href="' + url + '" class="delete-resource icon_link icon-trash no-text" data-action="remove" data-confirm="Are you sure?" url="' + url + '"></a>'
|
||||
#var html = '<a href="'+url+'" class="delete-resource" data-confirm="Are you sure?"><img alt="Delete" src="/assets/admin/icons/delete.png" /> Delete</a>';
|
||||
element.append html
|
||||
return
|
||||
@@ -0,0 +1,21 @@
|
||||
angular.module("admin.enterpriseFees").directive 'spreeEnsureCalculatorPreferencesMatchType', ->
|
||||
# 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) ->
|
||||
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
|
||||
settings.show()
|
||||
settings.find('input').prop 'disabled', false
|
||||
else
|
||||
settings.hide()
|
||||
settings.find('input').prop 'disabled', true
|
||||
return
|
||||
return
|
||||
@@ -0,0 +1 @@
|
||||
angular.module("admin.enterpriseFees", [])
|
||||
@@ -1,7 +1,7 @@
|
||||
= content_for :page_title do
|
||||
Enterprise Fees
|
||||
|
||||
= ng_form_for @enterprise_fee_set, :url => main_app.bulk_update_admin_enterprise_fees_path, :html => {'ng-app' => 'enterprise_fees', 'ng-controller' => 'AdminEnterpriseFeesCtrl'} do |enterprise_fee_set_form|
|
||||
= ng_form_for @enterprise_fee_set, :url => main_app.bulk_update_admin_enterprise_fees_path, :html => {'ng-app' => 'admin.enterpriseFees', 'ng-controller' => 'enterpriseFeesCtrl'} do |enterprise_fee_set_form|
|
||||
= hidden_field_tag 'enterprise_id', @enterprise.id if @enterprise
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise_fee_set }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user