SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/mcsm/mcsm-details-directive.js

103 lines
6.0 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('mcsmModule')
.directive('mcsmDetails', ['mcsmModel', '$filter', 'systemAlertService', 'i18nService',
function (mcsmModel, $filter, systemAlertService, i18nService) {
return {
restrict: 'E',
templateUrl: 'views/mcsm/mcsm-details.html',
scope: {
ticket: '=',
showDeleteIcon: '='
},
link: function (scope) {
scope.allManualAssociationSupportingSystems = [];
scope.manualAssociationSupportingSystems = [];
scope.isManualAssociationInProgress = false;
scope.allowManualAssociationToMultipleVendors = false;
scope.ticketType = i18nService.getLocalizedString('ticket.type.' + scope.ticket.type) || scope.ticket.type;
scope.manualAssociationHelpText = i18nService.getLocalizedStringwithParams('ticket.vendor.label.helpText', [scope.ticketType, scope.ticketType, scope.ticketType]);
if (scope.ticket.isMCSMEnabled) {
mcsmModel.getManualAssociationSupportingSystems(scope.ticket.type)
.then(function (response) {
scope.allManualAssociationSupportingSystems = response;
if (scope.allManualAssociationSupportingSystems.length > 0 && !scope.allowManualAssociationToMultipleVendors) {
if (scope.allManualAssociationSupportingSystems.length > 1) {
scope.manualAssociationHelpText += ' ' + i18nService.getLocalizedString('ticket.vendor.label.helpTextSingleVendor');
}
scope.$watchCollection('ticket.vendorInfo', function (newVendorInfo) {
if (_.isArray(newVendorInfo) && newVendorInfo[0] && newVendorInfo[0].vendor && newVendorInfo[0].vendor.id) {
scope.manualAssociationSupportingSystems = _.filter(scope.allManualAssociationSupportingSystems, { id: newVendorInfo[0].vendor.id });
}
else {
scope.manualAssociationSupportingSystems = scope.allManualAssociationSupportingSystems;
}
});
}
});
}
scope.startManualAssociation = function (systemSelected) {
scope.isManualAssociationInProgress = true;
mcsmModel.updateAssociation(scope.ticket.type, scope.ticket.displayId, systemSelected.id)
.then(function (response) {
scope.ticket.vendorInfo = response;
scope.ticket.brokerVendorName = systemSelected.providerName || systemSelected.name;
})
.catch(function (error) {
systemAlertService.error({
text: (error.data && (error.data.detailedMessage || error.data.error)) || error,
clear: false
});
})
.finally(function () {
scope.isManualAssociationInProgress = false;
});
};
scope.removeAssociation = function (item, $event) {
$event.stopPropagation();
var modalInstance = systemAlertService.modal({
title: $filter('i18n')('common.notification.delete.title'),
text: $filter('i18n')('common.notification.delete.message'),
buttons: [
{
text: $filter('i18n')('common.notification.delete.button1'),
data: true
},
{
text: $filter('i18n')('common.notification.delete.button2'),
data: false
}
]
});
modalInstance.result.then(function (data) {
if (data) {
item.isRemoveAssociationInProgress = true;
mcsmModel.removeAssociation(scope.ticket.type, scope.ticket.displayId, item.id, item.vendor.id)
.then(function () {
systemAlertService.success({
text: $filter('i18n')('ticket.notification.unlink.message', 1),
hide: 10000
});
_.remove(scope.ticket.vendorInfo, { id: item.id });
if (scope.ticket.vendorInfo.length === 0) {
scope.ticket.brokerVendorName = '';
}
})
.catch(function (error) {
systemAlertService.error({
text: (error.data && (error.data.detailedMessage || error.data.error)) || error,
clear: false
});
})
.finally(function () {
item.isRemoveAssociationInProgress = false;
});
}
});
};
}
};
}]);
})();