| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\UI;
- use \ThurData\Servers\KerioEmail\Core\Helper;
- use \ThurData\Servers\KerioEmail\Core\Http\Request;
- use \ThurData\Servers\KerioEmail\Core\ModuleConstants;
- use \ThurData\Servers\KerioEmail\Core\UI\Helpers\TemplateConstants;
- use \ThurData\Servers\KerioEmail\Core\Traits\AppParams;
- use \ThurData\Servers\KerioEmail\Core\Traits\IsDebugOn;
- /**
- * Main View Controller
- * @autor ThurData <info@thurdata.ch>
- */
- class View
- {
- use Traits\AppLayouts;
- use Traits\CustomJsCode;
- use Traits\ViewBreadcrumb;
- use AppParams;
- use IsDebugOn;
- /**
- * Controler for all widgets inside of View
- * @var \ThurData\Servers\KerioEmail\Core\UI\MainContainer
- */
- protected $mainContainer = null;
- protected $template = null;
- protected $name;
- protected $isBreadcrumbs = true;
- protected $templateDir = null;
- protected $defaultComponentsJs = null;
- protected $integration = false;
- public function __construct ($template = null)
- {
- $this->setTemplate($template);
- $this->mainContainer = new \ThurData\Servers\KerioEmail\Core\UI\MainContainer();
- $this->initBreadcrumbs();
- $this->initCustomAssetFiles();
- }
- /**
- * 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(),
- 'customCssCode' => $this->getCustomCssCode(),
- '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();
- }
- public function setIsIntegration($isIntegration = false)
- {
- if (is_bool($isIntegration))
- {
- $this->integration = $isIntegration;
- $this->initCustomAssetFiles();
- }
- }
- public function isIntegration()
- {
- return $this->integration;
- }
- }
|