123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['./UrlWidget', '../../../app/nls/StringResources', './media/MediaResolver', 'jquery', 'underscore'], function (UrlWidget, resources, MediaResolver, $, _) {
- var MediaWidget = UrlWidget.extend({
- init: function init(options) {
- MediaWidget.inherited('init', this, arguments);
- this.api = {
- getId: this.getId.bind(this),
- setMediaUrl: this.setUrl.bind(this)
- };
- this.model = this.model || {};
- this.model.mediaLink = options && options.initialConfigJSON && options.initialConfigJSON.mediaLink;
- this.propertyCallbacks = this.dashboardApi.getFeature('PropertyCallbacks');
- },
- onContainerReady: function onContainerReady() {
- MediaWidget.inherited('onContainerReady', this, arguments);
- if (this.model) {
- this.model.on('change:mediaLink', this._onMediaLinkChange, this);
- this.model.on('change:title', this._onPropertyChange, this);
- this.addWhiteListAttrs('mediaLink', 'mediaType', 'title');
- }
- this.eventRouter.trigger('media:ready', this.api);
- },
- render: function render() {
- if (this.propertyCallbacks.validateMediaInput(null, this.model.mediaLink).isValid) {
- this.model.mediaLink = this.encodeURL(this.model.mediaLink);
- this.media = MediaResolver.loadFromModel(this.model);
- this.$el.append(this.getHtmlRender());
- if (this.media) {
- this.media.markupLoaded(this.$el, this.isAuthoringMode ? 'authoring' : 'consume');
- }
- } else {
- this.$el.append(UrlWidget.getDefaultConsumeMarkup(resources.get('mediaMissingUrl')));
- }
- },
- setUrl: function setUrl(url) {
- var errorData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var ret = this.propertyCallbacks.validateMediaInput(null, url);
- errorData.message = ret.message;
- if (ret.isValid) {
- var transactionId = _.uniqueId('_addMedia_');
- this.set({
- mediaLink: url,
- mediaType: ret.media.type
- }, {
- sender: this,
- payloadData: {
- undoRedoTransactionId: transactionId
- }
- });
- this.updateModelContent();
- return true;
- }
- return false;
- },
- onAuthoringMode: function onAuthoringMode() {
- MediaWidget.inherited('onAuthoringMode', this, arguments);
- //Only prompt media to perform DOM operations when root DOM
- //reference is valid
- if (this.media && $.contains(document.body, this.el)) {
- this.media.showAuthoringMode();
- }
- },
- onConsumeMode: function onConsumeMode() {
- MediaWidget.inherited('onConsumeMode', this, arguments);
- //Only prompt media to perform DOM operations when root DOM
- //reference is valid
- if (this.media && $.contains(document.body, this.el)) {
- this.media.showConsumeMode();
- }
- },
- onEnterContainer: function onEnterContainer() {
- var mediaInput = this.$el.find('.inlineEditInput');
- mediaInput.focus();
- },
- isInlineEditMode: function isInlineEditMode() {
- return !this.model.mediaLink;
- },
- getInlineEditCaption: function getInlineEditCaption() {
- return resources.get('mediaPasteLink');
- },
- getMissingUrlText: function getMissingUrlText() {
- return resources.get('mediaMissingUrl');
- },
- getAriaLabelText: function getAriaLabelText() {
- return resources.get('mediaAriaLabel');
- },
- getLabel: function getLabel() {
- return this._getTitle() || resources.get('mediaWidgetTitle');
- },
- getContentClass: function getContentClass() {
- return 'mediaWidgetContent';
- },
- _getTitle: function _getTitle() {
- return this.model && this.model.get ? this.model.get('title') : null;
- },
- _onMediaLinkChange: function _onMediaLinkChange(options) {
- delete this.model.mediaType;
- return this._onPropertyChange(options);
- },
- _onPropertyChange: function _onPropertyChange(options) {
- var updatedHtml = null;
- if (this.model.mediaLink) {
- this.model.mediaLink = this.encodeURL(this.model.mediaLink);
- if (this.propertyCallbacks.validateMediaInput(null, this.model.mediaLink).isValid) {
- this.media = MediaResolver.loadFromModel(this.model);
- updatedHtml = this.getHtmlRender();
- var staticContent = this.$el.find('.staticContent');
- staticContent.empty();
- staticContent.replaceWith(updatedHtml);
- this.media.markupLoaded(this.$el, this.isAuthoringMode ? 'authoring' : 'consume');
- }
- } else {
- this.renderInlineEditUi();
- updatedHtml = UrlWidget.getDefaultConsumeMarkup(resources.get('mediaMissingUrl'));
- }
- this.updateMarkup();
- if (options.data && options.data.undoRedoTransactionId) {
- this.updateModelContent(updatedHtml, options.data.undoRedoTransactionId);
- } else {
- this.updateModelContent(updatedHtml);
- }
- },
- getHtmlRender: function getHtmlRender() {
- return this.media ? this.media.getMarkup(this._getMediaParams()) : '';
- },
- _getMediaParams: function _getMediaParams() {
- var params = {};
- var title = this._getTitle();
- if (title) {
- params.title = title;
- }
- return params;
- }
- });
- MediaWidget.getDefaultSpec = function () {
- var spec = {
- model: {
- type: 'media',
- avatarHtml: UrlWidget.getDefaultConsumeMarkup(),
- title: ''
- },
- layoutProperties: {
- style: {
- width: '480px',
- height: '360px'
- }
- }
- };
- return Promise.resolve(spec);
- };
- return MediaWidget;
- });
- //# sourceMappingURL=MediaWidget.js.map
|