Initial commit

This commit is contained in:
Senad Uka
2018-06-11 11:09:35 +02:00
commit ed7df7b11f
1954 changed files with 483354 additions and 0 deletions

View File

@@ -0,0 +1,189 @@
(function() {
global.dashModule.directive('createUser', createUserDirective).controller('createUserCtrl', [
'$scope',
'$',
'$http',
'$translate',
'utilsService',
createUserCtrl
]);
function createUserDirective() {
return {restrict: 'E', templateUrl: 'users/html/createUserTemplate'};
}
function createUserCtrl($scope, $, $http, $translate, utilsService) {
let commercialLeadKeyDropped;
let listSelector;
$scope.isSelectCLVisible = isSelectCLVisible;
$scope.info = {};
$scope.roles = [];
$scope.selectedUserType = '';
$scope.startEventStyle = startEventStyle;
$scope.endEventStyle = endEventStyle;
$scope.droppedCommercialLead = droppedCommercialLead;
$scope.saveUserInDB = saveUserInDB;
$scope.getUserTypes = getUserTypes;
$scope.checkIfCLIsNeeded = checkIfCLIsNeeded;
$scope.getDataForUserCreation = getDataForUserCreation;
$scope.selectCompany = selectCompany;
$scope.selectedCompany = '';
$scope.toggleNewCompany = toggleNewCompany;
$scope.showAddNewCompany = false;
$scope.getClassForCompany = getClassForCompany;
function getDataForUserCreation() {
getUserTypes();
getCompanies();
}
function getUserTypes() {
$http({method: 'POST', url: 'users/api/getUserTypes'}).then(setUserTypes, utilsService.onHttpError);
}
function setUserTypes(response) {
$scope.roles = response.data || [];
if ($scope.selectedUserType) {
const selectedUserType = $scope.roles.find(role => {
return role.name === $scope.selectedUserType;
});
$scope.userTypeSelected = {
id: selectedUserType.id
};
}
}
function getCompanies() {
$http({
method: 'GET',
url: 'users/api/getCompanies'
}).then(setCompanies, utilsService.onHttpError);
}
function setCompanies(response) {
$scope.availableCompanies = response.data || [];
if ($scope.selectedCompany) {
const selectedCompany = $scope.availableCompanies.find(company => {
return company.name === $scope.selectedCompany;
});
$scope.companySelected = {
id: selectedCompany.id
};
}
}
function selectCompany(selectedCompany = '') {
$scope.selectedCompany = selectedCompany;
}
function checkIfCLIsNeeded(selectedUserType = '') {
$scope.selectedUserType = selectedUserType;
if ($scope.userTypeSelected.id === '2') {
getCommercialLeads();
}
}
function getCommercialLeads() {
$http({method: 'GET', url: 'users/api/getCommercialLeads'}).then(setCommercialLeads, utilsService.onHttpError);
}
function setCommercialLeads(response) {
if (response.data) {
$scope.availableCommercialLeads = response.data;
$scope.selectedCommercialLeads = [];
}
}
function isSelectCLVisible() {
return $scope.userTypeSelected && $scope.userTypeSelected.name
? $scope.userTypeSelected.name.toLowerCase() === 'customer'
: false;
}
function saveUserInDB() {
$scope.info.idUserType = $scope.userTypeSelected && $scope.userTypeSelected.id
? $scope.userTypeSelected.id
: 0;
if(!$scope.showAddNewCompany) {
$scope.info.selectedCompanyId = $scope.companySelected ? $scope.companySelected.id : 0;
delete $scope.info.companyName;
delete $scope.info.vat;
}
const params = $.param({
info: JSON.stringify($scope.info),
cl: JSON.stringify($scope.selectedCommercialLeads)
});
$http({
method: 'POST',
data: params,
url: 'users/api/saveUserInDB'
}).then(showConfirmationMessage, utilsService.onHttpError);
}
function showConfirmationMessage(response) {
if (response.data && response.data.messages) {
const messagesData = response.data.messages;
messagesData.forEach(messageData => {
const message = $translate.instant('users.forms.messages.' + messageData.message);
utilsService.displayMessage(messageData.code, message);
if (messageData.code === 'success') {
$scope.info = {};
checkIfCLIsNeeded();
if($scope.showAddNewCompany) {
getCompanies();
toggleNewCompany();
}
}
});
}
}
function startEventStyle(event, ui, from, key) {
$('.choose-cl-list').css({overflow: 'visible'});
switch (from) {
case 'available':
$('#selected-cl-list-container').addClass('allowed-drop-zone');
break;
case 'selected':
$('#available-cl-list-container').addClass('allowed-drop-zone');
break;
default:
break;
}
commercialLeadKeyDropped = key;
listSelector = from;
}
function endEventStyle() {
$('.choose-cl-list').css({'overflow-y': 'scroll'});
$('.choose-cl-list').removeClass('allowed-drop-zone');
}
function droppedCommercialLead(event, ui, from) {
if (from !== listSelector) {
if (listSelector === 'available') {
$scope.selectedCommercialLeads.push($scope.availableCommercialLeads[commercialLeadKeyDropped]);
$scope.availableCommercialLeads.splice(commercialLeadKeyDropped, 1);
} else if (listSelector === 'selected') {
$scope.availableCommercialLeads.push($scope.selectedCommercialLeads[commercialLeadKeyDropped]);
$scope.selectedCommercialLeads.splice(commercialLeadKeyDropped, 1);
}
}
$(ui.helper).css({position: 'relative', left: 0, top: 0});
}
function toggleNewCompany() {
$scope.showAddNewCompany = !$scope.showAddNewCompany;
}
function getClassForCompany() {
return $scope.showAddNewCompany ? 'select-inactive' : '';
}
}
})();

