catreact
Version:
Catavolt Core React Components
1,287 lines (1,224 loc) • 2.8 MB
JavaScript
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var _react = require('react');
var React = _interopRequireWildcard(_react);
var _reactDom = require('react-dom');
var ReactDOM = _interopRequireWildcard(_reactDom);
var _reactRouter = require('react-router');
var _catreact = require('../../catreact');
var _catavoltSdk = require('catavolt-sdk');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
_catavoltSdk.Log.logLevel(_catavoltSdk.LogLevel.DEBUG); /**
* Created by rburson on 2/8/16.
*/
var CvReactBase = {
componentWillMount: function componentWillMount() {
this.waitProvider = new _catreact.CvValueAdapter();
this.waitListener = this.waitProvider.createValueListener();
this.navPopupProvider = new _catreact.CvValueAdapter();
this.navPopupListener = this.navPopupProvider.createValueListener();
},
contextTypes: {
router: React.PropTypes.object
},
_showWaitState: function _showWaitState(event) {
if (this.isMounted()) {
if (event.eventObj.type === _catreact.CvActionFiredResultType.ACTION_STARTED) {
this.waitListener(true);
} else if (event.eventObj.type === _catreact.CvActionFiredResultType.ACTION_COMPLETED) {
this.waitListener(false);
}
}
}
};
/**
* *********************************************************
* Create a Catavolt root pane and top-level wrapper
* *********************************************************
*/
var CvReactApp = React.createClass({
displayName: 'CvReactApp',
mixins: [CvReactBase],
render: function render() {
return React.createElement(
'div',
{ className: 'cv-container container-fluid' },
React.createElement(
_catreact.CatavoltPane,
{ enableResourceCaching: true },
this.props.children
),
React.createElement(CvReactFooter, null)
);
}
});
var CvReactFooter = React.createClass({
displayName: 'CvReactFooter',
render: function render() {
return React.createElement(
'div',
{ className: 'cv-footer navbar navbar-fixed-bottom' },
React.createElement(
'ul',
{ className: 'list-inline text-right' },
React.createElement(
'li',
null,
React.createElement(
'a',
{ className: 'cv-target' },
'About'
)
),
React.createElement(
'li',
null,
React.createElement(
'a',
{ className: 'cv-target' },
'Contact'
)
)
)
);
}
});
/**
* *********************************************************
* Create and configure a basic login panel
* *********************************************************
*/
var CvReactLogin = React.createClass({
displayName: 'CvReactLogin',
mixins: [CvReactBase],
render: function render() {
var _this = this;
return React.createElement(
'div',
null,
React.createElement(
'div',
{ className: 'cv-login-wrapper' },
React.createElement('div', { className: 'cv-login-logo' }),
React.createElement(_catreact.CvLoginPanel, { defaultGatewayUrl: 'gw.catavolt.net', defaultTenantId: 'solarsourcez', defaultUserId: 'sales', showGatewayUrl: false, showClientType: false, loginListeners: [function (event) {
var windowId = event.resourceId; //get the session (window) from the LoginEvent
_this.context.router.replace('/workbench/' + windowId + '/' + '0');
}] }),
React.createElement(_catreact.CvMessagePanel, null)
)
);
}
});
/**
* *********************************************************
* Create a 'window' top-level container, with a logout button
* *********************************************************
*/
var CvReactWindow = React.createClass({
displayName: 'CvReactWindow',
mixins: [CvReactBase],
render: function render() {
var _this2 = this;
var windowId = this.props.params.windowId; //get the window from the url param
return React.createElement(
_catreact.CvAppWindow,
{ windowId: windowId },
React.createElement(
'div',
{ className: 'cv-window' },
React.createElement('div', { className: 'cv-logo pull-left' }),
React.createElement(_catreact.CvMessagePanel, null),
React.createElement(
'div',
{ className: 'cv-top-nav text-right' },
React.createElement(_catreact.CvLogout, { renderer: function renderer(cvContext, callback) {
return React.createElement(
'a',
{ className: 'cv-target', onClick: callback.logout },
'Logout'
);
}, logoutListeners: [function () {
_this2.context.router.replace('/');
}] })
),
this.props.children
)
);
}
});
/**
* *********************************************************
* Create a Workbench for the supplied window
* *********************************************************
*/
var CvReactWorkbench = React.createClass({
displayName: 'CvReactWorkbench',
mixins: [CvReactBase],
render: function render() {
var _this3 = this;
var windowId = this.props.params.windowId; //get the window from the url param
var workbenchId = this.props.params.workbenchId; //get the workbench from the url param
var selectionAdapter = new _catreact.CvValueAdapter(); //the glue for our menu and workbench
selectionAdapter.subscribe(function (workbench) {
_this3.context.router.replace('/workbench/' + windowId + '/' + workbench.workbenchId);
});
var workbenchEl = null;
/**
****************************************************************
* Example 1 - Graphical Workbench with a 'Dropdown' Menu
****************************************************************
*/
//*
var menuRenderer = function menuRenderer() {
return React.createElement(
'div',
{ className: 'col-sm-3 col-sm-offset-9 text-right' },
React.createElement(_catreact.CvDropdownWorkbenchMenu, { workbenchSelectionListener: selectionAdapter.createValueListener(), initialSelectedWorkbenchId: workbenchId })
);
};
var workbenchRenderer = function workbenchRenderer() {
return React.createElement(_catreact.CvGraphicalWorkbench, { initialWorkbenchId: workbenchId, numCols: 3, actionListeners: [_this3._showWaitState], launchListeners: [function (launchEvent) {
var navigationId = launchEvent.resourceId;
_this3.context.router.push('/navigator/' + windowId + '/' + navigationId);
}] });
};
workbenchEl = React.createElement(_catreact.CvWorkbenchManager, { menuRenderer: menuRenderer, workbenchRenderer: workbenchRenderer, selectionProvider: selectionAdapter });
//*/
/**
*********** End Example 1 ****************************************
*/
/**
****************************************************************
* Example 2 - Graphical Workbench with a 'Tabbed' Menu
****************************************************************
*/
/*
const menuRenderer = ()=>{
return <div className="cv-workbench-tab-menu">
<CvTabbedWorkbenchMenu workbenchSelectionListener={selectionAdapter.createValueListener()} initialSelectedWorkbenchId={workbenchId}/>
</div>;
}
const workbenchRenderer = ()=>{
return <CvGraphicalWorkbench initialWorkbenchId={workbenchId} numCols={3}
actionListeners={[this._showWaitState]}
launchListeners={[(launchEvent:CvEvent<CvNavigationResult>)=>{
const navigationId = launchEvent.resourceId;
this.context.router.push('/navigator/' + windowId + '/' + navigationId);
}]}
/>
}
workbenchEl = <CvWorkbenchManager menuRenderer={menuRenderer} workbenchRenderer={workbenchRenderer} selectionProvider={selectionAdapter}/>
*/
/**
*********** End Example 2 ****************************************
*/
/**
****************************************************************
* Example 3 - Place a specific workbench (without menu)
****************************************************************
*/
/*
workbenchEl = <CvGraphicalWorkbench initialWorkbenchId="AAABACffAAAAAa6T" numCols={4}
actionListeners={[this._showWaitState]}
launchListeners={[(launchEvent:CvEvent<CvNavigationResult>)=>{
const navigationId = launchEvent.resourceId;
this.context.router.push('/navigator/' + windowId + '/' + navigationId);
}]}
/>
*/
/**
*********** End Example 3 ****************************************
*/
return React.createElement(
'div',
null,
workbenchEl,
React.createElement(CvWaitPopup, { dataProvider: this.waitProvider })
);
}
});
/**
* *********************************************************
* Create a Navigator for the supplied window
* e.g. layoutOverrideElem={CvTabbedFormPanel}
* or
* layoutOverrideElem={CvVerticalLayoutFormPane} //mobile
* *********************************************************
*/
var CvReactNavigator = React.createClass({
displayName: 'CvReactNavigator',
mixins: [CvReactBase],
componentWillMount: function componentWillMount() {
console.log("mounting CvReactNavigator");
},
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
console.log("receive props CvReactNavigator");
},
componentWillUpdate: function componentWillUpdate(nextProps, nextState, nextContext) {
console.log("updating CvReactNavigator");
},
render: function render() {
var _this4 = this;
var windowId = this.props.params.windowId; //get the window from the url param
var currentNavId = this.props.params.navId;
var router = this.context.router;
return React.createElement(
'div',
null,
React.createElement(_catreact.CvNavigator, { navigationId: currentNavId, navigationListeners: [function (event) {
var nextNavigationId = event.resourceId;
if (nextNavigationId) {
if (event.eventObj.type === _catreact.CvNavigationResultType.FORM) {
if (event.eventObj.noTransition) {
_this4.navPopupListener(nextNavigationId);
} else {
var target = '/navigator/' + windowId + '/' + nextNavigationId;
event.eventObj.sourceIsDestroyed ? router.replace(target) : router.push(target);
}
} else if (event.eventObj.type === _catreact.CvNavigationResultType.URL) {
window.open(event.eventObj.navRequest.webURL, '_blank');
}
} else {
//force a refresh if there's no new resource (i.e. a NullNavigation)
router.replace('/navigator/' + windowId + '/' + currentNavId);
}
}], actionListeners: [this._showWaitState], stateChangeListeners: [function (event) {
if (event.eventObj.type === _catreact.CvStateChangeType.DESTROYED) {
router.goBack();
}
}] }),
React.createElement(CvPopupNavigator, { dataProvider: this.navPopupProvider }),
React.createElement(CvWaitPopup, { dataProvider: this.waitProvider })
);
}
});
/**
Component that overlays a 'wait' spinner, shown between navigations
*/
var CvWaitPopup = React.createClass({
displayName: 'CvWaitPopup',
componentWillMount: function componentWillMount() {
if (this.props.dataProvider) {
this.props.dataProvider.subscribe(this._handleDataChange);
}
},
getDefaultProps: function getDefaultProps() {
return { dataProvider: null };
},
getInitialState: function getInitialState() {
return { visible: false };
},
render: function render() {
var _this5 = this;
return React.createElement(
'div',
{ className: 'modal', role: 'dialog', ref: function ref(d) {
if (_this5.state.visible) {
var m = $(d);
if (m && m.modal) {
m.modal({ show: true, keyboard: false, backdrop: 'static' });
}
} else {
var m = $(d);
if (m && m.modal) {
m.modal('hide');
}
}
} },
React.createElement(
'div',
{ className: 'modal-dialog' },
React.createElement(
'div',
{ className: 'modal-body' },
React.createElement(
'div',
{ className: 'cv-wait-screen text-center' },
React.createElement('i', { className: 'fa fa-spinner fa-pulse fa-5x' })
)
)
)
);
},
_handleDataChange: function _handleDataChange(visible) {
this.setState({ visible: visible });
}
});
var CvPopupNavigator = React.createClass({
displayName: 'CvPopupNavigator',
componentWillMount: function componentWillMount() {
if (this.props.dataProvider) {
this.props.dataProvider.subscribe(this._handleDataChange);
}
},
getDefaultProps: function getDefaultProps() {
return { dataProvider: null };
},
getInitialState: function getInitialState() {
return { navigationId: null };
},
render: function render() {
var _this6 = this;
return React.createElement(
'div',
{ className: 'modal', role: 'dialog', ref: function ref(d) {
if (_this6.state.navigationId) {
var m = $(d);
if (m && m.modal) {
m.modal({ show: true, keyboard: false, backdrop: 'static' });
}
} else {
var m = $(d);
if (m && m.modal) {
m.modal('hide');
}
}
} },
React.createElement(
'div',
{ className: 'modal-dialog modal-lg' },
React.createElement(
'div',
{ className: 'modal-body' },
React.createElement(
'div',
{ className: 'cv-popup-nav-container' },
this.state.navigationId ? React.createElement(_catreact.CvNavigator, { navigationId: this.state.navigationId, navigationListeners: [function (event) {
var nextNavigationId = event.resourceId;
if (nextNavigationId) {
if (event.eventObj.type === _catreact.CvNavigationResultType.FORM) {
_this6.setState({ navigationId: nextNavigationId });
} else if (event.eventObj.type === _catreact.CvNavigationResultType.URL) {
window.open(event.eventObj.navRequest.webURL, '_blank');
}
}
}], actionListeners: [], stateChangeListeners: [function (event) {
if (event.eventObj.type === _catreact.CvStateChangeType.DESTROYED) {
_this6.setState({ navigationId: null });
}
}] }) : null
)
)
)
);
},
_handleDataChange: function _handleDataChange(navigationId) {
this.setState({ navigationId: navigationId });
}
});
/**
* *********************************************************
* Wire things together with 'routes'
* *********************************************************
*/
ReactDOM.render(React.createElement(
_reactRouter.Router,
{ history: _reactRouter.hashHistory },
React.createElement(
_reactRouter.Route,
{ path: '/', component: CvReactApp },
React.createElement(_reactRouter.IndexRoute, { component: CvReactLogin }),
React.createElement(
_reactRouter.Route,
{ path: 'app', component: CvReactWindow },
React.createElement(_reactRouter.Route, { path: '/workbench/:windowId/:workbenchId', component: CvReactWorkbench }),
React.createElement(_reactRouter.Route, { path: '/navigator/:windowId/:navId', component: CvReactNavigator })
)
)
), document.getElementById('cvApp'));
},{"../../catreact":2,"catavolt-sdk":6,"react":539,"react-dom":301,"react-router":376}],2:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _catreact = require('../src/js/catreact');
Object.keys(_catreact).forEach(function (key) {
if (key === "default") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _catreact[key];
}
});
});
},{"../src/js/catreact":714}],3:[function(require,module,exports){
"use strict";
var utils = require("./utils");
module.exports = function batchProcessorMaker(options) {
options = options || {};
var reporter = options.reporter;
var asyncProcess = utils.getOption(options, "async", true);
var autoProcess = utils.getOption(options, "auto", true);
if(autoProcess && !asyncProcess) {
reporter && reporter.warn("Invalid options combination. auto=true and async=false is invalid. Setting async=true.");
asyncProcess = true;
}
var batch = Batch();
var asyncFrameHandler;
var isProcessing = false;
function addFunction(level, fn) {
if(!isProcessing && autoProcess && asyncProcess && batch.size() === 0) {
// Since this is async, it is guaranteed to be executed after that the fn is added to the batch.
// This needs to be done before, since we're checking the size of the batch to be 0.
processBatchAsync();
}
batch.add(level, fn);
}
function processBatch() {
// Save the current batch, and create a new batch so that incoming functions are not added into the currently processing batch.
// Continue processing until the top-level batch is empty (functions may be added to the new batch while processing, and so on).
isProcessing = true;
while (batch.size()) {
var processingBatch = batch;
batch = Batch();
processingBatch.process();
}
isProcessing = false;
}
function forceProcessBatch(localAsyncProcess) {
if (isProcessing) {
return;
}
if(localAsyncProcess === undefined) {
localAsyncProcess = asyncProcess;
}
if(asyncFrameHandler) {
cancelFrame(asyncFrameHandler);
asyncFrameHandler = null;
}
if(localAsyncProcess) {
processBatchAsync();
} else {
processBatch();
}
}
function processBatchAsync() {
asyncFrameHandler = requestFrame(processBatch);
}
function clearBatch() {
batch = {};
batchSize = 0;
topLevel = 0;
bottomLevel = 0;
}
function cancelFrame(listener) {
// var cancel = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.clearTimeout;
var cancel = clearTimeout;
return cancel(listener);
}
function requestFrame(callback) {
// var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || function(fn) { return window.setTimeout(fn, 20); };
var raf = function(fn) { return setTimeout(fn, 0); };
return raf(callback);
}
return {
add: addFunction,
force: forceProcessBatch
};
};
function Batch() {
var batch = {};
var size = 0;
var topLevel = 0;
var bottomLevel = 0;
function add(level, fn) {
if(!fn) {
fn = level;
level = 0;
}
if(level > topLevel) {
topLevel = level;
} else if(level < bottomLevel) {
bottomLevel = level;
}
if(!batch[level]) {
batch[level] = [];
}
batch[level].push(fn);
size++;
}
function process() {
for(var level = bottomLevel; level <= topLevel; level++) {
var fns = batch[level];
for(var i = 0; i < fns.length; i++) {
var fn = fns[i];
fn();
}
}
}
function getSize() {
return size;
}
return {
add: add,
process: process,
size: getSize
};
}
},{"./utils":4}],4:[function(require,module,exports){
"use strict";
var utils = module.exports = {};
utils.getOption = getOption;
function getOption(options, name, defaultValue) {
var value = options[name];
if((value === undefined || value === null) && defaultValue !== undefined) {
return defaultValue;
}
return value;
}
},{}],5:[function(require,module,exports){
var canUseDOM = !!(
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
);
module.exports = canUseDOM;
},{}],6:[function(require,module,exports){
/**
* Created by rburson on 1/27/16.
*/
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require('./catavolt/util'));
__export(require('./catavolt/fp'));
__export(require('./catavolt/ws'));
__export(require('./catavolt/dialog'));
},{"./catavolt/dialog":7,"./catavolt/fp":8,"./catavolt/util":9,"./catavolt/ws":10}],7:[function(require,module,exports){
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/**
* Created by rburson on 3/27/15.
*/
var util_1 = require("./util");
var fp_1 = require("./fp");
var ws_1 = require("./ws");
/*
IMPORTANT!
Note #1: Dependency cycles - These classes must be in a single file (module) because of commonjs and circular dependency issues.
Note #2 Dependent ordering - Important! : Because of typescript's 'extends' function, order matters in this file! super classes must be first!
*/
/**
* *********************************
*/
var CellValueDef = (function () {
function CellValueDef(_style) {
this._style = _style;
}
/* Note compact deserialization will be handled normally by OType */
CellValueDef.fromWS = function (otype, jsonObj) {
if (jsonObj['attributeCellValueDef']) {
return DialogTriple.fromWSDialogObject(jsonObj['attributeCellValueDef'], 'WSAttributeCellValueDef', OType.factoryFn);
}
else if (jsonObj['forcedLineCellValueDef']) {
return DialogTriple.fromWSDialogObject(jsonObj['forcedLineCellValueDef'], 'WSForcedLineCellValueDef', OType.factoryFn);
}
else if (jsonObj['labelCellValueDef']) {
return DialogTriple.fromWSDialogObject(jsonObj['labelCellValueDef'], 'WSLabelCellValueDef', OType.factoryFn);
}
else if (jsonObj['substitutionCellValueDef']) {
return DialogTriple.fromWSDialogObject(jsonObj['substitutionCellValueDef'], 'WSSubstitutionCellValueDef', OType.factoryFn);
}
else if (jsonObj['tabCellValueDef']) {
return DialogTriple.fromWSDialogObject(jsonObj['tabCellValueDef'], 'WSTabCellValueDef', OType.factoryFn);
}
else {
return new fp_1.Failure('CellValueDef::fromWS: unknown CellValueDef type: ' + util_1.ObjUtil.formatRecAttr(jsonObj));
}
};
Object.defineProperty(CellValueDef.prototype, "isInlineMediaStyle", {
get: function () {
return this.style && (this.style === PropDef.STYLE_INLINE_MEDIA || this.style === PropDef.STYLE_INLINE_MEDIA2);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CellValueDef.prototype, "style", {
get: function () {
return this._style;
},
enumerable: true,
configurable: true
});
return CellValueDef;
}());
exports.CellValueDef = CellValueDef;
/**
* *********************************
*/
var AttributeCellValueDef = (function (_super) {
__extends(AttributeCellValueDef, _super);
function AttributeCellValueDef(_propertyName, _presentationLength, _entryMethod, _autoFillCapable, _hint, _toolTip, _fieldActions, style) {
_super.call(this, style);
this._propertyName = _propertyName;
this._presentationLength = _presentationLength;
this._entryMethod = _entryMethod;
this._autoFillCapable = _autoFillCapable;
this._hint = _hint;
this._toolTip = _toolTip;
this._fieldActions = _fieldActions;
}
Object.defineProperty(AttributeCellValueDef.prototype, "autoFileCapable", {
get: function () {
return this._autoFillCapable;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "entryMethod", {
get: function () {
return this._entryMethod;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "fieldActions", {
get: function () {
return this._fieldActions;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "hint", {
get: function () {
return this._hint;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "isComboBoxEntryMethod", {
get: function () {
return this.entryMethod && this.entryMethod === 'ENTRY_METHOD_COMBO_BOX';
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "isDropDownEntryMethod", {
get: function () {
return this.entryMethod && this.entryMethod === 'ENTRY_METHOD_DROP_DOWN';
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "isTextFieldEntryMethod", {
get: function () {
return !this.entryMethod || this.entryMethod === 'ENTRY_METHOD_TEXT_FIELD';
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "presentationLength", {
get: function () {
return this._presentationLength;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "propertyName", {
get: function () {
return this._propertyName;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeCellValueDef.prototype, "toolTip", {
get: function () {
return this._toolTip;
},
enumerable: true,
configurable: true
});
return AttributeCellValueDef;
}(CellValueDef));
exports.AttributeCellValueDef = AttributeCellValueDef;
/**
* *********************************
*/
var ForcedLineCellValueDef = (function (_super) {
__extends(ForcedLineCellValueDef, _super);
function ForcedLineCellValueDef() {
_super.call(this, null);
}
return ForcedLineCellValueDef;
}(CellValueDef));
exports.ForcedLineCellValueDef = ForcedLineCellValueDef;
/**
* *********************************
*/
var LabelCellValueDef = (function (_super) {
__extends(LabelCellValueDef, _super);
function LabelCellValueDef(_value, style) {
_super.call(this, style);
this._value = _value;
}
Object.defineProperty(LabelCellValueDef.prototype, "value", {
get: function () {
return this._value;
},
enumerable: true,
configurable: true
});
return LabelCellValueDef;
}(CellValueDef));
exports.LabelCellValueDef = LabelCellValueDef;
/**
* *********************************
*/
var SubstitutionCellValueDef = (function (_super) {
__extends(SubstitutionCellValueDef, _super);
function SubstitutionCellValueDef(_value, style) {
_super.call(this, style);
this._value = _value;
}
Object.defineProperty(SubstitutionCellValueDef.prototype, "value", {
get: function () {
return this._value;
},
enumerable: true,
configurable: true
});
return SubstitutionCellValueDef;
}(CellValueDef));
exports.SubstitutionCellValueDef = SubstitutionCellValueDef;
/**
* *********************************
*/
var TabCellValueDef = (function (_super) {
__extends(TabCellValueDef, _super);
function TabCellValueDef() {
_super.call(this, null);
}
return TabCellValueDef;
}(CellValueDef));
exports.TabCellValueDef = TabCellValueDef;
/**
* *********************************
*/
var PaneContext = (function () {
function PaneContext(paneRef) {
this._lastRefreshTime = new Date(0);
this._parentContext = null;
this._paneRef = null;
this._paneRef = paneRef;
this._binaryCache = {};
}
PaneContext.resolveSettingsFromNavRequest = function (initialSettings, navRequest) {
var result = util_1.ObjUtil.addAllProps(initialSettings, {});
if (navRequest instanceof FormContext) {
util_1.ObjUtil.addAllProps(navRequest.dialogRedirection.fromDialogProperties, result);
util_1.ObjUtil.addAllProps(navRequest.offlineProps, result);
}
else if (navRequest instanceof NullNavRequest) {
util_1.ObjUtil.addAllProps(navRequest.fromDialogProperties, result);
}
var destroyed = result['fromDialogDestroyed'];
if (destroyed)
result['destroyed'] = true;
return result;
};
Object.defineProperty(PaneContext.prototype, "actionSource", {
get: function () {
return this.parentContext ? this.parentContext.actionSource : null;
},
enumerable: true,
configurable: true
});
PaneContext.prototype.binaryAt = function (propName, entityRec) {
var prop = entityRec.propAtName(propName);
if (prop) {
if (prop.value instanceof InlineBinaryRef) {
var binRef = prop.value;
return fp_1.Future.createSuccessfulFuture('binaryAt', new EncodedBinary(binRef.inlineData, binRef.settings['mime-type']));
}
else if (prop.value instanceof ObjectBinaryRef) {
var binRef = prop.value;
if (binRef.settings['webURL']) {
return fp_1.Future.createSuccessfulFuture('binaryAt', new UrlBinary(binRef.settings['webURL']));
}
else {
return this.readBinary(propName, entityRec);
}
}
else if (typeof prop.value === 'string') {
return fp_1.Future.createSuccessfulFuture('binaryAt', new UrlBinary(prop.value));
}
else {
return fp_1.Future.createFailedFuture('binaryAt', 'No binary found at ' + propName);
}
}
else {
return fp_1.Future.createFailedFuture('binaryAt', 'No binary found at ' + propName);
}
};
Object.defineProperty(PaneContext.prototype, "dialogAlias", {
get: function () {
return this.dialogRedirection.dialogProperties['dialogAlias'];
},
enumerable: true,
configurable: true
});
PaneContext.prototype.findMenuDefAt = function (actionId) {
var result = null;
if (this.menuDefs) {
this.menuDefs.some(function (md) {
result = md.findAtId(actionId);
return result != null;
});
}
return result;
};
PaneContext.prototype.formatForRead = function (propValue, propName) {
return PropFormatter.formatForRead(propValue, this.propDefAtName(propName));
};
PaneContext.prototype.formatForWrite = function (propValue, propName) {
return PropFormatter.formatForWrite(propValue, this.propDefAtName(propName));
};
Object.defineProperty(PaneContext.prototype, "formDef", {
get: function () {
return this.parentContext.formDef;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "isRefreshNeeded", {
get: function () {
return this._lastRefreshTime.getTime() < AppContext.singleton.lastMaintenanceTime.getTime();
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "lastRefreshTime", {
get: function () {
return this._lastRefreshTime;
},
set: function (time) {
this._lastRefreshTime = time;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "menuDefs", {
get: function () {
return this.paneDef.menuDefs;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "offlineCapable", {
get: function () {
return this._parentContext && this._parentContext.offlineCapable;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "paneDef", {
get: function () {
if (this.paneRef == null) {
return this.formDef.headerDef;
}
else {
return this.formDef.childrenDefs[this.paneRef];
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "paneRef", {
get: function () {
return this._paneRef;
},
set: function (paneRef) {
this._paneRef = paneRef;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "paneTitle", {
get: function () {
return this.paneDef.findTitle();
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "parentContext", {
get: function () {
return this._parentContext;
},
set: function (parentContext) {
this._parentContext = parentContext;
this.initialize();
},
enumerable: true,
configurable: true
});
PaneContext.prototype.parseValue = function (formattedValue, propName) {
return PropFormatter.parse(formattedValue, this.propDefAtName(propName));
};
PaneContext.prototype.propDefAtName = function (propName) {
return this.entityRecDef.propDefAtName(propName);
};
Object.defineProperty(PaneContext.prototype, "sessionContext", {
get: function () {
return this.parentContext.sessionContext;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PaneContext.prototype, "dialogRedirection", {
/** --------------------- MODULE ------------------------------*/
//*** let's pretend this has module level visibility
get: function () {
return this.paneDef.dialogRedirection;
},
enumerable: true,
configurable: true
});
//abstract
PaneContext.prototype.initialize = function () { };
PaneContext.prototype.readBinaries = function (entityRec) {
var _this = this;
return fp_1.Future.sequence(this.entityRecDef.propDefs.filter(function (propDef) {
return propDef.isBinaryType;
}).map(function (propDef) {
return _this.readBinary(propDef.name, entityRec);
}));
};
//abstract
PaneContext.prototype.readBinary = function (propName, entityRec) { return null; };
PaneContext.prototype.writeBinaries = function (entityRec) {
var _this = this;
return fp_1.Future.sequence(entityRec.props.filter(function (prop) {
return prop.value instanceof EncodedBinary;
}).map(function (prop) {
var ptr = 0;
var encBin = prop.value;
var data = encBin.data;
var writeFuture = fp_1.Future.createSuccessfulFuture('startSeq', {});
while (ptr < data.length) {
var boundPtr = function (ptr) {
writeFuture = writeFuture.bind(function (prevResult) {
var encSegment = (ptr + PaneContext.CHAR_CHUNK_SIZE) <= data.length ? data.substring(ptr, PaneContext.CHAR_CHUNK_SIZE) : data.substring(ptr);
return DialogService.writeProperty(_this.paneDef.dialogRedirection.dialogHandle, prop.name, encSegment, ptr != 0, _this.sessionContext);
});
};
boundPtr(ptr);
ptr += PaneContext.CHAR_CHUNK_SIZE;
}
return writeFuture;
}));
};
PaneContext.ANNO_NAME_KEY = "com.catavolt.annoName";
PaneContext.PROP_NAME_KEY = "com.catavolt.propName";
PaneContext.CHAR_CHUNK_SIZE = 128 * 1000; //size in chars for encoded 'write' operation
PaneContext.BINARY_CHUNK_SIZE = 256 * 1024; //size in byes for 'read' operation
return PaneContext;
}());
exports.PaneContext = PaneContext;
/**
* *********************************
*/
var EditorContext = (function (_super) {
__extends(EditorContext, _super);
function EditorContext(paneRef) {
_super.call(this, paneRef);
}
Object.defineProperty(EditorContext.prototype, "buffer", {
get: function () {
if (!this._buffer) {
this._buffer = new EntityBuffer(NullEntityRec.singleton);
}
return this._buffer;
},
enumerable: true,
configurable: true
});
EditorContext.prototype.changePaneMode = function (paneMode) {
var _this = this;
return DialogService.changePaneMode(this.paneDef.dialogHandle, paneMode, this.sessionContext).bind(function (changePaneModeResult) {
_this.putSettings(changePaneModeResult.dialogProps);
if (_this.isDestroyedSetting) {
_this._editorState = EditorState.DESTROYED;
}
else {
_this.entityRecDef = changePaneModeResult.entityRecDef;
if (_this.isReadModeSetting) {
_this._editorState = EditorState.READ;
}
else {
_this._editorState = EditorState.WRITE;
}
}
return fp_1.Future.createSuccessfulFuture('EditorContext::changePaneMode', _this.entityRecDef);
});
};
Object.defineProperty(EditorContext.prototype, "entityRec", {
get: function () {
return this._buffer.toEntityRec();
},
enumerable: true,
configurable: true
});
Object.defineProperty(EditorContext.prototype, "entityRecNow", {
get: function () {
return this.entityRec;
},
enumerable: true,
configurable: true
});
Object.defineProperty(EditorContext.prototype, "entityRecDef", {
get: function () {
return this._entityRecDef;
},
set: function (entityRecDef) {
this._entityRecDef = entityRecDef;
},
enumerable: true,
configurable: true
});
EditorContext.prototype.getAvailableValues = function (propName) {
return DialogService.getAvailableValues(this.paneDef.dialogHandle, propName, this.buffer.afterEffects(), this.sessionContext).map(function (valuesResult) {
return valuesResult.list;
});
};
EditorContext.prototype.isBinary = function (cellValueDef) {
var propDef = this.propDefAtName(cellValueDef.propertyName);
return propDef && (propDef.isBinaryType || (propDef.isURLType && cellValueDef.isInlineMediaStyle));
};
Object.defineProperty(EditorContext.prototype, "isDestroyed", {
get: function () {
return this._editorState === EditorState.DESTROYED;
},
enumerable: true,
configurable: true
});
Object.defineProperty(EditorContext.prototype, "isReadMode", {
get: function () {
return this._editorState === EditorState.READ;
},
enumerable: true,
configurable: true
});
EditorContext.prototype.isReadModeFor = function (propName) {
if (!this.isReadMode) {
var propDef = this.propDefAtName(propName);
return !propDef || !propDef.maintainable || !propDef.writeEnabled;
}
return true;
};
Object.defineProperty(EditorContext.prototype, "isWriteMode", {
get: function () {
return this._editorState === EditorState.WRITE;
},
enumerable: true,
configurable: true
});
EditorContext.prototype.performMenuAction = function (menuDef, pendingWrites) {
var _this = this;
return DialogService.performEditorAction(this.paneDef.dialogHandle, menuDef.actionId, pendingWrites, this.sessionContext).bind(function (redirection) {
var ca = new ContextAction(menuDef.actionId, _this.parentContext.dialogRedirection.objectId, _this.actionSource);
return NavRequestUtil.fromRedirection(redirection, ca, _this.sessionContext).map(function (navRequest) {
_this._settings = PaneContext.resolveSettingsFromNavRequest(_this._settings, navRequest);
if (_this.isDestroyedSetting) {
_this._editorState = EditorState.DESTROYED;
}
if (_this.isRefreshSetting) {
AppContext.singleton.lastMaintenanceTime = new Date();
}
return navRequest;
});
});
};
EditorContext.prototype.processSideEffects = function (propertyName, value) {
var _this = this;
var sideEffectsFr = DialogService.processSideEffects(this.paneDef.dialogHandle, this.sessionContext, propertyName, value, this.buffer.afterEffects()).map(function (changeResult) {
return changeResult.sideEffects ? changeResult.sideEffects.entityRec : new NullEntityRec();
});
return sideEffectsFr.map(function (sideEffectsRec) {
var originalProps = _this.buffer.before.props;
var userEffects = _this.buffer.afterEffects().props;
var sideEffects = sideEffectsRec.props;
sideEffects = sideEffects.filter(function (prop) {
return prop.name !== propertyName;
});
_this._buffer = EntityBuffer.createEntityBuffer(_this.buffer.objectId, EntityRecUtil.union(originalProps, sideEffects), EntityRecUtil.union(originalProps, EntityRecUtil.union(userEffects, sideEffects)));
return null;
});
};
EditorContext.prototype.read = function () {
var _this = this;
return DialogService.readEditorModel(this.paneDef.dialogHandle, this.sessionContext).map(function (readResult) {
_this.entityRecDef = readResult.entityRecDef;
return readResult.entityRec;
}).map(function (entityRec) {
_this.initBuffer(entityRec);
_this.lastRefreshTime = new Date();
return entityRec;
});
};
EditorContext.prototype.readBinary = function (propName, entityRec) {
var _this = this;
var seq = 0;
var buffer = '';
var f = function (result) {
buffer += result.data;
if (result.hasMore) {
return DialogService.readEditorProperty(_this.paneDef.dialogRedirection.dialogHandle, propName, ++seq, PaneContext.BINARY_CHUNK_SIZE, _this.sessionContext).bind(f);
}
else {
return fp_1.Future.createSuccessfulFuture('readProperty', new EncodedBinary(buffer));
}
};
return DialogService.readEditorProperty(this.paneDef.dialogRedirection.dialogHandle, propName, seq, PaneContext.BINARY_CHUNK_SIZE, this.sessionContext).bind(f);
};
EditorContext.prototype.requestedAccuracy = function () {
var accuracyStr = this.paneDef.settings[EditorContext.GPS_ACCURACY];
return accuracyStr ? Number(accuracyStr) : 500;
};
EditorContext.prototype.requestedTimeoutSeconds = function () {
var timeoutStr = this.paneDef.settings[EditorContext.GPS_SECONDS];
return timeoutStr ? Number(timeoutStr) : 30;
};
EditorContext.prototype.setPropValue = function (name, value) {
var propDef = this.propDefAtName(name);
var parsedValue = null;
if (propDef) {
parsedValue = value ? this.parseValue(value, propDef.name) : null;
this.buffer.setValue(propDef.name, parsedValue);
}
return parsedValue;
};
EditorContext.prototype.setBinaryPropWithDataUrl = function (name, dataUrl) {
var urlObj = new util_1.DataUrl(dataUrl);
this.setBinaryPropWithEncodedData(name, urlObj.data, urlObj.mimeType);
};
EditorContext.prototype.setBinaryPropWithEncodedData = function (name, encodedData, mimeType) {
var propDef = this.propDefAtName(name);
if (propDef) {
var value = new EncodedBinary(encodedData, mimeType);
this.buffer.setValue(propDef.name, value);
}
};
EditorContext.prototype.write = function () {
var _this = this;
var deltaRec = this.buffer.afterEffects();
return this.writeBinaries(deltaRec).bind(function (binResult) {
var result = DialogService.writeEditorModel(_this.paneDef.dialogRedirection.dialogHandle, deltaRec, _this.sessionContext).bind(function (either) {
if (either.isLeft) {
var ca = new ContextAction('#write', _this.parentContext.dialogRedirection.objectId, _this.actionSource);
return NavRequestUtil.fromRedirection(either.left, ca, _this.sessionContext).map(function (navRequest) {
return fp_1.Either.left(navRequest);
});
}
else {
var writeResult = either.right;
_this.putSettings(writeResult.dialogProps);
_this.entityRecDef = writeResult.entityRecDef;
return fp_1.Future.createSuccessfulFuture('EditorContext::write', fp_1.Either.right(writeResult.entityRec));
}
});
return result.map(