@aappddeevv/dynamics-client-ui
Version:
## What is it? A library to help you create great dynamics applications.
62 lines • 2.51 kB
JavaScript
;
/**
* Render an anchor element that opens an entity form.
* Uses the context to obtain Xrm variable or tries to obtain it
* by looking at the parent namespace. An additional onClick will
* also be called *before* opening the window. Adds "crmLink" to the
* the classnames.
* Props: id, entityName(singular), parameters, windowParameters,
* openInNewWindow (boolean, default is true, added to windowParmeters if present), className.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const cx = require("classnames");
const BuildSettings_1 = require("BuildSettings");
const PropTypes = require("prop-types");
class EntityLink extends React.Component {
constructor(props, context) {
super(props, context);
this.handleClick = (e) => {
if (this.props.onClick)
this.props.onClick(e);
const xrm = this.props.xrm || this.context.xrm || window.parent.Xrm;
if (!xrm) {
if (BuildSettings_1.DEBUG)
console.log("EntityLink: No Xrm provided in props, context or window parent.");
return;
}
const openInNewWindow = this.props.openInNewWindow || true;
const height = this.props.height || 1000;
const width = this.props.width || 1000;
const entityName = this.props.entityName;
const id = this.props.id;
const windowPosition = this.props.windowPosition || 2;
const opts = {
entityName,
entityId: id ? id : undefined,
openInNewWindow,
height,
width,
windowPosition,
};
if (BuildSettings_1.DEBUG)
console.log("EntityLink", opts);
if (entityName && xrm)
xrm.Navigation.openForm(opts, {});
else
console.log("EntityLink: No entityName, id or XRM provided", entityName, id);
};
}
render() {
const { className, children } = this.props;
return (React.createElement("a", { href: "#", className: cx("crmLink", className), onClick: this.handleClick }, children));
}
}
EntityLink.contextTypes = {
xrm: PropTypes.object
};
exports.EntityLink = EntityLink;
//export const EntityLink = withDynamics(_EntityLink)
//export const EntityLink = _EntityLink
exports.default = EntityLink;
//# sourceMappingURL=EntityLink.js.map