a-chart
Version:
A-Chart is a ReactJS Library/Package to address all posibilities of Reporting Functionality
167 lines (132 loc) • 7.58 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _utilFns = require('../../util/utilFns');
var Util = _interopRequireWildcard(_utilFns);
var _reactRedux = require('react-redux');
var _searchScope = require('./searchScope');
var _searchScope2 = _interopRequireDefault(_searchScope);
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; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var SearchBox = function (_Component) {
_inherits(SearchBox, _Component);
function SearchBox(props) {
_classCallCheck(this, SearchBox);
var _this = _possibleConstructorReturn(this, (SearchBox.__proto__ || Object.getPrototypeOf(SearchBox)).call(this, props));
_this.state = { "sTextDeltable": false, sSource: [] };
_this.searchChange = _this.searchChange.bind(_this);
_this.searchDelete = _this.searchDelete.bind(_this);
_this.search = _this.search.bind(_this);
_this._keyPress = _this._keyPress.bind(_this);
// alert(this.props.config.headers);
return _this;
}
_createClass(SearchBox, [{
key: 'searchChange',
value: function searchChange(e) {
var val = e.target.value,
df = true;
if (!val.length) {
df = false;
this.props.dispatch({ type: "RENDER", items: this.state.sSource.length ? this.state.sSource : this.props.items });
}
this.setState({ "sTextDeltable": df });
}
}, {
key: 'search',
value: function search() {
var _this2 = this;
var rst, sSource;
if (!this.state.sSource.length) {
this.state.sSource = this.props.items;
}
sSource = Object.assign([], this.state.sSource);
rst = sSource.filter(function (obj) {
return Util.isFindInObject(_this2.refs.searchFld.value, obj, _this2.searchScope ? _defineProperty({}, _this2.searchScope, _this2.searchScope) : _this2.props.config.headers);
});
this.props.dispatch({ type: "RENDER", items: rst });
// alert(nnn);
}
}, {
key: '_keyPress',
value: function _keyPress(e) {
if (e.which == 13) this.search();
}
}, {
key: 'searchDelete',
value: function searchDelete(e) {
this.refs.searchFld.value = "";
this.setState({ "sTextDeltable": false });
this.props.dispatch({ type: "RENDER", items: this.state.sSource.length ? this.state.sSource : this.props.items });
}
}, {
key: '_searchScopeChange',
value: function _searchScopeChange(e) {
this.searchScope = e.target.value === "-aa-" ? false : e.target.value;
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement(
'div',
{ className: 'aChart-SearchPanel' },
_react2.default.createElement(
'div',
{ className: 'aChart-Search' },
_react2.default.createElement('input', { type: 'text', placeholder: 'Search', ref: 'searchFld', onKeyPress: this._keyPress, onChange: this.searchChange }),
this.state.sTextDeltable && _react2.default.createElement('span', { className: 'closeIcn fa fa-times', onClick: this.searchDelete }),
_react2.default.createElement('span', { className: 'searchIcn fa fa-search', onClick: this.search })
),
this.props.config.searchScope ? _react2.default.createElement(_searchScope2.default, {
headers: this.props.config.headers,
fields: this.props.config.columnsForSort.split(","),
searchScopeChange: this._searchScopeChange.bind(this) }) : null
);
}
}]);
return SearchBox;
}(_react.Component);
var SearchComp = (0, _reactRedux.connect)(select)(SearchBox);
var GridToolBar = function (_Component2) {
_inherits(GridToolBar, _Component2);
function GridToolBar(props) {
_classCallCheck(this, GridToolBar);
return _possibleConstructorReturn(this, (GridToolBar.__proto__ || Object.getPrototypeOf(GridToolBar)).call(this, props));
}
_createClass(GridToolBar, [{
key: 'render',
value: function render() {
var _this4 = this;
return _react2.default.createElement(
'div',
{ className: 'GridToolBar' },
this.props.config.search && _react2.default.createElement(SearchComp, { config: this.props.config }),
this.props.config.export && _react2.default.createElement(
'div',
{ className: 'toolPanel' },
_react2.default.createElement('span', { className: 'toXls', title: "Export as " + this.props.config.export, onClick: function onClick() {
return Util.exportData(_this4.props.config.export, _this4.props.config);
} })
),
_react2.default.createElement('div', { style: { "clear": "both" } })
);
}
}]);
return GridToolBar;
}(_react.Component);
function select(state) {
return {
items: state.dataGridR.items
//listData: state.fireReducer.listData
};
}
exports.default = (0, _reactRedux.connect)(select)(GridToolBar);
//export default GridHeader;