1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

fix tours collision on F1

This commit is contained in:
Sylvain 2020-02-24 10:05:03 +01:00
parent 95338e267e
commit 32d5af9b87
3 changed files with 59 additions and 19 deletions

View File

@ -430,12 +430,7 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce',
uitour.start();
}
// start this tour when an user press F1 - this is contextual help
window.addEventListener('keydown', function (e) {
if (e.key === 'F1') {
e.preventDefault();
uitour.start();
}
});
window.addEventListener('keydown', handleF1);
}
/* PRIVATE SCOPE */
@ -447,6 +442,9 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce',
if (!membersPromise[0] || (membersPromise[0].maxMembers <= $scope.members.length)) {
return $scope.member.noMore = true;
}
$scope.$on('$destroy', function () {
window.removeEventListener('keydown', handleF1);
});
};
/**
@ -499,6 +497,18 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce',
});
};
/**
* Callback used to trigger the feature tour when the user press the F1 key.
* @param e {KeyboardEvent}
*/
const handleF1 = function (e) {
if (e.key === 'F1') {
e.preventDefault();
const tour = uiTourService.getTourByName('members');
if (tour) { tour.start(); }
}
};
// !!! MUST BE CALLED AT THE END of the controller
return initialize();
}

View File

@ -414,17 +414,34 @@ Application.Controllers.controller('TrainingsAdminController', ['$scope', '$stat
uitour.start();
}
// start this tour when an user press F1 - this is contextual help
window.addEventListener('keydown', function (e) {
if (e.key === 'F1') {
e.preventDefault();
uitour.start();
}
});
window.addEventListener('keydown', handleF1);
}
/* PRIVATE SCOPE */
/**
* Kind of constructor: these actions will be realized first when the controller is loaded
*/
const initialize = function () {
// listen the $destroy event of the controller to remove the F1 key binding
$scope.$on('$destroy', function () {
window.removeEventListener('keydown', handleF1);
});
};
/**
* Callback used to trigger the feature tour when the user press the F1 key.
* @param e {KeyboardEvent}
*/
const handleF1 = function (e) {
if (e.key === 'F1') {
e.preventDefault();
const tour = uiTourService.getTourByName('trainings');
if (tour) { tour.start(); }
}
};
/**
* Group the trainings availabilities by trainings and by dates and return the resulting tree
* @param trainings {Array} $scope.trainings is expected here
@ -456,6 +473,8 @@ Application.Controllers.controller('TrainingsAdminController', ['$scope', '$stat
return tree;
};
// !!! MUST BE CALLED AT THE END of the controller
return initialize();
}
]);

View File

@ -13,7 +13,7 @@ Application.Controllers.controller('HomeController', ['$scope', '$stateParams',
* Kind of constructor: these actions will be realized first when the controller is loaded
*/
const initialize = function () {
// if we recieve a token to reset the password as GET parameter, trigger the
// if we receive a token to reset the password as GET parameter, trigger the
// changePassword modal from the parent controller
if ($stateParams.reset_password_token) {
return $scope.$parent.editPassword($stateParams.reset_password_token);
@ -25,6 +25,10 @@ Application.Controllers.controller('HomeController', ['$scope', '$stateParams',
// setup the tour for admins
if ($scope.currentUser && $scope.currentUser.role === 'admin') {
setupWelcomeTour();
// listen the $destroy event of the controller to remove the F1 key binding
$scope.$on('$destroy', function () {
window.removeEventListener('keydown', handleF1);
});
}
};
@ -209,12 +213,19 @@ Application.Controllers.controller('HomeController', ['$scope', '$stateParams',
uitour.start();
}
// start this tour when an user press F1 - this is contextual help
window.addEventListener('keydown', function (e) {
if (e.key === 'F1') {
e.preventDefault();
uitour.start();
}
});
window.addEventListener('keydown', handleF1);
};
/**
* Callback used to trigger the feature tour when the user press the F1 key.
* @param e {KeyboardEvent}
*/
const handleF1 = function (e) {
if (e.key === 'F1') {
e.preventDefault();
const tour = uiTourService.getTourByName('welcome');
if (tour) { tour.start(); }
}
};
// !!! MUST BE CALLED AT THE END of the controller