mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
FilterWidget + Tabulator final version
This commit is contained in:
@@ -22,6 +22,7 @@ class FiltersLib
|
||||
const SESSION_RELOAD_DATASET = 'reloadDataset';
|
||||
const SESSION_DATASET_REPRESENTATION = 'datasetRepresentation';
|
||||
const SESSION_DATASET_REP_OPTIONS = 'datasetRepresentationOptions';
|
||||
const SESSION_DATASET_REP_FIELDS_DEFS = 'datasetRepresentationFieldsDefinitions';
|
||||
|
||||
// Alias for the dynamic table used to retrieve the dataset
|
||||
const DATASET_TABLE_ALIAS = 'datasetFilterTable';
|
||||
@@ -61,6 +62,7 @@ class FiltersLib
|
||||
// ...to specify how to represent the dataset (ex: tablesorter, pivotUI, ...)
|
||||
const DATASET_REPRESENTATION = 'datasetRepresentation';
|
||||
const DATASET_REP_OPTIONS = 'datasetRepOptions';
|
||||
const DATASET_REP_FIELDS_DEFS = 'datasetRepFieldsDefs';
|
||||
|
||||
// Different dataset representations
|
||||
const DATASET_REP_TABLESORTER = 'tablesorter';
|
||||
|
||||
@@ -49,6 +49,8 @@ class FilterWidget extends Widget
|
||||
|
||||
private $_datasetRepresentation; // dataset representation (ex: tablesorter, pivotUI, ...)
|
||||
private $_datasetRepresentationOptions; // dataset representation options for tablesorter, pivotUI, ...
|
||||
private $_datasetRepFieldsDefs; // dataset representation attributes for each record field
|
||||
|
||||
private $_reloadDataset; // Force Reload of Dataset
|
||||
|
||||
private static $_FilterWidgetInstance; // static property that contains the instance of itself
|
||||
@@ -175,6 +177,7 @@ class FilterWidget extends Widget
|
||||
$this->_customMenu = null;
|
||||
$this->_datasetRepresentation = null;
|
||||
$this->_datasetRepresentationOptions = null;
|
||||
$this->_datasetRepFieldsDefs = null;
|
||||
|
||||
// Retrieved the required permissions parameter if present
|
||||
if (isset($args[FiltersLib::REQUIRED_PERMISSIONS_PARAMETER]))
|
||||
@@ -281,6 +284,12 @@ class FilterWidget extends Widget
|
||||
{
|
||||
$this->_datasetRepresentationOptions = $args[FiltersLib::DATASET_REP_OPTIONS];
|
||||
}
|
||||
|
||||
// To specify how to represent each record field
|
||||
if (isset($args[FiltersLib::DATASET_REP_FIELDS_DEFS]) && !isEmptyString($args[FiltersLib::DATASET_REP_FIELDS_DEFS]))
|
||||
{
|
||||
$this->_datasetRepFieldsDefs = $args[FiltersLib::DATASET_REP_FIELDS_DEFS];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,7 +443,8 @@ class FilterWidget extends Widget
|
||||
FiltersLib::SESSION_DATASET => $dataset->retval, // the entire dataset
|
||||
FiltersLib::SESSION_RELOAD_DATASET => false, // if the dataset must be reloaded, not needed the first time
|
||||
FiltersLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation
|
||||
FiltersLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions // the choosen dataset representation options
|
||||
FiltersLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, // the choosen dataset representation options
|
||||
FiltersLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs // the choosen dataset representation record fields definition
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
+47
-10
@@ -833,7 +833,7 @@ var FHC_FilterWidget = {
|
||||
*/
|
||||
_renderDatasetTablesorter: function(data) {
|
||||
|
||||
if (data.hasOwnProperty("checkboxes") && data.checkboxes!=null && data.checkboxes.trim() != "")
|
||||
if (data.hasOwnProperty("checkboxes") && data.checkboxes != null && data.checkboxes.trim() != "")
|
||||
{
|
||||
$("#filterTableDataset > thead > tr").append("<th data-filter='false' title='Select'>Select</th>");
|
||||
}
|
||||
@@ -1055,18 +1055,20 @@ var FHC_FilterWidget = {
|
||||
|
||||
// Checks if options were given and returns them
|
||||
var options = FHC_FilterWidget._getRepresentationOptions(data);
|
||||
// Checks if record fields definitions were given and returns them
|
||||
var recordFieldsDefinitions = FHC_FilterWidget._getRepresentationFieldsDefinitions(data);
|
||||
|
||||
// Manipulation for the representation!
|
||||
var arrayFieldsToDisplay = FHC_FilterWidget._getFieldsToDisplayTabulator(data);
|
||||
var arrayTabulatorColumns = FHC_FilterWidget._getTabulatorColumns(data, recordFieldsDefinitions);
|
||||
|
||||
if (arrayFieldsToDisplay.length > 0)
|
||||
if (arrayTabulatorColumns.length > 0)
|
||||
{
|
||||
// ...if there are data to be displayed...
|
||||
if (data.hasOwnProperty("dataset") && $.isArray(data.dataset))
|
||||
{
|
||||
if (options == null) options = {};
|
||||
|
||||
options.columns = arrayFieldsToDisplay;
|
||||
options.columns = arrayTabulatorColumns;
|
||||
options.data = data.dataset;
|
||||
|
||||
// Renders the tabulator
|
||||
@@ -1109,7 +1111,7 @@ var FHC_FilterWidget = {
|
||||
/**
|
||||
* Retrives the fields to be displayed from the data parameter, if aliases are present then they are used
|
||||
*/
|
||||
_getFieldsToDisplayTabulator: function(data) {
|
||||
_getTabulatorColumns: function(data, recordFieldsDefinitions) {
|
||||
|
||||
var fieldsToDisplayTabulator = [];
|
||||
|
||||
@@ -1124,17 +1126,24 @@ var FHC_FilterWidget = {
|
||||
// Build the array of objects (columns) used by tabulator and store it in tabulatorColumns
|
||||
var tmpColumnObj = {}; // New object that represents a column
|
||||
|
||||
// If was given a definition for this field then use it!
|
||||
if (recordFieldsDefinitions.hasOwnProperty(data.selectedFields[sfc]))
|
||||
{
|
||||
tmpColumnObj = recordFieldsDefinitions[data.selectedFields[sfc]];
|
||||
}
|
||||
|
||||
tmpColumnObj.field = data.selectedFields[sfc]; // Field name to be linked with dataset field name
|
||||
|
||||
// If there is an alias for this field use it to give a title to this field (header)
|
||||
if (data.hasOwnProperty("columnsAliases") && $.isArray(data.columnsAliases))
|
||||
{
|
||||
tmpColumnObj.title = data.columnsAliases[fc];
|
||||
}
|
||||
else
|
||||
else // otherwise use the field name itself
|
||||
{
|
||||
tmpColumnObj.title = data.selectedFields[sfc];
|
||||
}
|
||||
|
||||
tmpColumnObj.field = data.selectedFields[sfc];
|
||||
|
||||
fieldsToDisplayTabulator.push(tmpColumnObj); // Add tmpColumnObj to tabulatorColumns
|
||||
}
|
||||
}
|
||||
@@ -1149,8 +1158,14 @@ var FHC_FilterWidget = {
|
||||
|
||||
var tmpColumnObj = {}; // New object that represents a column
|
||||
|
||||
tmpColumnObj.title = additionalColumn;
|
||||
tmpColumnObj.field = additionalColumn;
|
||||
// If was given a definition for this field then use it!
|
||||
if (recordFieldsDefinitions.hasOwnProperty(additionalColumn))
|
||||
{
|
||||
tmpColumnObj = recordFieldsDefinitions[additionalColumn];
|
||||
}
|
||||
|
||||
tmpColumnObj.title = additionalColumn; // Give a title to this field (header)
|
||||
tmpColumnObj.field = additionalColumn; // Field name to be linked with dataset field name
|
||||
|
||||
fieldsToDisplayTabulator.push(tmpColumnObj); // Add tmpColumnObj to tabulatorColumns
|
||||
});
|
||||
@@ -1181,6 +1196,28 @@ var FHC_FilterWidget = {
|
||||
return options;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets record fields definitions to represent the dataset
|
||||
*/
|
||||
_getRepresentationFieldsDefinitions: function(data) {
|
||||
|
||||
var fieldsDefinitions = {}; // eventually contains record fields definitions
|
||||
|
||||
// Checks if record fields definitions was given as parameter
|
||||
if (data.hasOwnProperty("datasetRepresentationFieldsDefinitions") && data.datasetRepresentationFieldsDefinitions != "")
|
||||
{
|
||||
var tmpFDefs = eval("(" + data.datasetRepresentationFieldsDefinitions + ")"); // and converts them from string to javascript code
|
||||
|
||||
// If it is an object then can be used
|
||||
if (typeof tmpFDefs == "object")
|
||||
{
|
||||
fieldsDefinitions = tmpFDefs;
|
||||
}
|
||||
}
|
||||
|
||||
return fieldsDefinitions;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set what type of dataset representation was choosen
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user