public function controllerIndex() { if (!$this->getModule()->hasAccess()) { if (zbase_auth_has()) { return $this->unathorized(_zt('You don\'t have enough access to the resource.')); } else { return redirect()->to(zbase_url_from_route('login')); } } /** * Check for widgets */ $widgetsAction = $action = str_replace('.', '-', $this->getRouteParameter('action', 'index')); $requestMethod = zbase_request_method(); if (!empty($this->nodeName)) { $widgetsAction = $requestMethod . '-node-' . $this->nodeName . '-' . $action; $htmls = []; } $isAjax = zbase_request_is_ajax(); if ($isAjax) { $widgetsAction = (!empty($this->nodeName) ? $requestMethod . '-node-' . $this->nodeName . '-' : '') . 'json-' . $action; $htmls = []; } if ($this->getModule()->hasAction($requestMethod . '-' . $action)) { $widgetsAction = $requestMethod . '-' . $action; $action = $widgetsAction; $htmls = []; } $widgets = $this->getModule()->pageProperties($action)->widgetsByControllerAction($widgetsAction); if (count($widgets) == 1) { $firstWidget = collect($widgets)->first(); if ($firstWidget instanceof \Zbase\Widgets\WidgetInterface) { $firstWidget->pageProperties($widgetsAction); } } if (!is_array($widgets) && $widgets instanceof \Illuminate\Http\RedirectResponse) { return $widgets; } zbase()->json()->addVariable('_widget', $this->getModule()->id() . '_' . str_replace('-', '', $action)); if (zbase_is_dev()) { zbase()->json()->addVariable(__METHOD__, $widgetsAction); if (zbase_request_is_post()) { zbase()->json()->addVariable('_POST_PARAMETERS', zbase_request_inputs()); } zbase()->json()->addVariable('_ROUTE_PARAMETERS', zbase_route_inputs()); zbase()->json()->addVariable('_GET_PARAMETERS', zbase_request_query_inputs()); } // dd($this->getModule(), $widgetsAction, $widgets); if (empty($widgets)) { return zbase_abort(404); } foreach ($widgets as $widget) { if (!empty($this->nodeName)) { zbase()->json()->addVariable('node', ['prefix' => $this->getModule()->nodeNamespace(), 'name' => $this->nodeName, 'support' => 1]); $widget->setNodename($this->nodeName)->setNodeSupport(true); } if ($widget instanceof \Zbase\Widgets\ControllerInterface) { $v = $widget->validateWidget($action); if ($v instanceof \Illuminate\Contracts\Validation\Validator) { if ($isAjax) { zbase()->json()->addVariable('errors', $v->errors()->getMessages()); return new \Illuminate\Http\JsonResponse($v->errors()->getMessages(), 422); } else { return redirect()->to($this->getRedirectUrl())->withInput(zbase_request_inputs())->withErrors($v->errors()->getMessages()); } } $ret = $widget->controller($this->getRouteParameter('action', 'index')); if ($ret instanceof \Zbase\Exceptions\NotFoundHttpException) { return $this->notFound(); } if ($ret instanceof \Zbase\Exceptions\UnauthorizedException) { return $this->unathorized(); } if ($ret instanceof \Zbase\Exceptions\Exception) { return $this->error(); } if ($ret instanceof \Illuminate\Http\RedirectResponse) { if ($isAjax) { zbase()->json()->addVariable('redirect', $ret->getTargetUrl()); } else { return $ret; } } if (zbase_is_json()) { zbase_response_format_set('json'); $jsonIndexName = $widget->getWidgetPrefix(); if (zbase_is_angular()) { if ($widget instanceof \Zbase\Widgets\Type\Datatable) { $angularTemplate = zbase_angular_widget_datatable($this->getModule(), $widget); $jsonIndexName = $angularTemplate['serviceName']; } } if (zbase_is_dev()) { zbase()->json()->addVariable('$jsonIndexName', $jsonIndexName); } if (!$widget->isExporting()) { zbase()->json()->addVariable($jsonIndexName, $widget->toArray()); } } else { if ($isAjax) { $htmls[str_replace('-', '_', $widget->id())] = $widget->render(); } } $widget->pageProperties($widgetsAction); } } if (!empty($isAjax)) { zbase()->json()->addVariable('_widgets', 1); zbase()->json()->addVariable('html', $htmls); } else { return $this->view(zbase_view_file('module.index'), array('module' => $this->getModule(), 'widgets' => $widgets)); } }
<?php $perPages = $ui->getRowsPerPages(); if ($paginator instanceof \Illuminate\Pagination\LengthAwarePaginator) { $perPageRequest = zbase_request_query_input('pp', false); if (!empty($perPageRequest) && !zbase_is_angular()) { $paginator->appends(['pp' => $perPageRequest]); } $presenter = new \Illuminate\Pagination\BootstrapThreePresenter($paginator); if (zbase_is_angular()) { echo str_replace(array('?page=', 'class="pagination', route('index')), array('/page/', 'class="pagination pagination-pages pagination-sm', '#'), $presenter->render()); } else { echo str_replace(array('class="pagination'), array('class="pagination pagination-pages pagination-sm'), $presenter->render()); } if (!zbase_is_angular()) { echo '<ul class="pagination pagination-perpage pagination-sm">'; if ($paginator->lastPage() > 1 && !empty($perPages)) { echo '<li><a class="btn disabled" href="#">Rows</a></li>'; } if (!empty($perPages)) { foreach ($perPages as $perPage) { if ($paginator->total() > $perPage) { echo '<li><a data-perpage="' . $perPage . '" ' . 'href="' . zbase_url_from_current(['pp' => $perPage], false) . '" ' . ($paginator->perPage() == $perPage ? 'class="active"' : '') . '>' . $perPage . '</a>' . '</li>'; } } } if ($paginator->total() > $paginator->perPage()) { echo '<li><a data-perpage="all" href="' . zbase_url_from_current(['pp' => $paginator->total()], false) . '" ' . ($paginator->perPage() > $perPageRequest ? 'class="pagination-view-all active"' : '') . ' title="View all rows">' . 'View all' . '</a></li>'; } echo '</ul>'; }
/** * Check if theme is Angular * @return boolean */ public function isAngular() { return zbase_is_angular(); }
/** * Render HTML between <head></head> * * @return string */ function zbase_view_render_head() { $str = ''; zbase()->view()->prepare(); if (zbase_is_angular()) { $str .= '<title ng-bind="pageTitle">' . zbase()->view()->pageTitle() . '</title>'; } else { $str .= '<title>' . zbase()->view()->pageTitle() . '</title>'; } $str .= zbase_view_head_metas_render(); $str .= zbase_view_stylesheets_render(); $str .= zbase_view_head_links_render(); $str .= zbase_view_placeholder_render('head_javascripts'); $str .= zbase_view_placeholder_render('head_scripts'); $str .= EOF . zbase_view_render(zbase_view_file_contents('google.analytics')); $str .= EOF . zbase_view_styles_render(); if (zbase()->system()->inMaintenance() && zbase_is_back()) { $str .= '<style type="text/css"> .header{background-color: maroon !important;} </style>'; } return $str; }