(function () {
global.dashModule
.controller('ordersController', ['$scope', '$rootScope', '$http', '$compile', '$translate', '$', 'dataTableHelper', 'utilsService', 'ORDER_STATUSES_ICONS', 'ORDER_STATUSES', ordersController])
.directive('orders', [ordersDirective]);
function ordersDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/ordersTemplate'
};
}
function ordersController($scope, $rootScope, $http, $compile, $translate, $, dataTableHelper, utilsService, ORDER_STATUSES_ICONS, ORDER_STATUSES) {
const translationPath = 'orders.tables.headers.';
$scope.subModule = global.getParameterByName('subModule') || 'ongoing_orders';
$scope.setSubModule = setSubModule;
$scope.isSubmoduleVisible = isSubmoduleVisible;
$scope.getOngoingOrders = getOngoingOrders;
$scope.getOrdersHistory = getOrdersHistory;
$scope.brokers = [];
addUrlListener();
function addUrlListener() {
window.addEventListener('popstate', function (e) {
$scope.$evalAsync($scope => {
$scope.subModule = e.state ? e.state.subModule : 'ongoing_orders';
});
}, 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;
}
function getOngoingOrders() {
$http({
method: 'POST',
url: 'orders/api/getOngoingOrdersHeaders',
}).then(showOngoingOrders, utilsService.onHttpError);
}
function showOngoingOrders(response) {
if (response.data.brokers && response.data.brokers.length > 0) {
$scope.brokers = response.data.brokers;
}
if (response.data.headers.length > 0) {
const params = {
selector: '#ongoing-orders',
url: 'orders/api/getOngoingOrders',
hasDetails: true,
extraTableOptions: {
responsive: false,
order: [
[1, 'asc']
]
}
};
dataTableHelper.generateColumns(response.data.headers, translationPath, dataTableHelper.showTable, params, formatOrderColumn)
.then((table) => {
addDetailsEvent(table, params.selector);
addAssignBrokerDirectives();
});
}
}
function addAssignBrokerDirectives() {
$('#ongoing-orders tbody').off('click', '.assign-icon');
$('#ongoing-orders tbody').on('click', '.assign-icon', function () {
const assignSelector = $(this).parent().find('.assign-broker');
if (assignSelector.length) {
assignSelector.remove();
} else {
const parent = $(this).parent();
const idOrder = parent.attr('id-order');
const directiveHtml = '