123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2018, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['jquery', 'underscore', '../../../lib/@waca/core-client/js/core-client/utils/ClassFactory', '../../layout/views/LayoutBaseView', 'react', 'react-dom', '../../layout/authoring/views/feature/CommonAuthoringFeature'], function ($, _, ClassFactory, LayoutBaseView, React, ReactDOM, CommonAuthoringFeature) {
- var makeReactLayoutClass = function makeReactLayoutClass(data) {
- var ReactLayout = null;
- ReactLayout = LayoutBaseView.extend({
- init: function init(options) {
- ReactLayout.inherited('init', this, arguments);
- this.model = options.model;
- this.content = options.content;
- this.layoutController = options.layoutController;
- this.services = options.services;
- this.commonAuthoringFeature = new CommonAuthoringFeature(this);
- },
- onShow: function onShow() {
- ReactLayout.inherited('onShow', this, arguments);
- if (this.layoutController) {
- var className = data.type + '-react-layout-view';
- var $root = null;
- if (this.domNode) {
- $root = $(this.domNode);
- } else {
- $root = this.layoutController.$el.find('.' + className);
- }
- if ($root.length > 0) {
- var existingDomNodes = this._collectExistingItemNodes($root);
- ReactDOM.render(React.createElement(data.Component, {
- items: this.model ? this.model.items : [],
- model: this.model,
- services: this.services,
- layoutController: this.layoutController
- }, null), $root.get(0));
- this._repositionExistingItemNodes($root, existingDomNodes);
- }
- }
- },
- _collectExistingItemNodes: function _collectExistingItemNodes($root) {
- var existingDomNodes = [];
- if (this.model && this.model.items) {
- _.each(this.model.items, function (item) {
- var $node = $root.find('#' + item.id);
- if ($node.length) {
- existingDomNodes.push({
- item: item,
- node: $node[0]
- });
- }
- });
- }
- return existingDomNodes;
- },
- _repositionExistingItemNodes: function _repositionExistingItemNodes($root, existingDomNodes) {
- _.each(existingDomNodes, function (o) {
- var $stub = $root.find('#' + o.item.id + '_stub');
- if ($stub.length) {
- $stub.append(o.node);
- }
- });
- },
- add: function add() /*layoutView, insertBeforeId*/{
- //no-op - expected by CommonAuthoringFeature.onModelAddItem
- },
- destroy: function destroy() {}
- });
- ReactLayout.getTemplate = function () {
- return ['<div id="{{id}}" tabindex="-1" class="page {{type}}-react-layout-view{{extraCSS}}"{{style}}>{{items}}</div>', '{{item}}'];
- };
- return ReactLayout;
- };
- var ReactBoardModule = function () {
- function ReactBoardModule(props) {
- _classCallCheck(this, ReactBoardModule);
- props = props || {};
- this._loader = props.loader || ClassFactory;
- this.logger = props.logger;
- }
- ReactBoardModule.prototype.load = function load(module) {
- var _this = this;
- var path = module.path || module;
- return this._loader.loadModule(path).then(function (Component) {
- var ModuleClass = makeReactLayoutClass({
- type: module.id,
- Component: Component
- });
- return {
- template: ModuleClass.getTemplate,
- module: ModuleClass
- };
- }).catch(function (error) {
- _this.logger.warn('[ReactBoardModule]: attempted to load module "' + path + ' and failed"', error);
- throw error;
- });
- };
- return ReactBoardModule;
- }();
- return ReactBoardModule;
- });
- //# sourceMappingURL=ReactBoardModule.js.map
|