1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

disable required training modal for machines associated with disabled trainings

This commit is contained in:
Sylvain 2017-10-10 18:12:07 +02:00
parent 4090fe2119
commit 4752fce762
2 changed files with 31 additions and 23 deletions

View File

@ -108,32 +108,40 @@ _reserveMachine = (machine, e) ->
$uibModalInstance.dismiss('cancel')
]
# ... but does not have booked the training, tell him to register for a training session first
# unless all associated trainings are disabled
else
_this.$uibModal.open
templateUrl: '<%= asset_path "machines/request_training_modal.html" %>'
controller: ['$scope', '$uibModalInstance', '$state', ($scope, $uibModalInstance, $state) ->
$scope.machine = machine
$scope.member = _this.$scope.currentUser
# if all trainings are disabled, just redirect the user to the reservation calendar
if machine.trainings.map((t) -> t.disabled).reduce(((acc, val) -> acc && val), true)
_this.$state.go('app.logged.machines_reserve', {id: machine.slug})
# otherwise open the information modal
else
_this.$uibModal.open
templateUrl: '<%= asset_path "machines/request_training_modal.html" %>'
controller: ['$scope', '$uibModalInstance', '$state', ($scope, $uibModalInstance, $state) ->
$scope.machine = machine
$scope.member = _this.$scope.currentUser
# transform the name of the trainings associated with the machine to integrate them in a sentence
$scope.humanizeTrainings = ->
text = ''
angular.forEach $scope.machine.trainings, (training) ->
if text.length > 0
text += _this._t('_or_the_')
text += training.name.substr(0,1).toLowerCase() + training.name.substr(1)
text
# transform the name of the trainings associated with the machine to integrate them in a sentence
$scope.humanizeTrainings = ->
text = ''
angular.forEach $scope.machine.trainings, (training) ->
if text.length > 0
text += _this._t('_or_the_')
text += training.name.substr(0,1).toLowerCase() + training.name.substr(1)
text
# modal is closed with validation
$scope.ok = ->
$state.go('app.logged.trainings_reserve', {id: $scope.machine.trainings[0].id})
$uibModalInstance.close(machine)
# modal is closed with escaping
$scope.cancel = (e)->
e.preventDefault()
$uibModalInstance.dismiss('cancel')
]
# modal is close with validation
$scope.ok = ->
$state.go('app.logged.trainings_reserve', {id: $scope.machine.trainings[0].id})
$uibModalInstance.close(machine)
# modal is closed with escaping
$scope.cancel = (e)->
e.preventDefault()
$uibModalInstance.dismiss('cancel')
]
# if the user is not logged, open the login modal window
else
_this.$scope.login()

View File

@ -5,7 +5,7 @@ json.machine_files_attributes @machine.machine_files do |f|
json.attachment f.attachment_identifier
json.attachment_url f.attachment_url
end
json.trainings @machine.trainings.each, :id, :name
json.trainings @machine.trainings.each, :id, :name, :disabled
json.current_user_is_training current_user.is_training_machine?(@machine) if current_user
json.current_user_training_reservation do
json.partial! 'api/reservations/reservation', reservation: current_user.training_reservation_by_machine(@machine)