[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [15732] controller: custom filter on status component
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [15732] controller: custom filter on status components |
Date: |
Sun, 25 Sep 2016 20:08:57 +0000 (UTC) |
Revision: 15732
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15732
Author: sigurdne
Date: 2016-09-25 20:08:56 +0000 (Sun, 25 Sep 2016)
Log Message:
-----------
controller: custom filter on status components
Modified Paths:
--------------
trunk/controller/inc/class.uicomponent.inc.php
trunk/controller/templates/base/component.xsl
Modified: trunk/controller/inc/class.uicomponent.inc.php
===================================================================
--- trunk/controller/inc/class.uicomponent.inc.php 2016-09-25 16:48:21 UTC
(rev 15731)
+++ trunk/controller/inc/class.uicomponent.inc.php 2016-09-25 20:08:56 UTC
(rev 15732)
@@ -57,6 +57,7 @@
private $edit;
private $delete;
private $org_units;
+ private $custom;
public $public_functions = array
(
'index' => true,
@@ -85,6 +86,8 @@
{
$GLOBALS['phpgw_info']['flags']['noframework']
= true;
}
+ $this->custom = createObject('phpgwapi.custom_fields');
+
}
public function add_controll_from_master()
@@ -465,6 +468,88 @@
}
}
+ private function _get_location_filter_options( $location_id )
+ {
+ $attrib_data = $this->_get_attrib_data( $location_id );
+
+ $combos = array();
+ $values_combo_box = array();
+
+ if ($attrib_data)
+ {
+ $count = 0;
+ foreach ($attrib_data as $attrib)
+ {
+ if (($attrib['datatype'] == 'LB' ||
$attrib['datatype'] == 'CH' || $attrib['datatype'] == 'R') && $attrib['choice'])
+ {
+ $values_combo_box[$count][] =
array(
+ 'id' => '',
+ 'name' =>
lang('select') . " '{$attrib['input_text']}'"
+ );
+
+ foreach ($attrib['choice'] as
$choice)
+ {
+
$values_combo_box[$count][] = array(
+ 'id' =>
$choice['id'],
+ 'name' =>
htmlspecialchars($choice['value'], ENT_QUOTES, 'UTF-8'),
+ );
+ }
+
+ $combos[] = array(
+ 'type' => 'filter',
+ 'name' =>
$attrib['column_name'],
+ 'list' =>
$values_combo_box[$count]
+ );
+
+ $count++;
+ }
+ }
+ }
+
+ return $combos;
+
+ }
+
+ private function _get_attrib_data( $location_id )
+ {
+ static $attrib_data = array();
+ if(!isset($attrib_data[$location_id]))
+ {
+ $attrib_data[$location_id] =
$this->custom->find2($location_id, 0, '', '', '', true, true);
+ }
+ return $attrib_data[$location_id];
+ }
+
+ private function _get_attrib_filter( $location_id )
+ {
+ $attrib_data = $this->_get_attrib_data( $location_id );
+
+ $attrib_filter = array();
+ if ($attrib_data)
+ {
+ foreach ($attrib_data as $attrib)
+ {
+ if ($attrib['datatype'] == 'LB' ||
$attrib['datatype'] == 'R')
+ {
+ if ($_attrib_filter_value =
phpgw::get_var("custom_{$location_id}_{$attrib['column_name']}", 'int'))
+ {
+ $attrib_filter[] =
"json_representation->>'{$attrib['column_name']}' = '{$_attrib_filter_value}'";
+ }
+ }
+ else if ($attrib['datatype'] == 'CH')
+ {
+ if ($_attrib_filter_value =
phpgw::get_var("custom_{$location_id}_{$attrib['column_name']}", 'int'))
+ {
+ $attrib_filter[] =
"json_representation->>'{$attrib['column_name']}' {$GLOBALS['phpgw']->db->like}
'%,{$_attrib_filter_value},%'";
+ }
+ }
+ }
+ }
+ return $attrib_filter;
+ }
+
+
+
public function query()
{
$entity_group_id = phpgw::get_var('entity_group_id',
'int');
@@ -573,6 +658,8 @@
$_location_id =
(int)$_location_filter['id'];
$exclude_locations[] = $_location_id;
+ $location_filter_options =
$this->_get_location_filter_options($_location_id);
+
$_components =
execMethod('property.soentity.read', array(
'filter_entity_group' =>
$entity_group_id,
'location_id' => $_location_id,
@@ -581,10 +668,12 @@
'allrows' => true,
'control_registered' =>
!$all_items,
'check_for_control' => true,
- 'filter_item' =>
$filter_component ? array($filter_component) : array()
+ 'filter_item' =>
$filter_component ? array($filter_component) : array(),
+ 'attrib_filter' =>
$this->_get_attrib_filter($_location_id)
)
);
$components = array_merge($components,
$_components);
+
}
if ($lookup_stray_items)
@@ -1021,7 +1110,9 @@
return array(
'components' => $result,
'summary' => null,
- 'location_filter' => $location_filter
+ 'location_filter' => $location_filter,
+ 'location_filter_options' =>
$location_filter_options,
+ 'return_location_id' =>
(int)$_location_id
);
}
Modified: trunk/controller/templates/base/component.xsl
===================================================================
--- trunk/controller/templates/base/component.xsl 2016-09-25 16:48:21 UTC
(rev 15731)
+++ trunk/controller/templates/base/component.xsl 2016-09-25 20:08:56 UTC
(rev 15732)
@@ -199,8 +199,20 @@
</td>
</tr>
</xsl:for-each>
+ <tr id = 'extra_row'>
+ <td>
+ <label for='extra_filter'>
+ Extra
+ </label>
+ </td>
+ <td>
+ <div id="extra_filter">
+ </div>
+ </td>
+ </tr>
</tbody>
</table>
+ <input type ='hidden' id='filtered_location_id'/>
</div>
</xsl:template>
@@ -414,6 +426,55 @@
}
+
+ var filter_options =
data.location_filter_options;
+ var return_location_id =
data.return_location_id;
+ var filtered_location_id =
$("#filtered_location_id").val();
+ var location_id =
$("#location_id").val();
+ if(filter_options == null)
+ {
+ $("#extra_row").hide();
+
+ }
+ if(filter_options !==null &&
filtered_location_id != return_location_id)
+ {
+
$("#filtered_location_id").val(location_id);
+ $("#extra_row").show();
+
$("#extra_filter").html('');
+ var $extra_filter =
$("#extra_filter");
+ $.each(filter_options,
function(key, filter) {
+ var list =
filter.list;
+
$extra_filter.append($("<select></select>").attr("id", location_id + '_' +
filter.name).text(location_id + '_' + filter.name));
+
+ var
custom_select = $("#" + location_id + '_' + filter.name);
+
+ $.each(list,
function(key, value) {
+
custom_select.append($("<option></option>").attr("value",
value.id).text(value.name));
+ });
+
+
$(document).on("change", "#" + location_id + '_' + filter.name , function() {
+
+ var
custom_input = document.getElementById("custom_" + location_id + '_' +
filter.name);
+
+
if(custom_input != null)
+ {
+
$("#custom_" + location_id + '_' + filter.name).val($(this).val());
+ }
+ else
+ {
+
$('<input />').attr('type', 'hidden')
+
.attr('id', 'custom_' + location_id + '_' + filter.name)
+
.attr('name', 'custom_' + location_id + '_' + filter.name)
+
.attr('value', $(this).val())
+
.appendTo('#queryForm');
+ }
+
update_table();
+
+ });
+
+ });
+ }
+
if(components_data !==null)
{
$("#tbody").html(components_data.tbody);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [15732] controller: custom filter on status components,
sigurdne <=