catreact
Version:
Catavolt Core React Components
121 lines (120 loc) • 5.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Created by rburson on 3/13/17.
*/
var React = require("react");
var catreact_core_1 = require("./catreact-core");
var catavolt_sdk_1 = require("catavolt-sdk");
exports.CvViewDesc = React.createClass({
mixins: [catreact_core_1.CvBaseMixin],
componentDidMount: function () {
},
getChildContext: function () {
var ctx = this.getDefaultChildContext();
ctx.cvContext.scopeCtx.scopeObj = this.viewDesc();
return ctx;
},
getDefaultProps: function () {
return {
paneContext: null,
actionListeners: [],
stateChangeListeners: [],
navigationListeners: [],
navTarget: null,
viewDesc: null,
renderer: null,
wrapperElemName: 'span',
wrapperElemProps: {},
wrapperEventHandlerName: 'onClick',
};
},
openView: function (resultCallback) {
exports.CvViewDesc.openView(this.viewDesc(), this.paneContext(), this.eventRegistry(), this.catavolt(), this.props.actionListeners, this.props.stateChangeListeners, this.props.navigationListeners, this.props.navTarget, resultCallback);
},
paneContext: function () {
var paneContext = null;
if (this.props.paneContext) {
paneContext = this.props.paneContext;
}
else {
paneContext = this.findPaneContext();
}
return paneContext;
},
render: function () {
var _this = this;
if (this.viewDesc()) {
if (this.props.renderer) {
return this.props.renderer(this.getChildContext().cvContext, this._getCallbackObj());
}
else if (this.props.children) {
var props = catavolt_sdk_1.ObjUtil.addAllProps(this.props.wrapperElemProps, {});
props[this.props.wrapperEventHandlerName] = function () { _this.openView(); };
return React.createElement(this.props.wrapperElemName, props, this.props.children);
}
else {
return null;
}
}
else {
return null;
}
},
viewDesc: function () {
return this.props.viewDesc;
},
_getCallbackObj: function () {
var _this = this;
return {
openView: function (resultCallback) {
_this.openView(resultCallback);
}
};
},
statics: {
publishStateChange: function (paneContext, eventRegistry, stateChangeListeners) {
if (paneContext) {
var event_1 = {
type: catreact_core_1.CvEventType.STATE_CHANGE,
resourceId: null,
eventObj: { source: paneContext, type: catreact_core_1.CvStateChangeType.PANE_DEF_CHANGE }
};
eventRegistry.publish(event_1, false);
stateChangeListeners.forEach(function (listener) {
listener(event_1);
});
}
},
publishNavigation: function (navRequest, actionId, paneContext, catavolt, eventRegistry, navigationListeners, navTarget) {
var e = catreact_core_1.CvNavigationResultUtil.publishNavigation(catavolt, eventRegistry, navRequest, actionId, null, navTarget, navigationListeners, paneContext.isDestroyed, false);
},
publishError: function (failure, eventRegistry) {
var event = { type: catreact_core_1.CvEventType.MESSAGE, eventObj: { message: 'Change View Failed',
messageObj: failure, type: catreact_core_1.CvMessageType.ERROR } };
eventRegistry.publish(event, false);
},
openView: function (viewDesc, paneContext, eventRegistry, catavolt, actionListeners, stateChangeListeners, navigationListeners, navTarget, resultCallback) {
var actionId = '#viewChange';
catreact_core_1.CvActionBase._publishActionStarted(actionId, paneContext, false, actionListeners, eventRegistry);
paneContext.openView(viewDesc).onComplete(function (openViewTry) {
catreact_core_1.CvActionBase._publishActionFinished(actionId, paneContext, actionListeners, eventRegistry);
if (openViewTry.isFailure) {
if (resultCallback)
resultCallback(null, openViewTry.failure);
exports.CvViewDesc.publishError(openViewTry.failure, eventRegistry);
}
else {
if (resultCallback)
resultCallback(openViewTry.success);
if (openViewTry.success.isLeft) {
exports.CvViewDesc.publishStateChange(openViewTry.success.left, eventRegistry, stateChangeListeners);
}
else {
exports.CvViewDesc.publishNavigation(openViewTry.success.right, actionId, paneContext, catavolt, eventRegistry, navigationListeners, navTarget);
}
}
});
},
}
});