Changes to the FilterWidget

This commit is contained in:
Paolo
2018-05-29 18:05:22 +02:00
parent dc580c9526
commit 0a71bce547
9 changed files with 2768 additions and 1923 deletions
File diff suppressed because it is too large Load Diff
+35
View File
@@ -20,6 +20,9 @@ class FHC_Controller extends CI_Controller
$this->load->helper('fhcauth');
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Wrapper to load phrases using the PhrasesLib
* NOTE: The library is loaded with the alias 'p', so must me used with this alias in the rest of the code.
@@ -30,6 +33,9 @@ class FHC_Controller extends CI_Controller
$this->load->library('PhrasesLib', array($categories, $language), 'p');
}
//------------------------------------------------------------------------------------------------------------------
// Protected methods
/**
* Sets the unique id for the called controller
* NOTE: it is only working with HTTP GET request, not neeaded with POST
@@ -67,4 +73,33 @@ class FHC_Controller extends CI_Controller
{
return $this->_controllerId;
}
/**
* Utility method to output a success using JSON as content type
* Wraps the private method _outputJson
*/
protected function outputJsonSuccess($mixed)
{
$this->_outputJson(success($mixed));
}
/**
* Utility method to output an error using JSON as content type
* Wraps the private method _outputJson
*/
protected function outputJsonError($mixed)
{
$this->_outputJson(error($mixed));
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
* Utility method to output using JSON as content type
*/
private function _outputJson($mixed)
{
$this->output->set_content_type('application/json')->set_output(json_encode($mixed));
}
}
+444
View File
@@ -0,0 +1,444 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* FilterWidget logic
*/
class FiltersLib
{
// Session parameters names
const SESSION_NAME = 'FHC_FILTER_WIDGET'; // Filter session name
const SESSION_FILTER_NAME = 'filterName';
const SESSION_FIELDS = 'fields';
const SESSION_SELECTED_FIELDS = 'selectedFields';
const SESSION_COLUMNS_ALIASES = 'columnsAliases';
const SESSION_ADDITIONAL_COLUMNS = 'additionalColumns';
const SESSION_CHECKBOXES = 'checkboxes';
const SESSION_FILTERS = 'filters';
const SESSION_DATASET_METADATA = 'datasetMetadata';
const SESSION_DATASET = 'dataset';
const SESSION_ROW_NUMBER = 'rowNumber';
// Alias for the dynamic table used to retrive the dataset
const DATASET_TABLE_ALIAS = 'datasetFilterTable';
// Parameters names...
// ...to identify a single filter widget in the session
const FHC_CONTROLLER_ID = 'fhc_controller_id';
// ...to identify a single filter widget in the DB
const APP_PARAMETER = 'app';
const DATASET_NAME_PARAMETER = 'datasetName';
const FILTER_KURZBZ_PARAMETER = 'filterKurzbz';
const FILTER_ID = 'filter_id';
// ...stament to retrive the dataset
const QUERY_PARAMETER = 'query';
// ...to specify more columns or aliases for them
const ADDITIONAL_COLUMNS = 'additionalColumns';
const CHECKBOXES = 'checkboxes';
const COLUMNS_ALIASES = 'columnsAliases';
// ...to format/mark records of a dataset
const FORMAT_RAW = 'formatRaw';
const MARK_ROW = 'markRow';
// ...to hide the options for a filter
const HIDE_HEADER = 'hideHeader';
const HIDE_SAVE = 'hideSave';
// Filter operations values
const OP_EQUAL = 'equal';
const OP_NOT_EQUAL = 'nequal';
const OP_GREATER_THAN = 'gt';
const OP_LESS_THAN = 'lt';
const OP_IS_TRUE = 'true';
const OP_IS_FALSE = 'false';
const OP_CONTAINS = 'contains';
const OP_NOT_CONTAINS = 'ncontains';
const OP_SET = 'set';
const OP_NOT_SET = 'nset';
// Filter options values
const OPT_DAYS = 'days';
const OPT_MONTHS = 'months';
const FILTER_PHRASES_CATEGORY = 'FilterWidget'; // The category used to store phrases for the FilterWidget
const FILTER_PAGE_PARAM = 'filter_page'; // Filter page parameter used to overwrite the page URI
private $_ci; // Code igniter instance
private $_filterUniqueId; // unique id for this filter widget
/**
* Gets the CI instance and loads message helper
*/
public function __construct($params = null)
{
$this->_ci =& get_instance();
// Loads helper message to manage returning messages
$this->_ci->load->helper('message');
$this->_filterUniqueId = $this->_getFilterUniqueId($params); // sets the id for the related filter widget
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Return an unique string that identify this filter widget
* NOTE: The default value is the URI where the FilterWidget is called
* If the fhc_controller_id is present then is also used
*/
private function _getFilterUniqueId($params)
{
//
if ($params != null
&& is_array($params)
&& isset($params[self::FILTER_PAGE_PARAM])
&& !empty(trim($params[self::FILTER_PAGE_PARAM])))
{
$filterUniqueId = $params[self::FILTER_PAGE_PARAM];
}
else
{
// Gets the current page URI
$filterUniqueId = $this->_ci->router->directory.$this->_ci->router->class.'/'.$this->_ci->router->method;
}
// If the FHC_CONTROLLER_ID parameter is present in the HTTP GET
if (isset($_GET[self::FHC_CONTROLLER_ID]))
{
$filterUniqueId .= '/'.$this->_ci->input->get(self::FHC_CONTROLLER_ID); // then use it
}
elseif (isset($_POST[self::FHC_CONTROLLER_ID])) // else if the FHC_CONTROLLER_ID parameter is present in the HTTP POST
{
$filterUniqueId .= '/'.$this->_ci->input->post(self::FHC_CONTROLLER_ID); // then use it
}
return $filterUniqueId;
}
/**
* Returns the whole session for this filter widget if found, otherwise null
*/
public function getSession()
{
$session = null;
// If it is present a session for this filter
if (isset($_SESSION[self::SESSION_NAME]) && isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId]))
{
$session = $_SESSION[self::SESSION_NAME][$this->_filterUniqueId];
}
return $session;
}
/**
* Returns one element from the session of this filter widget, otherwise null
*/
public function getElementSession($name)
{
$session = $this->getSession(); // get the whole session for this filter
if (isset($session[$name]))
{
return $session[$name];
}
return null;
}
/**
* Sets the whole session for this filter widget
*/
public function setSession($data)
{
// If is NOT already present into the session
if (!isset($_SESSION[self::SESSION_NAME])
|| (isset($_SESSION[self::SESSION_NAME]) && !is_array($_SESSION[self::SESSION_NAME])))
{
$_SESSION[self::SESSION_NAME] = array(); // then create it
}
$_SESSION[self::SESSION_NAME][$this->_filterUniqueId] = $data; // stores data
}
/**
* Sets one element of the session of this filter widget
*/
public function setElementSession($name, $value)
{
// If is NOT already present into the session
if (!isset($_SESSION[self::SESSION_NAME])
|| (isset($_SESSION[self::SESSION_NAME]) && !is_array($_SESSION[self::SESSION_NAME])))
{
$_SESSION[self::SESSION_NAME] = array(); // then create it
}
// If the session for this filter is NOT already present into the session
if (!isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId])
|| (isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId])
&& !is_array($_SESSION[self::SESSION_NAME][$this->_filterUniqueId])))
{
$_SESSION[self::SESSION_NAME][$this->_filterUniqueId] = array(); // then create it
}
$_SESSION[self::SESSION_NAME][$this->_filterUniqueId][$name] = $value; // stores the single value
}
/**
* Loads the definition data from DB for a filter widget
*/
public function loadDefinition($filterId, $app, $datasetName, $filterKurzbz)
{
// Loads the needed models
$this->_ci->load->model('system/Filters_model', 'FiltersModel');
$this->_ci->load->model('person/Benutzer_model', 'BenutzerModel'); // to get the default custom filter
$this->_ci->FiltersModel->resetQuery(); // reset any previous built query
$this->_ci->FiltersModel->addJoin('public.tbl_benutzer', 'person_id', 'LEFT'); // left join with benutzer table
$this->_ci->FiltersModel->addSelect('system.tbl_filters.*'); // select only from table filters
$this->_ci->FiltersModel->addOrder('sort', 'ASC'); // sort on column sort
$this->_ci->FiltersModel->addLimit(1); // if more than one filter is set as default only one will be retrived
$definition = null;
$whereParameters = null; // where clause parameters
// If we have a good filterId then use it!
if ($filterId != null && is_numeric($filterId) && $filterId > 0)
{
$whereParameters = array(
'filter_id' => $filterId
);
}
else
{
// If we can univocally retrive a filter
if ($app != null && $datasetName != null && $filterKurzbz != null)
{
$whereParameters = array(
'app' => $app,
'dataset_name' => $datasetName,
'filter_kurzbz' => $filterKurzbz
);
}
// Else if we have only app and datasetName
elseif ($app != null && $datasetName != null && $filterKurzbz == null)
{
// Try to load the custom filter (person_id = logged user person_id) with the given "app" and "dataset_name"
// that is set as default filter (default_filter = true)
$whereParameters = array(
'app' => $app,
'dataset_name' => $datasetName,
'uid' => getAuthUID(),
'default_filter' => true
);
$definition = $this->_ci->FiltersModel->loadWhere($whereParameters);
if (!hasData($definition)) // If a custom filter is NOT found
{
// Try to load the global filter (person_id = null) with the given "app" and "dataset_name" that is set as
// default filter (default_filter = true)
$whereParameters = array(
'app' => $app,
'dataset_name' => $datasetName,
'default_filter' => true
);
$definition = $this->_ci->FiltersModel->loadWhere($whereParameters);
}
}
}
// If no definition where loaded and where parameters were set
if ($definition == null && $whereParameters != null)
{
$definition = $this->_ci->FiltersModel->loadWhere($whereParameters);
}
return $definition;
}
/**
* Checks if the json definition of this filter is valid
*/
public function parseFilterJson($definition)
{
$jsonEncodedFilter = null;
// If the definition contains data and they are valid
if (hasData($definition) && isset($definition->retval[0]->filter) && trim($definition->retval[0]->filter) != '')
{
// Get the json definition of the filter
$tmpJsonEncodedFilter = json_decode($definition->retval[0]->filter);
// Checks required filter's properies
if (isset($tmpJsonEncodedFilter->name)
&& isset($tmpJsonEncodedFilter->columns)
&& is_array($tmpJsonEncodedFilter->columns)
&& isset($tmpJsonEncodedFilter->filters)
&& is_array($tmpJsonEncodedFilter->filters))
{
$jsonEncodedFilter = $tmpJsonEncodedFilter;
}
}
return $jsonEncodedFilter;
}
/**
* Generate the query to retrive the dataset for a filter
* NOTE: filterJson should be already checked using the method parseFilterJson
*/
public function generateDatasetQuery($query, $filterJson)
{
$datasetQuery = null;
// If the given query is valid and the json of the filter is valid
if (!empty(trim($query)) && $filterJson != null)
{
$definedFilters = $filterJson->filters;
$where = '';
for ($filtersCounter = 0; $filtersCounter < count($definedFilters); $filtersCounter++)
{
$filterDefinition = $definedFilters[$filtersCounter];
if ($filtersCounter > 0) $where .= ' AND ';
if (!empty(trim($filterDefinition->name)))
{
$where .= '"'.$filterDefinition->name.'"'.$this->_getDatasetQueryCondition($filterDefinition);
}
}
if ($where != '')
{
$datasetQuery = 'SELECT * FROM ('.$query.') '.self::DATASET_TABLE_ALIAS.' WHERE '.$where;
}
}
return $datasetQuery;
}
/**
* Retrives the dataset from the DB
*/
public function getDataset($datasetQuery)
{
$dataset = null;
if ($datasetQuery != null)
{
$dataset = @$this->_ci->FiltersModel->execReadOnlyQuery($datasetQuery);
}
return $dataset;
}
/**
* Get the filter name, the default is the "name" property of the JSON definition
* If the property namePhrase is present into the JSON definition, then try to load that from the phrases system
* NOTE: filterJson should be already checked using the method parseFilterJson
*/
public function getFilterName($filterJson)
{
$filterName = $filterJson->name; // always present, used as default
// Filter name from phrases system
if (isset($filterJson->namePhrase) && !empty(trim($filterJson->namePhrase)))
{
// Loads the library to use the phrases system
$this->_ci->load->library('PhrasesLib', array(self::FILTER_PHRASES_CATEGORY));
$tmpFilterNamePhrase = $this->_ci->phraseslib->t(self::FILTER_PHRASES_CATEGORY, $filterJson->namePhrase);
if (isset($tmpFilterNamePhrase) && !empty(trim($tmpFilterNamePhrase))) // if is not null or an empty string
{
$filterName = $tmpFilterNamePhrase;
}
}
return $filterName;
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
*
*/
private function _getDatasetQueryCondition($filterDefinition)
{
$condition = '';
if (!empty(trim($filterDefinition->operation)))
{
switch ($filterDefinition->operation)
{
case self::OP_EQUAL:
if (is_numeric($filterDefinition->condition)) $condition = '= '.$filterDefinition->condition;
break;
case self::OP_NOT_EQUAL:
if (is_numeric($filterDefinition->condition)) $condition = '!= '.$filterDefinition->condition;
break;
case self::OP_GREATER_THAN:
if (is_numeric($filterDefinition->condition)
&& isset($filterDefinition->option)
&& ($filterDefinition->option == self::OPT_DAYS
|| $filterDefinition->option == self::OPT_MONTHS))
{
$condition = '< (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)';
}
else
{
$condition = '> '.$filterDefinition->condition;
}
break;
case self::OP_LESS_THAN:
if (is_numeric($filterDefinition->condition)
&& isset($filterDefinition->option)
&& ($filterDefinition->option == self::OPT_DAYS
|| $filterDefinition->option == self::OPT_MONTHS))
{
$condition = '> (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)';
}
else
{
$condition = '< '.$filterDefinition->condition;
}
break;
case self::OP_CONTAINS:
$condition = 'ILIKE \'%'.$this->_ci->FiltersModel->escapeLike($filterDefinition->condition).'%\'';
break;
case self::OP_NOT_CONTAINS:
$condition = 'NOT ILIKE \'%'.$this->_ci->FiltersModel->escapeLike($filterDefinition->condition).'%\'';
break;
case self::OP_IS_TRUE:
$condition = 'IS TRUE';
break;
case self::OP_IS_FALSE:
$condition = 'IS FALSE';
break;
case self::OP_SET:
$condition = 'IS NOT NULL';
break;
case self::OP_NOT_SET:
$condition = 'IS NULL';
break;
default:
$condition = 'IS NOT NULL';
break;
}
}
if (!empty(trim($condition))) $condition = ' '.$condition;
return $condition;
}
}
@@ -151,7 +151,7 @@
),\', \'
) AS "StgAktiv",
pl.zeitpunkt AS "LockDate",
pl.lockuser as "LockUser",
pl.lockuser AS "LockUser",
pd.parkdate AS "ParkDate"
FROM public.tbl_person p
LEFT JOIN (SELECT person_id, zeitpunkt, uid as lockuser FROM system.tbl_person_lock WHERE app = \''.$APP.'\') pl USING(person_id)
@@ -299,18 +299,9 @@
}
);
$filterId = isset($_GET[InfoCenter::FILTER_ID]) ? $_GET[InfoCenter::FILTER_ID] : null;
if (isset($filterId) && is_numeric($filterId))
{
$filterWidgetArray[InfoCenter::FILTER_ID] = $filterId;
}
else
{
$filterWidgetArray['app'] = $APP;
$filterWidgetArray['datasetName'] = 'PersonActions';
$filterWidgetArray['filterKurzbz'] = 'InfoCenterNotSentApplicationAll';
}
$filterWidgetArray[InfoCenter::FILTER_ID] = $this->input->get(InfoCenter::FILTER_ID);
$filterWidgetArray['app'] = $APP;
$filterWidgetArray['datasetName'] = 'PersonActions';
echo $this->widgetlib->widget('FilterWidget', $filterWidgetArray);
?>
+1 -3
View File
@@ -1,9 +1,7 @@
<div class="row">
<div class="col-lg-12">
<div class="filter-name-title">
<?php FilterWidget::displayFilterName(); ?>
</div>
<div class="filter-name-title"></div>
<br>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+20 -20
View File
@@ -163,6 +163,26 @@ var FHC_AjaxClient = {
FHC_AjaxClient._hideVeil();
},
/**
* Retrives parameters from URL query string (HTTP GET parameters)
*/
getUrlParameter: function(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++)
{
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam)
{
return sParameterName[1];
}
}
},
//------------------------------------------------------------------------------------------------------------------
// Private methods
@@ -278,26 +298,6 @@ var FHC_AjaxClient = {
this._veilTimeout);
},
/**
* Retrives parameters from URL query string (HTTP GET parameters)
*/
getUrlParameter: function(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++)
{
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam)
{
return sParameterName[1];
}
}
},
/**
* Checks call parameters, if they are present and are valid
* It generates and returns all the parameters needed to perform an ajax remote call
+328 -246
View File
@@ -38,76 +38,339 @@ var FHC_FilterWidget = {
/**
*
*/
renderSelectedFields: function() {
//
display: function() {
FHC_FilterWidget._getFilter(FHC_FilterWidget._renderFilterWidget);
},
/**
*
*/
_getFilter: function(renderFunction) {
FHC_AjaxClient.ajaxCallGet(
'system/Filters/selectFields',
'system/Filters/getFilter',
{
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetEventsSF();
// console.log(data);
if (data != null)
if (FHC_AjaxClient.hasData(data) && typeof renderFunction == 'function')
{
var arrayFieldsToDisplay = [];
if (data.columnsAliases != null && $.isArray(data.columnsAliases))
{
arrayFieldsToDisplay = data.columnsAliases;
}
else if (data.selectedFields != null && $.isArray(data.selectedFields))
{
arrayFieldsToDisplay = data.selectedFields;
}
for (var i = 0; i < arrayFieldsToDisplay.length; i++)
{
var fieldToDisplay = arrayFieldsToDisplay[i];
var fieldName = data.selectedFields[i];
var strHtml = '<span id="dnd' + fieldName + '" class="filter-select-field-dnd-span">';
strHtml += '<span>';
strHtml += fieldToDisplay;
strHtml += '</span>';
strHtml += '<span><a class="remove-field" fieldToRemove="' + fieldName + '"> X </a></span>';
strHtml += '</span>';
$("#filterSelectFieldsDnd").append(strHtml);
}
var strDropDown = '<option value="">Select a field to add...</option>';
$("#addField").append(strDropDown);
if (data.allSelectedFields != null)
{
for (var i = 0; i < data.allSelectedFields.length; i++)
{
var fieldName = data.allSelectedFields[i];
var fieldToDisplay = data.allSelectedFields[i];
if (data.selectedFields.indexOf(fieldName) < 0)
{
if (data.allColumnsAliases != null && $.isArray(data.allColumnsAliases))
{
fieldToDisplay = data.allColumnsAliases[i];
}
strDropDown = '<option value="' + fieldName + '">' + fieldToDisplay + '</option>';
$("#addField").append(strDropDown);
}
}
}
renderFunction(FHC_AjaxClient.getData(data));
}
FHC_FilterWidget._dndSF();
FHC_FilterWidget._addEventsSF();
}
}
);
},
/**
*
*/
_renderFilterWidget: function(data) {
console.log(data);
FHC_FilterWidget._setFilterName(data); //
FHC_FilterWidget._renderDnDFields(data); //
FHC_FilterWidget._renderDropDownFields(data); //
FHC_FilterWidget._renderAppliedFilters(data); //
},
_setFilterName: function(data) {
if (data.hasOwnProperty('filterName'))
{
$(".filter-name-title").html(data.filterName);
}
},
/**
*
*/
_renderDnDFields: function(data) {
$(".remove-field").off('click');
if (data.hasOwnProperty('rowNumber') && data.rowNumber > 0)
{
var arrayFieldsToDisplay = [];
if (data.hasOwnProperty('selectedFields') && $.isArray(data.selectedFields))
{
if (data.hasOwnProperty('columnsAliases') && $.isArray(data.columnsAliases))
{
for (var i = 0; i < data.selectedFields.length; i++)
{
for (var j = 0; j < data.fields.length; j++)
{
if (data.selectedFields[i] == data.fields[j])
{
arrayFieldsToDisplay[i] = data.columnsAliases[j];
}
}
}
}
else
{
arrayFieldsToDisplay = data.selectedFields;
}
}
for (var i = 0; i < arrayFieldsToDisplay.length; i++)
{
var fieldToDisplay = arrayFieldsToDisplay[i];
var fieldName = data.selectedFields[i];
var strHtml = '<span id="dnd' + fieldName + '" class="filter-select-field-dnd-span">';
strHtml += ' <span>' + fieldToDisplay + '</span>';
strHtml += ' <span>';
strHtml += ' <a class="remove-field" fieldToRemove="' + fieldName + '"> X </a>';
strHtml += ' </span>';
strHtml += '</span>';
$("#filterSelectFieldsDnd").append(strHtml);
}
FHC_FilterWidget._drangAndDropEvents();
$(".remove-field").click(function(event) {
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/removeSelectedFields',
{
fieldName: $(this).attr('fieldToRemove'),
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFields();
FHC_FilterWidget.renderSelectedFields();
FHC_FilterWidget.renderTableDataset();
}
}
);
});
}
},
_renderDropDownFields: function(data) {
$("#addField").off('change');
var strDropDown = '<option value="">Select a field to add...</option>';
$("#addField").append(strDropDown);
if (data.fields != null)
{
for (var i = 0; i < data.fields.length; i++)
{
var fieldName = data.fields[i];
var fieldToDisplay = data.fields[i];
if (data.selectedFields.indexOf(fieldName) < 0)
{
if (data.allColumnsAliases != null && $.isArray(data.allColumnsAliases))
{
fieldToDisplay = data.allColumnsAliases[i];
}
strDropDown = '<option value="' + fieldName + '">' + fieldToDisplay + '</option>';
$("#addField").append(strDropDown);
}
}
}
$("#addField").change(function(event) {
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/addSelectedFields',
{
fieldName: $(this).val(),
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFields();
FHC_FilterWidget.renderSelectedFields();
FHC_FilterWidget.renderTableDataset();
}
}
);
});
},
/**
*
*/
_renderAppliedFilters: function(data) {
$("#addFilter").off('change');
var data = FHC_AjaxClient.getData(data);
var strDropDown = '<option value="">Select a filter to add...</option>';
$("#addFilter").append(strDropDown);
if (data.selectedFilters != null)
{
for (var i = 0; i < data.selectedFilters.length; i++)
{
var selectedFilters = '<div>';
selectedFilters += '<span class="filter-options-span">';
selectedFilters += data.selectedFiltersAliases[i];
selectedFilters += '</span>';
selectedFilters += FHC_FilterWidget._getSelectedFilterFields(
data.selectedFiltersMetaData[i],
data.selectedFiltersActiveFilters[i],
data.selectedFiltersActiveFiltersOperation[i],
data.selectedFiltersActiveFiltersOption[i]
);
selectedFilters += '<span>';
selectedFilters += '<input type="button" value="X" class="remove-selected-filter btn btn-default" filterToRemove="' + data.selectedFilters[i] + '">';
selectedFilters += '</span>';
selectedFilters += '</div>';
$("#selectedFilters").append(selectedFilters);
}
}
if (data.allSelectedFields != null)
{
for (var i = 0; i < data.allSelectedFields.length; i++)
{
var fieldName = data.allSelectedFields[i];
var fieldToDisplay = data.allSelectedFields[i];
if (data.selectedFilters.indexOf(fieldName) < 0)
{
if (data.allColumnsAliases != null && $.isArray(data.allColumnsAliases))
{
fieldToDisplay = data.allColumnsAliases[i];
}
strDropDown = '<option value="' + fieldName + '">' + fieldToDisplay + '</option>';
$("#addFilter").append(strDropDown);
}
}
}
$(".select-filter-operation").change(function() {
if ($(this).val() == "set" || $(this).val() == "nset")
{
$(this).parent().parent().find(".select-filter-operation-value").addClass("hidden-control");
$(this).parent().parent().find(".select-filter-option").addClass("hidden-control");
$(this).parent().parent().find(".select-filter-operation-value").prop('disabled', true);
$(this).parent().parent().find(".select-filter-option").prop('disabled', true);
}
else
{
$(this).parent().parent().find(".select-filter-operation-value").removeClass("hidden-control");
$(this).parent().parent().find(".select-filter-option").removeClass("hidden-control");
$(this).parent().parent().find(".select-filter-operation-value").prop('disabled', false);
$(this).parent().parent().find(".select-filter-option").prop('disabled', false);
}
});
$("#applyFilter").click(function() {
var selectFilterName = [];
var selectFilterOperation = [];
var selectFilterOperationValue = [];
var selectFilterOption = [];
$("#selectedFilters > div").each(function(i, e) {
var tmpSelectFilterName = $(this).find('.hidden-field-name').val();
var tmpSelectFilterOperation = $(this).find('.select-filter-operation').val();
var tmpSelectFilterOperationValue = $(this).find('.select-filter-operation-value:enabled').val();
var tmpSelectFilterOption = $(this).find('.select-filter-option:enabled').val();
selectFilterName.push(tmpSelectFilterName);
selectFilterOperation.push(tmpSelectFilterOperation);
selectFilterOperationValue.push(tmpSelectFilterOperationValue != null ? tmpSelectFilterOperationValue : "");
selectFilterOption.push(tmpSelectFilterOption != null ? tmpSelectFilterOption : "");
});
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/applyFilter',
{
filterNames: selectFilterName,
filterOperations: selectFilterOperation,
filterOperationValues: selectFilterOperationValue,
filterOptions: selectFilterOption,
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFilters();
location.reload();
}
}
);
});
$(".remove-selected-filter").click(function(event) {
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/removeSelectedFilters',
{
fieldName: $(this).attr('filterToRemove'),
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFilters();
location.reload();
}
}
);
});
},
/**
*
@@ -115,66 +378,16 @@ var FHC_FilterWidget = {
renderSelectedFilters: function() {
//
FHC_AjaxClient.ajaxCallGet(
'system/Filters/selectFilters',
'system/Filters/getFilters',
{
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetEventsSFilters();
if (data != null)
if (FHC_AjaxClient.hasData(data))
{
var strDropDown = '<option value="">Select a filter to add...</option>';
$("#addFilter").append(strDropDown);
if (data.selectedFilters != null)
{
for (var i = 0; i < data.selectedFilters.length; i++)
{
var selectedFilters = '<div>';
selectedFilters += '<span class="filter-options-span">';
selectedFilters += data.selectedFiltersAliases[i];
selectedFilters += '</span>';
selectedFilters += FHC_FilterWidget._getSelectedFilterFields(
data.selectedFiltersMetaData[i],
data.selectedFiltersActiveFilters[i],
data.selectedFiltersActiveFiltersOperation[i],
data.selectedFiltersActiveFiltersOption[i]
);
selectedFilters += '<span>';
selectedFilters += '<input type="button" value="X" class="remove-selected-filter btn btn-default" filterToRemove="' + data.selectedFilters[i] + '">';
selectedFilters += '</span>';
selectedFilters += '</div>';
$("#selectedFilters").append(selectedFilters);
}
}
if (data.allSelectedFields != null)
{
for (var i = 0; i < data.allSelectedFields.length; i++)
{
var fieldName = data.allSelectedFields[i];
var fieldToDisplay = data.allSelectedFields[i];
if (data.selectedFilters.indexOf(fieldName) < 0)
{
if (data.allColumnsAliases != null && $.isArray(data.allColumnsAliases))
{
fieldToDisplay = data.allColumnsAliases[i];
}
strDropDown = '<option value="' + fieldName + '">' + fieldToDisplay + '</option>';
$("#addFilter").append(strDropDown);
}
}
}
}
FHC_FilterWidget._addEventsSFilters();
@@ -309,7 +522,7 @@ var FHC_FilterWidget = {
/**
*
*/
_dndSF: function() {
_drangAndDropEvents: function() {
$(".filter-select-field-dnd-span").draggable({
containment: "parent",
cursor: "move",
@@ -401,57 +614,6 @@ var FHC_FilterWidget = {
});
},
/**
*
*/
_resetEventsSF: function() {
$("#addField").off('change');
$(".remove-field").off('click');
},
/**
*
*/
_addEventsSF: function() {
$("#addField").change(function(event) {
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/addSelectedFields',
{
fieldName: $(this).val(),
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFields();
FHC_FilterWidget.renderSelectedFields();
FHC_FilterWidget.renderTableDataset();
}
}
);
});
$(".remove-field").click(function(event) {
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/removeSelectedFields',
{
fieldName: $(this).attr('fieldToRemove'),
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFields();
FHC_FilterWidget.renderSelectedFields();
FHC_FilterWidget.renderTableDataset();
}
}
);
});
},
/**
*
*/
@@ -460,13 +622,6 @@ var FHC_FilterWidget = {
$("#addField").html("");
},
/**
*
*/
_resetEventsSFilters: function() {
$("#addFilter").off('change');
},
/**
*
*/
@@ -490,83 +645,7 @@ var FHC_FilterWidget = {
);
});
$(".select-filter-operation").change(function() {
if ($(this).val() == "set" || $(this).val() == "nset")
{
$(this).parent().parent().find(".select-filter-operation-value").addClass("hidden-control");
$(this).parent().parent().find(".select-filter-option").addClass("hidden-control");
$(this).parent().parent().find(".select-filter-operation-value").prop('disabled', true);
$(this).parent().parent().find(".select-filter-option").prop('disabled', true);
}
else
{
$(this).parent().parent().find(".select-filter-operation-value").removeClass("hidden-control");
$(this).parent().parent().find(".select-filter-option").removeClass("hidden-control");
$(this).parent().parent().find(".select-filter-operation-value").prop('disabled', false);
$(this).parent().parent().find(".select-filter-option").prop('disabled', false);
}
});
$("#applyFilter").click(function() {
var selectFilterName = [];
var selectFilterOperation = [];
var selectFilterOperationValue = [];
var selectFilterOption = [];
$("#selectedFilters > div").each(function(i, e) {
var tmpSelectFilterName = $(this).find('.hidden-field-name').val();
var tmpSelectFilterOperation = $(this).find('.select-filter-operation').val();
var tmpSelectFilterOperationValue = $(this).find('.select-filter-operation-value:enabled').val();
var tmpSelectFilterOption = $(this).find('.select-filter-option:enabled').val();
selectFilterName.push(tmpSelectFilterName);
selectFilterOperation.push(tmpSelectFilterOperation);
selectFilterOperationValue.push(tmpSelectFilterOperationValue != null ? tmpSelectFilterOperationValue : "");
selectFilterOption.push(tmpSelectFilterOption != null ? tmpSelectFilterOption : "");
});
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/applyFilter',
{
filterNames: selectFilterName,
filterOperations: selectFilterOperation,
filterOperationValues: selectFilterOperationValue,
filterOptions: selectFilterOption,
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFilters();
location.reload();
}
}
);
});
$(".remove-selected-filter").click(function(event) {
//
FHC_AjaxClient.ajaxCallPost(
'system/Filters/removeSelectedFilters',
{
fieldName: $(this).attr('filterToRemove'),
filter_page: FHC_FilterWidget._getFilterPage()
},
{
successCallback: function(data, textStatus, jqXHR) {
FHC_FilterWidget._resetSelectedFilters();
location.reload();
}
}
);
});
},
@@ -743,8 +822,11 @@ $(document).ready(function() {
}
});
FHC_FilterWidget.renderSelectedFields();
FHC_FilterWidget.renderSelectedFilters();
FHC_FilterWidget.renderTableDataset();
// FHC_FilterWidget.setFilterName();
// FHC_FilterWidget.renderSelectedFields();
// FHC_FilterWidget.renderSelectedFilters();
// FHC_FilterWidget.renderTableDataset();
FHC_FilterWidget.display();
});