View File

@@ -0,0 +1,118 @@
(function () {
global.dashModule
.directive('linkCustomers', linkCustomersDirective)
.controller('linkCustomersCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', linkCustomersCtrl]);
function linkCustomersDirective() {
return {
restrict: 'E',
templateUrl: 'users/html/linkCustomersTemplate'
};
}
function linkCustomersCtrl($scope, $http, $, $translate, utilsService) {
$scope.getCustomersAndCl = getCustomersAndCl;
$scope.getUserClass = getUserClass;
$scope.customerDragStart = customerDragStart;
$scope.customerDragStop = customerDragStop;
$scope.customerDropped = customerDropped;
$scope.selectCommercialLead = selectCommercialLead;
$scope.updateLinkedCustomers = updateLinkedCustomers;
$scope.customers = [];
$scope.commercialLeads = [];
$scope.selectedCommercialLead = {};
function getCustomersAndCl(){
$http({
method: 'GET',
url: 'users/api/getCustomersAndCl'
}).then(showCustomersAndCl, utilsService.onHttpError);
}
function showCustomersAndCl(response){
if(response.data){
$scope.customers = response.data.customers;
$scope.commercialLeads = response.data.commercialLeads;
$scope.selectedCommercialLead = response.data.commercialLeads[Object.keys(response.data.commercialLeads)[0]] || {};
$scope.customers.forEach(hideLinkedCustomers);
}
}
function selectCommercialLead(selected) {
$scope.selectedCommercialLead = selected;
$scope.customers.forEach(hideLinkedCustomers);
}
function hideLinkedCustomers(curentCustomer) {
let isCustomerInArray = false;
if ($scope.selectedCommercialLead.linkedCustomers) {
isCustomerInArray = $scope.selectedCommercialLead.linkedCustomers.find((customer) => {
return customer.id === curentCustomer.id;
});
}
curentCustomer.isNotLinked = isCustomerInArray ? false : true;
}
function getUserClass(curent) {
return curent === $scope.selectedCommercialLead ? 'selected-user' : '';
}
function customerDragStart(event, ui, selector) {
$('#'+selector).css({
overflow: 'visible',
});
}
function customerDragStop(event, ui, selector) {
$('#'+ selector).css({
'overflow': 'auto'
});
}
function customerDropped(event, ui, dropContainer) {
const dropToSelector = $(ui.helper).attr('drop-to');
const idCustomer = $(ui.helper).attr('id-customer');
if(dropContainer !== dropToSelector){
return;
}
if (dropToSelector === 'linked-customers') {
const dragedCustomer = $scope.customers.find((customer) => {
return customer.id === idCustomer;
});
$scope.selectedCommercialLead.linkedCustomers.push(dragedCustomer);
} else {
const dragedCustomerIndex = $scope.selectedCommercialLead.linkedCustomers.findIndex((customer) => {
return customer.id === idCustomer;
});
$scope.selectedCommercialLead.linkedCustomers.splice(dragedCustomerIndex, 1);
}
$scope.customers.forEach(hideLinkedCustomers);
}
function updateLinkedCustomers(){
const params = $.param({
idCommercialLead: $scope.selectedCommercialLead.id,
customers: JSON.stringify($scope.selectedCommercialLead.linkedCustomers)
});
$http({
method: 'POST',
url: 'users/api/updateLinkedCustomers',
data: params
}).then(updateMessage, utilsService.onHttpError);
}
function updateMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
let translatedMessage = $translate.instant('users.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
});
}
}
}
})();

