incentro-adf-msoffice-module
Version:
Office module for Alfresco Apps Development Framework. Edit with MS Office
319 lines (315 loc) • 11.8 kB
JavaScript
import { Injectable, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* OfficeActionsService uses the Alfresco Office Services link to open documents.
*/
var OfficeActionsService = /** @class */ (function () {
function OfficeActionsService() {
this.DEFAULT_TIMEOUT = 2000;
this.userAgent = navigator.userAgent.toLowerCase();
this.messages = {
'WINDOWS_MAC_ONLY': 'Deze feature werkt alleen op Windows en Mac OS X.',
'TIMEOUT': 'U gebruikt een versie van Microsoft Office die niet door Alfresco wordt ondersteund. Probeer Microsoft Office bij te werken.'
};
}
/**
*
* @param entry NodeEntry
* @param ecmHost
* @param timeout (optional) in ms if it is 0 the timeout will not be set at all.
* @param messages (optional) {'WINDOWS_MAC_ONLY', 'TIMEOUT'} Translated strings
* @param openByMimeType (optional) boolean representing whether the correct protocol is chosen by the mimetype. false if not set.
*/
/**
*
* @param {?} entry NodeEntry
* @param {?} ecmHost
* @param {?=} timeout (optional) in ms if it is 0 the timeout will not be set at all.
* @param {?=} messages (optional) {'WINDOWS_MAC_ONLY', 'TIMEOUT'} Translated strings
* @param {?=} openByMimeType (optional) boolean representing whether the correct protocol is chosen by the mimetype. false if not set.
* @return {?}
*/
OfficeActionsService.prototype.editOnline = /**
*
* @param {?} entry NodeEntry
* @param {?} ecmHost
* @param {?=} timeout (optional) in ms if it is 0 the timeout will not be set at all.
* @param {?=} messages (optional) {'WINDOWS_MAC_ONLY', 'TIMEOUT'} Translated strings
* @param {?=} openByMimeType (optional) boolean representing whether the correct protocol is chosen by the mimetype. false if not set.
* @return {?}
*/
function (entry, ecmHost, timeout, messages, openByMimeType) {
if (messages) {
this.updateMessages(messages);
}
this.timeout = timeout || this.DEFAULT_TIMEOUT;
/** @type {?} */
var filepath = entry.path.name;
/** @type {?} */
var position = filepath.split('/', 2).join('/').length;
filepath = filepath.slice(position) + '/' + entry.name;
/** @type {?} */
var url = ecmHost + '/alfresco/aos' + filepath;
if (openByMimeType) {
/** @type {?} */
var mimeType = entry.content.mimeType;
this.triggerEditOnlineAosByMimeType(url, mimeType);
}
else {
/** @type {?} */
var extension = entry.name.substring(entry.name.lastIndexOf('.') + 1, entry.name.length);
this.triggerEditOnlineAosByExtension(url, extension);
}
};
/**
* @param {?} messages
* @return {?}
*/
OfficeActionsService.prototype.updateMessages = /**
* @param {?} messages
* @return {?}
*/
function (messages) {
if (messages.TIMEOUT) {
this.messages.TIMEOUT = messages.TIMEOUT;
}
if (messages.WINDOWS_MAC_ONLY) {
this.messages.WINDOWS_MAC_ONLY = messages.WINDOWS_MAC_ONLY;
}
};
/**
* @param {?} onlineEditUrlAos
* @param {?} fileExtension
* @return {?}
*/
OfficeActionsService.prototype.triggerEditOnlineAosByExtension = /**
* @param {?} onlineEditUrlAos
* @param {?} fileExtension
* @return {?}
*/
function (onlineEditUrlAos, fileExtension) {
/** @type {?} */
var protocolHandler = OfficeActionsService.getProtocolForFileExtension(fileExtension);
this.checkSupportedOSAndLaunch(protocolHandler, onlineEditUrlAos);
};
/**
* @param {?} onlineEditUrlAos
* @param {?} mimeType
* @return {?}
*/
OfficeActionsService.prototype.triggerEditOnlineAosByMimeType = /**
* @param {?} onlineEditUrlAos
* @param {?} mimeType
* @return {?}
*/
function (onlineEditUrlAos, mimeType) {
/** @type {?} */
var protocolHandler = OfficeActionsService.getProtocolForMimeType(mimeType);
this.checkSupportedOSAndLaunch(protocolHandler, onlineEditUrlAos);
};
/**
* @param {?} protocolHandler
* @param {?} onlineEditUrlAos
* @return {?}
*/
OfficeActionsService.prototype.checkSupportedOSAndLaunch = /**
* @param {?} protocolHandler
* @param {?} onlineEditUrlAos
* @return {?}
*/
function (protocolHandler, onlineEditUrlAos) {
// detect if we are on a supported operating system
if (!this.isWin() && !this.isMac()) {
alert(this.messages.WINDOWS_MAC_ONLY);
return;
}
this.launchMsOfficeProtocolHandler(protocolHandler, onlineEditUrlAos);
};
/**
* @param {?} protocolHandler
* @param {?} url
* @return {?}
*/
OfficeActionsService.prototype.launchMsOfficeProtocolHandler = /**
* @param {?} protocolHandler
* @param {?} url
* @return {?}
*/
function (protocolHandler, url) {
/** @type {?} */
var protocolHandlerPresent = false;
/** @type {?} */
var input = document.createElement('input');
/** @type {?} */
var inputTop = document.body.scrollTop + 10;
input.setAttribute('style', "\n z-index: 1000; \n background-color: rgba(0, 0, 0, 0); \n border: none; \n outline: none; \n position: absolute; \n left: 10px; \n top: " + inputTop + "px;\n ");
document.getElementsByTagName('body')[0].appendChild(input);
input.focus();
input.onblur = function () {
protocolHandlerPresent = true;
};
location.href = protocolHandler + ':ofe%7Cu%7C' + url;
/** @type {?} */
var TIMEOUT_MESSAGE = this.messages.TIMEOUT;
if (this.timeout > 0) {
setTimeout(function () {
input.onblur = null;
input.remove();
if (!protocolHandlerPresent) {
alert(TIMEOUT_MESSAGE);
}
}, this.timeout);
}
};
/**
* @return {?}
*/
OfficeActionsService.prototype.isWin = /**
* @return {?}
*/
function () {
return (this.userAgent.indexOf('win') !== -1);
};
/**
* @return {?}
*/
OfficeActionsService.prototype.isMac = /**
* @return {?}
*/
function () {
return (this.userAgent.indexOf('mac') !== -1);
};
/**
* @param {?} fileExtension
* @return {?}
*/
OfficeActionsService.getProtocolForFileExtension = /**
* @param {?} fileExtension
* @return {?}
*/
function (fileExtension) {
/** @type {?} */
var msProtocolNames = {
'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',
'vsd': 'ms-visio',
'vdw': 'ms-visio',
'vsdm': 'ms-visio',
'vsdx': 'ms-visio',
'vss': 'ms-visio',
'vssm': 'ms-visio',
'vssx': 'ms-visio',
'vst': 'ms-visio',
'vstm': 'ms-visio',
'vstx': 'ms-visio',
'mpp': 'ms-project',
'mpt': 'ms-project'
};
return msProtocolNames[fileExtension];
};
/**
* @param {?} mimeType
* @return {?}
*/
OfficeActionsService.getProtocolForMimeType = /**
* @param {?} mimeType
* @return {?}
*/
function (mimeType) {
/** @type {?} */
var msProtocolNames = {
'application/msword': 'ms-word',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'ms-word',
'application/vnd.ms-word.document.macroEnabled.12': 'ms-word',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': 'ms-word',
'application/vnd.ms-word.template.macroEnabled.12': 'ms-word',
'application/vnd.ms-excel': 'ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'ms-excel',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': 'ms-excel',
'application/vnd.ms-excel.sheet.macroEnabled.12': 'ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': 'ms-excel',
'application/vnd.ms-excel.template.macroEnabled.12': 'ms-excel',
'application/vnd.ms-powerpoint': 'ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.template': 'ms-powerpoint',
'application/vnd.ms-powerpoint.template.macroEnabled.12': 'ms-powerpoint',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': 'ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': 'ms-powerpoint',
'application/vnd.ms-powerpoint.addin.macroEnabled.12': 'ms-powerpoint',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': 'ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.slide': 'ms-powerpoint',
'application/vnd.ms-powerpoint.slide.macroenabled.12': 'ms-powerpoint',
'application/vnd.visio': 'ms-visio',
'application/vnd.ms-visio.drawing.macroEnabled': 'ms-visio',
'application/vnd.visio2013': 'ms-visio',
'application/vnd.ms-visio.stencil.macroEnabled': 'ms-visio',
'application/vnd.ms-visio.stencil': 'ms-visio',
'application/vnd.ms-visio.template.macroEnabled': 'ms-visio',
'application/vnd.ms-visio.template': 'ms-visio',
'application/vnd.ms-project': 'ms-project'
};
return msProtocolNames[mimeType];
};
OfficeActionsService.decorators = [
{ type: Injectable },
];
return OfficeActionsService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var IncentroOfficeModule = /** @class */ (function () {
function IncentroOfficeModule() {
}
/**
* @return {?}
*/
IncentroOfficeModule.forRoot = /**
* @return {?}
*/
function () {
return {
ngModule: IncentroOfficeModule,
providers: [OfficeActionsService]
};
};
IncentroOfficeModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
declarations: [],
exports: []
},] },
];
return IncentroOfficeModule;
}());
export { IncentroOfficeModule, OfficeActionsService };