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,42 @@
(function () {
global.dashModule
.controller('showProductDocumentsCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', showProductDocumentsCtrl])
.directive('showProductDocuments', [showProductDocumentsDirective]);
function showProductDocumentsDirective() {
return {
restrict: 'E',
templateUrl: 'suppliers/html/showProductDocumentsTemplate'
};
}
function showProductDocumentsCtrl($scope, $http, $, $translate, utilsService) {
$scope.data = $scope.data || {};
$scope.removeProductDocument = removeProductDocument;
function removeProductDocument(idDocument){
const params = $.param({
idDocument
});
const url = 'suppliers/api/removeProductDocument';
$http({
method: 'POST',
url: url,
data: params
}).then(showUpdateMessage, utilsService.onHttpError);
}
function showUpdateMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
let translatedMessage = $translate.instant('suppliers.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
if (typeof $scope.onUpdated !== 'undefined' && messageObj.code === 'success') {
$scope.onUpdated();
}
});
}
}
}
})();

View File

@@ -0,0 +1,52 @@
(function () {
global.dashModule
.controller('suppliersAddEditCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', suppliersAddEditCtrl])
.directive('suppliersAddEdit', [suppliersAddEditDirective]);
function suppliersAddEditDirective() {
return {
restrict: 'E',
templateUrl: 'suppliers/html/suppliersAddEditFormTemplate'
};
}
function suppliersAddEditCtrl($scope, $http, $, $translate, utilsService) {
$scope.suppliersFormInit = suppliersFormInit;
$scope.addEditSupplier = addEditSupplier;
$scope.data = $scope.data || {};
function suppliersFormInit(action) {
$scope.formAction = action;
}
function addEditSupplier() {
const params = $.param({
idSupplier: $scope.data.id || 0,
name: $scope.data.name || '',
phone: $scope.data.phone || '',
mail: $scope.data.mail || ''
});
const url = 'suppliers/api/' + $scope.formAction.toLowerCase() + 'Supplier';
$http({
method: 'POST',
url: url,
data: params
}).then(showUpdateMessage, utilsService.onHttpError);
}
function showUpdateMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const key = messageObj.key ? $translate.instant('suppliers.tables.headers.' + messageObj.key) : '';
let translatedMessage = $translate.instant('suppliers.messages.' + messageObj.message);
translatedMessage = key !== '' ? key + ': ' + translatedMessage : translatedMessage;
utilsService.displayMessage(messageObj.code, translatedMessage);
if (typeof $scope.onUpdated !== 'undefined' && messageObj.code === 'success') {
$scope.onUpdated();
}
});
}
}
}
})();

View File

