Commit cc42337e authored by metzlerd's avatar metzlerd
Browse files

Fixed inline theming to work with Ajax requests. Form now also expands

and collapses properly. 
parent 767e99c8
......@@ -425,38 +425,31 @@ function theme_forena_inline_form($variables) {
$build = '';
$output = '';
$fields = array();
$template = @$form['#forena_form_template'];
// Convert interior elements into inline fields
_forena_set_inline_theme($form);
// Render the inline fields and store them into the array.
_forena_render_inline_elements($form, $fields);
// Render the child form in the template.
if (isset($form['#forena_form_template'])) {
$teng = new FrxSyntaxEngine(FRX_TOKEN_EXP,'{}');
$o = Frx::Data()->push($fields, 'form-fields');
$build = $teng->replace($form['#forena_form_template'], TRUE);
$o = Frx::Data()->pop();
if ($template) {
_forena_set_inline_theme($form, $template);
// Render the inline fields and store them into the array.
$build = _forena_render_inline_elements($form, $fields, $template);
$build .= $fields['form_build_id'] . $fields['form_token'] . $fields['form_id'];
$form['#children'] = $build;
} else {
}
else {
$build = $form['#children'];
}
// Return the for
// Return the form
return $build;
}
function _forena_render_inline_elements(&$elements, &$fields) {
foreach ($elements as $key => $value) if (strpos($key, '#')===FALSE) {
if (@$value['#type'] != 'fieldset') {
$fields[$key] = drupal_render($value);
}
else {
_forena_render_inline_elements($elements[$key], $fields);
}
}
function _forena_render_form_template($fields, $template) {
static $teng = '';
if (!$teng) $teng = new FrxSyntaxEngine(FRX_TOKEN_EXP,'{}');
$o = Frx::Data()->push($fields, 'form-fields');
$build = $teng->replace($template, TRUE);
$o = Frx::Data()->pop();
return $build;
}
function _forena_set_inline_theme(&$elements) {
......@@ -465,15 +458,12 @@ function _forena_set_inline_theme(&$elements) {
// Set theme functions for specific types to be inline forms.
switch ($type) {
case 'fieldset':
case 'submit':
case '':
case NULL:
_forena_set_inline_theme($elements[$key]);
case 'submit':
case '';
break;
default:
$elements[$key]['#theme_wrappers'] = array('forena_inline_form_element');
}
}
......@@ -488,9 +478,6 @@ function theme_forena_inline_form_element($variables) {
// This is also used in the installer, pre-database setup.
$t = get_t();
// drupal_set_message ('<pre>' . print_r($variables,1) . '</pre>');
// This function is invoked as theme wrapper, but the rendered form element
// may not necessarily have been processed by form_builder().
$element += array(
......@@ -547,9 +534,28 @@ function theme_forena_inline_form_element($variables) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
*/
$output .= "</span>\n";
return $output;
}
function theme_forena_fieldset_template(&$variables) {
$element = $variables['fieldset'];
element_set_attributes($element, array('id'));
_form_set_class($element, array('form-wrapper'));
$output = '';
$fields = array();
foreach($element as $key => $value ) if (strpos($key, '#') ===FALSE) {
$fields[$key] = drupal_render($value);
}
$output .= _forena_render_form_template($fields, $element['#forena-template']);
if (isset($element['#value'])) {
$output .= $element['#value'];
}
$output .= "</span>\n";
return $output;
}
......
......@@ -463,12 +463,9 @@ function forena_parameter_form($formid, &$form_state, $parameters, $collapse=FAL
unset($parms['q']);
$form = array();
$menu_parms = Frx::Data()->getContext('menu-parms');
$form['#forena_form_template'] = $template;
if (trim($form['#forena_form_template'])) $form['#theme'] = 'forena_inline_form';
if ($parameters) {
$report_name = '';
drupal_alter('forena_parameters', $report_name, $parms);
if ($parameters) {
$form['params'] = array(
......@@ -481,9 +478,9 @@ function forena_parameter_form($formid, &$form_state, $parameters, $collapse=FAL
'#suffix' => '</div>',
);
foreach ($parameters as $node) {
$disabled = FALSE;
$label = @(string)$node['label'];
$id = @(string)$node['id'];
$data_source = @(string)$node['data_source'];
......@@ -538,8 +535,7 @@ function forena_parameter_form($formid, &$form_state, $parameters, $collapse=FAL
}
if (isset($menu_parms[$id]) && $type=='textfield') {
$type = 'item';
$value = $menu_parms[$id];
$disabled = TRUE;
}
//If a data_source attr was found then create an array of
......@@ -553,6 +549,7 @@ function forena_parameter_form($formid, &$form_state, $parameters, $collapse=FAL
'#type' => $type,
'#title' => ($label) ? t($label) : t($id),
'#default_value' => $value,
'#disabled' => $disabled,
'#required' => $required,
'#description' => t($desc),
);
......@@ -588,10 +585,17 @@ function forena_parameter_form($formid, &$form_state, $parameters, $collapse=FAL
}
if ($template) {
$form['params']['#forena-template'] = $template;
$form['params']['#theme'] = 'forena_fieldset_template';
_forena_set_inline_theme($form['params']);
}
$form['params']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
}
return $form;
}
......@@ -1233,14 +1237,14 @@ function forena_theme() {
'forena_web_report' => array(
'variables' => array('doc_types' => NULL, 'parameters' => NULL, 'content' => NULL),
),
'forena_inline_form' => array(
'render element' => 'form',
'file' => 'forena.common.inc',
),
'forena_inline_form_element' => array(
'render element' => 'element',
'file' => 'forena.common.inc',
),
'forena_fieldset_template' => array(
'render element' => 'fieldset',
'file' => 'forena.common.inc',
),
);
}
......
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