function theme_webform_edit_file in Webform 6.2
Same name and namespace in other branches
- 5.2 components/file.inc \theme_webform_edit_file()
- 5 components/file.inc \theme_webform_edit_file()
File
- components/
file.inc, line 175 - Webform module file component.
Code
function theme_webform_edit_file($form) {
// Add a little javascript to check all the items in one type.
$javascript = '
<script type="text/javascript">
function check_category_boxes () {
var checkValue = !document.getElementById("edit-extra-filtering-types-"+arguments[0]+"-"+arguments[1]).checked;
for(var i=1; i < arguments.length; i++) {
document.getElementById("edit-extra-filtering-types-"+arguments[0]+"-"+arguments[i]).checked = checkValue;
}
}
</script>
';
drupal_set_html_head($javascript);
// Format the components into a table.
$per_row = 5;
$rows = array();
foreach (element_children($form['extra']['filtering']['types']) as $key => $filtergroup) {
$row = array();
$first_row = count($rows);
if ($form['extra']['filtering']['types'][$filtergroup]['#type'] == 'checkboxes') {
// Add the title.
$row[] = $form['extra']['filtering']['types'][$filtergroup]['#title'];
$row[] = ' ';
// Convert the checkboxes into individual form-items.
$checkboxes = expand_checkboxes($form['extra']['filtering']['types'][$filtergroup]);
// Render the checkboxes in two rows.
$checkcount = 0;
$jsboxes = '';
foreach (element_children($checkboxes) as $key) {
$checkbox = $checkboxes[$key];
if ($checkbox['#type'] == 'checkbox') {
$checkcount++;
$jsboxes .= "'" . $checkbox['#return_value'] . "',";
if ($checkcount <= $per_row) {
$row[] = array(
'data' => drupal_render($checkbox),
);
}
elseif ($checkcount == $per_row + 1) {
$rows[] = array(
'data' => $row,
'style' => 'border-bottom: none;',
);
$row = array(
array(
'data' => ' ',
),
array(
'data' => ' ',
),
);
$row[] = array(
'data' => drupal_render($checkbox),
);
}
else {
$row[] = array(
'data' => drupal_render($checkbox),
);
}
}
}
// Pretty up the table a little bit.
$current_cell = $checkcount % $per_row;
if ($current_cell > 0) {
$colspan = $per_row - $current_cell + 1;
$row[$current_cell + 1]['colspan'] = $colspan;
}
// Add the javascript links.
$jsboxes = drupal_substr($jsboxes, 0, drupal_strlen($jsboxes) - 1);
$rows[] = array(
'data' => $row,
);
$select_link = ' <a href="javascript:check_category_boxes(\'' . $filtergroup . '\',' . $jsboxes . ')">(select)</a>';
$rows[$first_row]['data'][1] = array(
'data' => $select_link,
'width' => 40,
);
unset($form['extra']['filtering']['types'][$filtergroup]);
}
elseif ($filtergroup != 'size') {
// Add other fields to the table (ie. additional extensions).
$row[] = $form['extra']['filtering']['types'][$filtergroup]['#title'];
unset($form['extra']['filtering']['types'][$filtergroup]['#title']);
$row[] = array(
'data' => drupal_render($form['extra']['filtering']['types'][$filtergroup]),
'colspan' => $per_row + 1,
);
unset($form['extra']['filtering']['types'][$filtergroup]);
$rows[] = array(
'data' => $row,
);
}
}
$header = array(
array(
'data' => t('Category'),
'colspan' => '2',
),
array(
'data' => t('Types'),
'colspan' => $per_row,
),
);
// Create the table inside the form.
$form['extra']['filtering']['types']['table'] = array(
'#value' => theme('table', $header, $rows),
);
$output = drupal_render($form);
// Prefix the upload location field with the default path for webform.
$output = str_replace('Upload Directory: </label>', 'Upload Directory: </label>' . file_directory_path() . '/webform/', $output);
return $output;
}