Просмотр исходного кода

TableAjax add special filter - messages

Piotr Labudda 10 лет назад
Родитель
Сommit
0631e553ac
2 измененных файлов с 36 добавлено и 2 удалено
  1. 30 0
      SE/se-lib/Data_Source.php
  2. 6 2
      SE/se-lib/TableAjax.php

+ 30 - 0
SE/se-lib/Data_Source.php

@@ -27,6 +27,7 @@ class Data_Source {
 	private $_fieldOwner = null;
 	private $_fieldGroupWrite = null;
 	private $_fieldGroupRead = null;
+	private $_showMsgsSpecialFilter = false;
 
 	function __construct($db = null) {
 		if ($db) {
@@ -37,6 +38,7 @@ class Data_Source {
 		$this->_default_sql_limit = 10;
 
 		$this->_geomFields = array('the_geom');
+		$this->_showMsgsSpecialFilter = true;// TODO: allow by acl, procesy?
 	}
 
 	function set_table($tbl) {// TODO: RMME
@@ -212,6 +214,14 @@ class Data_Source {
 	function getSpecialFilters() {
 		$fltrs = array();
 
+		if ($this->_showMsgsSpecialFilter) {
+			$fltrs['Msgs'] = new stdClass();
+			$fltrs['Msgs']->icon = 'glyphicon glyphicon-envelope';
+			$fltrs['Msgs']->label = 'Wiadomości';
+			$fltrs['Msgs']->btns = array();
+			$fltrs['Msgs']->btns['WIADOMOSCI'] = (object)array('value'=>'HAS_MSGS');
+			$fltrs['Msgs']->btns['BRAK_WIAD.'] = (object)array('value'=>'NO_MSGS');
+		}
 		if (array_key_exists('A_PROBLEM', $this->_cols)) {
 			$fltrs['Problemy'] = new stdClass();
 			$fltrs['Problemy']->icon = 'glyphicon glyphicon-warning-sign';
@@ -256,6 +266,26 @@ class Data_Source {
 		$sqlFltr = "";
 
 		switch ($fltr) {
+			case 'Msgs':
+				if ($this->_showMsgsSpecialFilter) {
+					$sqlFltrMsgs = "
+						select 1
+						from `CRM_UI_MSGS` m
+						where m.`uiTargetName`=CONCAT('{$this->_tbl}.', t.`ID`)
+							and m.`uiTargetType`='default_db_table_record'
+							and m.`A_STATUS` not in('DELETED')
+						limit 1
+					";
+					switch ($value) {
+						case 'HAS_MSGS':
+							$sqlFltr = " ({$sqlFltrMsgs})=1 ";
+							break;
+						case 'NO_MSGS':
+							$sqlFltr = " ({$sqlFltrMsgs}) is null ";
+							break;
+					}
+				}
+				break;
 			case 'Problemy':
 				if (array_key_exists('A_PROBLEM', $this->_cols)) {
 					switch ($value) {

+ 6 - 2
SE/se-lib/TableAjax.php

@@ -1305,13 +1305,17 @@ class TableAjax extends ViewAjax {
 			}
 			var node = $('<div class="btn-toolbar tblAjax__head__specialFilter"></div>');
 			$.map(priv.options.specialFilterFunctions, function(groupObj, groupName) {
-				var btnHtml, btnSelected, groupHtml = $('<div class="btn-group"></div>');
+				var btnHtml,
+						btnSelected,
+						groupLabel = groupObj.label || groupName,
+						groupHtml = $('<div class="btn-group"></div>')
+				;
 				// _state.specialFilters[e.data.group] = e.data.value;
 				if (groupName in _state.specialFilters) {
 					btnSelected = _state.specialFilters[groupName];
 				}
 				if (groupObj.icon) {
-					$('<button class="btn btn-xs btn-default" title="' + groupName + '"><i class="' + groupObj.icon + '"></i></button>').appendTo(groupHtml);
+					$('<button class="btn btn-xs btn-default" title="' + groupLabel + '"><i class="' + groupObj.icon + '"></i></button>').appendTo(groupHtml);
 				}
 				$.map(groupObj.btns, function(btnObj, btnName) {
 					btnHtml = $('<button class="btn btn-xs btn-default' + ((btnSelected && btnSelected == btnObj.value)? ' active' : '') + '">' + btnName + '</button>').appendTo(groupHtml);