| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui\Js; |
| 6: | |
| 7: | use Atk4\Ui\VirtualPage; |
| 8: | |
| 9: | /** |
| 10: | * Create Fomantic-UI Modal using JS. |
| 11: | */ |
| 12: | class JsModal extends JsExpression |
| 13: | { |
| 14: | /** |
| 15: | * @param string|null $title when empty, header will be removed in modal |
| 16: | * @param string|VirtualPage $url |
| 17: | */ |
| 18: | public function __construct($title, $url, array $args = [], string $dataType = 'json') |
| 19: | { |
| 20: | if ($url instanceof VirtualPage) { |
| 21: | $url = $url->getJsUrl('cut'); |
| 22: | } |
| 23: | |
| 24: | parent::__construct('$(this).atkCreateModal([arg])', ['arg' => ['url' => $url, 'title' => $title, 'dataType' => $dataType, 'urlOptions' => $args]]); |
| 25: | |
| 26: | if (!$title) { |
| 27: | $this->removeHeader(); |
| 28: | } |
| 29: | } |
| 30: | |
| 31: | /** |
| 32: | * Set additional option for this JsModal. |
| 33: | * |
| 34: | * Valuable option are headerCss and label: |
| 35: | * 'headerCss' -> customize CSS class name for the header. |
| 36: | * ex: changing color text for header |
| 37: | * $jsModal->setOption('headerCss', 'ui blue header'); |
| 38: | * |
| 39: | * 'loadingLabel' -> set the text loader value. |
| 40: | * ex: changing default 'Loading...' for no text |
| 41: | * $jsModal->setOption('loadingLabel', ''); |
| 42: | * |
| 43: | * 'modalCss' -> customize CSS class name for the entire modal. |
| 44: | * ex: making modal fullscreen |
| 45: | * $jsModal->setOption('modalCss', 'fullscreen'); |
| 46: | * |
| 47: | * 'contentCss' -> customize CSS class name for Modal content. |
| 48: | * ex: making content scrollable |
| 49: | * $jsModal->setOption('contentCss', 'scrolling'); |
| 50: | * Note: Default to 'image' for backward compatibility. |
| 51: | * |
| 52: | * You can set option individually or supply an array. |
| 53: | * |
| 54: | * @param string|array $options |
| 55: | * @param ($options is array ? never : mixed) $value |
| 56: | * |
| 57: | * @return $this |
| 58: | */ |
| 59: | public function setOption($options, $value = null) |
| 60: | { |
| 61: | if (is_array($options)) { |
| 62: | foreach ($options as $k => $v) { |
| 63: | $this->args['arg'][$k] = $v; |
| 64: | } |
| 65: | } else { |
| 66: | $this->args['arg'][$options] = $value; |
| 67: | } |
| 68: | |
| 69: | return $this; |
| 70: | } |
| 71: | |
| 72: | /** |
| 73: | * Clear header class and title. |
| 74: | * |
| 75: | * @return $this |
| 76: | */ |
| 77: | public function removeHeader() |
| 78: | { |
| 79: | $this->args['arg']['headerCss'] = ''; |
| 80: | $this->args['arg']['title'] = ''; |
| 81: | |
| 82: | return $this; |
| 83: | } |
| 84: | } |
| 85: |