50 lines
2.5 KiB
JavaScript
50 lines
2.5 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.directive('chatAssignSuggestion', ['chatModel', function (chatModel) {
|
|
return {
|
|
restrict: 'AE',
|
|
templateUrl: 'components/chat/chat-assign-suggestion.html',
|
|
replace: true,
|
|
link: function (scope, $element) {
|
|
var jid = "";
|
|
scope.userProfilesCache = chatModel.cachedProfiles;
|
|
if (scope.item.hasOwnProperty('firstName') || scope.item.hasOwnProperty('loginId')) {
|
|
scope.item.isPerson = true;
|
|
jid = scope.item.jid;
|
|
if (jid) {
|
|
var cachedProfile = _.find(chatModel.cachedProfiles, { loginId: scope.item.loginId }) || {};
|
|
jid = cachedProfile.jid;
|
|
if (!jid) {
|
|
jid = chatModel.generateUserJID(scope.item.loginId);
|
|
jid && chatModel.checkUserAvailability(scope.jid);
|
|
}
|
|
}
|
|
}
|
|
else if (scope.item.hasOwnProperty('category')) {
|
|
scope.item.isPerson = false;
|
|
scope.item.itemStatus = scope.item.additionalInformation ? (scope.item.additionalInformation.status ? scope.item.additionalInformation.status.value : "") : "";
|
|
// scope.item.lastModified = moment(value.additionalInformation.modifiedDate).fromNow();
|
|
}
|
|
var clearProfileWatch = scope.$watch(function () {
|
|
return (jid && scope.userProfilesCache[jid]);
|
|
}, function (newVal) {
|
|
if (newVal) {
|
|
scope.item.available = chatModel.cachedProfiles[jid].available;
|
|
}
|
|
});
|
|
scope.generateSelectedClass = function ($index) {
|
|
var className = ($index == scope.searchBar.selectedSuggestionIndex) ? 'chat__search-result_selected-item' : '';
|
|
if (className && scope.searchBar.alignWithTop !== null) {
|
|
$element[0].scrollIntoView(false);
|
|
scope.searchBar.alignWithTop = null;
|
|
}
|
|
return className;
|
|
};
|
|
scope.$on('destroy', clearProfileWatch);
|
|
}
|
|
};
|
|
}]);
|
|
}());
|