View File

@@ -0,0 +1,61 @@
(function () {
global.dashModule
.directive('showEditUsers', showEditUsersDirective)
.controller('showEditUsersCtrl', ['$scope', '$', '$http', '$translate', 'utilsService', showEditUsersCtrl]);
function showEditUsersDirective() {
return {
restrict: 'E',
templateUrl: 'users/html/showEditUsersTemplate'
};
}
function showEditUsersCtrl($scope, $, $http, $translate, utilsService) {
$scope.getUsers = getUsers;
$scope.generateTokenForUserPassword = generateTokenForUserPassword;
$scope.showHideDialog = showHideDialog;
$scope.isDialogVisible = false;
$scope.users = [];
function getUsers() {
$http({
method: 'GET',
url: 'users/api/getUsers'
}).then(showUsers, utilsService.onHttpError);
}
function showUsers(response) {
if(response.data) {
$scope.users = response.data;
}
}
function generateTokenForUserPassword(userInfo) {
const params = $.param({
userInfo: JSON.stringify(userInfo)
});
$http({
method: 'POST',
data: params,
url: 'utils/api/generateTokenForUserPassword'
}).then(showConfirmationMessage, utilsService.onHttpError);
}
function showConfirmationMessage(response) {
if (response.data && response.data.messages) {
response.data.messages.forEach(messageData => {
const message = $translate.instant('users.forms.messages.' + messageData.message);
utilsService.displayMessage(messageData.code, message);
});
}
}
function showHideDialog(userInfo = '') {
$scope.userSelected = userInfo;
$scope.$evalAsync(() => {
$scope.isDialogVisible = !$scope.isDialogVisible;
});
}
}
})();

View File

@@ -0,0 +1,38 @@
(function () {
global.dashModule
.directive('users', usersDirective)
.controller('usersCtrl', ['$scope', usersCtrl]);
function usersDirective() {
return {
restrict: 'E',
templateUrl: 'users/html/UsersTemplate'
};
}
function usersCtrl($scope) {
$scope.subModule = global.getParameterByName('subModule') || 'users';
$scope.setSubModule = setSubModule;
$scope.isSubmoduleVisible = isSubmoduleVisible;
addUrlListener();
function addUrlListener() {
window.addEventListener('popstate', function (e) {
$scope.$evalAsync($scope => {
$scope.subModule = e.state ? e.state.subModule : 'users';
});
}, false);
}
function setSubModule($event) {
$scope.subModule = $event.currentTarget.attributes.subModule.value;
history.pushState({
subModule: $scope.subModule
}, null, '?subModule=' + $scope.subModule);
}
function isSubmoduleVisible(subModule) {
return subModule === $scope.subModule;
}
}
})();

