2018-10-25 16:51:20 +02:00
|
|
|
/* eslint-disable
|
|
|
|
handle-callback-err,
|
|
|
|
no-return-assign,
|
|
|
|
no-self-compare,
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2018-10-25 16:50:16 +02:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* COMMON CODE */
|
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Provides a set of common callback methods to the $scope parameter. These methods are used
|
|
|
|
* in the various spaces' admin controllers.
|
|
|
|
*
|
|
|
|
* Provides :
|
|
|
|
* - $scope.submited(content)
|
|
|
|
* - $scope.cancel()
|
|
|
|
* - $scope.fileinputClass(v)
|
|
|
|
* - $scope.addFile()
|
|
|
|
* - $scope.deleteFile(file)
|
|
|
|
*
|
|
|
|
* Requires :
|
|
|
|
* - $scope.space.space_files_attributes = []
|
|
|
|
* - $state (Ui-Router) [ 'app.public.spaces_list' ]
|
2018-11-19 16:52:48 +01:00
|
|
|
*/
|
2018-10-25 16:50:16 +02:00
|
|
|
class SpacesController {
|
2018-10-25 16:51:20 +02:00
|
|
|
constructor ($scope, $state) {
|
2018-11-19 16:17:49 +01:00
|
|
|
/*
|
|
|
|
* For use with ngUpload (https://github.com/twilson63/ngUpload).
|
|
|
|
* Intended to be the callback when the upload is done: any raised error will be stacked in the
|
|
|
|
* $scope.alerts array. If everything goes fine, the user is redirected to the spaces list.
|
|
|
|
* @param content {Object} JSON - The upload's result
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.submited = function (content) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ((content.id == null)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.alerts = [];
|
2018-11-20 12:26:06 +01:00
|
|
|
angular.forEach(content, function (v, k) {
|
|
|
|
angular.forEach(v, function (err) {
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.alerts.push({
|
2018-10-25 16:51:20 +02:00
|
|
|
msg: k + ': ' + err,
|
2017-02-14 11:28:07 +01:00
|
|
|
type: 'danger'
|
2018-11-21 11:08:53 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-25 16:50:16 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
$state.go('app.public.spaces_list');
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Changes the current user's view, redirecting him to the spaces list
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.cancel = function () { $state.go('app.public.spaces_list'); };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* For use with 'ng-class', returns the CSS class name for the uploads previews.
|
|
|
|
* The preview may show a placeholder or the content of the file depending on the upload state.
|
|
|
|
* @param v {*} any attribute, will be tested for truthiness (see JS evaluation rules)
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.fileinputClass = function (v) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if (v) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return 'fileinput-exists';
|
2018-10-25 16:50:16 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return 'fileinput-new';
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
2018-11-20 12:26:06 +01:00
|
|
|
* This will create a single new empty entry into the space attachments list.
|
2018-11-19 16:17:49 +01:00
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.addFile = function () { $scope.space.space_files_attributes.push({}); };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
2018-11-20 12:26:06 +01:00
|
|
|
* This will remove the given file from the space attachments list. If the file was previously uploaded
|
2018-11-19 16:17:49 +01:00
|
|
|
* to the server, it will be marked for deletion on the server. Otherwise, it will be simply truncated from
|
2018-11-20 12:26:06 +01:00
|
|
|
* the attachments array.
|
2018-11-19 16:17:49 +01:00
|
|
|
* @param file {Object} the file to delete
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.deleteFile = function (file) {
|
2018-11-21 11:08:53 +01:00
|
|
|
const index = $scope.space.space_files_attributes.indexOf(file);
|
2018-10-25 16:50:16 +02:00
|
|
|
if (file.id != null) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return file._destroy = true;
|
2018-10-25 16:50:16 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.space.space_files_attributes.splice(index, 1);
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Controller used in the public listing page, allowing everyone to see the list of spaces
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
Application.Controllers.controller('SpacesController', ['$scope', '$state', 'spacesPromise', function ($scope, $state, spacesPromise) {
|
2018-11-19 16:17:49 +01:00
|
|
|
// Retrieve the list of spaces
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.spaces = spacesPromise;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Redirect the user to the space details page
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.showSpace = function (space) { $state.go('app.public.space_show', { id: space.slug }); };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Callback to book a reservation for the current space
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.reserveSpace = function (space) { $state.go('app.logged.space_reserve', { id: space.slug }); };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Default: we show only enabled spaces
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.spaceFiltering = 'enabled';
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Available options for filtering spaces by status
|
2018-11-20 12:26:06 +01:00
|
|
|
$scope.filterDisabled = [
|
2017-10-11 15:15:30 +02:00
|
|
|
'enabled',
|
|
|
|
'disabled',
|
2018-10-25 16:51:20 +02:00
|
|
|
'all'
|
2018-11-21 11:08:53 +01:00
|
|
|
];
|
|
|
|
}]);
|
2017-02-13 17:18:06 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Controller used in the space creation page (admin)
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
Application.Controllers.controller('NewSpaceController', ['$scope', '$state', 'CSRF', function ($scope, $state, CSRF) {
|
2018-11-21 11:08:53 +01:00
|
|
|
CSRF.setMetaTags();
|
2017-02-13 17:18:06 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// API URL where the form will be posted
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.actionUrl = '/api/spaces/';
|
2017-02-13 17:18:06 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Form action on the above URL
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.method = 'post';
|
2017-02-13 17:18:06 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// default space parameters
|
2017-02-13 17:18:06 +01:00
|
|
|
$scope.space =
|
2018-11-21 11:08:53 +01:00
|
|
|
{ space_files_attributes: [] };
|
2017-02-13 17:18:06 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Using the SpacesController
|
2018-11-21 11:08:53 +01:00
|
|
|
return new SpacesController($scope, $state);
|
|
|
|
}]);
|
2017-02-14 13:36:10 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Controller used in the space edition page (admin)
|
|
|
|
*/
|
2018-11-20 14:44:41 +01:00
|
|
|
Application.Controllers.controller('EditSpaceController', ['$scope', '$state', '$stateParams', 'spacePromise', 'CSRF',
|
|
|
|
function ($scope, $state, $stateParams, spacePromise, CSRF) {
|
2018-11-21 11:08:53 +01:00
|
|
|
CSRF.setMetaTags();
|
2017-02-14 13:36:10 +01:00
|
|
|
|
2018-11-21 10:59:07 +01:00
|
|
|
// API URL where the form will be posted
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.actionUrl = `/api/spaces/${$stateParams.id}`;
|
2017-02-14 13:36:10 +01:00
|
|
|
|
2018-11-21 10:59:07 +01:00
|
|
|
// Form action on the above URL
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.method = 'put';
|
2017-02-14 13:36:10 +01:00
|
|
|
|
2018-11-21 10:59:07 +01:00
|
|
|
// space to modify
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.space = spacePromise;
|
2017-02-14 13:36:10 +01:00
|
|
|
|
2018-11-21 10:59:07 +01:00
|
|
|
// Using the SpacesController
|
2018-11-21 11:08:53 +01:00
|
|
|
return new SpacesController($scope, $state);
|
|
|
|
}]);
|
2017-02-14 13:36:10 +01:00
|
|
|
|
2018-11-20 14:44:41 +01:00
|
|
|
Application.Controllers.controller('ShowSpaceController', ['$scope', '$state', 'spacePromise', '_t', 'dialogs', 'growl',
|
|
|
|
function ($scope, $state, spacePromise, _t, dialogs, growl) {
|
2018-11-19 16:17:49 +01:00
|
|
|
// Details of the space witch id/slug is provided in the URL
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.space = spacePromise;
|
2017-02-14 12:41:51 +01:00
|
|
|
|
2018-11-21 10:59:07 +01:00
|
|
|
/**
|
2018-11-19 16:17:49 +01:00
|
|
|
* Callback to book a reservation for the current space
|
|
|
|
* @param event {Object} see https://docs.angularjs.org/guide/expression#-event-
|
|
|
|
*/
|
2018-11-21 10:59:07 +01:00
|
|
|
$scope.reserveSpace = function (event) {
|
2018-11-21 11:08:53 +01:00
|
|
|
event.preventDefault();
|
|
|
|
return $state.go('app.logged.space_reserve', { id: $scope.space.slug });
|
|
|
|
};
|
2017-02-14 12:41:51 +01:00
|
|
|
|
2018-11-21 10:59:07 +01:00
|
|
|
/**
|
2018-11-19 16:17:49 +01:00
|
|
|
* Callback to book a reservation for the current space
|
|
|
|
* @param event {Object} see https://docs.angularjs.org/guide/expression#-event-
|
|
|
|
*/
|
2018-11-21 10:59:07 +01:00
|
|
|
$scope.deleteSpace = function (event) {
|
2018-11-21 11:08:53 +01:00
|
|
|
event.preventDefault();
|
2018-11-21 10:59:07 +01:00
|
|
|
// check the permissions
|
|
|
|
if ($scope.currentUser.role !== 'admin') {
|
2018-11-21 11:08:53 +01:00
|
|
|
return console.error(_t('space_show.unauthorized_operation'));
|
2018-11-21 10:59:07 +01:00
|
|
|
} else {
|
|
|
|
return dialogs.confirm({
|
|
|
|
resolve: {
|
|
|
|
object () {
|
|
|
|
return {
|
2019-12-16 16:54:40 +01:00
|
|
|
title: _t('app.public.space_show.confirmation_required'),
|
|
|
|
msg: _t('app.public.space_show.do_you_really_want_to_delete_this_space')
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 10:59:07 +01:00
|
|
|
, function () { // deletion confirmed
|
2018-10-25 16:50:16 +02:00
|
|
|
// delete the machine then redirect to the machines listing
|
2018-11-21 10:59:07 +01:00
|
|
|
$scope.space.$delete(
|
|
|
|
function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
$state.go('app.public.spaces_list');
|
2018-11-21 10:59:07 +01:00
|
|
|
},
|
|
|
|
function (error) {
|
2019-12-16 16:54:40 +01:00
|
|
|
growl.warning(_t('app.public.space_show.the_space_cant_be_deleted_because_it_is_already_reserved_by_some_users'));
|
2018-11-21 11:08:53 +01:00
|
|
|
console.error(error);
|
2018-11-21 10:59:07 +01:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
);
|
|
|
|
});
|
2018-11-21 10:59:07 +01:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
|
|
|
}]);
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Controller used in the spaces reservation agenda page.
|
|
|
|
* This controller is very similar to the machine reservation controller with one major difference: here, there is many places
|
|
|
|
* per slots.
|
|
|
|
*/
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
Application.Controllers.controller('ReserveSpaceController', ['$scope', '$stateParams', 'Auth', '$timeout', 'Availability', 'Member', 'availabilitySpacesPromise', 'plansPromise', 'groupsPromise', 'settingsPromise', 'spacePromise', '_t', 'uiCalendarConfig', 'CalendarConfig',
|
|
|
|
function ($scope, $stateParams, Auth, $timeout, Availability, Member, availabilitySpacesPromise, plansPromise, groupsPromise, settingsPromise, spacePromise, _t, uiCalendarConfig, CalendarConfig) {
|
2018-10-25 16:50:16 +02:00
|
|
|
/* PRIVATE STATIC CONSTANTS */
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
// Color of the selected event backgound
|
2018-11-21 11:08:53 +01:00
|
|
|
const SELECTED_EVENT_BG_COLOR = '#ffdd00';
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
// Slot free to be booked
|
2018-11-21 11:08:53 +01:00
|
|
|
const FREE_SLOT_BORDER_COLOR = '<%= AvailabilityHelper::SPACE_COLOR %>';
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
// Slot with reservation from current user
|
2018-11-21 11:08:53 +01:00
|
|
|
const RESERVED_SLOT_BORDER_COLOR = '<%= AvailabilityHelper::IS_RESERVED_BY_CURRENT_USER %>';
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
/* PUBLIC SCOPE */
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// bind the spaces availabilities with full-Calendar events
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.eventSources = [ { events: availabilitySpacesPromise, textColor: 'black' } ];
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// the user to deal with, ie. the current user for non-admins
|
2017-02-23 17:45:55 +01:00
|
|
|
$scope.ctrl =
|
2018-11-21 11:08:53 +01:00
|
|
|
{ member: {} };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// list of plans, classified by group
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.plansClassifiedByGroup = [];
|
2018-10-25 16:50:16 +02:00
|
|
|
for (let group of Array.from(groupsPromise)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
const groupObj = { id: group.id, name: group.name, plans: [] };
|
2018-10-25 16:50:16 +02:00
|
|
|
for (let plan of Array.from(plansPromise)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
if (plan.group_id === group.id) { groupObj.plans.push(plan); }
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.plansClassifiedByGroup.push(groupObj);
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// mapping of fullCalendar events.
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.events = {
|
|
|
|
reserved: [], // Slots that the user wants to book
|
|
|
|
modifiable: null, // Slot that the user wants to change
|
|
|
|
placable: null, // Destination slot for the change
|
|
|
|
paid: [], // Slots that were just booked by the user (transaction ok)
|
|
|
|
moved: null // Slots that were just moved by the user (change done) -> {newSlot:* oldSlot: *}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// the moment when the slot selection changed for the last time, used to trigger changes in the cart
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectionTime = null;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// the last clicked event in the calender
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedEvent = null;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// indicates the state of the current view : calendar or plans information
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.plansAreShown = false;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// will store the user's plan if he choosed to buy one
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedPlan = null;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// the moment when the plan selection changed for the last time, used to trigger changes in the cart
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.planSelectionTime = null;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Selected space
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.space = spacePromise;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// fullCalendar (v2) configuration
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.calendarConfig = CalendarConfig({
|
|
|
|
minTime: moment.duration(moment(settingsPromise.booking_window_start).format('HH:mm:ss')),
|
|
|
|
maxTime: moment.duration(moment(settingsPromise.booking_window_end).format('HH:mm:ss')),
|
2018-10-25 16:51:20 +02:00
|
|
|
eventClick (event, jsEvent, view) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return calendarEventClickCb(event, jsEvent, view);
|
2018-10-25 16:50:16 +02:00
|
|
|
},
|
2018-10-25 16:51:20 +02:00
|
|
|
eventRender (event, element, view) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return eventRenderCb(event, element, view);
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
});
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Application global settings
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.settings = settingsPromise;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Global config: message to the end user concerning the subscriptions rules
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.subscriptionExplicationsAlert = settingsPromise.subscription_explications_alert;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// Global config: message to the end user concerning the space reservation
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.spaceExplicationsAlert = settingsPromise.space_explications_alert;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Change the last selected slot's appearence to looks like 'added to cart'
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.markSlotAsAdded = function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedEvent.backgroundColor = SELECTED_EVENT_BG_COLOR;
|
|
|
|
return updateCalendar();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Change the last selected slot's appearence to looks like 'never added to cart'
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.markSlotAsRemoved = function (slot) {
|
2018-11-21 11:08:53 +01:00
|
|
|
slot.backgroundColor = 'white';
|
|
|
|
slot.title = '';
|
|
|
|
slot.borderColor = FREE_SLOT_BORDER_COLOR;
|
|
|
|
slot.id = null;
|
|
|
|
slot.isValid = false;
|
|
|
|
slot.is_reserved = false;
|
|
|
|
slot.can_modify = false;
|
|
|
|
slot.offered = false;
|
|
|
|
if (slot.is_completed) { slot.is_completed = false; }
|
|
|
|
return updateCalendar();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Callback when a slot was successfully cancelled. Reset the slot style as 'ready to book'
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.slotCancelled = function () { $scope.markSlotAsRemoved($scope.selectedEvent); };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Change the last selected slot's appearence to looks like 'currently looking for a new destination to exchange'
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.markSlotAsModifying = function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedEvent.backgroundColor = '#eee';
|
2019-12-17 18:06:56 +01:00
|
|
|
$scope.selectedEvent.title = _t('app.logged.space_reserve.i_change');
|
2018-11-21 11:08:53 +01:00
|
|
|
return updateCalendar();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Change the last selected slot's appearence to looks like 'the slot being exchanged will take this place'
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.changeModifyTrainingSlot = function () {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ($scope.events.placable) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.events.placable.backgroundColor = 'white';
|
|
|
|
$scope.events.placable.title = '';
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (!$scope.events.placable || ($scope.events.placable._id !== $scope.selectedEvent._id)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedEvent.backgroundColor = '#bbb';
|
2019-12-17 18:06:56 +01:00
|
|
|
$scope.selectedEvent.title = _t('app.logged.space_reserve.i_shift');
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
return updateCalendar();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* When modifying an already booked reservation, callback when the modification was successfully done.
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.modifyTrainingSlot = function () {
|
2019-12-17 18:06:56 +01:00
|
|
|
$scope.events.placable.title = _t('app.logged.space_reserve.i_ve_reserved');
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.events.placable.backgroundColor = 'white';
|
|
|
|
$scope.events.placable.borderColor = $scope.events.modifiable.borderColor;
|
|
|
|
$scope.events.placable.id = $scope.events.modifiable.id;
|
|
|
|
$scope.events.placable.is_reserved = true;
|
|
|
|
$scope.events.placable.can_modify = true;
|
|
|
|
|
|
|
|
$scope.events.modifiable.backgroundColor = 'white';
|
|
|
|
$scope.events.modifiable.title = '';
|
|
|
|
$scope.events.modifiable.borderColor = FREE_SLOT_BORDER_COLOR;
|
|
|
|
$scope.events.modifiable.id = null;
|
|
|
|
$scope.events.modifiable.is_reserved = false;
|
|
|
|
$scope.events.modifiable.can_modify = false;
|
|
|
|
if ($scope.events.modifiable.is_completed) { $scope.events.modifiable.is_completed = false; }
|
|
|
|
|
|
|
|
return updateCalendar();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Cancel the current booking modification, reseting the whole process
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.cancelModifyTrainingSlot = function () {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ($scope.events.placable) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.events.placable.backgroundColor = 'white';
|
|
|
|
$scope.events.placable.title = '';
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2019-12-17 18:06:56 +01:00
|
|
|
$scope.events.modifiable.title = _t('app.logged.space_reserve.i_ve_reserved');
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.events.modifiable.backgroundColor = 'white';
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 11:08:53 +01:00
|
|
|
return updateCalendar();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Callback to deal with the reservations of the user selected in the dropdown list instead of the current user's
|
|
|
|
* reservations. (admins only)
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.updateMember = function () {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ($scope.ctrl.member) {
|
2018-10-25 16:51:20 +02:00
|
|
|
Member.get({ id: $scope.ctrl.member.id }, function (member) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.ctrl.member = member;
|
2018-10-25 16:51:20 +02:00
|
|
|
return Availability.spaces({ spaceId: $scope.space.id, member_id: $scope.ctrl.member.id }, function (spaces) {
|
2018-11-21 11:08:53 +01:00
|
|
|
uiCalendarConfig.calendars.calendar.fullCalendar('removeEvents');
|
2018-10-25 16:50:16 +02:00
|
|
|
return $scope.eventSources.splice(0, 1, {
|
|
|
|
events: spaces,
|
2017-02-23 17:45:55 +01:00
|
|
|
textColor: 'black'
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
// as the events are re-fetched for the new user, we must re-init the cart
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.events.reserved = [];
|
|
|
|
$scope.selectedPlan = null;
|
|
|
|
return $scope.plansAreShown = false;
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Add the provided plan to the current shopping cart
|
|
|
|
* @param plan {Object} the plan to subscribe
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.selectPlan = function (plan) {
|
2018-10-25 16:50:16 +02:00
|
|
|
// toggle selected plan
|
|
|
|
if ($scope.selectedPlan !== plan) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedPlan = plan;
|
2018-10-25 16:50:16 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedPlan = null;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.planSelectionTime = new Date();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Changes the user current view from the plan subsription screen to the machine reservation agenda
|
|
|
|
* @param e {Object} see https://docs.angularjs.org/guide/expression#-event-
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.doNotSubscribePlan = function (e) {
|
2018-11-21 11:08:53 +01:00
|
|
|
e.preventDefault();
|
|
|
|
$scope.plansAreShown = false;
|
|
|
|
$scope.selectedPlan = null;
|
|
|
|
return $scope.planSelectionTime = new Date();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Switch the user's view from the reservation agenda to the plan subscription
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.showPlans = function () { $scope.plansAreShown = true; };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Once the reservation is booked (payment process successfully completed), change the event style
|
|
|
|
* in fullCalendar, update the user's subscription and free-credits if needed
|
|
|
|
* @param reservation {Object}
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.afterPayment = function (reservation) {
|
|
|
|
angular.forEach($scope.events.paid, function (spaceSlot, key) {
|
2018-11-21 11:08:53 +01:00
|
|
|
spaceSlot.is_reserved = true;
|
|
|
|
spaceSlot.can_modify = true;
|
2019-12-17 18:06:56 +01:00
|
|
|
spaceSlot.title = _t('app.logged.space_reserve.i_ve_reserved');
|
2018-11-21 11:08:53 +01:00
|
|
|
spaceSlot.backgroundColor = 'white';
|
|
|
|
spaceSlot.borderColor = RESERVED_SLOT_BORDER_COLOR;
|
|
|
|
return updateSpaceSlotId(spaceSlot, reservation);
|
|
|
|
});
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
if ($scope.selectedPlan) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.ctrl.member.subscribed_plan = angular.copy($scope.selectedPlan);
|
|
|
|
Auth._currentUser.subscribed_plan = angular.copy($scope.selectedPlan);
|
|
|
|
$scope.plansAreShown = false;
|
|
|
|
$scope.selectedPlan = null;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.ctrl.member.training_credits = angular.copy(reservation.user.training_credits);
|
|
|
|
$scope.ctrl.member.machine_credits = angular.copy(reservation.user.machine_credits);
|
|
|
|
Auth._currentUser.training_credits = angular.copy(reservation.user.training_credits);
|
|
|
|
Auth._currentUser.machine_credits = angular.copy(reservation.user.machine_credits);
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 11:08:53 +01:00
|
|
|
return refetchCalendar();
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* To use as callback in Array.prototype.filter to get only enabled plans
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.filterDisabledPlans = function (plan) { return !plan.disabled; };
|
2018-10-25 16:50:16 +02:00
|
|
|
|
|
|
|
/* PRIVATE SCOPE */
|
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Kind of constructor: these actions will be realized first when the controller is loaded
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
const initialize = function () {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ($scope.currentUser.role !== 'admin') {
|
2018-11-21 11:08:53 +01:00
|
|
|
return Member.get({ id: $scope.currentUser.id }, function (member) { $scope.ctrl.member = member; });
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Triggered when the user clicks on a reservation slot in the agenda.
|
|
|
|
* Defines the behavior to adopt depending on the slot status (already booked, free, ready to be reserved ...),
|
|
|
|
* the user's subscription (current or about to be took) and the time (the user cannot modify a booked reservation
|
|
|
|
* if it's too late).
|
|
|
|
* @see http://fullcalendar.io/docs/mouse/eventClick/
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
var calendarEventClickCb = function (event, jsEvent, view) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.selectedEvent = event;
|
2018-10-25 16:50:16 +02:00
|
|
|
if ($stateParams.id === 'all') {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.training = event.training;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.selectionTime = new Date();
|
|
|
|
};
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Triggered when fullCalendar tries to graphicaly render an event block.
|
|
|
|
* Append the event tag into the block, just after the event title.
|
|
|
|
* @see http://fullcalendar.io/docs/event_rendering/eventRender/
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
var eventRenderCb = function (event, element, view) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if (($scope.currentUser.role === 'admin') && (event.tags.length > 0)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
let html = '';
|
2018-10-25 16:50:16 +02:00
|
|
|
for (let tag of Array.from(event.tags)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
html += `<span class='label label-success text-white' title='${tag.name}'>${tag.name}</span>`;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
element.find('.fc-time').append(html);
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* After payment, update the id of the newly reserved slot with the id returned by the server.
|
|
|
|
* This will allow the user to modify the reservation he just booked.
|
|
|
|
* @param slot {Object}
|
|
|
|
* @param reservation {Object}
|
|
|
|
*/
|
2018-11-20 12:26:06 +01:00
|
|
|
var updateSpaceSlotId = function (slot, reservation) {
|
2018-10-25 16:51:20 +02:00
|
|
|
angular.forEach(reservation.slots, function (s) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if (slot.start_at === slot.start_at) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return slot.id = s.id;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
});
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Update the calendar's display to render the new attributes of the events
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
var updateCalendar = function () { uiCalendarConfig.calendars.calendar.fullCalendar('rerenderEvents'); };
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
/**
|
|
|
|
* Asynchronously fetch the events from the API and refresh the calendar's view with these new events
|
|
|
|
*/
|
2018-11-20 12:26:06 +01:00
|
|
|
var refetchCalendar = function () {
|
2018-10-25 16:51:20 +02:00
|
|
|
$timeout(function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
uiCalendarConfig.calendars.calendar.fullCalendar('refetchEvents');
|
|
|
|
return uiCalendarConfig.calendars.calendar.fullCalendar('rerenderEvents');
|
|
|
|
});
|
|
|
|
};
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-19 16:17:49 +01:00
|
|
|
// !!! MUST BE CALLED AT THE END of the controller
|
2018-11-21 11:08:53 +01:00
|
|
|
return initialize();
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2017-02-23 17:45:55 +01:00
|
|
|
|
2018-11-21 11:08:53 +01:00
|
|
|
]);
|