catreact
Version:
Catavolt Core React Components
51 lines (50 loc) • 1.65 kB
JavaScript
/**
* Created by rburson on 1/15/16.
*/
"use strict";
var React = require('react');
var catreact_core_1 = require('./catreact-core');
/*
***************************************************
* Render a simple message
***************************************************
*/
exports.CvResource = React.createClass({
mixins: [catreact_core_1.CvBaseMixin],
getDefaultProps: function () {
return {
type: 'image',
resourceName: null,
resourceUrl: null,
className: null,
fallbackImageUrl: 'http://cdn.churchm.ag/wp-content/uploads/2013/06/404-Space-Invaders.png',
style: null
};
},
render: function () {
if (this.props.resourceName || this.props.resourceUrl) {
var url = this.props.resourceUrl;
if (this.props.resourceName) {
var baseUrl = null;
var tenantSettingsTry = this.catavolt().tenantSettingsTry;
if (tenantSettingsTry.isSuccess) {
baseUrl = tenantSettingsTry.success['GMLAssetsURL'];
}
url = baseUrl + this.props.resourceName;
}
if (this.props.type === 'image') {
return React.createElement("img", {style: this.props.style, className: this.props.className, src: url, onError: this._loadPlaceholder});
}
else {
return null;
}
}
else {
return null;
}
},
_loadPlaceholder: function (e) {
e.preventDefault();
e.target.src = this.props.fallbackImageUrl;
},
});