diff --git a/app/frontend/src/javascript/components/angular/switch.ts b/app/frontend/src/javascript/components/angular/switch.ts index 0a5aa139f..778088415 100644 --- a/app/frontend/src/javascript/components/angular/switch.ts +++ b/app/frontend/src/javascript/components/angular/switch.ts @@ -7,4 +7,4 @@ import { IApplication } from '../../models/application'; declare var Application: IApplication; -Application.Components.component('switch', react2angular(Switch, ['checked', 'onChange', 'id', 'className'])); +Application.Components.component('switch', react2angular(Switch, ['checked', 'onChange', 'id', 'className', 'disabled'])); diff --git a/app/frontend/src/javascript/controllers/admin/members.js b/app/frontend/src/javascript/controllers/admin/members.js index 3f105e484..505076714 100644 --- a/app/frontend/src/javascript/controllers/admin/members.js +++ b/app/frontend/src/javascript/controllers/admin/members.js @@ -810,12 +810,18 @@ Application.Controllers.controller('EditMemberController', ['$scope', '$state', templateUrl: '/admin/subscriptions/create_modal.html', size: 'lg', controller: ['$scope', '$uibModalInstance', 'Subscription', function ($scope, $uibModalInstance, Subscription) { - // selected user + // selected user $scope.user = user; // available plans for the selected user $scope.plans = plans; + // default parameters for the new subscription + $scope.subscription = { + payment_schedule: false, + payment_method: 'check' + }; + /** * Generate a string identifying the given plan by literal human-readable name * @param plan {Object} Plan object, as recovered from GET /api/plan/:id @@ -826,6 +832,29 @@ Application.Controllers.controller('EditMemberController', ['$scope', '$state', */ $scope.humanReadablePlanName = function (plan, groups, short) { return `${$filter('humanReadablePlanName')(plan, groups, short)}`; }; + /** + * Check if the currently selected plan can be paid with a payment schedule or not + * @return {boolean} + */ + $scope.allowMonthlySchedule = function () { + if (!$scope.subscription) return false; + + const plan = plans.find(p => p.id === $scope.subscription.plan_id); + return plan && plan.monthly_payment; + }; + + /** + * Triggered by the component. + * We must use a setTimeout to workaround the react integration. + * @param checked {Boolean} + */ + $scope.toggleSchedule = function (checked) { + setTimeout(() => { + $scope.subscription.payment_schedule = checked; + $scope.$apply(); + }, 50); + }; + /** * Modal dialog validation callback */ diff --git a/app/frontend/src/javascript/controllers/admin/plans.js b/app/frontend/src/javascript/controllers/admin/plans.js index 8c57522ca..9172956ab 100644 --- a/app/frontend/src/javascript/controllers/admin/plans.js +++ b/app/frontend/src/javascript/controllers/admin/plans.js @@ -182,6 +182,14 @@ Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal', }; /* PRIVATE SCOPE */ + const initialize = function () { + $scope.$watch(scope => scope.plan.interval, + (newValue, oldValue) => { + if (newValue === 'week') { $scope.plan.monthly_payment = false; } + } + ); + }; + /** * Asynchronously updates the given property with the new provided value * @param property {string} @@ -194,6 +202,7 @@ Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal', }, 50); }; + initialize(); return new PlanController($scope, groups, prices, partners, CSRF, _t); } ]); diff --git a/app/frontend/templates/admin/plans/_form.html b/app/frontend/templates/admin/plans/_form.html index a8534f179..b40c91a02 100644 --- a/app/frontend/templates/admin/plans/_form.html +++ b/app/frontend/templates/admin/plans/_form.html @@ -121,7 +121,7 @@
- + {{ (plan.monthly_payment ? 'app.shared.buttons.yes' : 'app.shared.buttons.no') | translate }} {{ 'app.shared.plan.monthly_payment_info' }} diff --git a/app/frontend/templates/admin/subscriptions/create_modal.html b/app/frontend/templates/admin/subscriptions/create_modal.html index 3554747eb..80ba7b896 100644 --- a/app/frontend/templates/admin/subscriptions/create_modal.html +++ b/app/frontend/templates/admin/subscriptions/create_modal.html @@ -7,11 +7,15 @@ {{ 'app.admin.members_edit.you_are_about_to_purchase_a_subscription_to_NAME' }}

-
+
+
+ + +