@@ -0,0 +1,123 @@
(function () {
global.dashModule
.controller('suppliersProductsAddEditCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', suppliersProductsAddEditCtrl])
.directive('suppliersProductsAddEdit', [suppliersProductsAddEditDirective]);
function suppliersProductsAddEditDirective() {
return {
restrict: 'E',
templateUrl: 'suppliers/html/suppliersProductsAddEditFormTemplate'
};
}
function suppliersProductsAddEditCtrl($scope, $http, $, $translate, utilsService) {
$scope.productsFormInit = productsFormInit;
$scope.addEditSupplierProducts = addEditSupplierProducts;
$scope.isAddAction = isAddAction;
$scope.getProductCategories = getProductCategories;
$scope.isPriceRecurring = isPriceRecurring;
$scope.data = $scope.data || {};
$scope.virtual = $scope.virtual || {};
$scope.countries = [];
$scope.suppliers = [];
$scope.productCategories = [];
$scope.selectedCategory = '';
function productsFormInit(action) {
getCountries();
getSuppliers();
getProductCategories();
$scope.formAction = action;
}
function isAddAction() {
return $scope.formAction === 'ADD';
}
function isPriceRecurring() {
return $scope.data.isPriceRecurring === '1';
}
function getCountries() {
const params = $.param({getArray : true});
$http({
method: 'POST',
data: params,
url: 'countries/api/getAllCountries'
}).then(showCountries, utilsService.onHttpError);
}
function showCountries(response) {
$scope.countries = response.data;
}
function getSuppliers() {
$http({
method: 'GET',
url: 'suppliers/api/getSuppliers'
}).then(showSuppliers, utilsService.onHttpError);
}
function showSuppliers(response) {
$scope.suppliers = response.data.data;
}
function getProductCategories(selectedCategory = '') {
$scope.selectedCategory = selectedCategory;
$http({
method: 'GET',
url: 'suppliers/api/getProductCategories'
}).then(showProductCategories, utilsService.onHttpError);
}
function showProductCategories(response) {
$scope.productCategories = response.data;
if ($scope.selectedCategory) {
const categorySelected = $scope.productCategories.find(productTypes => {
return productTypes.category === $scope.selectedCategory;
});
$scope.data.productCategory = {
id: categorySelected.id
};
}
}
function addEditSupplierProducts() {
const params = $.param($scope.data);
const url = 'suppliers/api/' + $scope.formAction.toLowerCase() + 'SupplierProduct';
$http({
method: 'POST',
url: url,
data: params
}).then(showUpdateMessage, utilsService.onHttpError);
}
function showUpdateMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const key = messageObj.key ? $translate.instant('suppliers.tables.headers.' + messageObj.key) : '';
let translatedMessage = $translate.instant('suppliers.messages.' + messageObj.message);
translatedMessage = key !== '' ? key + ': ' + translatedMessage : translatedMessage;
utilsService.displayMessage(messageObj.code, translatedMessage);
if (messageObj.code === 'success') {
if (typeof $scope.onUpdated !== 'undefined') {
$scope.onUpdated();
} else {
Object.keys($scope.data).forEach(productData => {
if (productData !== 'idCountry' && productData !== 'idSupplier') {
$scope.data[productData] = '';
}
});
}
}
});
}
}
}
})();

View File

