Initial commit: apps.supersamsev.ru
This commit is contained in:
commit
54475e7d3d
17284 files changed
+98268
No files matched your search
@@ -0,0 +1,169 @@
|
||||
supersamApp.controller('UsersController', [
|
||||
'$scope',
|
||||
'$http',
|
||||
'$timeout',
|
||||
'config',
|
||||
'$filter',
|
||||
function($scope,
|
||||
$http,
|
||||
$timeout,
|
||||
config,
|
||||
$filter) {
|
||||
var cutUsers;
|
||||
cutUsers = (function() {
|
||||
class cutUsers {
|
||||
constructor() {
|
||||
this.getUserRoleLabel = this.getUserRoleLabel.bind(this);
|
||||
this.userModal = this.userModal.bind(this);
|
||||
this.addUser = this.addUser.bind(this);
|
||||
this.editUser = this.editUser.bind(this);
|
||||
this.confirmUserEdit = this.confirmUserEdit.bind(this);
|
||||
this.deleteUser = this.deleteUser.bind(this);
|
||||
$scope.utilities.showContentOnLoad();
|
||||
config.sortFields = {
|
||||
users: {
|
||||
field: 'name',
|
||||
direction: 'asc'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getUserRoleLabel(role) {
|
||||
var label;
|
||||
label = "";
|
||||
if (config.userRoles[role]) {
|
||||
label = config.userRoles[role].label;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
userModal(action) {
|
||||
$timeout(() => {
|
||||
return angular.element("#userModal").modal(action);
|
||||
});
|
||||
this.warning = "";
|
||||
this.error = "";
|
||||
return $scope.userForm.$setPristine();
|
||||
}
|
||||
|
||||
addUser() {
|
||||
this.userModalData = {
|
||||
role: 'manager',
|
||||
is_active: true,
|
||||
available_apps: [],
|
||||
availableToOrder: false,
|
||||
availableToOrderDefault: false
|
||||
};
|
||||
return this.userModal("show");
|
||||
}
|
||||
|
||||
editUser(user) {
|
||||
this.userModalData = angular.copy(user);
|
||||
return this.userModal("show");
|
||||
}
|
||||
|
||||
confirmUserEdit() {
|
||||
if (!this.isSubmitting) {
|
||||
this.isSubmitting = true;
|
||||
this.warning = "";
|
||||
this.error = "";
|
||||
return $http({
|
||||
method: 'POST',
|
||||
url: config.urls.addUpdateUser,
|
||||
data: this.userModalData,
|
||||
timeout: 30000
|
||||
}).then((response) => {
|
||||
var data;
|
||||
this.isSubmitting = false;
|
||||
if (response.data) {
|
||||
data = response.data;
|
||||
if (data.status && (data.status === "success")) {
|
||||
if (this.userModalData.id) {
|
||||
toastr.success("Данные пользователя были успешно обновлены");
|
||||
} else {
|
||||
toastr.success("Пользователь был успешно добавлен");
|
||||
}
|
||||
config.users = angular.copy(data.users);
|
||||
$scope.utilities.setUpdateDates("users", data, config.updates);
|
||||
return this.userModal("hide");
|
||||
} else {
|
||||
if (data.warning) {
|
||||
this.warning = data.warning;
|
||||
}
|
||||
if (data.error) {
|
||||
return this.error = data.error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
this.isSubmitting = false;
|
||||
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteUser(deleteUser) {
|
||||
var dataToSend;
|
||||
if (!this.isSubmitting) {
|
||||
if (confirm("Вы уверены, что хотите удалить данного пользователя?")) {
|
||||
this.isSubmitting = true;
|
||||
dataToSend = {
|
||||
id: deleteUser.id
|
||||
};
|
||||
return $http({
|
||||
method: 'POST',
|
||||
url: config.urls.deleteUser,
|
||||
data: dataToSend,
|
||||
timeout: 30000
|
||||
}).then((response) => {
|
||||
var data, key, ref, user;
|
||||
this.isSubmitting = false;
|
||||
if (response.data) {
|
||||
data = response.data;
|
||||
if (data.status && (data.status === "success")) {
|
||||
ref = config.users;
|
||||
for (key in ref) {
|
||||
user = ref[key];
|
||||
if (user.id === deleteUser.id) {
|
||||
config.users.splice(key, 1);
|
||||
}
|
||||
}
|
||||
$scope.utilities.setUpdateDates("users", data, config.updates);
|
||||
return toastr.success("Пользователь был успешно удалён");
|
||||
} else {
|
||||
if (data.warning) {
|
||||
toastr.warning(data.warning);
|
||||
}
|
||||
if (data.error) {
|
||||
return toastr.warning(data.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
this.isSubmitting = false;
|
||||
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
cutUsers.prototype.isSubmitting = false;
|
||||
|
||||
cutUsers.prototype.userModalData = {};
|
||||
|
||||
cutUsers.prototype.warning = "";
|
||||
|
||||
cutUsers.prototype.error = "";
|
||||
|
||||
return cutUsers;
|
||||
|
||||
}).call(this);
|
||||
$scope.config = config;
|
||||
$scope.utilities = new UtilitiesClass(config,
|
||||
$filter,
|
||||
$timeout);
|
||||
return $scope.users = new cutUsers();
|
||||
}
|
||||
]);
|
||||
Reference in new issue
Block a user