| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Buttons;
- use \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Builder\BaseContainer;
- class ButtonCustomAction extends BaseContainer
- {
- protected $id = 'ButtonCustomAction';
- protected $class = ['lu-btn lu-btn--sm lu-btn--link lu-btn--icon lu-btn--plain lu-btn--default'];
- protected $icon = 'lu-zmdi lu-zmdi-plus';
- protected $title = 'ButtonCustomAction';
- protected $htmlAttributes = [
- 'href' => 'javascript:;',
- 'data-toggle' => 'lu-tooltip',
- ];
-
- protected $customActionName = null;
- protected $customActionParams = [];
-
- /**
- * Overwrite this function in order to set up:
- * $customActionName and $customActionParams values
- */
- public function initContent()
- {
- }
- /**
- * Do not use or override this method!
- */
- protected function afterInitContent()
- {
- $this->htmlAttributes['@click'] = 'makeCustomAction(\'' . $this->customActionName . '\', ' . $this->parseCustomParams() . ', $event, \'' . $this->getNamespace() . '\', \'' . $this->getIndex() . '\')';
- }
- public function setCustomActionName($name)
- {
- $this->customActionName = $name;
-
- return $this;
- }
-
- public function setCustomActionParams(array $params)
- {
- $this->customActionParams = $params;
-
- return $this;
- }
-
- public function addCustomActionParam($key, $value)
- {
- $this->customActionParams[$key] = $value;
-
- return $this;
- }
-
- protected function parseCustomParams()
- {
- if (count($this->customActionParams) === 0)
- {
- return '{}';
- }
-
- return $this->parseListTOJsString($this->customActionParams);
- }
-
- protected function parseListTOJsString($params)
- {
- $jsString = '{';
- foreach ($params as $key => $value)
- {
- $jsString .= ' ' . $key . ': ' . (is_array($value) ? ($this->parseListTOJsString($value) . ',') : ("'" . (string) $value) . "',");
- }
-
- $jsString = trim($jsString, ',') . ' } ';
-
- return $jsString;
- }
-
- }
|