@@ -0,0 +1,225 @@
(function () {
global.dashModule
.controller('suppliersController', ['$scope', '$rootScope', '$compile', '$http', '$', 'dataTableHelper', 'utilsService', suppliersController])
.directive('suppliers', [suppliersDirective]);
function suppliersDirective() {
return {
restrict: 'E',
templateUrl: 'suppliers/html/suppliersTemplate'
};
}
function suppliersController($scope, $rootScope, $compile, $http, $, dataTableHelper, utilsService) {
const translationPath = 'suppliers.tables.headers.';
$scope.subModule = 'suppliers';
$scope.setSubModule = setSubModule;
$scope.isSubmoduleVisible = isSubmoduleVisible;
$scope.getSuppliers = getSuppliers;
$scope.getSuppliersProducts = getSuppliersProducts;
function setSubModule($event) {
$scope.subModule = $event.currentTarget.attributes.subModule.value;
}
function isSubmoduleVisible(subModule) {
return subModule === $scope.subModule;
}
function getSuppliersProducts() {
$http({
method: 'GET',
url: 'suppliers/api/getSuppliersProductsHeaders'
}).then(showSuppliersProducts, utilsService.onHttpError);
}
function showSuppliersProducts(response) {
if (response.data.length > 0) {
const params = {
selector: '#suppliers-products',
url: 'suppliers/api/getSuppliersProducts',
hasEdit: true,
extraTableOptions: {
responsive: false,
order: [
[1, 'asc']
]
}
};
dataTableHelper.generateColumns(response.data, translationPath, dataTableHelper.showTable, params, formatSuppliersProductsColumn)
.then((table) => {
addEditEvent(table, params.selector, 'suppliers-products-add-edit', 'suppliersProductsAddEditCtrl', getSuppliersProducts);
addShowDocumentsEvent(table, params.selector, getSuppliersProducts);
});
}
}
function getSuppliers() {
$http({
method: 'GET',
url: 'suppliers/api/getSuppliersHeaders',
}).then(showSuppliers, utilsService.onHttpError);
}
function showSuppliers(response) {
if (response.data.length > 0) {
const params = {
selector: '#suppliers',
url: 'suppliers/api/getSuppliers',
hasEdit: true,
extraTableOptions: {
responsive: false,
order: [
[1, 'asc']
]
}
};
dataTableHelper.generateColumns(response.data, translationPath, dataTableHelper.showTable, params, formatSuppliersColumn)
.then((table) => {
addEditEvent(table, params.selector, 'suppliers-add-edit', 'suppliersAddEditCtrl', getSuppliers);
});
}
}
function addShowDocumentsEvent(table, containerSelector, callback) {
$(containerSelector + ' tbody').off('click', 'td.show-documents');
$(containerSelector + ' tbody').on('click', 'td.show-documents', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
row.child.hide();
tr.removeClass('shown');
} else {
const newScope = $rootScope.$new();
newScope.data = $.extend(true, {}, row.data());
const directiveHtml = '<show-product-documents class="product-documents" ng-controller="showProductDocumentsCtrl" ></show-product-documents>';
const layerId = newScope.data.idProduct + '-' + newScope.data.idSupplier + '-' + newScope.data.idCountry;
newScope.formAction = 'EDIT';
newScope.onUpdated = callback;
const layerSelector = 'edit-layer-' + layerId;
row.child('<div class="edit-tr" id="' + layerSelector + '"></div>').show();
const comp = $compile($(directiveHtml))(newScope);
newScope.$apply();
$('#' + layerSelector).append(comp);
tr.addClass('shown');
}
});
}
function addEditEvent(table, containerSelector, directive, controller, callback) {
$(containerSelector + ' tbody').off('click', 'td.info-edit');
$(containerSelector + ' tbody').on('click', 'td.info-edit', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
row.child.hide();
tr.removeClass('shown');
} else {
const newScope = $rootScope.$new();
newScope.data = $.extend(true, {}, row.data());
const directiveHtml = '<' + directive + ' class="' + directive + '" ng-controller="' + controller + '" ng-init="getProductCategories(\'' + newScope.data.category + '\')"></' + directive + '>';
const layerId = directive === 'suppliers-add-edit' ? newScope.data.id : newScope.data.idProduct + '-' + newScope.data.idSupplier + '-' + newScope.data.idCountry;
newScope.formAction = 'EDIT';
newScope.onUpdated = callback;
const layerSelector = 'edit-layer-' + layerId;
row.child('<div class="edit-tr" id="' + layerSelector + '"></div>').show();
const comp = $compile($(directiveHtml))(newScope);
newScope.$apply();
$('#' + layerSelector).append(comp);
tr.addClass('shown');
}
});
}
function formatSuppliersProductsColumn(value, translations) {
const columnObj = {
data: value,
title: translations[translationPath + value]
};
const renders = getSupplierProductsRenders();
columnObj.visible = isColumnVisible(value);
if (typeof renders[value] !== 'undefined') {
columnObj.render = renders[value];
}
if(value === 'documents'){
columnObj.className = 'show-documents';
}
return columnObj;
}
function isColumnVisible(value) {
const notVisibleFields = [
'idCountry',
'idSupplier',
'isPriceRecurring',
'idProductType'
];
return notVisibleFields.indexOf(value) === -1;
}
function getSupplierProductsRenders() {
return {
payPeriod: payPeriodRender,
unitCostPrice: priceRender,
unitVatCost: priceRender,
isAvailable: isAvailableRender,
documents: documentsRender
};
function payPeriodRender(data) {
return data !== '0' ? data : null;
}
function priceRender(data, type, row) {
return parseInt(row.isPriceRecurring) === 1 ? data + ' / month' : data;
}
function isAvailableRender(data){
return parseInt(data) === 1 ? 'yes' : 'no';
}
function documentsRender(data){
let html = data.length > 0 ? '<div class="show-documents-icon"><span class="glyphicon glyphicon-plus"></span> Show</div>' : '-';
return html;
}
}
function formatSuppliersColumn(value, translations) {
const columnObj = {
data: value,
title: translations[translationPath + value]
};
const renders = getSuppliersRenders();
columnObj.visible = isColumnVisible(value);
if (typeof renders[value] !== 'undefined') {
columnObj.render = renders[value];
}
return columnObj;
}
function getSuppliersRenders() {
return {
sellsIn: suppliersSellsInRender
};
function suppliersSellsInRender(data) {
return data ? data.replace(/,/g, '<br/>') : '-';
}
}
}
})();

