Commit 87729615 authored by jaapjansma's avatar jaapjansma

added size option to add Filter Criteria To Form

parent 278281bf
......@@ -151,11 +151,21 @@ abstract class CRM_Dataprocessor_Form_Output_AbstractUIOutputForm extends CRM_Co
if (!$fieldSpec || !$filterHandler->isExposed()) {
continue;
}
$filterElements[$fieldSpec->alias]['filter'] = $filterHandler->addToFilterForm($this, $filterHandler->getDefaultFilterValues());
$filterElements[$fieldSpec->alias]['filter'] = $filterHandler->addToFilterForm($this, $filterHandler->getDefaultFilterValues(), $this->getCriteriaElementSize());
$filterElements[$fieldSpec->alias]['template'] = $filterHandler->getTemplateFileName();
}
$this->assign('filters', $filterElements);
}
}
}
\ No newline at end of file
/**
* Returns the size of the crireria form element.
* There are two sizes full and compact.
*
* @return string
*/
protected function getCriteriaElementSize() {
return 'full';
}
}
......@@ -102,5 +102,15 @@ class CRM_DataprocessorDashlet_Form_Dashlet extends CRM_DataprocessorSearch_Form
// Don't add exports
}
/**
* Returns the size of the crireria form element.
* There are two sizes full and compact.
*
* @return string
*/
protected function getCriteriaElementSize() {
return 'compact';
}
}
......@@ -330,7 +330,26 @@ abstract class AbstractFilterHandler {
$isFilterSet = TRUE;
}
break;
case 'bw':
if (isset($submittedValues['min']) && $submittedValues['min'] && isset($submittedValues['max']) && $submittedValues['max']) {
$filterParams = [
'op' => 'BETWEEN',
'value' => array($submittedValues['min'], $submittedValues['max']),
];
$this->setFilter($filterParams);
$isFilterSet = TRUE;
}
break;
case 'nbw':
if (isset($submittedValues['min']) && $submittedValues['min'] && isset($submittedValues['max']) && $submittedValues['max']) {
$filterParams = [
'op' => 'NOT BETWEEN',
'value' => array($submittedValues['min'], $submittedValues['max']),
];
$this->setFilter($filterParams);
$isFilterSet = TRUE;
}
break;
}
}
if ($this->isRequired() && !$isFilterSet) {
......@@ -384,10 +403,12 @@ abstract class AbstractFilterHandler {
*
* @param \CRM_Core_Form $form
* @param array $defaultFilterValue
* @param string $size
* Possible values: full or compact
* @return array
* Return variables belonging to this filter.
*/
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue) {
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue, $size='full') {
static $count = 1;
$types = \CRM_Utils_Type::getValidTypes();
$fieldSpec = $this->getFieldSpecification();
......@@ -401,19 +422,33 @@ abstract class AbstractFilterHandler {
$title .= ' <span class="crm-marker">*</span>';
}
$sizeClass = 'huge';
$minWidth = 'min-width: 250px;';
if ($size =='compact') {
$sizeClass = 'medium';
$minWidth = '';
}
if (isset($types[$fieldSpec->type])) {
$type = $types[$fieldSpec->type];
}
if ($fieldSpec->getOptions()) {
$form->addElement('select', "{$alias}_op", E::ts('Operator:'), $operations);
$form->addElement('select', "{$alias}_value", NULL, $fieldSpec->getOptions(), [
'style' => 'min-width:250px',
'class' => 'crm-select2 huge',
$form->add('select', "{$alias}_op", E::ts('Operator:'), $operations, true, [
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => FALSE,
'placeholder' => E::ts('- select -'),
]);
$form->add('select', "{$alias}_value", NULL, $fieldSpec->getOptions(), [
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => TRUE,
'placeholder' => E::ts('- select -'),
]);
if (isset($defaultFilterValue['op'])) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
} else {
$defaults[$alias . '_op'] = key($operations);
}
if (isset($defaultFilterValue['value'])) {
$defaults[$alias.'_value'] = $defaultFilterValue['value'];
......@@ -423,7 +458,7 @@ abstract class AbstractFilterHandler {
switch ($type) {
case \CRM_Utils_Type::T_DATE:
case \CRM_Utils_Type::T_TIMESTAMP:
\CRM_Core_Form_Date::buildDateRange($form, $alias, $count, '_from', '_to', E::ts('From:'), $this->isRequired(), $operations);
\CRM_Core_Form_Date::buildDateRange($form, $alias, $count, '_from', '_to', E::ts('From:'), $this->isRequired(), $operations, 'searchDate', FALSE, ['class' => 'crm-select2 '.$sizeClass]);
if (isset($defaultFilterValue['op'])) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
}
......@@ -450,27 +485,50 @@ abstract class AbstractFilterHandler {
break;
case \CRM_Utils_Type::T_INT:
case \CRM_Utils_Type::T_FLOAT:
$form->add('select', "{$alias}_op", E::ts('Operator:'), $operations, true, [
'onchange' => "return showHideMaxMinVal( '$alias', this.value );",
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => FALSE,
'placeholder' => E::ts('- select -'),
]);
// we need text box for value input
$form->add('text', "{$alias}_value", NULL, ['class' => $sizeClass]);
if (isset($defaultFilterValue['op']) && $defaultFilterValue['op']) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
} else {
$defaults[$alias . '_op'] = key($operations);
}
if (isset($defaultFilterValue['value'])) {
$defaults[$alias.'_value'] = $defaultFilterValue['value'];
}
// and a min value input box
$form->add('text', "{$alias}_min", E::ts('Min'));
$form->add('text', "{$alias}_min", E::ts('Min'), ['class' => 'six']);
// and a max value input box
$form->add('text', "{$alias}_max", E::ts('Max'));
if (isset($defaultFilterValue['min'])) {
$defaults[$alias.'_min'] = $defaultFilterValue['min'];
}
if (isset($defaultFilterValue['max'])) {
$defaults[$alias.'_max'] = $defaultFilterValue['max'];
}
$form->add('text', "{$alias}_max", E::ts('Max'), ['class' => 'six']);
if (isset($defaultFilterValue['min'])) {
$defaults[$alias.'_min'] = $defaultFilterValue['min'];
}
if (isset($defaultFilterValue['max'])) {
$defaults[$alias.'_max'] = $defaultFilterValue['max'];
}
break;
default:
// default type is string
$form->addElement('select', "{$alias}_op", E::ts('Operator:'), $operations,
['onchange' => "return showHideMaxMinVal( '$alias', this.value );"]
);
$form->add('select', "{$alias}_op", E::ts('Operator:'), $operations, true, [
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => FALSE,
'placeholder' => E::ts('- select -'),
]);
// we need text box for value input
$form->add('text', "{$alias}_value", NULL, ['class' => 'huge']);
if (isset($defaultFilterValue['op'])) {
$form->add('text', "{$alias}_value", NULL, ['class' => $sizeClass]);
if (isset($defaultFilterValue['op']) && $defaultFilterValue['op']) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
} else {
$defaults[$alias . '_op'] = key($operations);
}
if (isset($defaultFilterValue['value'])) {
$defaults[$alias.'_value'] = $defaultFilterValue['value'];
......@@ -482,7 +540,7 @@ abstract class AbstractFilterHandler {
$filter['type'] = $fieldSpec->type;
$filter['alias'] = $fieldSpec->alias;
$filter['title'] = $title;
$filter['size'] = $size;
if (count($defaults)) {
$form->setDefaults($defaults);
......@@ -518,6 +576,8 @@ abstract class AbstractFilterHandler {
'>' => E::ts('Is greater than'),
'!=' => E::ts('Is not equal to'),
'null' => E::ts('Is empty'),
'bw' => E::ts('Is between'),
'nbw' => E::ts('Is not between'),
);
break;
}
......
......@@ -117,10 +117,12 @@ class ActivityFilter extends AbstractFieldFilterHandler {
*
* @param \CRM_Core_Form $form
* @param array $defaultFilterValue
* @param string $size
* Possible values: full or compact
* @return array
* Return variables belonging to this filter.
*/
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue) {
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue, $size='full') {
$fieldSpec = $this->getFieldSpecification();
$operations = $this->getOperatorOptions($fieldSpec);
$defaults = array();
......@@ -131,13 +133,27 @@ class ActivityFilter extends AbstractFieldFilterHandler {
$title .= ' <span class="crm-marker">*</span>';
}
$form->addElement('select', "{$alias}_op", E::ts('Operator:'), $operations);
$sizeClass = 'huge';
$minWidth = 'min-width: 250px;';
if ($size =='compact') {
$sizeClass = 'medium';
$minWidth = '';
}
$form->add('select', "{$alias}_op", E::ts('Operator:'), $operations, true, [
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => FALSE,
'placeholder' => E::ts('- select -'),
]);
$props = array(
'placeholder' => E::ts('Select a Contact'),
'entity' => 'Contact',
'create' => false,
'multiple' => true,
'style' => $minWidth,
'class' => $sizeClass,
);
if (!empty($this->configuration['limit_activity_types'])) {
$optionValueApi = civicrm_api3('OptionValue', 'get', array('option_group_id' => "activity_type", 'options' => array('limit' => 0)));
......@@ -168,6 +184,8 @@ class ActivityFilter extends AbstractFieldFilterHandler {
$form->addEntityRef( "{$alias}_value", '', $props);
if (isset($defaultFilterValue['op'])) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
} else {
$defaults[$alias . '_op'] = key($operations);
}
if (isset($defaultFilterValue['value'])) {
$defaults[$alias.'_value'] = $defaultFilterValue['value'];
......@@ -178,6 +196,8 @@ class ActivityFilter extends AbstractFieldFilterHandler {
$filter['type'] = $fieldSpec->type;
$filter['title'] = $title;
$filter['size'] = $size;
$filter['alias'] = $fieldSpec->alias;
return $filter;
}
......@@ -191,4 +211,4 @@ class ActivityFilter extends AbstractFieldFilterHandler {
}
}
\ No newline at end of file
}
......@@ -168,12 +168,14 @@ class CaseRoleFilter extends AbstractFieldFilterHandler {
*
* @param \CRM_Core_Form $form
* @param array $defaultFilterValue
*
* @param string $size
* Possible values: full or compact
* @return array
* Return variables belonging to this filter.
*/
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue) {
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue, $size='full') {
$fieldSpec = $this->getFieldSpecification();
$alias = $fieldSpec->alias;
$operations = $this->getOperatorOptions($fieldSpec);
$title = $fieldSpec->title;
......@@ -181,17 +183,44 @@ class CaseRoleFilter extends AbstractFieldFilterHandler {
$title .= ' <span class="crm-marker">*</span>';
}
$form->addElement('select', "{$fieldSpec->alias}_op", E::ts('Operator:'), $operations);
$sizeClass = 'huge';
$minWidth = 'min-width: 250px;';
if ($size =='compact') {
$sizeClass = 'medium';
$minWidth = '';
}
$form->add('select', "{$fieldSpec->alias}_op", E::ts('Operator:'), $operations, true, [
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => FALSE,
'placeholder' => E::ts('- select -'),
]);
$form->addEntityRef( "{$fieldSpec->alias}_value", NULL, array(
'placeholder' => E::ts('Select a contact'),
'entity' => 'Contact',
'create' => false,
'multiple' => true,
'style' => $minWidth,
'class' => $sizeClass,
));
if (isset($defaultFilterValue['op'])) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
} else {
$defaults[$alias . '_op'] = key($operations);
}
if (isset($defaultFilterValue['value'])) {
$defaults[$alias.'_value'] = $defaultFilterValue['value'];
}
if (count($defaults)) {
$form->setDefaults($defaults);
}
$filter['type'] = $fieldSpec->type;
$filter['alias'] = $fieldSpec->alias;
$filter['title'] = $title;
$filter['size'] = $size;
return $filter;
}
......@@ -204,4 +233,4 @@ class CaseRoleFilter extends AbstractFieldFilterHandler {
}
}
\ No newline at end of file
}
......@@ -115,10 +115,12 @@ class ContactFilter extends AbstractFieldFilterHandler {
*
* @param \CRM_Core_Form $form
* @param array $defaultFilterValue
* @param string $size
* Possible values: full or compact
* @return array
* Return variables belonging to this filter.
*/
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue) {
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue, $size='full') {
$fieldSpec = $this->getFieldSpecification();
$operations = $this->getOperatorOptions($fieldSpec);
$defaults = array();
......@@ -129,13 +131,27 @@ class ContactFilter extends AbstractFieldFilterHandler {
$title .= ' <span class="crm-marker">*</span>';
}
$form->addElement('select', "{$alias}_op", E::ts('Operator:'), $operations);
$sizeClass = 'huge';
$minWidth = 'min-width: 250px;';
if ($size =='compact') {
$sizeClass = 'medium';
$minWidth = '';
}
$form->add('select', "{$alias}_op", E::ts('Operator:'), $operations, true, [
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => FALSE,
'placeholder' => E::ts('- select -'),
]);
$props = array(
'placeholder' => E::ts('Select a contact'),
'entity' => 'Contact',
'create' => false,
'multiple' => true,
'style' => $minWidth,
'class' => $sizeClass,
);
if (!empty($this->configuration['limit_groups'])) {
$props['api'] = ['params' => ['group' => ['IN' => $this->configuration['limit_groups']]]];
......@@ -144,6 +160,8 @@ class ContactFilter extends AbstractFieldFilterHandler {
if (isset($defaultFilterValue['op'])) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
} else {
$defaults[$alias . '_op'] = key($operations);
}
if (isset($defaultFilterValue['value'])) {
$defaults[$alias.'_value'] = $defaultFilterValue['value'];
......@@ -155,6 +173,7 @@ class ContactFilter extends AbstractFieldFilterHandler {
$filter['type'] = $fieldSpec->type;
$filter['title'] = $title;
$filter['alias'] = $fieldSpec->alias;
$filter['size'] = $size;
return $filter;
}
......@@ -168,4 +187,4 @@ class ContactFilter extends AbstractFieldFilterHandler {
}
}
\ No newline at end of file
}
......@@ -155,12 +155,14 @@ class ContactInGroupFilter extends AbstractFieldFilterHandler {
*
* @param \CRM_Core_Form $form
* @param array $defaultFilterValue
*
* @param string $size
* Possible values: full or compact
* @return array
* Return variables belonging to this filter.
*/
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue) {
public function addToFilterForm(\CRM_Core_Form $form, $defaultFilterValue, $size='full') {
$fieldSpec = $this->getFieldSpecification();
$alias = $fieldSpec->alias;
$operations = $this->getOperatorOptions($fieldSpec);
$title = $fieldSpec->title;
......@@ -168,13 +170,25 @@ class ContactInGroupFilter extends AbstractFieldFilterHandler {
$title .= ' <span class="crm-marker">*</span>';
}
$sizeClass = 'huge';
$minWidth = 'min-width: 250px;';
if ($size =='compact') {
$sizeClass = 'medium';
$minWidth = '';
}
$api_params['is_active'] = 1;
if ($this->parent_group_id) {
$childGroupIds = \CRM_Contact_BAO_GroupNesting::getDescendentGroupIds([$this->parent_group_id], FALSE);
$api_params['id']['IN'] = $childGroupIds;
}
$form->addElement('select', "{$fieldSpec->alias}_op", E::ts('Operator:'), $operations);
$form->add('select', "{$fieldSpec->alias}_op", E::ts('Operator:'), $operations, true, [
'style' => $minWidth,
'class' => 'crm-select2 '.$sizeClass,
'multiple' => FALSE,
'placeholder' => E::ts('- select -'),
]);
$form->addEntityRef( "{$fieldSpec->alias}_value", NULL, array(
'placeholder' => E::ts('Select a group'),
'entity' => 'Group',
......@@ -183,9 +197,23 @@ class ContactInGroupFilter extends AbstractFieldFilterHandler {
'multiple' => true,
));
if (isset($defaultFilterValue['op'])) {
$defaults[$alias . '_op'] = $defaultFilterValue['op'];
} else {
$defaults[$alias . '_op'] = key($operations);
}
if (isset($defaultFilterValue['value'])) {
$defaults[$alias.'_value'] = $defaultFilterValue['value'];
}
if (count($defaults)) {
$form->setDefaults($defaults);
}
$filter['type'] = $fieldSpec->type;
$filter['alias'] = $fieldSpec->alias;
$filter['title'] = $title;
$filter['size'] = $size;
return $filter;
}
......@@ -198,4 +226,4 @@ class ContactInGroupFilter extends AbstractFieldFilterHandler {
}
}
\ No newline at end of file
}
......@@ -8,12 +8,13 @@
<span class="crm-absolute-date-range">
<span class="crm-absolute-date-from">
{assign var=fromName value=$fieldName|cat:$from}
{$form.$fromName.label}
{$form.$fromName.label}{if $filter.size == 'compact'}<br />{/if}
{include file="CRM/common/jcalendar.tpl" elementName=$fromName}
</span>
{if $filter.size == 'compact'}<br />{/if}
<span class="crm-absolute-date-to">
{assign var=toName value=$fieldName|cat:$to}
{$form.$toName.label}
{$form.$toName.label}{if $filter.size == 'compact'}<br />{/if}
{include file="CRM/common/jcalendar.tpl" elementName=$toName}
</span>
</span>
......@@ -30,4 +31,4 @@
}).change();
</script>
{/literal}
</td>
\ No newline at end of file
</td>
......@@ -11,11 +11,8 @@
{elseif $form.$fieldOp.html}
<tr>
<td class="label">{$filter.title}</td>
{if (empty($smallCriteriaForm))}<td>{$form.$fieldOp.html}</td>{/if}
<td>{$form.$fieldOp.html}</td>
<td>
{if (!empty($smallCriteriaForm))}
{$form.$fieldOp.html}
{/if}
<span id="{$filterVal}_cell">{$form.$filterVal.label}&nbsp;{$form.$filterVal.html}</span>
<span id="{$filterMin}_max_cell">{$form.$filterMin.label}&nbsp;{$form.$filterMin.html}&nbsp;&nbsp;{$form.$filterMax.label}&nbsp;{$form.$filterMax.html}</span>
</td>
......
......@@ -9,7 +9,7 @@
<table>
<tr>
<th>{ts}Name{/ts}</th>
{if (empty($smallCriteriaForm))}<th>{ts}Operator{/ts}</th>{/if}
<th>{ts}Operator{/ts}</th>
<th>{ts}Value{/ts}</th>
</tr>
{foreach from=$filters key=filterName item=filter}
......
{include file="CRM/DataprocessorSearch/Form/Search.tpl" smallCriteriaForm=true}
{include file="CRM/DataprocessorSearch/Form/Search.tpl"}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment