| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace ModulesGarden\ProxmoxAddon\Core\UI;
- use \ModulesGarden\ProxmoxAddon\Core\Helper;
- use \ModulesGarden\ProxmoxAddon\Core\Http\Request;
- use \ModulesGarden\ProxmoxAddon\Core\ModuleConstants;
- use \ModulesGarden\ProxmoxAddon\Core\UI\Helpers\TemplateConstants;
- /**
- * Main View Controller
- * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
- */
- class View
- {
- use Traits\AppLayouts;
- use Traits\CustomJsCode;
- use Traits\ViewBreadcrumb;
- /**
- * Controler for all widgets inside of View
- * @var \ModulesGarden\ProxmoxAddon\Core\UI\MainContainer
- */
- protected $mainContainer = null;
- protected $template = null;
- protected $name;
- protected $isBreadcrumbs = true;
- protected $templateDir = null;
- protected $defaultComponentsJs = null;
- public function __construct($template = null)
- {
- $this->setTemplate($template);
- $this->mainContainer = new \ModulesGarden\ProxmoxAddon\Core\UI\MainContainer();
- $this->initBreadcrumbs();
- }
- /**
- * Adds elements to the root element
- */
- public function addElement($element, $containerName = null)
- {
- $this->mainContainer->addElement($element, $containerName);
- return $this;
- }
- /**
- * Generates all responses for UI elements
- */
- public function getResponse()
- {
- $this->mainContainer->setTemplate($this->getAppLayoutTemplateDir(), $this->getAppLayout());
- $request = Request::build();
- if ($request->get('ajax', false))
- {
- return $this->mainContainer->getAjaxResponse();
- }
- return Helper\response([
- 'tpl' => $this->template,
- 'tplDir' => $this->templateDir,
- 'data' => [
- 'mainContainer' => $this->mainContainer,
- 'customJsCode' => $this->getCustomJsCode(),
- 'breadcrumbs' => $this->getBreadcrumbs()
- ]
- ])->setStatusCode(200)->setName($this->name)->setBreadcrumbs($this->isBreadcrumbs);
- }
- public function validateAcl($isAdmin)
- {
- $this->mainContainer->valicateACL($isAdmin);
- return $this;
- }
- /**
- * Sets custom View template
- */
- public function setTemplate($template = null)
- {
- if ($template === null)
- {
- $this->template = 'view';
- $this->templateDir = ModuleConstants::getTemplateDir()
- . DS . (Helper\isAdmin() ? TemplateConstants::ADMIN_PATH : TemplateConstants::CLIENT_PATH)
- . DS . TemplateConstants::MAIN_DIR;
- return;
- }
- $this->template = $template;
- $this->templateDir = null;
- }
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- public function disableBreadcrumbs()
- {
- $this->isBreadcrumbs = false;
- return $this;
- }
- /**
- * this function is deprecated
- * @return type
- */
- public function genResponse()
- {
- return $this->getResponse();
- }
- }
|