diff --git a/app/assets/javascripts/controllers/admin/members.js.erb b/app/assets/javascripts/controllers/admin/members.js.erb
index 97c23cb55..d3a7318a3 100644
--- a/app/assets/javascripts/controllers/admin/members.js.erb
+++ b/app/assets/javascripts/controllers/admin/members.js.erb
@@ -217,6 +217,18 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce',
}
};
+ /**
+ * Change the managers ordering criterion to the one provided
+ * @param orderManager {string} ordering criterion
+ */
+ $scope.setOrderManager = function (orderManager) {
+ if ($scope.orderManager === orderManager) {
+ return $scope.orderManager = `-${orderManager}`;
+ } else {
+ return $scope.orderManager = orderManager;
+ }
+ };
+
/**
* Open a modal dialog allowing the admin to create a new partner user
@@ -343,6 +355,36 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce',
);
}
+ /**
+ * Ask for confirmation then delete the specified manager
+ * @param managers {Array} full list of managers
+ * @param manager {Object} manager to delete
+ */
+ $scope.destroyManager = function (managers, manager) {
+ dialogs.confirm(
+ {
+ resolve: {
+ object () {
+ return {
+ title: _t('app.admin.members.confirmation_required'),
+ msg: $sce.trustAsHtml(_t('app.admin.members.delete_this_manager') + '
' + _t('app.admin.members.this_may_take_a_while_please_wait'))
+ };
+ }
+ }
+ },
+ function () { // cancel confirmed
+ User.delete(
+ { id: manager.id },
+ function () {
+ managers.splice(findItemIdxById(managers, manager.id), 1);
+ return growl.success(_t('app.admin.members.manager_successfully_deleted'));
+ },
+ function (error) { growl.error(_t('app.admin.members.unable_to_delete_the_manager')); }
+ );
+ }
+ );
+ }
+
/**
* Callback for the 'load more' button.
* Will load the next results of the current search, if any
@@ -1029,3 +1071,65 @@ Application.Controllers.controller('NewAdminController', ['$state', '$scope', 'A
}
]);
+
+/**
+ * Controller used in the manager's creation page (admin view)
+ */
+Application.Controllers.controller('NewManagerController', ['$state', '$scope', 'User', 'growl', '_t', function ($state, $scope, User, growl, _t) {
+ // default admin profile
+ $scope.manager = {
+ statistic_profile_attributes: {
+ gender: true
+ },
+ profile_attributes: {},
+ invoicing_profile_attributes: {}
+ };
+
+ // Default parameters for AngularUI-Bootstrap datepicker
+ $scope.datePicker = {
+ format: Fablab.uibDateFormat,
+ opened: false,
+ options: {
+ startingDay: Fablab.weekStartingDay
+ }
+ };
+
+ /**
+ * Shows the birth day datepicker
+ * @param $event {Object} jQuery event object
+ */
+ $scope.openDatePicker = function ($event) { $scope.datePicker.opened = true; };
+
+ /**
+ * Send the new manager, currently stored in $scope.manager, to the server for database saving
+ */
+ $scope.saveManager = function () {
+ User.save(
+ {},
+ { manager: $scope.manager },
+ function () {
+ growl.success(_t('app.admin.manager_new.manager_successfully_created', { GENDER: getGender($scope.manager) }));
+ return $state.go('app.admin.members');
+ }
+ , function (error) {
+ growl.error(_t('app.admin.admins_new.failed_to_create_admin') + JSON.stringify(error.data ? error.data : error));
+ console.error(error);
+ }
+ );
+ };
+
+ /* PRIVATE SCOPE */
+
+ /**
+ * Return an enumerable meaningful string for the gender of the provider user
+ * @param user {Object} Database user record
+ * @return {string} 'male' or 'female'
+ */
+ const getGender = function (user) {
+ if (user.statistic_profile_attributes) {
+ if (user.statistic_profile_attributes.gender) { return 'male'; } else { return 'female'; }
+ } else { return 'other'; }
+ };
+}
+
+]);
diff --git a/app/assets/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb
index 1e995dad0..1bed35283 100644
--- a/app/assets/javascripts/router.js.erb
+++ b/app/assets/javascripts/router.js.erb
@@ -931,8 +931,17 @@ angular.module('application.router', ['ui.router'])
}
}
})
+ .state('app.admin.managers_new', {
+ url: '/admin/managers/new',
+ views: {
+ 'main@': {
+ templateUrl: '<%= asset_path "admin/managers/new.html" %>',
+ controller: 'NewManagerController'
+ }
+ }
+ })
- // authentification providers
+ // authentication providers
.state('app.admin.authentication_new', {
url: '/admin/authentications/new',
views: {
diff --git a/app/assets/templates/admin/managers/new.html.erb b/app/assets/templates/admin/managers/new.html.erb
new file mode 100644
index 000000000..ddcb029e9
--- /dev/null
+++ b/app/assets/templates/admin/managers/new.html.erb
@@ -0,0 +1,34 @@
+
{{ 'app.admin.members.surname' | translate }} | +{{ 'app.admin.members.surname' | translate }} | -{{ 'app.admin.members.first_name' | translate }} | +{{ 'app.admin.members.first_name' | translate }} | -{{ 'app.admin.members.email' | translate }} | +{{ 'app.admin.members.email' | translate }} | -{{ 'app.admin.members.phone' | translate }} | +{{ 'app.admin.members.phone' | translate }} | |
---|---|---|---|---|---|---|---|---|
{{ admin.profile_attributes.last_name }} | -{{ admin.profile_attributes.first_name }} | -{{ admin.email }} | -{{ admin.profile_attributes.phone }} | +|||||
{{ manager.profile_attributes.last_name }} | +{{ manager.profile_attributes.first_name }} | +{{ manager.email }} | +{{ manager.profile_attributes.phone }} | - | diff --git a/app/assets/templates/admin/members/partners.html.erb b/app/assets/templates/admin/members/partners.html.erb index 0261b68e2..aedfae2dc 100644 --- a/app/assets/templates/admin/members/partners.html.erb +++ b/app/assets/templates/admin/members/partners.html.erb @@ -33,7 +33,7 @@{{ partner.email }} | {{ partner.resource ? partner.resource.base_name : '' }} |
- |
diff --git a/app/assets/templates/admin/members/users.html.erb b/app/assets/templates/admin/members/users.html.erb
index ef99ef151..689d9d955 100644
--- a/app/assets/templates/admin/members/users.html.erb
+++ b/app/assets/templates/admin/members/users.html.erb
@@ -8,9 +8,9 @@