UNPKG

adf-aos-editonline-action

Version:
198 lines (197 loc) 7.13 kB
import { Injectable, NgModule } from '@angular/core'; import { AlfrescoApiService, AppConfigService, AuthenticationService, NotificationService } from '@alfresco/adf-core'; import { CommonModule } from '@angular/common'; var AosEditOnlineService = (function () { /** * @param {?} alfrescoApiService * @param {?} alfrescoAuthenticationService * @param {?} appConfigService * @param {?} notificationService */ function AosEditOnlineService(alfrescoApiService, alfrescoAuthenticationService, appConfigService, notificationService) { this.alfrescoApiService = alfrescoApiService; this.alfrescoAuthenticationService = alfrescoAuthenticationService; this.appConfigService = appConfigService; this.notificationService = notificationService; } /** * @param {?} node * @return {?} */ AosEditOnlineService.prototype.onActionEditOnlineAos = function (node) { if (node.isFile) { if (node.isLocked) { var /** @type {?} */ checkedOut = node.aspectNames.find(function (aspect) { return aspect === 'cm:checkedOut'; }); var /** @type {?} */ lockOwner = node.properties['cm:lockOwner']; var /** @type {?} */ differentLockOwner = lockOwner.id !== this.alfrescoAuthenticationService.getEcmUsername(); if (checkedOut && differentLockOwner) { this.onAlreadyLockedNotification(node.id, lockOwner); } else { this.triggerEditOnlineAos(node); } } else { this.triggerEditOnlineAos(node); } } }; /** * @return {?} */ AosEditOnlineService.prototype.getUserAgent = function () { return navigator.userAgent.toLowerCase(); }; /** * @return {?} */ AosEditOnlineService.prototype.isWindows = function () { return this.getUserAgent().indexOf('win') !== -1 ? true : false; }; /** * @return {?} */ AosEditOnlineService.prototype.isMacOs = function () { return this.getUserAgent().indexOf('mac') !== -1 ? true : false; }; /** * @param {?} nodeId * @param {?} lockOwner * @return {?} */ AosEditOnlineService.prototype.onAlreadyLockedNotification = function (nodeId, lockOwner) { this.notificationService.openSnackMessage("Document {nodeId} locked by {lockOwner}", 3000); }; /** * @param {?} fileExtension * @return {?} */ AosEditOnlineService.prototype.getProtocolForFileExtension = function (fileExtension) { return AosEditOnlineService.MS_PROTOCOL_NAMES[fileExtension]; }; /** * @param {?} node * @return {?} */ AosEditOnlineService.prototype.triggerEditOnlineAos = function (node) { var /** @type {?} */ url = this.onlineEditUrlAos(node); var /** @type {?} */ fileExtension = node.name.split('.').pop() !== null ? node.name.split('.').pop().toLowerCase() : ''; var /** @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 {?} */ AosEditOnlineService.prototype.onlineEditUrlAos = function (node) { var /** @type {?} */ pathElements = node.path.elements.slice(1, node.path.elements.length); var /** @type {?} */ path = '/'; for (var _i = 0, pathElements_1 = pathElements; _i < pathElements_1.length; _i++) { var element = pathElements_1[_i]; path = path + element.name + '/'; } var /** @type {?} */ ecmHost = this.appConfigService.get(AosEditOnlineService.ECM_HOST_CONFIG_KEY); var /** @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 {?} */ AosEditOnlineService.prototype.aos_tryToLaunchOfficeByMsProtocolHandler = function (protocolHandler, url) { var /** @type {?} */ protocolUrl = protocolHandler + ':ofe%7Cu%7C' + url; var /** @type {?} */ input = document.createElement('input'); var /** @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); }; return AosEditOnlineService; }()); 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 = function () { return [ { type: AlfrescoApiService, }, { type: AuthenticationService, }, { type: AppConfigService, }, { type: NotificationService, }, ]; }; var AosModule = (function () { function AosModule() { } return AosModule; }()); AosModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [], exports: [], providers: [ AosEditOnlineService ] },] }, ]; /** * @nocollapse */ AosModule.ctorParameters = function () { return []; }; /** * Generated bundle index. Do not edit. */ export { AosEditOnlineService, AosModule }; //# sourceMappingURL=adf-aos-editonline-action.es5.js.map