'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 Business Analytics (C) Copyright IBM Corp. 2019, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /** * @class DashboardState * @hideconstructor * @classdesc This class provides APIs for dashboard activity state */ define(['../../../app/nls/StringResources', './DomainValidator', '../../../dashboard/widgets/staticwidget/media/MediaResolver'], function (resources, DomainValidator, MediaResolver) { /** * this class is used in VisPropertyProvider. */ var PropertyCallbacks = function () { function PropertyCallbacks(options) { _classCallCheck(this, PropertyCallbacks); this._features = options.features; } PropertyCallbacks.prototype.getAPI = function getAPI() { // we have to return implementation here. return this; }; /** * Restore the crosstab format to default */ PropertyCallbacks.prototype.setProperties = function setProperties(_content, props) { var transaction = this._features['Transaction']; var transactionToken = transaction.startTransaction(); var propNames = Object.keys(props); propNames.forEach(function (propName) { var propVal = props[propName]; _content.setPropertyValue(propName, propVal, transactionToken); }); transaction.endTransaction(transactionToken); }; /** Validates a URL. * @param sUrl - the url to validate. * @param errorData - if the URL is invalid, it will contain a message describing that fact. * @returns - returns true if the URL is valid, false otherwise. */ PropertyCallbacks.prototype.validateImageInput = function validateImageInput(_content, sUrl) { var imagePattern = /(^https?:\/\/.+\.(jpeg|jpg|gif|png)$)|(^data:image\/(jpeg|jpg|gif|png);)|(^v[1-9]\/ext\/.+\.(jpeg|jpg|gif|png))/i; var localImageRegex = /(^data:image\/(jpeg|jpg|gif|png);)|(^v[1-9]\/ext\/.+\.(jpeg|jpg|gif|png))/i; var ret = { isValid: true }; if (!imagePattern.test(sUrl)) { ret.message = resources.get('imgUrlValidationError'); ret.isValid = false; } else { var domainValidator = this._getDomainValidator(); if (!domainValidator.isAllowedDomain(sUrl) && !localImageRegex.test(sUrl)) { ret.message = resources.get('imgUrlInvalidDomainError', { domains: domainValidator.getAllowedDomains() }); ret.isValid = false; } } return ret; }; /** Callback provided to WidgetPropertiesManager for URL validation. * @param sUrl - the URI to test. * @param errorData - Will be filled with a message saying the URI is invalid, if it is invalid. * @returns - true if it is valid, false otherwise. */ PropertyCallbacks.prototype.validateWebpageLink = function validateWebpageLink(_content, sUrl) { var ret = { isValid: true }; if (!sUrl) { ret.message = resources.get('webpageMissingUrl'); ret.isValid = false; } else { var domainValidator = this._getDomainValidator(); if (!domainValidator.isAllowedProtocol(sUrl)) { ret.message = resources.get('webpageHttpValidationError'); ret.isValid = false; } else if (!domainValidator.isAllowedDomain(sUrl)) { ret.message = resources.get('webpageInvalidDomainError', { domains: domainValidator.getAllowedDomains() }); ret.isValid = false; } } return ret; }; /** Validates the specified URL. * @param url - the URL to validate. * @param errorData - if the URL is invalid, this will contain an error message indicating the reason. * @returns true if the URL is valid, false otherwise. */ PropertyCallbacks.prototype.validateMediaInput = function validateMediaInput(_content, url) { var ret = { isValid: true }; if (!url) { ret.message = resources.get('mediaUrlValidationError'); ret.isValid = false; } else { var domainValidator = this._getDomainValidator(); if (!domainValidator.isAllowedProtocol(url)) { ret.message = resources.get('mediaHttpValidationError'); ret.isValid = false; } else if (!domainValidator.isAllowedDomain(url)) { ret.message = resources.get('mediaInvalidDomainError', { domains: domainValidator.getAllowedDomains() }); ret.isValid = false; } else { var media = MediaResolver.loadFromUrl(url); if (!media) { ret.message = resources.get('mediaUnknownValidationError'); ret.isValid = false; } else { ret.media = media; } } } return ret; }; PropertyCallbacks.prototype._getDomainValidator = function _getDomainValidator() { if (!this._domainValidator) { var domainList = this._features.UserProfile.getValidDomainList(); this._domainValidator = new DomainValidator(domainList); } return this._domainValidator; }; return PropertyCallbacks; }(); return PropertyCallbacks; }); //# sourceMappingURL=PropertyCallbacks.js.map