UNPKG

catreact

Version:

Catavolt Core React Components

159 lines (158 loc) 7.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Created by rburson on 7/25/16. */ var React = require("react"); var catreact_core_1 = require("./catreact-core"); var catavolt_sdk_1 = require("catavolt-sdk"); exports.FILTER_VALUE_SUFFIX = '_FILTER_VALUE'; exports.FILTER_OPERATOR_SUFFIX = '_FILTER_OPER'; exports.SORT_DIRECTION_SUFFIX = '_SORT_DIRECTION'; exports.SORT_SEQUENCE_SUFFIX = '_SORT_SEQUENCE'; /** * Render a Search Model */ exports.CvSearchPane = React.createClass({ mixins: [catreact_core_1.CvBaseMixin, catreact_core_1.CvEditorBase], componentDidMount: function () { this._componentDidMount(); }, componentWillReceiveProps: function (nextProps, nextContext) { this._componentWillReceiveProps(nextProps, nextContext); }, componentWillUnmount: function () { this._componentWillUnmount(); }, detailsContext: function (nextProps, nextContext) { return this.editorContext(nextProps, nextContext); }, getDefaultProps: function () { return catreact_core_1.CvEditorBase._getDefaultProps(); }, render: function () { var editorContext = this.editorContext(); if (editorContext && !editorContext.isDestroyed) { if (this.props.renderer) { return this.props.renderer(this.getChildContext().cvContext); } else if (this.props.detailsRenderer) { if (editorContext.buffer) { return this.props.detailsRenderer(this.getChildContext().cvContext, editorContext.entityRec, this._getSearchCallbackObj()); } else { return null; } } else { return null; } } else { return null; } }, _getSearchCallbackObj: function () { var _this = this; var editorCallback = this._getCallbackObj(); var me = { clearSearchValues: function () { _this.detailsContext().entityRec.propNames.filter(function (propName) { return catavolt_sdk_1.StringUtil.endsWith(propName, exports.FILTER_OPERATOR_SUFFIX) || catavolt_sdk_1.StringUtil.endsWith(propName, exports.FILTER_VALUE_SUFFIX); }).forEach(function (propName) { editorCallback.setPropValue(propName, null); }); }, clearSortValues: function () { _this.detailsContext().entityRec.propNames.filter(function (propName) { return catavolt_sdk_1.StringUtil.endsWith(propName, exports.SORT_DIRECTION_SUFFIX) || catavolt_sdk_1.StringUtil.endsWith(propName, exports.SORT_SEQUENCE_SUFFIX); }).forEach(function (propName) { editorCallback.setPropValue(propName, null); }); }, getSearchValue: function (propName) { return editorCallback.getPropValueForEdit(propName + exports.FILTER_VALUE_SUFFIX); }, getSearchValueOperation: function (propName) { return editorCallback.getPropValueForEdit(propName + exports.FILTER_OPERATOR_SUFFIX); }, getSortValueDirection: function (propName) { return editorCallback.getPropValueForEdit(propName + exports.SORT_DIRECTION_SUFFIX); }, getSortValuePriority: function (propName) { return editorCallback.getPropValueForEdit(propName + exports.SORT_SEQUENCE_SUFFIX); }, isAscending: function (propName) { var dir = me.getSortValueDirection(propName); //server may return ASCENDING or ASC and DSC or DESCENDING return dir && dir.indexOf('A') === 0; }, isDescending: function (propName) { var dir = me.getSortValueDirection(propName); //server may return ASCENDING or ASC and DSC or DESCENDING return dir && dir.indexOf('D') === 0; }, reopenSearch: function (resultCallback) { editorCallback.openWriteMode(resultCallback); }, setAscending: function (propName, sortFieldPriority) { if (sortFieldPriority === void 0) { sortFieldPriority = 0; } me.setSortValue(propName, 'ASC', sortFieldPriority); }, setDescending: function (propName, sortFieldPriority) { if (sortFieldPriority === void 0) { sortFieldPriority = 0; } me.setSortValue(propName, 'DSC', sortFieldPriority); }, setSearchValue: function (propName, searchValue) { editorCallback.setPropValue(propName + exports.FILTER_VALUE_SUFFIX, searchValue); }, setSearchValueOperation: function (propName, operator) { editorCallback.setPropValue(propName + exports.FILTER_OPERATOR_SUFFIX, operator); }, setSortValue: function (propName, sortDirection, sortFieldPriority) { if (sortDirection === void 0) { sortDirection = 'ASC'; } if (sortFieldPriority === void 0) { sortFieldPriority = 0; } editorCallback.setPropValue(propName + exports.SORT_DIRECTION_SUFFIX, sortDirection); editorCallback.setPropValue(propName + exports.SORT_SEQUENCE_SUFFIX, sortFieldPriority); }, submitSearch: function (resultCallback) { editorCallback.saveChanges(resultCallback); }, /* proxy through the 'base class' methods */ clear: function () { editorCallback.clear(); }, getPropValueForDisplay: function (propName) { return editorCallback.getPropValueForDisplay(propName); }, getPropValueForEdit: function (propName) { return editorCallback.getPropValueForEdit(propName); }, openReadMode: function (resultCallback) { editorCallback.openReadMode(resultCallback); }, openWriteMode: function (resultCallback) { editorCallback.openWriteMode(resultCallback); }, refresh: function () { editorCallback.refresh(); }, saveChanges: function (resultCallback, navTarget) { editorCallback.saveChanges(resultCallback, navTarget); }, setBinaryPropWithDataUrl: function (name, dataUrl) { editorCallback.setBinaryPropWithDataUrl(name, dataUrl); }, setBinaryPropWithEncodedData: function (name, encodedData) { editorCallback.setBinaryPropWithEncodedData(name, encodedData); }, setPropValue: function (name, value) { editorCallback.setPropValue(name, value); }, suppressEvents: function (suppressEvents) { editorCallback.suppressEvents(suppressEvents); } }; return me; }, });