mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
interface to set credits for spaces
This commit is contained in:
parent
ec4a06a0e4
commit
36a0eafef3
@ -3,8 +3,8 @@
|
||||
##
|
||||
# Controller used in the prices edition page
|
||||
##
|
||||
Application.Controllers.controller "EditPricingController", ["$scope", "$state", '$uibModal', '$filter', 'TrainingsPricing', 'Credit', 'Pricing', 'Plan', 'Coupon', 'plans', 'groups', 'growl', 'machinesPricesPromise', 'Price', 'dialogs', 'trainingsPricingsPromise', 'trainingsPromise', 'machineCreditsPromise', 'machinesPromise', 'trainingCreditsPromise', 'couponsPromise', 'spacesPromise', 'spacesPricesPromise', '_t'
|
||||
, ($scope, $state, $uibModal, $filter, TrainingsPricing, Credit, Pricing, Plan, Coupon, plans, groups, growl, machinesPricesPromise, Price, dialogs, trainingsPricingsPromise, trainingsPromise, machineCreditsPromise, machinesPromise, trainingCreditsPromise, couponsPromise, spacesPromise, spacesPricesPromise, _t) ->
|
||||
Application.Controllers.controller "EditPricingController", ["$scope", "$state", '$uibModal', '$filter', 'TrainingsPricing', 'Credit', 'Pricing', 'Plan', 'Coupon', 'plans', 'groups', 'growl', 'machinesPricesPromise', 'Price', 'dialogs', 'trainingsPricingsPromise', 'trainingsPromise', 'machineCreditsPromise', 'machinesPromise', 'trainingCreditsPromise', 'couponsPromise', 'spacesPromise', 'spacesPricesPromise', 'spacesCreditsPromise', '_t'
|
||||
, ($scope, $state, $uibModal, $filter, TrainingsPricing, Credit, Pricing, Plan, Coupon, plans, groups, growl, machinesPricesPromise, Price, dialogs, trainingsPricingsPromise, trainingsPromise, machineCreditsPromise, machinesPromise, trainingCreditsPromise, couponsPromise, spacesPromise, spacesPricesPromise, spacesCreditsPromise, _t) ->
|
||||
|
||||
### PUBLIC SCOPE ###
|
||||
## List of machines prices (not considering any plan)
|
||||
@ -40,6 +40,9 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
|
||||
## List of spaces
|
||||
$scope.spaces = spacesPromise
|
||||
|
||||
## Associate free space hours with subscriptions
|
||||
$scope.spaceCredits = spacesCreditsPromise
|
||||
|
||||
## List of spaces prices (not considering any plan)
|
||||
$scope.spacesPrices = spacesPricesPromise
|
||||
|
||||
@ -185,9 +188,14 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
|
||||
$scope.showCreditableName = (credit) ->
|
||||
selected = _t('pricing.not_set')
|
||||
if credit and credit.creditable_id
|
||||
angular.forEach $scope.machines, (m)->
|
||||
if m.id == credit.creditable_id
|
||||
selected = m.name+' ( id. '+m.id+' )'
|
||||
if credit.creditable_type == 'Machine'
|
||||
angular.forEach $scope.machines, (m)->
|
||||
if m.id == credit.creditable_id
|
||||
selected = m.name + ' ( id. ' + m.id + ' )'
|
||||
else if credit.creditable_type == 'Space'
|
||||
angular.forEach $scope.spaces, (s)->
|
||||
if s.id == credit.creditable_id
|
||||
selected = s.name
|
||||
return selected
|
||||
|
||||
|
||||
@ -221,7 +229,7 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
|
||||
##
|
||||
# Removes the newly inserted but not saved machine credit / Cancel the current machine credit modification
|
||||
# @param rowform {Object} see http://vitalets.github.io/angular-xeditable/
|
||||
# @param index {number} theme index in the $scope.machineCredits array
|
||||
# @param index {number} credit index in the $scope.machineCredits array
|
||||
##
|
||||
$scope.cancelMachineCredit = (rowform, index) ->
|
||||
if $scope.machineCredits[index].id?
|
||||
@ -241,6 +249,70 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Create a new empty entry in the $scope.spaceCredits array
|
||||
# @param e {Object} see https://docs.angularjs.org/guide/expression#-event-
|
||||
##
|
||||
$scope.addSpaceCredit = (e)->
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
$scope.inserted =
|
||||
creditable_type: 'Space'
|
||||
$scope.spaceCredits.push($scope.inserted)
|
||||
$scope.status.isopen = !$scope.status.isopen
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Validation callback when editing space's credits. Save the changes.
|
||||
# This will prevent the creation of two credits associated with the same space and plan.
|
||||
# @param data {Object} space, associated plan and number of credit hours.
|
||||
# @param [id] {number} credit id for edition, create a new credit object if not provided
|
||||
##
|
||||
$scope.saveSpaceCredit = (data, id) ->
|
||||
for sc in $scope.spaceCredits
|
||||
if sc.plan_id == data.plan_id and sc.creditable_id == data.creditable_id and (id == null or sc.id != id)
|
||||
growl.error(_t('pricing.error_a_credit_linking_this_space_with_that_subscription_already_exists'))
|
||||
unless id
|
||||
$scope.spaceCredits.pop()
|
||||
return false
|
||||
|
||||
if id?
|
||||
Credit.update {id: id}, credit: data, ->
|
||||
growl.success(_t('pricing.changes_have_been_successfully_saved'))
|
||||
else
|
||||
data.creditable_type = 'Space'
|
||||
Credit.save
|
||||
credit: data
|
||||
, (resp) ->
|
||||
$scope.spaceCredits[$scope.spaceCredits.length - 1].id = resp.id
|
||||
growl.success(_t('pricing.credit_was_successfully_saved'))
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Removes the newly inserted but not saved space credit / Cancel the current space credit modification
|
||||
# @param rowform {Object} see http://vitalets.github.io/angular-xeditable/
|
||||
# @param index {number} credit index in the $scope.spaceCredits array
|
||||
##
|
||||
$scope.cancelSpaceCredit = (rowform, index) ->
|
||||
if $scope.spaceCredits[index].id?
|
||||
rowform.$cancel()
|
||||
else
|
||||
$scope.spaceCredits.splice(index, 1)
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Deletes the space credit at the specified index
|
||||
# @param index {number} space credit index in the $scope.spaceCredits array
|
||||
##
|
||||
$scope.removeSpaceCredit = (index) ->
|
||||
Credit.delete $scope.spaceCredits[index]
|
||||
$scope.spaceCredits.splice(index, 1)
|
||||
|
||||
|
||||
|
||||
##
|
||||
# If the plan does not have a type, return a default value for display purposes
|
||||
# @param type {string|undefined|null} plan's type (eg. 'partner')
|
||||
|
@ -830,6 +830,9 @@ angular.module('application.router', ['ui.router']).
|
||||
spacesPricesPromise: ['Price', (Price)->
|
||||
Price.query(priceable_type: 'Space', plan_id: 'null').$promise
|
||||
]
|
||||
spacesCreditsPromise: ['Credit', (Credit) ->
|
||||
Credit.query({creditable_type: 'Space'}).$promise
|
||||
]
|
||||
|
||||
# plans
|
||||
.state 'app.admin.plans',
|
||||
|
@ -94,4 +94,56 @@
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2 class="m-t-lg" translate>{{ 'pricing.spaces' }}</h2>
|
||||
<div class="btn-group m-t-md m-b-md">
|
||||
<button type="button" class="btn btn-warning" ng-click="addSpaceCredit($event)" translate>{{ 'pricing.add_a_space_credit' }}</button>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:20%" translate>{{ 'pricing.space' }}</th>
|
||||
<th style="width:10%" translate>{{ 'pricing.hours' }}</th>
|
||||
<th style="width:50%" translate>{{ 'pricing.related_subscriptions' }}</th>
|
||||
<th style="width:20%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="sc in spaceCredits">
|
||||
<td>
|
||||
<span editable-select="sc.creditable_id" e-name="creditable_id" e-form="rowform" e-ng-options="s.id as s.name for s in spaces" e-required>
|
||||
{{ showCreditableName(sc) }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span editable-number="sc.hours" e-name="hours" e-form="rowform" e-required>
|
||||
{{ sc.hours }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span editable-select="sc.plan_id" e-ng-options="p.id as humanReadablePlanName(p, groups, 'short') for p in plans" e-name="plan_id" e-form="rowform">
|
||||
{{ getPlanFromId(sc.plan_id) | humanReadablePlanName: groups: 'short' }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<form editable-form name="rowform" onbeforesave="saveSpaceCredit($data, sc.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == sc">
|
||||
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-warning">
|
||||
<i class="fa fa-check"></i>
|
||||
</button>
|
||||
<button type="button" ng-disabled="rowform.$waiting" ng-click="cancelSpaceCredit(rowform, $index)" class="btn btn-default">
|
||||
<i class="fa fa-times"></i>
|
||||
</button>
|
||||
</form>
|
||||
<div class="buttons" ng-show="!rowform.$visible">
|
||||
<button class="btn btn-default" ng-click="rowform.$show()">
|
||||
<i class="fa fa-edit"></i> {{ 'edit' | translate }}
|
||||
</button>
|
||||
<button class="btn btn-danger" ng-click="removeSpaceCredit($index)">
|
||||
<i class="fa fa-trash-o"></i> {{ 'delete' | translate }} (!)
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
@ -201,6 +201,9 @@ en:
|
||||
valid_until: "Valid until (included)"
|
||||
spaces: "Spaces"
|
||||
these_prices_match_space_hours_rates_: "These prices match space hours rates"
|
||||
add_a_space_credit: "Add a Space credit"
|
||||
space: "Espace"
|
||||
error_a_credit_linking_this_space_with_that_subscription_already_exists: "Error : a credit linking this space with that subscription already exists."
|
||||
|
||||
coupons_new:
|
||||
# ajouter un code promotionnel
|
||||
|
@ -201,6 +201,9 @@ fr:
|
||||
valid_until: "Valable jusqu'au (inclus)"
|
||||
spaces: "Espaces"
|
||||
these_prices_match_space_hours_rates_: "Ces tarifs correspondent au prix d'une heure espace"
|
||||
add_a_space_credit: "Ajouter un crédit Espace"
|
||||
space: "Espace"
|
||||
error_a_credit_linking_this_space_with_that_subscription_already_exists: "Erreur : un crédit associant cet espace et cet abonnement existe déjà."
|
||||
|
||||
coupons_new:
|
||||
# ajouter un code promotionnel
|
||||
|
Loading…
x
Reference in New Issue
Block a user