- Enh: Added Modal::closable in order to respect backdrop and keyboard data setting of Modal and ModalDialog widget

This commit is contained in:
buddh4 2017-07-20 18:03:47 +02:00
parent 806149e143
commit dd7545f19d
3 changed files with 45 additions and 10 deletions

View File

@ -67,6 +67,14 @@ class Modal extends JsWidget
*/
public $showClose;
/**
* If set to false $backdrop and §keyboard will be set to false automaticly, so
* the modal is only closable by buttons.
*
* @var bool
*/
public $closable = true;
/**
* Defines if a click on the modal background should close the modal
* @var boolean
@ -128,11 +136,11 @@ class Modal extends JsWidget
{
$result = [];
if(!$this->backdrop) {
if(!$this->closable || !$this->backdrop) {
$result['backdrop'] = 'static';
}
if(!$this->keyboard) {
if(!$this->closable || !$this->keyboard) {
$result['keyboard'] = 'false';
}

View File

@ -11,6 +11,8 @@ class ModalDialog extends Modal
public $dialogContent;
private $dialogClass;
/**
* @inheritdoc
*/
@ -34,31 +36,45 @@ class ModalDialog extends Modal
//The x close button is rendered by default either if forced by showClose or a headertext is given
$showClose = ($this->showClose != null) ? $this->showClose : ($this->header != null);
$dialogClass = 'modal-dialog';
$dialogClass .= ($this->size != null) ? ' modal-dialog-'.$this->size : '';
$dialogClass .= ($this->animation != null) ? ' animated '.$this->animation : '';
$bodyClass = 'modal-body';
$bodyClass .= ($this->centerText) ? ' text-center' : '';
$this->initialLoader = ($this->initialLoader ==! null) ? $this->initialLoader : ($this->body === null);
$modalData = '';
$modalData .= !$this->backdrop ? 'data-backdrop="static"' : '';
$modalData .= !$this->keyboard ? 'data-keyboard="false"' : '';
$modalData .= !$this->closable || !$this->backdrop ? 'data-backdrop="static"' : '';
$modalData .= !$this->closable || !$this->keyboard ? 'data-keyboard="false"' : '';
$modalData .= $this->show ? 'data-show="true"' : '';
return $this->render('modalDialog', [
'header' => $this->header,
'options' => $this->getOptions(),
'dialogContent' => $this->dialogContent,
'body' => $this->body,
'bodyClass' => $bodyClass,
'footer' => $this->footer,
'dialogClass' => $dialogClass,
'initialLoader' => $this->initialLoader,
'showClose' => $showClose
]);
}
public function getAttributes()
{
$dialogClass = 'modal-dialog';
$dialogClass .= ($this->size != null) ? ' modal-dialog-'.$this->size : '';
$dialogClass .= ($this->animation != null) ? ' animated '.$this->animation : '';
return [
'class' => $dialogClass
];
}
public function getData()
{
return [
'backdrop' => (!$this->closable || $this->backdrop === false) ? "static" : $this->backdrop,
'keyboard' => (!$this->closable || !$this->keyboard) ? "false" : 'true',
];
}
}

View File

@ -428,9 +428,20 @@ humhub.module('ui.modal', function (module, require, $) {
this.applyAdditions();
this.$.find('input[type="text"]:visible, textarea:visible, [contenteditable="true"]:visible').first().focus();
this.checkAriaLabel();
this.updateDialogOptions();
return this;
};
Modal.prototype.updateDialogOptions = function() {
var test = this.getDialog();
var test2 = this.getDialog().data('backdrop');
var test3 = this.getDialog().data('keyboard');
this.set({
backdrop : this.getDialog().data('backdrop'),
keyboard : this.getDialog().data('keyboard')
});
};
/**
* Retrieves the modal-body element
* @returns {humhub.ui.modal_L18.Modal.prototype@pro;$modal@call;find}