adf-aos-editonline-action
Version:
Alfresco ADF AOS action
198 lines (192 loc) • 6.48 kB
JavaScript
import { Injectable, NgModule } from '@angular/core';
import { AlfrescoApiService, AppConfigService, AuthenticationService, NotificationService } from '@alfresco/adf-core';
import { CommonModule } from '@angular/common';
class AosEditOnlineService {
/**
* @param {?} alfrescoApiService
* @param {?} alfrescoAuthenticationService
* @param {?} appConfigService
* @param {?} notificationService
*/
constructor(alfrescoApiService, alfrescoAuthenticationService, appConfigService, notificationService) {
this.alfrescoApiService = alfrescoApiService;
this.alfrescoAuthenticationService = alfrescoAuthenticationService;
this.appConfigService = appConfigService;
this.notificationService = notificationService;
}
/**
* @param {?} node
* @return {?}
*/
onActionEditOnlineAos(node) {
if (node.isFile) {
if (node.isLocked) {
let /** @type {?} */ checkedOut = node.aspectNames.find((aspect) => aspect === 'cm:checkedOut');
let /** @type {?} */ lockOwner = node.properties['cm:lockOwner'];
let /** @type {?} */ differentLockOwner = lockOwner.id !== this.alfrescoAuthenticationService.getEcmUsername();
if (checkedOut && differentLockOwner) {
this.onAlreadyLockedNotification(node.id, lockOwner);
}
else {
this.triggerEditOnlineAos(node);
}
}
else {
this.triggerEditOnlineAos(node);
}
}
}
/**
* @return {?}
*/
getUserAgent() {
return navigator.userAgent.toLowerCase();
}
/**
* @return {?}
*/
isWindows() {
return this.getUserAgent().indexOf('win') !== -1 ? true : false;
}
/**
* @return {?}
*/
isMacOs() {
return this.getUserAgent().indexOf('mac') !== -1 ? true : false;
}
/**
* @param {?} nodeId
* @param {?} lockOwner
* @return {?}
*/
onAlreadyLockedNotification(nodeId, lockOwner) {
this.notificationService.openSnackMessage(`Document {nodeId} locked by {lockOwner}`, 3000);
}
/**
* @param {?} fileExtension
* @return {?}
*/
getProtocolForFileExtension(fileExtension) {
return AosEditOnlineService.MS_PROTOCOL_NAMES[fileExtension];
}
/**
* @param {?} node
* @return {?}
*/
triggerEditOnlineAos(node) {
let /** @type {?} */ url = this.onlineEditUrlAos(node);
let /** @type {?} */ fileExtension = node.name.split('.').pop() !== null ? node.name.split('.').pop().toLowerCase() : '';
let /** @type {?} */ protocolHandler = this.getProtocolForFileExtension(fileExtension);
if (protocolHandler === undefined) {
this.notificationService.openSnackMessage(`No protocol handler found for {fileExtension}`, 3000);
return;
}
if (!this.isWindows() && !this.isMacOs()) {
this.notificationService.openSnackMessage('Only supported for Windows and Mac', 3000);
}
else {
this.aos_tryToLaunchOfficeByMsProtocolHandler(protocolHandler, url);
}
}
/**
* @param {?} node
* @return {?}
*/
onlineEditUrlAos(node) {
let /** @type {?} */ pathElements = node.path.elements.slice(1, node.path.elements.length);
let /** @type {?} */ path = '/';
for (let /** @type {?} */ element of pathElements) {
path = path + element.name + '/';
}
let /** @type {?} */ ecmHost = this.appConfigService.get(AosEditOnlineService.ECM_HOST_CONFIG_KEY);
let /** @type {?} */ url = ecmHost + '/alfresco/aos' + path + '/' + node.name;
if (encodeURI(url).length > 256) {
url = ecmHost + '/alfresco/aos/' + '_aos_nodeid' + '/' + node.id + '/' + node.name;
}
return url;
}
/**
* @param {?} protocolHandler
* @param {?} url
* @return {?}
*/
aos_tryToLaunchOfficeByMsProtocolHandler(protocolHandler, url) {
let /** @type {?} */ protocolUrl = protocolHandler + ':ofe%7Cu%7C' + url;
let /** @type {?} */ input = document.createElement('input');
let /** @type {?} */ inputTop = document.body.scrollTop + 10;
input.setAttribute('style', 'z-index: 1000; background-color: rgba(0, 0, 0, 0); border: none; outline: none; position: absolute; left: 10px; top: ' + inputTop + 'px;');
document.getElementsByTagName('body')[0].appendChild(input);
input.focus();
input.onblur = function () {
};
location.href = protocolUrl;
setTimeout(function () {
input.onblur = null;
input.remove();
}, 500);
}
}
AosEditOnlineService.ECM_HOST_CONFIG_KEY = 'ecmHost';
AosEditOnlineService.AOS_EDITONLINE_ACTION_HANDLER_KEY = 'aos-editonline';
AosEditOnlineService.MS_PROTOCOL_NAMES = {
'doc': 'ms-word',
'docx': 'ms-word',
'docm': 'ms-word',
'dot': 'ms-word',
'dotx': 'ms-word',
'dotm': 'ms-word',
'xls': 'ms-excel',
'xlsx': 'ms-excel',
'xlsb': 'ms-excel',
'xlsm': 'ms-excel',
'xlt': 'ms-excel',
'xltx': 'ms-excel',
'xltm': 'ms-excel',
'ppt': 'ms-powerpoint',
'pptx': 'ms-powerpoint',
'pot': 'ms-powerpoint',
'potx': 'ms-powerpoint',
'potm': 'ms-powerpoint',
'pptm': 'ms-powerpoint',
'pps': 'ms-powerpoint',
'ppsx': 'ms-powerpoint',
'ppam': 'ms-powerpoint',
'ppsm': 'ms-powerpoint',
'sldx': 'ms-powerpoint',
'sldm': 'ms-powerpoint'
};
AosEditOnlineService.decorators = [
{ type: Injectable },
];
/**
* @nocollapse
*/
AosEditOnlineService.ctorParameters = () => [
{ type: AlfrescoApiService, },
{ type: AuthenticationService, },
{ type: AppConfigService, },
{ type: NotificationService, },
];
class AosModule {
}
AosModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
declarations: [],
exports: [],
providers: [
AosEditOnlineService
]
},] },
];
/**
* @nocollapse
*/
AosModule.ctorParameters = () => [];
/**
* Generated bundle index. Do not edit.
*/
export { AosEditOnlineService, AosModule };
//# sourceMappingURL=adf-aos-editonline-action.js.map