Ver Fonte

added rm table cols filter in user profile

Piotr Labudda há 9 anos atrás
pai
commit
4d9606a772
2 ficheiros alterados com 68 adições e 0 exclusões
  1. 26 0
      SE/se-lib/Route/ViewTableAjax.php
  2. 42 0
      SE/se-lib/TableAjax.php

+ 26 - 0
SE/se-lib/Route/ViewTableAjax.php

@@ -176,6 +176,32 @@ class Route_ViewTableAjax extends RouteBase {
 		UI::dol();
 	}
 
+	public function rmUserTableFilterAjaxAction() {
+		Response::sendTryCatchJson(array($this, 'rmUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
+	}
+	public function rmUserTableFilterAjax($args) {
+		$namespace = V::get('namespace', '', $args);
+		$filtrName = V::get('filtrName', '', $args);
+		if (!$namespace) throw new Exception("Missing namespace");
+		if (!$filtrName) throw new Exception("Missing filtrName");
+
+		$userFltrConfKey = "tableColFilters__" . User::getLogin();
+		$currentFilters = DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY = '{$userFltrConfKey}' ");
+		if (!$currentFilters) return [
+			'type' => 'warning',
+			'msg' => "Brak filtrów w bazie",
+		];
+		$currentFilters = json_decode($currentFilters, 'assoc');
+		unset($currentFilters[$namespace][$filtrName]);
+		$affeced = DB::getPDO()->update('CRM_CONFIG', 'CONF_KEY', $userFltrConfKey, [
+			'CONF_VAL' => json_encode($currentFilters)
+		]);
+		return [
+			'type' => 'success',
+			'msg' => 'Zapisano nowy filtr',
+			'data' => $currentFilters[$namespace]
+		];
+	}
 	public function addUserTableFilterAjaxAction() {
 		Response::sendTryCatchJson(array($this, 'addUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
 	}

+ 42 - 0
SE/se-lib/TableAjax.php

@@ -1823,6 +1823,10 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
 							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 ('all' != colFltr && 'most_used' != colFltr) {
+								arm = $('<button data-col_filter="' + colFltr.name + '" class="pull-right btn btn-xs btn-link" style="color:red">' + '&times;' + '</a>').appendTo(a);
+								arm.on('click', priv.modelColFilter_onClickRemoveFilter)
+							}
 				});
 
 				{// if (!selectedFilter) {// save current filter
@@ -2846,6 +2850,44 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
 				});
 			}
 		};
+		priv.modelColFilter_onClickRemoveFilter = function (e) {
+			e.preventDefault()
+			e.stopPropagation()
+			var filtrName = $(this).data('col_filter')
+			if (!filtrName) return
+			fetch('<?= Request::getPathUri() . "index.php?_route=ViewTableAjax&_task=rmUserTableFilterAjax" ?>', {
+				method: 'POST',
+				headers: {
+					'Content-Type': 'application/json'
+				},
+				credentials: 'same-origin',// add cookies
+				body: JSON.stringify({
+					namespace: '<?= $acl->getNamespace(); ?>',
+					filtrName: filtrName,
+				})
+			}).then(function (response) {
+				return response.json()
+			}).then(function (result) {
+				if ('success' == result.type) {
+					p5UI__notifyAjaxCallback(result)
+					var userTableFilters = result.data;// resolve(result.data)
+					_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', ['foot__columnPicker']);
+				} else {
+					p5UI__notifyAjaxCallback(result)
+				}
+			}).catch(function (e) {
+				p5UI__notifyAjaxCallback({ type: 'error', msg: new String(e) })
+			});
+		};
 		priv.modelColFilter_saveBtnClicked = function (e) {
 			swal({
 				title: 'Zapisz widoczne kolumny',