Function is
Code: Select all
function kogroups_html($table, &$groups, $after = '') {
ob_start(); ?>
<?php
foreach ($groups as $group => $groupinfo) {
$style = (isset($groupinfo['style']) ? $groupinfo['style'] : 'horizontal');
echo "<div id='{$group}-holder' class=\"panel panel-default form-group form-{$style}\">";
if (!empty($groupinfo['name'])) {
echo "<div class='panel-heading'>{$groupinfo[name]}</div>";
}
echo "<div id='{$group}' class=\"panel-body\">";
echo "</div>";
echo "</div>";
}
?>
<script>
$j(function(){
<?php
foreach ($groups as $group => $groupinfo) {
if (isset($groupinfo['position_after'])){
echo "\$j('#{$groupinfo['position_after']}').parents('.form-group').after(\$j('#{$group}-holder'));\n";
} else {
echo "\$j('fieldset').prepend(\$j('#{$group}-holder'));\n";
}
foreach ($groupinfo['fields'] as $groupfield) {
echo "\$j('#{$groupfield}').parents('.form-group').appendTo('#{$group}');\n";
}
}
?>
})
</script>
<?php
$html = ob_get_contents();
ob_end_clean();
return $html;
}
Create a php file, called for example mylib.php inside your hooks folder.
In your __global.php do require('mylib.php');
Now, in your table hooks file, inside your table_dv hook you can do:
Code: Select all
//put the fields you want in a group into an array
$firstgroup_fields = array(
'referencia',
'contador',
'estado_documento',
'totalDocumento'
);
$secondgroup_fields = array(
'fechaDocumento',
'entidad_id',
'serie_id',
'direccionEntidad_id'
);
/*
You have to build an assoc array. First dimension is the id of the group. Second dimension is the params.
In params you can use:
['name'] = Specify the header of the group. If you don't specify, block will not have header named.
['fields'] = array with the fields you want inside this group
['style'] = If not specified block will be form-horizontal. You can use 'inline' here. I'm working on a way to specifiy number of fields. Not yet.
['position_after'] = If provided, your block will be rendred after the field you specify here. If not provided, block will be positioned at start
*/
$groups['firstgroup']['name'] = '';
$groups['firstgroup']['fields'] = $firstgroup_fields;
$groups['firstgroup']['style'] = 'inline';
$groups['secondgroup']['name'] = 'Another group';
$groups['secondgroup']['fields'] = $secondgroup_fields;
$groups['secondgroup']['position_after'] = 'firstgroup';
$groups['otro']['name'] = 'Another one';
$groups['otro']['fields'] = array('comercial_id');
$groups['otro']['position_after'] = 'condicionDePago_id';
// Attach the function to HTML as always, being first param the table, and second the array with group/s
$html .= kogroups_html('cab_fac_s', $groups);