View File

@@ -0,0 +1,237 @@
@layer-background: rgba(255, 255, 255, 0.7);
.module-layer {
position: relative;
margin-top: 1%;
background: @layer-background;
margin-bottom: 3%;
padding-bottom: 2%;
}
#create-user-template-container {
.module-layer;
#user-whole-container {
padding-top: 2%;
}
.label-value-pair {
margin-bottom: 1%;
}
.choose-cl-title {
display: inline-block;
margin-bottom: 1%;
font-weight: bold;
font-size: 120%;
}
.cl-lists {
height: 400px;
overflow: hidden;
}
.choose-cl {
vertical-align: top;
}
.choose-cl-list {
display: inline-block;
width: 95%;
border: 1px solid #000;
border-radius: 5px;
min-height: 400px;
overflow-y: auto;
height: 300px;
}
.link-cl-user {
display: block;
.link-cl-user-header {
display: inline;
width: 25%;
font-weight: bold;
}
.link-cl-user-data {
width: 70%;
display: inline;
}
}
.choose-cl-row {
width: 100%;
background-color: #fff;
border: 1px solid #ddd;
border-top-right-radius: 4px;
border-top-left-radius: 4px;
display: block;
padding: 10px 15px;
margin-bottom: -1px;
cursor: pointer;
}
.choose-cl-row:hover {
background: rgba(223, 240, 216, 0.5);
}
.choose-cl-row .dndDraggingSource {
display: none;
}
.choose-cl-row .dndPlaceholder {
background-color: #ddd;
display: block;
}
.choose-cl-row.selected {
background-color: #dff0d8;
color: #3c763d;
}
#user-action-buttons {
margin: 1% 0 2% 1%;
}
.draggable-icon {
color: #3c763d;
left: 28.5%;
font-size: 200%;
}
.new-company-details {
padding-left: 2%;
}
.select-inactive {
background-color: #dddddd;
}
.company-admin-box {
padding-left: 1.5%;
}
.new-company-details-container {
margin-top: 1%;
width: 100%;
border-top: 2px solid #3bb9ff;
border-bottom: 2px solid #3bb9ff;
background: rgba(59, 185, 255, 0.1);
padding: 2% 0;
margin-bottom: 2%;
}
}
#show-users {
padding-bottom: 2%;
.search-input {
padding: 1%;
.search-icon {
margin-left: 1%;
}
}
.user-types-container {
padding-bottom: 2%;
}
.users-informations-container {
width: 100%;
display: inline-block;
}
.users-info-button {
display: inline-block;
text-align: right;
width: 90%;
position: absolute;
}
.show-users-layer {
position: relative;
margin-top: 2%;
background: @layer-background;
padding: 3%;
height: 270px;
}
.show-users-title {
font-size: 120%;
font-weight: bold;
display: inline-block;
}
.users-info {
margin-bottom: 4%;
}
.user-type-show {
text-align: center;
font-size: 140%;
font-weight: bold;
}
.company-name-info-title {
text-align: center;
margin-bottom: 5%;
border-bottom: 2px solid #000;
}
}
#link-customers-template-container{
.module-layer;
padding-top: 2%;
.user-header {
padding: 1%;
text-align: center;
background: #337ab7;
color: #FFF;
font-size: 120%;
font-weight: bold;
}
.user-big-container{
height: 445px;
overflow: hidden;
}
.user-container {
border: 2px solid #337ab7;
border-radius: 10px;
}
.user-list{
min-height: 400px;
height: 400px;
overflow: auto;
}
.user-layer {
padding: 1%;
border-bottom: 2px solid #337ab7;
cursor: pointer;
}
.customer-row {
padding: 1%;
border-bottom: 2px solid #337ab7;
cursor: move;
}
.customer-row:hover,
.customer-layer:hover {
background: rgba(59, 185, 255, 0.5);
}
.selected-user {
background: rgba(59, 185, 255, 1);
}
.users-link-buttons {
margin: 2% 0;
}
}