|
|
@@ -17,6 +17,7 @@ var ReduxThunk = global.p5VendorJs.ReduxThunk;
|
|
|
var createStoreWithThunkMiddleware = Redux.applyMiddleware(ReduxThunk)(Redux.createStore); // TODO: to vendor.js
|
|
|
var p5UI__FieldCheckboxSearch = global.p5VendorJs['p5UI__FieldCheckboxSearch'];
|
|
|
var p5UI__FieldCheckboxLoading = global.p5VendorJs['p5UI__FieldCheckboxLoading'];
|
|
|
+var p5UI__TableAjax = global.p5VendorJs['p5UI__TableAjax'];
|
|
|
|
|
|
if (!String.prototype.startsWith) { // TODO: to global js utils
|
|
|
String.prototype.startsWith = function(search, pos) {
|
|
|
@@ -224,6 +225,7 @@ function selectedActions(idContext) {
|
|
|
return { type: 'SET_ERROR_MSG', errorMsg: errorMsg }
|
|
|
}
|
|
|
function toggle(namespace, primaryKey, checked) {
|
|
|
+ DBG && console.log('DBG::toggle action: (pks:['+primaryKey+'])...');
|
|
|
if ('select-all' === primaryKey) return toggleAll(namespace, checked);
|
|
|
|
|
|
return function(dispatch, getState) {
|
|
|
@@ -1144,6 +1146,7 @@ var TableAjax = function() {
|
|
|
mapEditorContainer: 'window' // 'window' or 'dock'
|
|
|
};
|
|
|
|
|
|
+ var _reactUITableNode; // TODO: react table node
|
|
|
var _uiNodeCont; // container holding table
|
|
|
var _uiNodeSelectedInfo;
|
|
|
var _uiNodeSpecialFilters;
|
|
|
@@ -1179,7 +1182,7 @@ var TableAjax = function() {
|
|
|
initialize the plugin.
|
|
|
*/
|
|
|
priv.init = function() {
|
|
|
- _uiNodeCont = priv.options.id;
|
|
|
+ _uiNodeCont = priv.options.id; // <div id="{_htmlID}" style="..."><table class="AjaxTable...
|
|
|
_state = {};// init state
|
|
|
_state.page = 1;
|
|
|
_state.specialFilters = {};
|
|
|
@@ -1188,6 +1191,7 @@ var TableAjax = function() {
|
|
|
jQuery(window).on('resize', priv.onWindowResize)
|
|
|
}
|
|
|
priv.initialRender();// set up _uiNode$...
|
|
|
+ // priv.initialReactRender(); // set up _reactUITableNode
|
|
|
priv.options.types.string = ((priv.options.types || {}).string || {});
|
|
|
priv.options.types.number = ((priv.options.types || {}).number || {});
|
|
|
priv.options.types.bool = ((priv.options.types || {}).bool || {});
|
|
|
@@ -1270,6 +1274,10 @@ var TableAjax = function() {
|
|
|
priv.options.router.apply(this);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ if (_reactUITableNode) {
|
|
|
+
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
priv.onRender = function(e) {
|
|
|
@@ -1331,11 +1339,77 @@ var TableAjax = function() {
|
|
|
jQuery(_uiNodeCont).prev('.doubleScroll-scroll-wrapper').css({display:'none'})
|
|
|
}
|
|
|
}
|
|
|
+ priv.uiFixStickyCols = function () {
|
|
|
+ var stickyCol1Width = priv.getStickyCol1Width();
|
|
|
+ var stickyCol2Width = priv.getStickyCol2Width();
|
|
|
+ var stickyCol3Width = priv.getStickyCol3Width();
|
|
|
+ if (undefined === _tableWidth) {
|
|
|
+ _tableWidth = true;
|
|
|
+ var contW = jQuery(_uiNodeCont).width();
|
|
|
+ var th1 = _uiNode$Table.find('.stickyCol1:first');
|
|
|
+ var th2 = th1.next();
|
|
|
+ var th1W = th1.innerWidth();
|
|
|
+ var th2W = 50 + 2 * 5;//th2.innerWidth();
|
|
|
+ // var colsW = stickyCol1Width + stickyCol2Width + stickyCol3Width;
|
|
|
+ var colsW = priv.getStickyColsSumWidth();
|
|
|
+ jQuery(_uiNodeCont).css({
|
|
|
+ width: '' + (contW - colsW) + 'px',
|
|
|
+ marginLeft: '' + colsW + 'px',
|
|
|
+ minHeight: '360px',
|
|
|
+ overflowX: 'scroll',
|
|
|
+ overflowY: 'visible',
|
|
|
+ paddingBottom: '1px',
|
|
|
+ clear: 'both',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ _uiNode$Table.find('.stickyCol1').css({
|
|
|
+ position: 'absolute',
|
|
|
+ left: '0',
|
|
|
+ top: 'auto',
|
|
|
+ width: '' + (stickyCol1Width) + 'px',
|
|
|
+ });
|
|
|
+ //_uiNode$Table.find('.filter').find('.stickyCol1').css({height:'34px'});
|
|
|
+ var sortStickyColHeight = _uiNode$Table.find('.sort').find('th:last').outerHeight();
|
|
|
+ _uiNode$Table.find('.sort').find('.stickyCol').css({height: sortStickyColHeight + 'px'});
|
|
|
+ var filterStickyColHeight = _uiNode$Table.find('.filter').find('th:last').outerHeight() + 1;
|
|
|
+ _uiNode$Table.find('.filter').find('.stickyCol').css({height: filterStickyColHeight + 'px'});
|
|
|
+ if (priv.options.checkboxes) _uiNode$Table.find('.stickyCol2').css({
|
|
|
+ position: 'absolute',
|
|
|
+ left: '' + (stickyCol1Width) + 'px',
|
|
|
+ top: 'auto',
|
|
|
+ width: '' + (stickyCol2Width) + 'px',
|
|
|
+ borderRight: '1px solid silver',
|
|
|
+ overflow: 'hidden'
|
|
|
+ });
|
|
|
+ _uiNode$Table.find('.stickyCol3').css({
|
|
|
+ position: 'absolute',
|
|
|
+ left: '' + (stickyCol1Width + stickyCol2Width) + 'px',
|
|
|
+ top: 'auto',
|
|
|
+ width: '' + (stickyCol3Width) + 'px',
|
|
|
+ borderRight: '1px solid silver',
|
|
|
+ overflow: 'hidden'
|
|
|
+ });
|
|
|
+ _uiNode$Table.find('tbody').find('.stickyCol').css({
|
|
|
+ height: '' + (29 + 1) + 'px',
|
|
|
+ });
|
|
|
+ };
|
|
|
priv.getStickyCol1Width = function () { return (12 + 3) * 4 + 2 * 5 + 1; }
|
|
|
priv.getStickyCol2Width = function () { return (priv.options.checkboxes) ? 20 + 2 * 5 + 1 : 0; }
|
|
|
priv.getStickyCol3Width = function () { return 50 + 2 * 5 + 1; }
|
|
|
priv.getStickyColsSumWidth = function () { return priv.getStickyCol1Width() + priv.getStickyCol2Width() + priv.getStickyCol3Width(); }
|
|
|
|
|
|
+ priv.initialReactRender = function () { // TODO: render table as React node
|
|
|
+ _reactUITableNode = document.createElement('div')
|
|
|
+ _reactUITableNode.setAttribute('class', "TableAjax-reactUITableNode");
|
|
|
+ _uiNodeCont.parentNode.appendChild(_reactUITableNode);
|
|
|
+ ReactDOM.render(
|
|
|
+ h(p5UI__TableAjax, {
|
|
|
+ namespace: priv.options.namespace
|
|
|
+ }),
|
|
|
+ _reactUITableNode
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
priv.initialRender = function() {
|
|
|
_uiNode$Table = $('<table class="AjaxTable table table-striped table-hover table-bordered table-condensed"></table>').appendTo(_uiNodeCont);
|
|
|
_head = $('<thead></thead>').prependTo(_uiNode$Table);
|
|
|
@@ -1404,8 +1478,11 @@ var TableAjax = function() {
|
|
|
_headSpecialFilter = true;
|
|
|
}
|
|
|
if (!_body) {
|
|
|
- _uiNode$Table.find('tbody').remove();
|
|
|
- _bodyNode = $('<tbody></tbody>').insertAfter(_head);
|
|
|
+ DBG && console.log('DBG:renderTable !_body', { _bodyNode })
|
|
|
+ // _uiNode$Table.find('tbody').remove();
|
|
|
+ // _bodyNode = $('<tbody></tbody>').insertAfter(_head);
|
|
|
+ // _uiNode$Table.find('tbody > tr').remove();
|
|
|
+ _bodyNode.find('tr').remove();
|
|
|
|
|
|
// find out what rows to show next...
|
|
|
var rowsAdded = 0;
|
|
|
@@ -1439,57 +1516,7 @@ var TableAjax = function() {
|
|
|
}
|
|
|
_foot = $(_uiNodeCont).next('.foot');
|
|
|
|
|
|
- var stickyCol1Width = priv.getStickyCol1Width();
|
|
|
- var stickyCol2Width = priv.getStickyCol2Width();
|
|
|
- var stickyCol3Width = priv.getStickyCol3Width();
|
|
|
- if (undefined === _tableWidth) {
|
|
|
- _tableWidth = true;
|
|
|
- var contW = jQuery(_uiNodeCont).width();
|
|
|
- var th1 = _uiNode$Table.find('.stickyCol1:first');
|
|
|
- var th2 = th1.next();
|
|
|
- var th1W = th1.innerWidth();
|
|
|
- var th2W = 50 + 2 * 5;//th2.innerWidth();
|
|
|
- var colsW = stickyCol1Width + stickyCol2Width + stickyCol3Width;
|
|
|
- jQuery(_uiNodeCont).css({
|
|
|
- width: '' + (contW - colsW) + 'px',
|
|
|
- marginLeft: '' + colsW + 'px',
|
|
|
- minHeight: '360px',
|
|
|
- overflowX: 'scroll',
|
|
|
- overflowY: 'visible',
|
|
|
- paddingBottom: '1px',
|
|
|
- clear: 'both',
|
|
|
- });
|
|
|
- }
|
|
|
- _uiNode$Table.find('.stickyCol1').css({
|
|
|
- position: 'absolute',
|
|
|
- left: '0',
|
|
|
- top: 'auto',
|
|
|
- width: '' + stickyCol1Width + 'px',
|
|
|
- });
|
|
|
- //_uiNode$Table.find('.filter').find('.stickyCol1').css({height:'34px'});
|
|
|
- var sortStickyColHeight = _uiNode$Table.find('.sort').find('th:last').outerHeight();
|
|
|
- _uiNode$Table.find('.sort').find('.stickyCol').css({height: sortStickyColHeight + 'px'});
|
|
|
- var filterStickyColHeight = _uiNode$Table.find('.filter').find('th:last').outerHeight() + 1;
|
|
|
- _uiNode$Table.find('.filter').find('.stickyCol').css({height: filterStickyColHeight + 'px'});
|
|
|
- if (priv.options.checkboxes) _uiNode$Table.find('.stickyCol2').css({
|
|
|
- position: 'absolute',
|
|
|
- left: '' + (stickyCol1Width) + 'px',
|
|
|
- top: 'auto',
|
|
|
- width: '' + stickyCol2Width + 'px',
|
|
|
- borderRight: '1px solid silver',
|
|
|
- overflow: 'hidden'
|
|
|
- });
|
|
|
- _uiNode$Table.find('.stickyCol3').css({
|
|
|
- position: 'absolute',
|
|
|
- left: '' + (stickyCol1Width + stickyCol2Width) + 'px',
|
|
|
- top: 'auto',
|
|
|
- width: '' + stickyCol3Width + 'px',
|
|
|
- borderRight: '1px solid silver',
|
|
|
- overflow: 'hidden'
|
|
|
- });
|
|
|
- _uiNode$Table.find('tbody').find('.stickyCol').css({
|
|
|
- height: '' + (29 + 1) + 'px',
|
|
|
- });
|
|
|
+ priv.uiFixStickyCols();
|
|
|
|
|
|
if (_data.total == 0 && priv.options.hidePagerOnEmpty) {
|
|
|
$('.btn-toolbar', _foot).remove();
|
|
|
@@ -1592,22 +1619,31 @@ var TableAjax = function() {
|
|
|
fieldWidget = (function(fldName, fieldProps) {
|
|
|
var _fieldName = fldName;
|
|
|
var _fieldProps = fieldProps;
|
|
|
+ var _formatDefault = _.get(_fieldProps, 'format', null);
|
|
|
var _formatByValue = _.get(_fieldProps, 'formatByValue', null);
|
|
|
+ var _formatEmpty = _.get(_fieldProps, 'formatEmpty', null);
|
|
|
var _aliasMap = _.get(_fieldProps, 'aliasMap', null);
|
|
|
return function(val, fieldPK, row) {
|
|
|
+ var outValue = '';
|
|
|
if (_formatByValue && val in _formatByValue) {
|
|
|
- val = p5Utils__format(_formatByValue[val], [val])
|
|
|
- // console.log('p5:string value', val, '_aliasMap', _aliasMap)
|
|
|
- if (_aliasMap) {
|
|
|
- Object.keys(_aliasMap).map(function (mapKey) {
|
|
|
- var mapField = _aliasMap[mapKey]
|
|
|
- if (undefined !== row[mapField]) {
|
|
|
- val = val.replace(new RegExp('\{' + mapKey + '\}', 'g'), row[mapField]);
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ outValue = p5Utils__format(_formatByValue[val], [val])
|
|
|
}
|
|
|
- return val;
|
|
|
+ else if (val && _formatDefault) {
|
|
|
+ outValue = p5Utils__format(_formatDefault, [val])
|
|
|
+ }
|
|
|
+ else if (!val && _formatEmpty) {
|
|
|
+ outValue = p5Utils__format(_formatEmpty, [])
|
|
|
+ }
|
|
|
+ // console.log('p5:string value', val, '_aliasMap', _aliasMap)
|
|
|
+ if (_aliasMap) {
|
|
|
+ Object.keys(_aliasMap).map(function (mapKey) {
|
|
|
+ var mapField = _aliasMap[mapKey]
|
|
|
+ if (undefined !== row[mapField]) {
|
|
|
+ outValue = outValue.replace(new RegExp('\{' + mapKey + '\}', 'g'), row[mapField]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return outValue;
|
|
|
}
|
|
|
}(fldName, fieldProps));
|
|
|
break;
|
|
|
@@ -1805,12 +1841,11 @@ var TableAjax = function() {
|
|
|
};
|
|
|
|
|
|
priv.renderRow = function(props) {
|
|
|
- var rowNode = $('<tr></tr>'),
|
|
|
- rowPK = (_state.primaryKey in props) ? props[_state.primaryKey] : null,
|
|
|
- cellNode,
|
|
|
- columnName, columnProps, val, cellCnt, format, showTooltip, fldWidgetNode,
|
|
|
- dbg = (priv.options.debug || DBG)
|
|
|
- ;
|
|
|
+ var rowNode = $('<tr></tr>');
|
|
|
+ var rowPK = (_state.primaryKey in props) ? props[_state.primaryKey] : null;
|
|
|
+ var cellNode;
|
|
|
+ var columnName, columnProps, val, cellCnt, format, showTooltip, fldWidgetNode;
|
|
|
+ var dbg = (priv.options.debug || DBG);
|
|
|
// ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event);"
|
|
|
rowNode.attr('ondrop', "p5TA_onDrop(event, '"+rowPK+"', '"+priv.options.namespace+"')")
|
|
|
rowNode.attr('ondragover', "p5TA_onDragOver(event, this, '"+rowPK+"', '"+priv.options.namespace+"')")
|
|
|
@@ -2132,15 +2167,6 @@ var TableAjax = function() {
|
|
|
|
|
|
if (_state.primaryKey && priv.options.checkboxes) {
|
|
|
var cellNode = $('<td class="stickyCol stickyCol2" style="padding:3px 5px"></td>').appendTo(rowNode);
|
|
|
- // ReactDOM.render(
|
|
|
- // h(P5UI__TableAjaxRowCheckbox, {
|
|
|
- // disabled: true,
|
|
|
- // primaryKey: 'empty',
|
|
|
- // store: priv.options.selectedStore,
|
|
|
- // actions: priv.options.selectedActions
|
|
|
- // }),
|
|
|
- // cellNode.get(0)
|
|
|
- // );
|
|
|
}
|
|
|
for (var i = 0; i < _state.colsSorted.length; i++) {
|
|
|
var columnName = _state.colsSorted[i],
|
|
|
@@ -2765,7 +2791,6 @@ var TableAjax = function() {
|
|
|
if (state.data.cols && Object.keys(state.data.cols).length > 0) {
|
|
|
priv.setStateCols(state.data.cols, state.data.primaryKey);
|
|
|
priv.setStateData(state.data);
|
|
|
- renderParts['head'] = true;
|
|
|
} else {
|
|
|
priv.setStateData(state.data);
|
|
|
}
|