Commit 0459e781 authored by metzlerd's avatar metzlerd
Browse files

Added more form control support.

parent d8b2ad79
......@@ -277,7 +277,7 @@ class FrxEditor {
$this->setFrxHeader('parameters', 'parm',
$parmElements,
array('id', 'label', 'require', 'desc', 'data_source', 'data_field', 'type', 'class'),
array('id', 'label', 'require', 'desc', 'data_source', 'data_field', 'type', 'class', 'options'),
'value');
}
......
......@@ -2162,6 +2162,7 @@ function forena_admin_params_form($formid, $form_state, $report_name) {
$class = (string)$attrs['class'];
$desc = (string)$attrs['desc'];
$type = (string)$attrs['type'];
$options = (string)$attrs['options'];
//make a subtree for each param
$form['params'][$id] = array(
......@@ -2222,23 +2223,38 @@ function forena_admin_params_form($formid, $form_state, $report_name) {
'#default_value' => $data_field,
'#description' => t('Column in data block to be used for ID'),
);
$control_types= array('textfield' => 'Text',
'hidden' => 'Hidden',
'radios' => 'Radios',
'checkbox' => 'Checkbox',
'checkboxes' => 'Checkboxes',
'select' => 'Select',
'selectajax' => 'Select with Refresh',
'multiselect' => 'Multi-Select',
'multiselectajax' => 'Multi-select With Refresh',
);
$form['params'][$id]['type'] = array(
if (module_exists('date_api')) {
$control_types['date_select'] = 'Date Select';
}
if (module_exists('date_popup')) {
$control_types['date_popup'] = 'Date Popup';
}
$form['params'][$id]['type'] = array(
'#type' => 'select',
'#title' => t('Input Control Type'),
'#default_value' => $type,
'#options' => array
('textfield' => 'Text',
'hidden' => 'Hidden',
'radios' => 'Radios',
'select' => 'Select',
'selectajax' => 'Select with Refresh',
'multiselect' => 'Multi-Select',
'checkboxes' => 'Checkboxes'
),
'#options' => $control_types,
'#description' => t('Enter a helpful description about this parameter. This will display on the form when the user is prompted to enter a parameter.'),
);
$form['params'][$id]['options'] = array(
'#type' => 'textfield',
'#title' => t('Options'),
'#default_value' => $options,
'#description' => t('Used to configure the control type above options depend on the control type above.')
);
$form['params'][$id]['class'] = array(
'#type' => 'textfield',
'#title' => t('Class'),
......
......@@ -494,15 +494,20 @@ function forena_parameter_form($formid, &$form_state, $parameters, $attributes=
);
foreach ($parameters as $node) {
$list='';
$disabled = FALSE;
$label = @(string)$node['label'];
$id = @(string)$node['id'];
$data_source = @(string)$node['data_source'];
$data_field = @(string)$node['data_field'];
$class = @(string)$node['class'];
$type = @(string)$node['type'];
$option_str = @(string)$node['options'];
$options = array();
if ($option_str) {
parse_str($option_str, $options);
}
if (isset($parms[$id])) {
$value = $parms[$id];
$multi_value=(array)$parms[$id];
......@@ -516,6 +521,7 @@ function forena_parameter_form($formid, &$form_state, $parameters, $attributes=
$label_field = @(string)$node['label_field'];
@(strcmp((string)$node['require'], "1") == 0) ? $required = TRUE : $required = FALSE;
$ctl_attrs = array();
//Determine the form element type to be displayed
//If select or radios is chosen then begin a $list array for display values.
......@@ -546,6 +552,22 @@ function forena_parameter_form($formid, &$form_state, $parameters, $attributes=
case 'select':
$add_null = TRUE;
break;
case 'date_select':
case 'date_popup':
if (@$options['date_format']) {
$ctl_attrs['#date_format'] = $options['date_format'];
}
if (@$options['date_year_range']) {
$ctl_attrs['#date_year_range'] = $options['date_year_range'];
}
$list='';
break;
case 'checkbox':
if (@$option_str['return_value']) {
$ctl_attrs['#return_value'] = $options['return_value'];
}
$list='';
break;
case 'radios':
break;
case 'hidden':
......@@ -556,16 +578,16 @@ function forena_parameter_form($formid, &$form_state, $parameters, $attributes=
$list = '';
}
if (isset($menu_parms[$id]) && $type=='textfield') {
$disabled = TRUE;
}
//If a data_source attr was found then create an array of
//returned values filtered against data_field attr.
if ($data_source) {
$list = Frx::RepoMan()->dataBlockParams($data_source, $data_field, $label_field);
if (!$required && $add_null) $list = array('' => '') + $list;
}
if (isset($menu_parms[$id]) && $type=='textfield') {
$disabled = TRUE;
}
//If a data_source attr was found then create an array of
$form['params'][$id] = array(
'#type' => $type,
......@@ -576,6 +598,8 @@ function forena_parameter_form($formid, &$form_state, $parameters, $attributes=
'#description' => t($desc),
);
array_merge($form['params'][$id], $ctl_attrs);
if ($type == 'item') {
$form['params'][$id]['#markup'] = $value;
......@@ -593,16 +617,18 @@ function forena_parameter_form($formid, &$form_state, $parameters, $attributes=
}
//if $list is not empty then push options
//onto the array. options will cause an error for
//textfield elements.
if ($type != 'textfield') {
if ($list) {
$form['params'][$id]['#options'] = $list;
$form['params'][$id]['#multiple'] = $multiselect;
if ($ajax) {
$form['params'][$id]['#ajax'] = array('callback' => 'forena_parameters_callback',
'wrapper' => 'parameters-wrapper');
}
}
if ($ajax) {
$form['params'][$id]['#ajax'] = array('callback' => 'forena_parameters_callback',
'wrapper' => 'parameters-wrapper');
}
}
......
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