(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 = '