diff --git a/demos/interactive/modal.php b/demos/interactive/modal.php index 6504677e50..576e895db5 100644 --- a/demos/interactive/modal.php +++ b/demos/interactive/modal.php @@ -117,7 +117,7 @@ $transitionModal = Modal::addTo($app, ['title' => 'Animated modal']); Message::addTo($transitionModal)->set('A lot of animated transition available'); -$transitionModal->duration(1000); +$transitionModal->setOption('duration', 1000); $menuBar = View::addTo($app, ['ui' => 'buttons']); $main = Menu::addTo($menuBar); @@ -156,7 +156,6 @@ // Add modal to layout. $stepModal = Modal::addTo($app, ['title' => 'Multi step actions']); -$stepModal->setOption('observeChanges', true); // Add buttons to modal for next and previous actions. $action = new View(['ui' => 'buttons']); diff --git a/docs/js.rst b/docs/js.rst index 67ffbcce0f..eed8b63f06 100644 --- a/docs/js.rst +++ b/docs/js.rst @@ -410,7 +410,6 @@ Modal .. php:method:: addContentCss() .. php:method:: addScrolling() .. php:method:: setOption() -.. php:method:: setOptions() This class allows you to open modal dialogs and close them easily. It's based around Fomantic-UI `.modal(), `_ but integrates PHP callback for dynamically diff --git a/src/Modal.php b/src/Modal.php index ddf96c047c..3132814f99 100644 --- a/src/Modal.php +++ b/src/Modal.php @@ -24,8 +24,6 @@ * $modal->addApproveAction('Yes', new JsExpression('function() { window.alert("You\'re good to go!"); }')); * * You may also prevent modal from closing via the esc or dimmed area click using $modal->notClosable(). - * - * Some helper methods are also available to set: transition time, transition type or modal settings from Fomantic-UI. */ class Modal extends View { @@ -47,7 +45,11 @@ class Modal extends View /** @var array */ public $args = []; /** @var array */ - public $options = []; + public $options = [ + // any change in modal DOM should automatically refresh cached positions + // allow modal window to add scrolling when content is added after modal is created + 'observeChanges' => true, + ]; /** @var string Currently only "json" response type is supported. */ public $type = 'json'; @@ -160,38 +162,7 @@ public function hide() */ public function setOption($option, $value) { - $this->options['modal_option'][$option] = $value; - - return $this; - } - - /** - * Set modal options passing an array. - * - * @param array $options - * - * @return $this - */ - public function setOptions($options) - { - if (isset($this->options['modal_option'])) { - $this->options['modal_option'] = array_merge($this->options['modal_option'], $options); - } else { - $this->options['modal_option'] = $options; - } - - return $this; - } - - /** - * Whether any change in modal DOM should automatically refresh cached positions. - * Allow modal window to add scrolling when adding content dynamically after modal creation. - * - * @return $this - */ - public function observeChanges() - { - $this->setOptions(['observeChanges' => true]); + $this->options[$option] = $value; return $this; } @@ -208,49 +179,6 @@ public function addScrolling() return $this; } - /** - * Set modal transition. - * - * @param string $transitionType - * - * @return $this - */ - public function transition($transitionType) - { - $this->settings('transition', $transitionType); - - return $this; - } - - /** - * Set modal transition duration. - * - * @param float|int $time - * - * @return $this - */ - public function duration($time) - { - $this->settings('duration', $time); - - return $this; - } - - /** - * Add modal settings. - * - * @param string $settingOption - * @param mixed $value - * - * @return $this - */ - public function settings($settingOption, $value) - { - $this->options['setting'][$settingOption] = $value; - - return $this; - } - /** * Add a deny action to modal. * @@ -264,7 +192,7 @@ public function addDenyAction($label, $jsAction) $button = new Button(); $button->set($label)->addClass('red cancel'); $this->addButtonAction($button); - $this->options['modal_option']['onDeny'] = $jsAction; + $this->options['onDeny'] = $jsAction; return $this; } @@ -282,7 +210,7 @@ public function addApproveAction($label, $jsAction) $b = new Button(); $b->set($label)->addClass('green ok'); $this->addButtonAction($b); - $this->options['modal_option']['onApprove'] = $jsAction; + $this->options['onApprove'] = $jsAction; return $this; } @@ -309,7 +237,7 @@ public function addButtonAction($button) */ public function notClosable() { - $this->options['modal_option']['closable'] = false; + $this->options['closable'] = false; return $this; } @@ -337,21 +265,9 @@ protected function renderView(): void $this->template->del('ActionContainer'); } - // call modal creation first - if (isset($this->options['modal_option'])) { - $this->js(true)->modal($this->options['modal_option']); - } else { - $this->js(true)->modal(); - } - - // add setting if available. - if (isset($this->options['setting'])) { - foreach ($this->options['setting'] as $key => $value) { - $this->js(true)->modal('setting', $key, $value); - } - } + $this->js(true)->modal($this->options); - if (!isset($this->options['modal_option']['closable']) || $this->options['modal_option']['closable']) { + if (!isset($this->options['closable']) || $this->options['closable']) { $this->template->trySet('closeIcon', 'close'); } diff --git a/src/Popup.php b/src/Popup.php index 53d19bad42..6c8fc189bc 100644 --- a/src/Popup.php +++ b/src/Popup.php @@ -212,18 +212,6 @@ public function setOption(string $name, $option) return $this; } - /** - * Setting options using using an array. - * - * @return $this - */ - public function setOptions(array $options) - { - $this->popOptions = array_merge($this->popOptions, $options); - - return $this; - } - /** * Return js action need to display popup. * When a grid is reloading, this method can be call diff --git a/src/Table/Column/ActionButtons.php b/src/Table/Column/ActionButtons.php index d6e03e5fe8..8c00ff133e 100644 --- a/src/Table/Column/ActionButtons.php +++ b/src/Table/Column/ActionButtons.php @@ -95,8 +95,6 @@ public function addModal($button, $defaults, \Closure $callback, $owner = null, $modal = Modal::addTo($owner, $defaults); - $modal->observeChanges(); // adds scrollbar if needed - $modal->set(function (View $t) use ($callback) { $callback($t, $t->stickyGet($this->name)); }); diff --git a/src/UserAction/ConfirmationExecutor.php b/src/UserAction/ConfirmationExecutor.php index 8198123a03..6fd51dbbe9 100644 --- a/src/UserAction/ConfirmationExecutor.php +++ b/src/UserAction/ConfirmationExecutor.php @@ -53,7 +53,6 @@ protected function init(): void { parent::init(); - $this->observeChanges(); $this->addClass($this->size); } diff --git a/src/UserAction/ModalExecutor.php b/src/UserAction/ModalExecutor.php index 3ec4eca5b8..8610a5b06f 100644 --- a/src/UserAction/ModalExecutor.php +++ b/src/UserAction/ModalExecutor.php @@ -46,7 +46,6 @@ protected function init(): void protected function initExecutor(): void { - $this->observeChanges(); } public function getAction(): Model\UserAction