61 lines
3.1 KiB
JavaScript
61 lines
3.1 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('knowledgeArticleModule')
|
|
.directive('previewKnowledgeArticle', ['events', 'configurationModel', 'utilityFunctions', function (events, configurationModel, utilityFunctions) {
|
|
return {
|
|
restrict: 'A',
|
|
templateUrl: 'views/knowledge-article/knowledge-article-details.html',
|
|
controller: 'KnowledgeArticleController',
|
|
scope: {
|
|
selectedItem: '='
|
|
},
|
|
link: function (scope, element, attr) {
|
|
scope.isFullVersion = false;
|
|
scope.noPreviewAvailable = false;
|
|
scope.previewId;
|
|
function editClickHandler() {
|
|
scope.handleEditClick();
|
|
}
|
|
element.on(events.CHANGE_TO_EDIT_MODE, editClickHandler);
|
|
scope.$on(events.REFRESH_KNOWLEDGE_ARTICLE, function () {
|
|
scope.getArticle(scope.article.id, true);
|
|
});
|
|
scope.$on('$destroy', function () {
|
|
if (scope.editMode || scope.state.gettingEditStatus) {
|
|
scope.editMode = false;
|
|
scope.$emit(events.TOGGLE_KNOWLEDGE_ARTICLE_EDIT_MODE);
|
|
}
|
|
element.off(events.CHANGE_TO_EDIT_MODE, editClickHandler);
|
|
});
|
|
scope.openArticleRevision = function (revision) {
|
|
scope.$emit(events.SET_PREVIEW_ITEM, { id: revision.id, type: EntityVO.TYPE_KNOWLEDGE, status: revision.status });
|
|
};
|
|
scope.openHKM = function () {
|
|
if (scope.selectedItem && scope.selectedItem.additionalInformation && scope.selectedItem.additionalInformation.comaroundGetUrl
|
|
&& utilityFunctions.isValidHttpUrl(scope.selectedItem.additionalInformation.comaroundGetUrl)) {
|
|
scope.$broadcast(events.CLOSE_TICKET_PREVIEW);
|
|
window.open(scope.selectedItem.additionalInformation.comaroundGetUrl, '_blank');
|
|
}
|
|
else {
|
|
console.error("Provided Comaround URL is invalid");
|
|
}
|
|
};
|
|
attr.$observe('previewKnowledgeArticle', function (articleId) {
|
|
if (configurationModel.comaroundEnabled && (attr.isFromLivechat !== "true")) {
|
|
scope.noPreviewAvailable = true;
|
|
scope.previewId = articleId;
|
|
return;
|
|
}
|
|
if (scope.editMode) {
|
|
scope.editMode = false;
|
|
scope.$emit(events.CANCEL_EDIT_MODE);
|
|
}
|
|
scope.articleId = articleId;
|
|
scope.getArticle(articleId, false, false); //increment view count for preview.
|
|
});
|
|
}
|
|
};
|
|
}]);
|
|
}());
|