WIP: Angularise payment methods on enterprise edit page

This commit is contained in:
Rob H
2014-07-03 10:14:31 +10:00
parent 2200392031
commit 6dbe2a3098
14 changed files with 66 additions and 22 deletions

View File

@@ -16,7 +16,8 @@
//= require admin/spree_auth
//= require admin/spree_promo
//= require ./admin
//= require ./products/products
//= require ./enterprises/enterprises
//= require ./payment_methods/payment_methods
//= require ./products/products
//= require_tree .

View File

@@ -1,3 +1,19 @@
angular.module("admin.enterprises")
.controller "enterpriseCtrl", ($scope, Enterprise) ->
$scope.enterprise = Enterprise.enterprise
.controller "enterpriseCtrl", ($scope, Enterprise, PaymentMethods) ->
$scope.Enterprise = Enterprise.enterprise
$scope.PaymentMethods = PaymentMethods.paymentMethods
for PaymentMethod in $scope.PaymentMethods
PaymentMethod.selected = if PaymentMethod.id in $scope.Enterprise.payment_method_ids then true else false
$scope.selectedPaymentMethodsCount = ->
$scope.PaymentMethods.reduce (count, PaymentMethod) ->
count++ if PaymentMethod.selected
count
, 0
$scope.paymentMethodsColor = ->
if $scope.PaymentMethods.length > 0
if $scope.selectedPaymentMethodsCount() > 0 then "blue" else "red"
else
"red"

View File

@@ -1 +1 @@
angular.module("admin.enterprises", [])
angular.module("admin.enterprises", ["admin.payment_methods"])

View File

@@ -0,0 +1,4 @@
angular.module("admin.payment_methods")
.controller "paymentMethodCtrl", ($scope, PaymentMethods) ->
$scope.findPaymentMethodByID = (id) ->
$scope.PaymentMethod = PaymentMethods.findByID(id)

View File

@@ -0,0 +1 @@
angular.module("admin.payment_methods", [])

View File

@@ -0,0 +1,8 @@
angular.module("admin.payment_methods")
.factory "PaymentMethods", (paymentMethods) ->
new class PaymentMethods
paymentMethods: paymentMethods
findByID: (id) ->
for paymentMethod in @paymentMethods
return paymentMethod if paymentMethod.id is id