|
|
@@ -241,8 +241,10 @@ class TableAjax extends ViewAjax {
|
|
|
<?php if ($tblAjaxMap) $tblAjaxMap->printCSS(); ?>
|
|
|
<?php if ($tblAjaxMap) $tblAjaxMap->printJS(); ?>
|
|
|
<script src="stuff/jquery-ui-1.10.4.custom.min.js"></script>
|
|
|
+ <script src="static/sweetalert2.min.js"></script>
|
|
|
<script src="static/jquery.doubleScroll.js"></script>
|
|
|
<link rel="stylesheet" type="text/css" href="stuff/jquery-ui-smoothness/jquery-ui-1.10.4.custom.min.css">
|
|
|
+ <link rel="stylesheet" type="text/css" href="static/sweetalert2.min.css">
|
|
|
<style type="text/css">
|
|
|
.AjaxTable{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0;}
|
|
|
|
|
|
@@ -671,6 +673,15 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
|
|
|
}
|
|
|
priv.renderTable();
|
|
|
priv.onWindowResize();
|
|
|
+
|
|
|
+ {// activate saveBtn if some columns hidden
|
|
|
+ var selectedFilter = priv.modelColFilter_getSelected();
|
|
|
+ if (null === selectedFilter) {
|
|
|
+ priv.modelColFilter_getSaveBtn().prop("disabled", false)
|
|
|
+ } else {
|
|
|
+ priv.modelColFilter_getSaveBtn().prop("disabled", true)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -1806,14 +1817,19 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
|
|
|
var span = $('<span class="caret"></span>').appendTo(btn);
|
|
|
var ul = $('<ul class="dropdown-menu" style="max-height:250px;overflow:auto;">').appendTo(node);
|
|
|
|
|
|
- var columnFilters = priv.modelColFilter_getFilters();
|
|
|
var selectedFilter = priv.modelColFilter_getSelected();
|
|
|
- $.each(columnFilters, function(idx, colFltr) {
|
|
|
+ priv.modelColFilter_getFilters().map(function(colFltr) {
|
|
|
var li = $('<li></li>').appendTo(ul),
|
|
|
selected = (selectedFilter && selectedFilter == colFltr.name)? 'checked="checked"' : '',
|
|
|
input = '<input ' + selected + ' type="radio" style="margin:0"/>',
|
|
|
a = $('<a href="#" data-col_filter="' + colFltr.name + '" style="padding:0px 20px;">' + input + ' ' + colFltr.label + '</a>').appendTo(li);
|
|
|
});
|
|
|
+
|
|
|
+ {// if (!selectedFilter) {// save current filter
|
|
|
+ var li = $('<li style="text-align:center"></li>').appendTo(ul)
|
|
|
+ priv.modelColFilter_getSaveBtn().appendTo(li);
|
|
|
+ }
|
|
|
+
|
|
|
$('<li class="divider"></li>').appendTo(ul);
|
|
|
$.each(_data.cols, function(col, props) {
|
|
|
if (props.type != "unique" && col != 'ID') {
|
|
|
@@ -2766,7 +2782,7 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
|
|
|
jQuery(_uiNodeCont).trigger('TableAjax:render', ['head', 'body']);
|
|
|
};
|
|
|
|
|
|
- priv.modelColFilter_init = function() {
|
|
|
+ priv.modelColFilter_init = function() {// run only once, set _state._modelColFilter {selected, filters: [ {name, label, visibleCols} ]}
|
|
|
var isAllSelected = true;
|
|
|
if (undefined === _state._modelColFilter) {
|
|
|
var columnFilters = [];
|
|
|
@@ -2779,24 +2795,122 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
|
|
|
});
|
|
|
columnFilters.push(fltrAll);
|
|
|
}
|
|
|
- {
|
|
|
- var fltrMostUsed = {'name': 'most_used', 'label': 'Najczęściej używane', visibleCols: []};
|
|
|
- var fltrMostUsedLimit = 10;
|
|
|
- $.each(_data.cols, function(col, props) {
|
|
|
- if ("unique" == props.type) return;
|
|
|
- if (fltrMostUsedLimit-- > 0) {
|
|
|
- fltrMostUsed.visibleCols.push(col);
|
|
|
- }
|
|
|
- });
|
|
|
- columnFilters.push(fltrMostUsed);
|
|
|
- }
|
|
|
+ // {
|
|
|
+ // var fltrMostUsed = {'name': 'most_used', 'label': 'Najczęściej używane', visibleCols: []};
|
|
|
+ // var fltrMostUsedLimit = 10;
|
|
|
+ // $.each(_data.cols, function(col, props) {
|
|
|
+ // if ("unique" == props.type) return;
|
|
|
+ // if (fltrMostUsedLimit-- > 0) {
|
|
|
+ // fltrMostUsed.visibleCols.push(col);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // columnFilters.push(fltrMostUsed);
|
|
|
+ // }
|
|
|
|
|
|
_state._modelColFilter = {
|
|
|
selected: (isAllSelected)? 'all' : null,
|
|
|
- filters: columnFilters
|
|
|
+ filters: columnFilters,
|
|
|
+ saveBtn: $('<button class="btn btn-xs btn-primary" disabled="disabled">Zapisz widoczne kolumny</button>')
|
|
|
};
|
|
|
+ _state._modelColFilter.saveBtn.on('click', priv.modelColFilter_saveBtnClicked)
|
|
|
+
|
|
|
+ fetch('<?= Request::getPathUri() . "index.php?_route=ViewTableAjax&_task=getUserTableFilterAjax" ?>', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ credentials: 'same-origin',// add cookies
|
|
|
+ body: JSON.stringify({
|
|
|
+ namespace: '<?= $acl->getNamespace(); ?>',
|
|
|
+ })
|
|
|
+ }).then(function (response) {
|
|
|
+ return response.json()
|
|
|
+ }).then(function (result) {
|
|
|
+ if ('success' == result.type) {
|
|
|
+ // p5UI__notifyAjaxCallback(result)
|
|
|
+ _state._modelColFilter.filters = _state._modelColFilter.filters.filter(function (filter) {
|
|
|
+ return ('all' === filter.name || 'most_used' == filter.name)
|
|
|
+ }).concat(Object.keys(result.data).map(function (fltr) {
|
|
|
+ return {
|
|
|
+ name: fltr,
|
|
|
+ label: fltr,
|
|
|
+ visibleCols: result.data[fltr].split(',')
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ jQuery(_uiNodeCont).trigger('TableAjax:render', ['foot__columnPicker']);
|
|
|
+ } else {
|
|
|
+ p5UI__notifyAjaxCallback(result)
|
|
|
+ }
|
|
|
+ }).catch(function (e) {
|
|
|
+ // TODO: show error ("ajax response error: " + e)
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
+ priv.modelColFilter_saveBtnClicked = function (e) {
|
|
|
+ swal({
|
|
|
+ title: 'Zapisz widoczne kolumny',
|
|
|
+ html: '',
|
|
|
+ animation: true,
|
|
|
+ input: 'text',
|
|
|
+ inputPlaceholder: 'nazwa filtra',
|
|
|
+ // inputValue: null,
|
|
|
+ // inputAttributes: {'step': '0.01'},
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonText: 'Zapisz',
|
|
|
+ showLoaderOnConfirm: true,
|
|
|
+ showCloseButton: true,
|
|
|
+ preConfirm: function(filtrName) {
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ if (!filtrName) reject('Proszę podać nazwę filtra')
|
|
|
+ if (filtrName.length > 255) reject('Nazwa za długa')
|
|
|
+ fetch('<?= Request::getPathUri() . "index.php?_route=ViewTableAjax&_task=addUserTableFilterAjax" ?>', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ credentials: 'same-origin',// add cookies
|
|
|
+ body: JSON.stringify({
|
|
|
+ namespace: '<?= $acl->getNamespace(); ?>',
|
|
|
+ filtrName: filtrName,
|
|
|
+ visibleCols: Object.keys(_data.cols).filter(function(col) {
|
|
|
+ return !_data.cols[col].hidden
|
|
|
+ }).join(','),
|
|
|
+ })
|
|
|
+ }).then(function (response) {
|
|
|
+ return response.json()
|
|
|
+ }).then(function (result) {
|
|
|
+ if ('success' == result.type) {
|
|
|
+ p5UI__notifyAjaxCallback(result)
|
|
|
+ resolve(result.data)
|
|
|
+ } else {
|
|
|
+ p5UI__notifyAjaxCallback(result)
|
|
|
+ reject(result.msg || "Wystąpił błąd!")
|
|
|
+ }
|
|
|
+ }).catch(function (e) {
|
|
|
+ reject("ajax response error: " + e)
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
+ allowOutsideClick: false
|
|
|
+ }).then(function(userTableFilters) {
|
|
|
+ _state._modelColFilter.filters = _state._modelColFilter.filters.filter(function (filter) {
|
|
|
+ return ('all' === filter.name || 'most_used' == filter.name)
|
|
|
+ }).concat(Object.keys(userTableFilters).map(function (fltr) {
|
|
|
+ return {
|
|
|
+ name: fltr,
|
|
|
+ label: fltr,
|
|
|
+ visibleCols: userTableFilters[fltr].split(',')
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ jQuery(_uiNodeCont).trigger('TableAjax:render', ['head', 'body', 'foot__columnPicker']);
|
|
|
+ }).catch(function(e) {
|
|
|
+ // eg. hit Cancel
|
|
|
+ })
|
|
|
+ }
|
|
|
+ priv.modelColFilter_getSaveBtn = function () {
|
|
|
+ priv.modelColFilter_init();
|
|
|
+ return _state._modelColFilter.saveBtn
|
|
|
+ }
|
|
|
priv.modelColFilter_getFilters = function() {
|
|
|
priv.modelColFilter_init();
|
|
|
return _state._modelColFilter.filters;
|
|
|
@@ -2885,7 +2999,6 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
|
|
|
//_data.cols[column].index = new priv.ext.XDate();
|
|
|
jQuery(_uiNodeCont).trigger('TableAjax:render', ['head', 'body']);
|
|
|
}
|
|
|
-
|
|
|
};
|
|
|
|
|
|
priv.columnHideClicked = function(e) {
|