View File

@@ -0,0 +1,139 @@
.module-layer{
position : relative;
margin-top: 1%;
background: rgba(255, 255, 255, 0.8);
margin-bottom: 3%;
}
.suppliers-info{
display: inline-block;
width:10%;
}
#suppliers-layer{
.module-layer;
.edit-tr{
display: block;
width:100%;
}
.suppliers-add-edit{
width: 100%;
display: block;
}
.supplier-input{
display: block;
width: 100%;
}
.supplier-group{
display: block;
width:100%;
margin-bottom: 1%;
}
}
#suppliers-products-layer{
.module-layer;
.edit-tr{
display: block;
width:100%;
}
.product-input{
display: block;
width: 100%;
}
.product-group{
display: inline-block;
width:48%;
margin-bottom: 1%;
}
.drop-box {
cursor: pointer;
color: #337ab7;
border: 5px dashed #337ab7;
border-radius: 10px;
text-align: center;
vertical-align: middle;
font-size: 150%;
padding: 10% 0;
margin-top: 2%;
}
.dragover {
border: 5px dashed #4CC417;
}
.show-documents-icon{
cursor: pointer;
}
.remove-document-icon{
cursor: pointer;
color: red;
margin-left: 5px;
}
}
#suppliers-products-add-layer{
.module-layer;
padding-bottom: 2%;
.form-notice{
display: inline-block;
}
.notice-icon{
color: #337ab7;
}
.product-radio-layer{
display: inline-block;
margin-left: 1%;
}
}
#suppliers-add-layer{
.module-layer;
padding-bottom: 2%;
#suppliers-add-steps-layer{
display: inline-block;
width:100%;
text-align: center;
}
.suppliers-add-step{
display: inline-block;
padding: 1%;
border-radius: 5px;
}
.step-ongoing{
background: #2184be;
color: #FFF;
}
.step-done{
background: #9dc8e2;
color: #FFF;
}
.step-inactive{
background: #eee;
color: #aaa;
}
.step-link{
display: inline-block;
height: 2px;
width: 5%;
background: #2184be;
vertical-align: middle;
}
}

View File

@@ -0,0 +1,72 @@
(function () {
global.dashModule
.controller('uploadProductDocumentCtrl', ['$scope', '$', '$http', '$translate', 'utilsService', 'Upload', uploadProductDocumentCtrl])
.directive('uploadProductDocument', [uploadProductDocumentDirective]);
function uploadProductDocumentDirective() {
return {
restrict: 'E',
templateUrl: 'suppliers/html/uploadProductDocumentTempalte'
};
}
function uploadProductDocumentCtrl($scope, $, $http, $translate, utilsService, Upload) {
$scope.uploadFile = uploadFile;
$scope.getDocumentTypes = getDocumentTypes;
$scope.selectFileType = selectFileType;
$scope.visibleToCustomer = '1';
$scope.selectedFileType = {};
const idSupplierProduct = $scope.$parent.data.idProduct;
function getDocumentTypes() {
$http({
url: 'documents/api/getDocumentTypes',
method: 'POST',
data: $.param({
withoutTemplates: true
})
}).then(setDocumentTypes, utilsService.onHttpError);
}
function setDocumentTypes(response){
if(response.data && response.data.length){
$scope.documentTypes = response.data.filter((documentType) => {
return documentType.isSpecialType !== 1;
});
}
}
function selectFileType(docType){
$scope.selectedFileType = docType;
}
function uploadFile(file) {
Upload.upload({
url: 'suppliers/api/uploadProductDocument',
method: 'POST',
file: file,
data: {
idSupplierProduct,
idDocumentType: $scope.selectedFileType.idDocumentType || 0,
visibleToCustomer: $scope.visibleToCustomer,
documentName: $scope.documentName
}
}).then(displayMessage, utilsService.onHttpError);
}
function displayMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('suppliers.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
if(messageObj.code === 'success'){
$scope.fileName = '';
if (typeof $scope.$parent.onUpdated !== 'undefined') {
$scope.$parent.onUpdated();
}
}
});
}
}
}
})();