Beispiel #1
0
    $toolbar['create'] = \Swayok\Html\Tag::a()->setContent(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.toolbar.create'))->setClass('btn btn-primary')->setHref(route('cmf_item_add_form', [$tableNameForRoutes], false))->build();
}
// row actions
$actionsTpl = '';
if ($dataGridConfig->isDetailsViewerAllowed()) {
    $url = $dblClickUrl = route('cmf_item_details', [$tableNameForRoutes, ":{$pkName}:"], false);
    $btn = \Swayok\Html\Tag::a()->setClass('row-action text-light-blue item-details')->setContent('<i class="glyphicon glyphicon-info-sign"></i>')->setTitle(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.actions.view_item'))->setDataAttr('toggle', 'tooltip')->setDataAttr('container', '#section-content .content')->setHref($url)->build();
    $actionsTpl .= '{{? !!it.___details_allowed }}' . $btn . '{{?}}';
}
if ($dataGridConfig->isEditAllowed()) {
    $url = $dblClickUrl = route('cmf_item_edit_form', [$tableNameForRoutes, ":{$pkName}:"], false);
    $btn = \Swayok\Html\Tag::a()->setClass('row-action text-green item-edit')->setContent('<i class="glyphicon glyphicon-edit"></i>')->setTitle(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.actions.edit_item'))->setDataAttr('toggle', 'tooltip')->setDataAttr('container', '#section-content .content')->setHref($url)->build();
    $actionsTpl .= '{{? !!it.___edit_allowed }}' . $btn . '{{?}}';
}
if ($dataGridConfig->isDeleteAllowed()) {
    $btn = \Swayok\Html\Tag::a()->setContent('<i class="glyphicon glyphicon-trash"></i>')->setClass('row-action text-red item-delete')->setTitle(\PeskyCMF\Config\CmfConfig::transBase('.datagrid.actions.delete_item'))->setDataAttr('toggle', 'tooltip')->setDataAttr('container', '#section-content .content')->setDataAttr('block-datagrid', '1')->setDataAttr('action', 'request')->setDataAttr('method', 'delete')->setDataAttr('url', route('cmf_api_delete_item', [$tableNameForRoutes, ":{$pkName}:"], false))->setDataAttr('confirm', \PeskyCMF\Config\CmfConfig::transBase('.action.delete.please_confirm'))->setHref('javascript: void(0)')->build();
    $actionsTpl .= '{{? !!it.___delete_allowed }}' . $btn . '{{?}}';
}
$customRowActions = $dataGridConfig->getRowActions();
if (!empty($customRowActions)) {
    foreach ($customRowActions as $rowAction) {
        $actionsTpl .= $rowAction;
    }
}
$actionsTpl = '<div class="row-actions text-nowrap">' . preg_replace('%:([a-zA-Z0-9_]+):%is', '{{= it.$1 }}', $actionsTpl) . '</div>';
?>

    <script type="application/javascript">
        (function() {
            <?php 
$dataTablesConfig = array_replace(\PeskyCMF\Config\CmfConfig::getInstance()->data_tables_config(), $dataGridConfig->getAdditionalDataTablesConfig(), ['processing' => true, 'serverSide' => true, 'ajax' => route('cmf_api_get_items', ['model' => $tableNameForRoutes], false), 'pageLength' => $dataGridConfig->getLimit(), 'toolbarItems' => array_values($toolbar), 'order' => []]);
 public function buildLinkToExternalRecord(DbColumnConfig $columnConfig, array $record, $linkLabel = null)
 {
     if (empty($record[$columnConfig->getName()])) {
         return '-';
     }
     $relationConfig = null;
     $relationAlias = null;
     foreach ($columnConfig->getRelations() as $alias => $relation) {
         if (in_array($relation->getType(), [DbRelationConfig::BELONGS_TO, DbRelationConfig::HAS_ONE])) {
             $relationConfig = $relation;
             $relationAlias = $alias;
             break;
         }
     }
     if (empty($relation)) {
         throw new ScaffoldFieldException($this, "Column [{$columnConfig->getName()}] has no fitting relation");
     }
     if (empty($record[$relationAlias]) || empty($record[$relationAlias][$relationConfig->getDisplayField()])) {
         return CmfConfig::transBase('.item_details.field.no_relation');
     } else {
         return Tag::a(empty($linkLabel) ? $record[$relationAlias][$relationConfig->getDisplayField()] : $linkLabel)->setHref(route('cmf_item_details', [$relationConfig->getForeignTable(), $record[$columnConfig->getName()]]))->build();
     }
 }