SmartIT_Extensions/BMC/smart-it-full/scripts/app/person/person-controller.js

232 lines
13 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('personModule')
.controller('PersonController', ['$scope', 'personModel', 'userModel', '$state', '$filter', 'attachmentService', 'screenConfigurationModel', 'events', 'ticketActionService', '$q', 'chatModel', '$modal', 'openMailClientService', 'configurationModel', 'metadataModel',
function ($scope, personModel, userModel, $state, $filter, attachmentService, screenConfigurationModel, events, ticketActionService, $q, chatModel, $modal, openMailClientService, configurationModel, metadataModel) {
var screenName = screenConfigurationModel.getScreenNameByTicketType(EntityVO.TYPE_PERSON);
$scope.isServiceBrokerEnabled = configurationModel.isServerApplicationEnabled(EntityVO.TYPE_SBEREQUEST);
/**
* Public functions
*
*/
$scope.follow = function () {
var userLoginId = userModel.userFullData.loginId;
return personModel.followPerson(userLoginId, $scope.person.loginId);
};
$scope.unfollow = function () {
var userLoginId = userModel.userFullData.loginId;
return personModel.unfollowPerson(userLoginId, $scope.person.loginId);
};
$scope.toggleFollowingFlag = function () {
var toggleFollowingFunction = $scope.person.following ? $scope.unfollow : $scope.follow;
toggleFollowingFunction($scope.person).then(function () {
$scope.person.following = !$scope.person.following;
});
};
$scope.share = function ($event) {
ticketActionService.showShareDialog($scope.person).result.then(function () {
$event.currentTarget.focus();
}, function () {
$event.currentTarget.focus();
});
};
$scope.emailPerson = function () {
var subject = userModel.userFullData.fullName + $filter('i18n')('shareBlade.emailSubject');
openMailClientService.openMailClient($scope.person.email, subject, '');
};
$scope.showPrintDialog = function ($event) {
var ticketPrintDialog = $modal.open({
templateUrl: 'views/common/print-action-blade.html',
controller: 'PrintController',
windowClass: 'action-blade',
size: 'extra-lg',
resolve: {
params: function () {
return {
entity: $scope.person,
feed: $scope.person.feed
};
}
}
});
ticketPrintDialog.result.finally(function () {
$event.currentTarget.focus();
});
};
/**
* Set active task section (Home / Workorders / View All)
* @param {String} sectionId
*/
$scope.setTaskSection = function (sectionId) {
$scope.activeTaskSection = sectionId;
};
/**
* Entry point
*/
$scope.init = function (personId) {
$scope.$on(events.TOGGLE_EDIT_MODE, handleToggleEditMode);
$scope.$on(events.EDIT_COMPLETE, handleEditComplete);
$scope.$on('personDataUpdated', handlePersonDataUpdated);
if (!personId) {
return;
}
$scope.editHeader = false;
$scope.isCollapsed = true;
$scope.activeTaskSection = 'assets';
$scope.state = {
isPersonDataLoading: true
};
$scope.chatModel = chatModel;
personModel.getServiceSummaryStats(personId).then(function () {
$scope.serviceSummary = personModel.serviceSummary;
});
$q.all([personModel.getPersonDetailsByID(personId), screenConfigurationModel.loadScreenConfigurationAndCustomFieldLabels(screenName, EntityVO.TYPE_PERSON)]).then(onPersonDetailsLoaded).finally(onDataLoadComplete);
personModel.getPersonAssets(personId, true).then(function () {
$scope.personAssetList = personModel.personAssets;
});
$q.all(metadataModel.getMetadataByType(EntityVO.TYPE_WORKORDER), metadataModel.getMetadataByType(EntityVO.TYPE_INCIDENT), metadataModel.getMetadataByType(EntityVO.TYPE_ASSET), metadataModel.getMetadataByType(EntityVO.TYPE_PROBLEM), metadataModel.getMetadataByType(EntityVO.TYPE_CHANGE), metadataModel.getMetadataByType(EntityVO.TYPE_TASK), metadataModel.getMetadataByType(EntityVO.TYPE_RELEASE), metadataModel.getMetadataByType(EntityVO.TYPE_KNOWLEDGE)).then(function () {
personModel.getOpenTickets(personId).then(function () {
$scope.personOpenTickets = personModel.personOpenTickets.ticketList;
$scope.personOpenTicketsTotalMatches = personModel.personOpenTickets.totalMatches;
});
});
};
$scope.showProfileDetails = function (item, type, $event) {
if ('href' in $event.target) {
return;
}
switch (type) {
case EntityVO.TYPE_TICKET:
$state.go(item.type, { id: item.id });
break;
case EntityVO.TYPE_ASSET:
$state.go(type, { assetId: item.reconciliationId, assetClassId: item.classId });
break;
case EntityVO.TYPE_KNOWLEDGE:
$state.go(type, { id: item.uuid });
break;
}
};
$scope.handleFileChange = function (fileInput) {
//TODO: create ng-upload directive, which will be handling file inputs, to get rid of input class hardcoding
attachmentService.uploadProfileThumbnail($scope.person.loginId, EntityVO.TYPE_PERSON, fileInput, '')
.then(function (response) {
if (response.thumbnail) {
$scope.person.thumbnail = response.thumbnail;
if ($scope.person.loginId === userModel.userFullData.loginId) {
userModel.userFullData.thumbnail = response.thumbnail;
}
}
});
};
/**
* Handler for toggling edit mode
*
* @param event
* @param editableContentSectionId
*/
function handleToggleEditMode(event, editableContentSectionId) {
$scope.activeEditableSectionId = editableContentSectionId;
if (editableContentSectionId === 'ticket-header') {
$scope.editHeader = true;
}
}
function handleEditComplete(event, editableContentSectionId) {
$scope.activeEditableSectionId = null;
if (editableContentSectionId === 'ticket-header') {
$scope.editHeader = false;
}
}
function handlePersonDataUpdated() {
$scope.person = personModel.personDetails;
}
$scope.editDisabledFor = function (sectionId) {
return $scope.activeEditableSectionId && $scope.activeEditableSectionId !== sectionId;
};
/**
* Handle "Load More" event
*/
$scope.loadMoreRequestedByTickets = function () {
if (!$scope.state.isPersonDataLoading && !$scope.state.isMoreRequestedByTicketsLoading
&& personModel.personOpenTickets.totalMatches > personModel.personOpenTickets.ticketList.length) {
$scope.state.isMoreRequestedByTicketsLoading = true;
personModel.getOpenTickets(personModel.personDetails.id, personModel.personOpenTickets.ticketList.length).finally(function () {
$scope.state.isMoreRequestedByTicketsLoading = false;
$scope.personOpenTickets = personModel.personOpenTickets.ticketList;
$scope.personOpenTicketsTotalMatches = personModel.personOpenTickets.totalMatches;
});
}
};
$scope.loadMoreAllTickets = function () {
if (!$scope.state.isPersonDataLoading && !$scope.state.isMoreAllTicketsLoading
&& personModel.personAllTickets.totalMatches > personModel.personAllTickets.ticketList.length) {
$scope.state.isMoreAllTicketsLoading = true;
personModel.getAllTickets(personModel.personDetails.id, personModel.personAllTickets.ticketList.length).finally(function () {
$scope.state.isMoreAllTicketsLoading = false;
$scope.personAllTickets = personModel.personAllTickets.ticketList;
$scope.personAllTicketsTotalMatches = personModel.personAllTickets.totalMatches;
});
}
};
$scope.loadMoreAssignedTickets = function () {
if (!$scope.state.isPersonDataLoading && !$scope.state.isPersonMoreTicketsLoading
&& personModel.personAssignedTickets.totalMatches > personModel.personAssignedTickets.ticketList.length) {
$scope.state.isPersonMoreTicketsLoading = true;
personModel.getAssignedTickets(personModel.personDetails.id, personModel.personAssignedTickets.ticketList.length).finally(function () {
$scope.state.isPersonMoreTicketsLoading = false;
$scope.personAssignedTickets = personModel.personAssignedTickets.ticketList;
$scope.totalMatches = personModel.personAssignedTickets.totalMatches;
});
}
};
$scope.getMoreOpenServiceBrokerTickets = function () {
$scope.state.isPersonMoreOpenSBETicketsLoading = true;
personModel.getOpenServiceBrokerTickets(personModel.personDetails.id, personModel.personOpenServiceBrokerTickets.ticketList.length).finally(function () {
$scope.state.isPersonMoreOpenSBETicketsLoading = false;
$scope.personOpenSBETickets = personModel.personOpenServiceBrokerTickets.ticketList;
$scope.personOpenSBETicketsTotalMatches = personModel.personOpenServiceBrokerTickets.totalMatches;
});
};
$scope.isURL = function (str) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
return regexp.test(str);
};
function onPersonDetailsLoaded() {
$scope.person = personModel.personDetails;
$scope.disableClick = (_.isUndefined($scope.person.email) || $scope.person.email == "") ? true : false;
$scope.personSupportGroups = personModel.personDetails.supportGroups;
$scope.personAvailability = $scope.person.availability;
if (!$scope.isFullVersion) {
$scope.person.accessMappings.detailsEditAllowed = false;
}
if ($scope.person.isSupportStaff) {
personModel.getAssignedTickets($scope.person.loginId).then(function () {
$scope.personAssignedTickets = personModel.personAssignedTickets.ticketList;
$scope.personAssignedTicketsTotalMatches = personModel.personAssignedTickets.totalMatches;
});
personModel.getKnowledgeArticles($scope.person.loginId).then(function () {
$scope.personKnowledgeArticles = personModel.personKnowledgeArticles;
$scope.personKnowledgeArticlesTotalMatches = personModel.personKnowledgeArticles.totalMatches;
});
}
else {
personModel.getAllTickets($scope.person.loginId).then(function () {
$scope.personAllTickets = personModel.personAllTickets.ticketList;
$scope.personAllTicketsTotalMatches = personModel.personAllTickets.totalMatches;
});
}
if ($scope.isServiceBrokerEnabled) {
personModel.getOpenServiceBrokerTickets($scope.person.loginId).then(function () {
$scope.personOpenSBETickets = personModel.personOpenServiceBrokerTickets.ticketList;
$scope.personOpenSBETicketsTotalMatches = personModel.personOpenServiceBrokerTickets.totalMatches;
});
}
}
function onDataLoadComplete() {
$scope.state.isPersonDataLoading = false;
}
$scope.$on(events.EDIT_COMPLETE, handleEditComplete);
}]);
})();