Created
March 17, 2014 15:45
-
-
Save ermand/9601760 to your computer and use it in GitHub Desktop.
This macro creates a simple table with edit, view and delete actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTML::macro('table', function($fields = array(), $table_fields = array(), $data = array(), $resource, $status = true, $showEdit = true, $showDelete = true, $showView = true) | |
{ | |
$table = '<table id="sample-table-2" class="table table-striped table-bordered table-hover well datatables">'; | |
$table .='<thead>'; | |
$table .='<tr>'; | |
foreach ($table_fields as $table_field) | |
{ | |
$table .= '<th>' . Str::title($table_field) . '</th>'; | |
} | |
if ( $status ) | |
{ | |
$table .= '<th class="hidden-480">Status</th>'; | |
} | |
if ($showEdit || $showDelete || $showView ) | |
{ | |
$table .= '<th></th>'; | |
} | |
$table .= '</tr>'; | |
$table .='</thead>'; | |
foreach ( $data as $d ) | |
{ | |
$table .= '<tr>'; | |
foreach($fields as $key) { | |
$table .= '<td>' . $d->$key . '</td>'; | |
} | |
if ( $status ) | |
{ | |
$table .= '<td class="hidden-480 center">'; | |
$table .= '<span class="label label-' . Status::getColor($d->status_id) . ' bigger-110">' . $d->status->status . '</span>'; | |
$table .= '</td>'; | |
} | |
if ($showEdit || $showDelete || $showView ) | |
{ | |
$table .= '<td class="td-actions center">'; | |
$table .= '<div class="hidden-phone visible-desktop action-buttons bigger-110">'; | |
if ($showEdit) | |
{ | |
$table .= '<a class="green" href="' . $resource . '/' . $d->id . '/edit" data-toggle="tooltip" data-original-title="Fshi"> <i class="icon-pencil bigger-130"></i> </a>'; | |
} | |
if ($showView) | |
{ | |
$table .= ' '; | |
$table .= '<a class="blue" href="' . $resource . '/' . $d->id . '" data-toggle="tooltip" data-original-title="Detaje"> <i class="icon-eye-open bigger-130"></i> </a>'; | |
} | |
if ($showDelete) | |
{ | |
if( Status::checkActive($d->status_id) ) | |
{ | |
$table .= ' '; | |
$table .= '<a class="red" href="' . $resource . '/' . $d->id . '/deactivate" data-toggle="tooltip" data-original-title="Caktivizo"> <i class="icon-remove bigger-130"></i> </a>'; | |
} elseif ( Status::checkDeactive($d->status_id) ) | |
{ | |
$table .= ' '; | |
$table .= '<a class="green" href="' . $resource . '/' . $d->id . '/activate" data-toggle="tooltip" data-original-title="Aktivizo"> <i class="icon-ok bigger-130"></i> </a>'; | |
} | |
} | |
$table .= '</div>'; | |
$table .= '</td>'; | |
} | |
$table .= '</tr>'; | |
} | |
$table .= '</table>'; | |
return $table; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment