mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
fix ERB JS directives
This commit is contained in:
parent
cfedb643b5
commit
0814f8c2fa
@ -11,8 +11,8 @@
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs', 'growl', 'Auth', 'Price', 'Wallet', 'CustomAsset', 'Slot', 'helpers', '_t',
|
||||
($rootScope, $uibModal, dialogs, growl, Auth, Price, Wallet, CustomAsset, Slot, helpers, _t) =>
|
||||
({
|
||||
function ($rootScope, $uibModal, dialogs, growl, Auth, Price, Wallet, CustomAsset, Slot, helpers, _t) {
|
||||
return ({
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
slot: '=',
|
||||
@ -49,8 +49,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
$scope.totalNoCoupon = 0
|
||||
|
||||
// Discount coupon to apply to the basket, if any
|
||||
$scope.coupon =
|
||||
{ applied: null }
|
||||
$scope.coupon = { applied: null }
|
||||
|
||||
// Global config: is the user authorized to change his bookings slots?
|
||||
$scope.enableBookingMove = ($scope.settings.booking_move_enable === 'true')
|
||||
@ -146,7 +145,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
/**
|
||||
* When modifying an already booked reservation, confirm the modification.
|
||||
*/
|
||||
$scope.modifySlot = () =>
|
||||
$scope.modifySlot = function () {
|
||||
Slot.update({ id: $scope.events.modifiable.id }, {
|
||||
slot: {
|
||||
start_at: $scope.events.placable.start,
|
||||
@ -170,6 +169,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
growl.error(_t('cart.unable_to_change_the_reservation'))
|
||||
return console.error(err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the current booking modification, reseting the whole process
|
||||
@ -210,7 +210,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
* Check if the currently logged user has teh 'admin' role?
|
||||
* @returns {boolean}
|
||||
*/
|
||||
$scope.isAdmin = () => $rootScope.currentUser && ($rootScope.currentUser.role === 'admin')
|
||||
$scope.isAdmin = function() { return $rootScope.currentUser && ($rootScope.currentUser.role === 'admin') }
|
||||
|
||||
/* PRIVATE SCOPE */
|
||||
|
||||
@ -218,7 +218,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
* Kind of constructor: these actions will be realized first when the directive is loaded
|
||||
*/
|
||||
const initialize = function () {
|
||||
// What the binded slot
|
||||
// What the bound slot
|
||||
$scope.$watch('slotSelectionTime', function (newValue, oldValue) {
|
||||
if (newValue !== oldValue) {
|
||||
return slotSelectionChanged()
|
||||
@ -303,7 +303,8 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
if (typeof $scope.onSlotStartToModify === 'function') { $scope.onSlotStartToModify() }
|
||||
return $scope.events.modifiable = $scope.slot
|
||||
} else if (type === 'cancel') {
|
||||
return dialogs.confirm({
|
||||
return dialogs.confirm(
|
||||
{
|
||||
resolve: {
|
||||
object () {
|
||||
return {
|
||||
@ -312,15 +313,16 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
, () => // cancel confirmed
|
||||
},
|
||||
function () { // cancel confirmed
|
||||
Slot.cancel({ id: $scope.slot.id }, function () { // successfully canceled
|
||||
growl.success(_t('cart.reservation_was_cancelled_successfully'))
|
||||
if (typeof $scope.onSlotCancelSuccess === 'function') { return $scope.onSlotCancelSuccess() }
|
||||
}
|
||||
, () => // error while canceling
|
||||
, function() { // error while canceling
|
||||
growl.error(_t('cart.cancellation_failed'))
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
@ -407,15 +409,16 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
}
|
||||
}
|
||||
|
||||
var setSlotsDetails = details =>
|
||||
angular.forEach($scope.events.reserved, slot =>
|
||||
var setSlotsDetails = function (details) {
|
||||
angular.forEach($scope.events.reserved, function (slot) {
|
||||
angular.forEach(details.slots, function (s) {
|
||||
if (moment(s.start_at).isSame(slot.start)) {
|
||||
slot.promo = s.promo
|
||||
return slot.price = s.price
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the parameters expected by /api/prices/compute or /api/reservations and return the resulting object
|
||||
@ -424,22 +427,20 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
* @return {{reservation:Object, coupon_code:string}}
|
||||
*/
|
||||
var mkRequestParams = function (reservation, coupon) {
|
||||
const params = {
|
||||
return {
|
||||
reservation,
|
||||
coupon_code: ((coupon ? coupon.code : undefined))
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an hash map implementing the Reservation specs
|
||||
* @param member {Object} User as retreived from the API: current user / selected user if current is admin
|
||||
* @param member {Object} User as retrieved from the API: current user / selected user if current is admin
|
||||
* @param slots {Array<Object>} Array of fullCalendar events: slots selected on the calendar
|
||||
* @param [plan] {Object} Plan as retrived from the API: plan to buy with the current reservation
|
||||
* @param [plan] {Object} Plan as retrieved from the API: plan to buy with the current reservation
|
||||
* @return {{user_id:Number, reservable_id:Number, reservable_type:String, slots_attributes:Array<Object>, plan_id:Number|null}}
|
||||
*/
|
||||
var mkReservation = function (member, slots, plan = null) {
|
||||
var mkReservation = function (member, slots, plan) {
|
||||
const reservation = {
|
||||
user_id: member.id,
|
||||
reservable_id: $scope.reservableId,
|
||||
@ -447,14 +448,14 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
slots_attributes: [],
|
||||
plan_id: ((plan ? plan.id : undefined))
|
||||
}
|
||||
angular.forEach(slots, (slot, key) =>
|
||||
angular.forEach(slots, function (slot, key) {
|
||||
reservation.slots_attributes.push({
|
||||
start_at: slot.start,
|
||||
end_at: slot.end,
|
||||
availability_id: slot.availability_id,
|
||||
offered: slot.offered || false
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
return reservation
|
||||
}
|
||||
@ -462,7 +463,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
/**
|
||||
* Open a modal window that allows the user to process a credit card payment for his current shopping cart.
|
||||
*/
|
||||
var payByStripe = reservation =>
|
||||
var payByStripe = function (reservation) {
|
||||
$uibModal.open({
|
||||
templateUrl: '<%= asset_path "stripe/payment_modal.html" %>',
|
||||
size: 'md',
|
||||
@ -503,14 +504,16 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
/**
|
||||
* Callback to process the payment with Stripe, triggered on button click
|
||||
*/
|
||||
return $scope.payment = function (status, response) {
|
||||
$scope.payment = function (status, response) {
|
||||
if (response.error) {
|
||||
return growl.error(response.error.message)
|
||||
growl.error(response.error.message)
|
||||
} else {
|
||||
$scope.attempting = true
|
||||
$scope.reservation.card_token = response.id
|
||||
return Reservation.save(mkRequestParams($scope.reservation, coupon), reservation => $uibModalInstance.close(reservation)
|
||||
, function (response) {
|
||||
Reservation.save(
|
||||
mkRequestParams($scope.reservation, coupon),
|
||||
function(reservation) { $uibModalInstance.close(reservation) },
|
||||
function (response) {
|
||||
$scope.alerts = []
|
||||
if (response.status === 500) {
|
||||
$scope.alerts.push({
|
||||
@ -531,17 +534,18 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
}
|
||||
}
|
||||
return $scope.attempting = false
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
] })
|
||||
.result['finally'](null).then(reservation => afterPayment(reservation))
|
||||
|
||||
]
|
||||
}).result['finally'](null).then(function (reservation) { afterPayment(reservation) })
|
||||
}
|
||||
/**
|
||||
* Open a modal window that allows the user to process a local payment for his current shopping cart (admin only).
|
||||
*/
|
||||
var payOnSite = reservation =>
|
||||
var payOnSite = function (reservation) {
|
||||
$uibModal.open({
|
||||
templateUrl: '<%= asset_path "shared/valid_reservation_modal.html" %>',
|
||||
size: 'sm',
|
||||
@ -602,11 +606,11 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
return $scope.attempting = false
|
||||
})
|
||||
}
|
||||
return $scope.cancel = () => $uibModalInstance.dismiss('cancel')
|
||||
$scope.cancel = function() { $uibModalInstance.dismiss('cancel') }
|
||||
}
|
||||
]
|
||||
}).result['finally'](null).then(function(reservation) { afterPayment(reservation) })
|
||||
}
|
||||
] })
|
||||
.result['finally'](null).then(reservation => afterPayment(reservation))
|
||||
|
||||
/**
|
||||
* Actions to run after the payment was successfull
|
||||
*/
|
||||
@ -626,5 +630,5 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
return initialize()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
])
|
||||
|
@ -9,8 +9,8 @@
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
Application.Directives.directive('coupon', [ '$rootScope', 'Coupon', '_t', ($rootScope, Coupon, _t) =>
|
||||
({
|
||||
Application.Directives.directive('coupon', [ '$rootScope', 'Coupon', '_t', function ($rootScope, Coupon, _t) {
|
||||
return ({
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
show: '=',
|
||||
@ -69,8 +69,7 @@ Application.Directives.directive('coupon', [ '$rootScope', 'Coupon', '_t', ($roo
|
||||
/**
|
||||
* Callback to remove the message at provided index from the displayed list
|
||||
*/
|
||||
return $scope.closeMessage = index => $scope.messages.splice(index, 1)
|
||||
$scope.closeMessage = function (index) { $scope.messages.splice(index, 1) }
|
||||
}
|
||||
})
|
||||
|
||||
])
|
||||
}])
|
||||
|
@ -8,8 +8,8 @@
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
Application.Directives.directive('fabUserAvatar', [ () =>
|
||||
({
|
||||
Application.Directives.directive('fabUserAvatar', [ function() {
|
||||
return ({
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
userAvatar: '=ngModel',
|
||||
@ -18,4 +18,4 @@ Application.Directives.directive('fabUserAvatar', [ () =>
|
||||
templateUrl: '<%= asset_path "shared/_user_avatar.html" %>'
|
||||
})
|
||||
|
||||
])
|
||||
}])
|
||||
|
@ -19,8 +19,8 @@
|
||||
* which have a valid running subscription or not.
|
||||
* Usage: <select-member [subscription="false|true"]></select-member>
|
||||
*/
|
||||
Application.Directives.directive('selectMember', [ 'Diacritics', 'Member', (Diacritics, Member) =>
|
||||
({
|
||||
Application.Directives.directive('selectMember', [ 'Diacritics', 'Member', function (Diacritics, Member) {
|
||||
return ({
|
||||
restrict: 'E',
|
||||
templateUrl: '<%= asset_path "shared/_member_select.html" %>',
|
||||
link (scope, element, attributes) {
|
||||
@ -40,10 +40,10 @@ Application.Directives.directive('selectMember', [ 'Diacritics', 'Member', (Diac
|
||||
scope.matchingMembers = users
|
||||
return scope.isLoadingMembers = false
|
||||
}
|
||||
, error => console.error(error))
|
||||
, function (error) { console.error(error) })
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
])
|
||||
}])
|
||||
|
@ -9,8 +9,8 @@
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
Application.Directives.directive('socialLink', [ () =>
|
||||
({
|
||||
Application.Directives.directive('socialLink', [ function() {
|
||||
return ({
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
network: '@?',
|
||||
@ -34,4 +34,4 @@ Application.Directives.directive('socialLink', [ () =>
|
||||
}
|
||||
})
|
||||
|
||||
])
|
||||
}])
|
||||
|
Loading…
x
Reference in New Issue
Block a user