123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- '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: BI Cloud (C) Copyright IBM Corp. 2018, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'underscore', './Absolute', './ScalingAbsolute', '../TemplateHelper', '../../../util/PxPercentUtil', '../../../../app/util/DeepClone'], function ($, _, Absolute, ScalingAbsolute, TemplateHelper, PxPercentUtil) {
- /*
- * The generic page class is an authoring view manager that can switch between relative (scalingAbsolute)
- * and absolute (Absolute) layouts.
- * It isn't a view as it delegates that work off to one of the 2 authoring layout views.
- * There are only a few api's on the view that are utilized directly on the object [destroy() and _addWidget].
- */
- return function () {
- function GenericPage(options) {
- _classCallCheck(this, GenericPage);
- // Cache the options, so that we can switch views at will
- this._options = options;
- var templateHelperOptions = {
- model: options.model,
- layoutController: options.layoutController
- };
- this._options.templateHelper = new TemplateHelper(templateHelperOptions);
- var layoutPositioning = options.model.getValueFromSelfOrParent('layoutPositioning');
- this._switchLayoutView(layoutPositioning);
- this._setPageLayoutStyling(layoutPositioning);
- this._delegateView.model.on('change:layoutPositioning', this._onChangeLayoutPositioning, this);
- }
- /**
- * Called when the view is destroyed
- */
- GenericPage.prototype.destroy = function destroy() {
- this._delegateView.model.off('change:layoutPositioning', this._onChangeLayoutPositioning, this);
- this._delegateView.destroy();
- this._options.templateHelper.destroy();
- this._options.templateHelper = null;
- };
- GenericPage.prototype._switchLayoutView = function _switchLayoutView(layoutPositioning) {
- // Cleanup existing authoring view if present
- if (this._delegateView) {
- this._delegateView.destroy();
- }
- if (layoutPositioning === 'absolute') {
- this._delegateView = new Absolute(this._options);
- } else {
- this._delegateView = new ScalingAbsolute(this._options);
- }
- // Set the author view reference to this generic page, so we can clean up after.
- this._delegateView.consumeView.authorViewManager = this;
- };
- GenericPage.prototype._onChangeLayoutPositioning = function _onChangeLayoutPositioning(payload) {
- this._switchLayoutView(payload.value);
- this._setPageLayoutStyling(payload.value);
- // In the case of undo/redo we have already updated the models
- if (payload.sender !== 'UndoRedoController') {
- this._convertLayoutPositioning(payload);
- }
- };
- // Convert widget/group style values (px->percent or percent->pixel)
- GenericPage.prototype._convertLayoutPositioning = function _convertLayoutPositioning(payload) {
- // Need to know the page size to use for the conversions
- // If the current layout is absolute, then we need to use the current absolute page size to generate the correct
- // widget percentages for the destination page.
- // If the current layout is relative, then we need to use the destination page size (absolute) to generate the correct
- // pixel values in the destination page.
- var pageSize = this._delegateView.getPhysicalPageSize('absolute');
- var items = this._delegateView.model.findDescendantsWithType(['widget', 'group']);
- var childItemsToUpdate = items.map(function (item) {
- var styleCopy = _.deepClone(item.style);
- if (payload.value === 'relative') {
- PxPercentUtil.changePixelPropertiesToPercent(styleCopy, pageSize);
- } else {
- PxPercentUtil.changePercentPropertiesToPixel(styleCopy, pageSize);
- }
- return {
- id: item.id,
- style: styleCopy
- };
- });
- var transactionApi = this._delegateView.dashboardApi.getFeature('Transaction');
- var transactionToken = transactionApi.startTransactionById(payload.data.undoRedoTransactionId);
- var validate = payload.eventName !== 'change:layoutPositioning';
- // Add a hint to the data that the operation is caused by updating the style to percent
- // This is to avoid doing an extra call to 'updateStyleToPercent' as a result of a layout style change
- if (payload.value === 'absolute') {
- _.extend(payload.data, { hint: 'updateStyleToPercent' });
- }
- this._delegateView.updateModel(childItemsToUpdate, transactionToken, validate);
- transactionApi.endTransaction(transactionToken);
- };
- // Switch the styles for the different layout types
- GenericPage.prototype._setPageLayoutStyling = function _setPageLayoutStyling(layoutPositioning) {
- var isRelative = layoutPositioning === 'relative';
- this._delegateView.$el.toggleClass('pagescalingAbsolute', isRelative);
- this._delegateView.$el.toggleClass('pageabsolute', !isRelative);
- };
- return GenericPage;
- }();
- });
- //# sourceMappingURL=GenericPage.js.map
|