UNPKG

ng2-alfresco-aos-editonline

Version:
341 lines (325 loc) 15.1 kB
/*! * @license * Copyright 2016 Alfresco Software, Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("@angular/core"), require("ng2-alfresco-core"), require("ng2-alfresco-documentlist"), require("rxjs/Observable")); else if(typeof define === 'function' && define.amd) define(["@angular/core", "ng2-alfresco-core", "ng2-alfresco-documentlist", "rxjs/Observable"], factory); else if(typeof exports === 'object') exports["ng2-alfresco-aos-editonline"] = factory(require("@angular/core"), require("ng2-alfresco-core"), require("ng2-alfresco-documentlist"), require("rxjs/Observable")); else root["ng2-alfresco-aos-editonline"] = factory(root["@angular/core"], root["ng2-alfresco-core"], root["ng2-alfresco-documentlist"], root["rxjs/Observable"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // identity function for calling harmony imports with the correct context /******/ __webpack_require__.i = function(value) { return value; }; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 5); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = __webpack_require__(1); var Observable_1 = __webpack_require__(4); var ng2_alfresco_core_1 = __webpack_require__(2); var ng2_alfresco_documentlist_1 = __webpack_require__(3); var AOSEditOnlineService = AOSEditOnlineService_1 = (function () { function AOSEditOnlineService(alfrescoApiService, alfrescoAuthenticationService, appConfigService, documentActionService, translationService) { this.alfrescoApiService = alfrescoApiService; this.alfrescoAuthenticationService = alfrescoAuthenticationService; this.appConfigService = appConfigService; this.documentActionService = documentActionService; this.translationService = translationService; this.errorMessage = new core_1.EventEmitter(); documentActionService.setHandler('aos-edit-online', this.onActionEditOnlineAos.bind(this)); } AOSEditOnlineService.prototype.onActionEditOnlineAos = function (nodeId) { var _this = this; var opts = { include: ['isLocked', 'path'] }; return Observable_1.Observable.fromPromise(this.alfrescoApiService.getInstance().core.nodesApi.getNode(nodeId, opts) .then(function (data) { if (data) { var node = data.entry; if (node.isFile) { if (node.isLocked) { var checkedOut = node.aspectNames.contains('cm:checkedOut'); var lockOwner = node.properties['cm:lockOwner']; var differentLockOwner = lockOwner.id !== _this.alfrescoAuthenticationService.getEcmUsername(); if (checkedOut && differentLockOwner) { _this.onAlreadyLockedNotification(node.id, lockOwner); return false; } else { _this.triggerEditOnlineAos(node); return true; } } else { _this.triggerEditOnlineAos(node); return true; } } } })); }; AOSEditOnlineService.prototype.getUserAgent = function () { return navigator.userAgent.toLowerCase(); }; AOSEditOnlineService.prototype.isWindows = function () { return this.getUserAgent().indexOf('win') !== -1 ? true : false; }; AOSEditOnlineService.prototype.isMacOs = function () { return this.getUserAgent().indexOf('mac') !== -1 ? true : false; }; AOSEditOnlineService.prototype.onAlreadyLockedNotification = function (nodeId, lockOwner) { this.errorMessage.emit("Document {nodeId} locked by {lockOwner}"); }; AOSEditOnlineService.prototype.getProtocolForFileExtension = function (fileExtension) { return AOSEditOnlineService_1.MS_PROTOCOL_NAMES[fileExtension]; }; AOSEditOnlineService.prototype.triggerEditOnlineAos = function (node) { var url = this.onlineEditUrlAos(node); var fileExtension = node.name.split('.').pop() !== null ? node.name.split('.').pop().toLowerCase() : ''; var protocolHandler = this.getProtocolForFileExtension(fileExtension); if (protocolHandler === undefined) { var message = this.translationService.get('AOS.ERROR.NO_PROTOCOL_HANDLER'); this.errorMessage.emit(message.value); return; } if (!this.isWindows() && !this.isMacOs()) { var message = this.translationService.get('AOS.ERROR.UNSUPPORTED_CLIENT_OS'); this.errorMessage.emit(message.value); } else { this.aos_tryToLaunchOfficeByMsProtocolHandler(protocolHandler, url); } }; AOSEditOnlineService.prototype.onlineEditUrlAos = function (node) { var pathElements = node.path.elements.slice(1, node.path.elements.length); var path = '/'; for (var _i = 0, pathElements_1 = pathElements; _i < pathElements_1.length; _i++) { var element = pathElements_1[_i]; path = path + element.name + '/'; } var ecmHost = this.appConfigService.get(AOSEditOnlineService_1.ECM_HOST_CONFIG_KEY); var url = ecmHost + '/alfresco/aos' + path + '/' + node.name; if (encodeURI(url).length > 256) { url = ecmHost + '/alfresco/aos/' + '_aos_nodeid' + '/' + node.id + '/' + node.name; } return url; }; AOSEditOnlineService.prototype.aos_tryToLaunchOfficeByMsProtocolHandler = function (protocolHandler, url) { var protocolUrl = protocolHandler + ':ofe%7Cu%7C' + url; var protocolHandlerPresent = false; var input = document.createElement('input'); var 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 () { protocolHandlerPresent = true; }; location.href = protocolUrl; var that = this; setTimeout(function () { input.onblur = null; input.remove(); if (!protocolHandlerPresent) { var message = that.translationService.get('AOS.ERROR.UNSUPPORTED_CLIENT_VERSION'); that.errorMessage.emit(message.value); } }, 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' }; __decorate([ core_1.Output(), __metadata("design:type", typeof (_a = typeof core_1.EventEmitter !== "undefined" && core_1.EventEmitter) === "function" && _a || Object) ], AOSEditOnlineService.prototype, "errorMessage", void 0); AOSEditOnlineService = AOSEditOnlineService_1 = __decorate([ core_1.Injectable(), __metadata("design:paramtypes", [typeof (_b = typeof ng2_alfresco_core_1.AlfrescoApiService !== "undefined" && ng2_alfresco_core_1.AlfrescoApiService) === "function" && _b || Object, typeof (_c = typeof ng2_alfresco_core_1.AlfrescoAuthenticationService !== "undefined" && ng2_alfresco_core_1.AlfrescoAuthenticationService) === "function" && _c || Object, typeof (_d = typeof ng2_alfresco_core_1.AppConfigService !== "undefined" && ng2_alfresco_core_1.AppConfigService) === "function" && _d || Object, typeof (_e = typeof ng2_alfresco_documentlist_1.DocumentActionsService !== "undefined" && ng2_alfresco_documentlist_1.DocumentActionsService) === "function" && _e || Object, typeof (_f = typeof ng2_alfresco_core_1.AlfrescoTranslationService !== "undefined" && ng2_alfresco_core_1.AlfrescoTranslationService) === "function" && _f || Object]) ], AOSEditOnlineService); exports.AOSEditOnlineService = AOSEditOnlineService; var AOSEditOnlineService_1, _a, _b, _c, _d, _e, _f; /***/ }), /* 1 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_1__; /***/ }), /* 2 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_2__; /***/ }), /* 3 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_3__; /***/ }), /* 4 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_4__; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = __webpack_require__(1); var ng2_alfresco_core_1 = __webpack_require__(2); var aos_edit_online_service_1 = __webpack_require__(0); __export(__webpack_require__(0)); var Ng2AlfrescoAosEditonlineModule = (function () { function Ng2AlfrescoAosEditonlineModule() { } return Ng2AlfrescoAosEditonlineModule; }()); Ng2AlfrescoAosEditonlineModule = __decorate([ core_1.NgModule({ imports: [ng2_alfresco_core_1.CoreModule], declarations: [], providers: [ aos_edit_online_service_1.AOSEditOnlineService, { provide: ng2_alfresco_core_1.TRANSLATION_PROVIDER, multi: true, useValue: { name: 'ng2-alfresco-aos-editonline', source: 'assets/ng2-alfresco-aos-editonline' } } ], exports: [] }) ], Ng2AlfrescoAosEditonlineModule); exports.Ng2AlfrescoAosEditonlineModule = Ng2AlfrescoAosEditonlineModule; /***/ }) /******/ ]); }); //# sourceMappingURL=ng2-alfresco-aos-editonline.js.map