| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- /* * ********************************************************************
- * KerioEmail product developed. (Nov 19, 2018)
- * *
- *
- * CREATED BY THURDATA -> http://thurdata.com
- * CONTACT -> contact@thurdata.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar;
- use \ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates;
- /**
- * Description of SidebarAjax
- *
- * @autor ThurData <info@thurdata.ch>
- */
- class SidebarAjax extends Sidebar implements \ThurData\Servers\KerioEmail\Core\UI\Interfaces\AjaxElementInterface
- {
- use \ThurData\Servers\KerioEmail\Core\Traits\Lang;
-
- protected $id = 'sidebarAjax';
- protected $name = 'sidebarAjax';
- protected $vueComponent = true;
- protected $defaultVueComponentName = 'mg-ajax-sidebar';
-
- protected $ajaxMenuElements = [];
-
- /**
- * overwrite this function, use add function to add ajax elements
- */
- public function prepareAjaxData()
- {
-
- }
-
- /**
- * do not overwrite this function
- * @return type \ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\RawDataJsonResponse
- */
- public function returnAjaxData()
- {
- $this->prepareAjaxData();
-
- $returnData = $this->parseProvidedData();
- return (new ResponseTemplates\RawDataJsonResponse($returnData))->setCallBackFunction($this->callBackFunction);
- }
-
- protected function parseProvidedData()
- {
- $this->loadLang();
-
- $data = [];
- foreach ($this->ajaxMenuElements as $mItem)
- {
- $data[] = [
- 'id' => $mItem->getId(),
- 'namespace' => $mItem->getNamespace(),
- 'icon' => $mItem->getIcon(),
- 'href' => method_exists($mItem, 'getHref') ? $mItem->getHref() : null,
- 'htmlAtributes' => $mItem->getHtmlAttributes(),
- 'class' => $mItem->getClasses(),
- 'clickAction' => $this->parseOnClickAction($mItem->getHtmlAttributes()['@click']),
- 'title' => $this->lang->tr($this->id, $mItem->getTitle())
- ];
- }
- return $data;
- }
-
- public function add($sidebar)
- {
- $this->ajaxMenuElements[$sidebar->getId()] = $sidebar;
-
- if (method_exists($sidebar, 'setParent'))
- {
- $sidebar->setParent($this);
- }
-
- return $this;
- }
-
- public function parseOnClickAction($actionString)
- {
- if (stripos($actionString, '(') > 0)
- {
- $actions = explode('(', $actionString);
- $action = $actions[0];
- $paramsString = trim(trim(trim($actions[1], ';'), ')'), "'");
- $params = explode(',', $paramsString);
- foreach ($params as $key => $param)
- {
- $params[$key] = trim(trim(trim($param), "'"), '"');
- }
-
- return ['action' => $action, 'params' => $params];
- }
-
- return ['action' => $actionString, 'params' => []];
- }
- }
|