mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Enh: data-action-confirm
now works on non action based links in combination with data-action-method
This commit is contained in:
parent
9a103ce03b
commit
4584d7e2b7
@ -7,6 +7,7 @@ HumHub Change Log
|
||||
- Fix #2567 No results in directory search containing single quote ( ' )
|
||||
- Fix #3468 Private space stream contains public content filter
|
||||
- Fix #3473 Captcha validation breaks invite by mail
|
||||
- Enh: `data-action-confirm` now works on non action based links in combination with `data-action-method`
|
||||
|
||||
1.3.9 (February 13, 2019)
|
||||
--------------------------
|
||||
|
@ -200,6 +200,13 @@ class Button extends BootstrapComponent
|
||||
$this->htmlOptions['data-ui-loader'] = '';
|
||||
}
|
||||
|
||||
// Workaround since data-method handler prevents confirm or other action handlers from being executed.
|
||||
if(isset($this->htmlOptions['data-action-confirm']) && isset($this->htmlOptions['data-method'])) {
|
||||
$method = $this->htmlOptions['data-method'];
|
||||
$this->htmlOptions['data-method'] = null;
|
||||
$this->htmlOptions['data-action-method'] = $method;
|
||||
}
|
||||
|
||||
if ($this->_link) {
|
||||
$href = isset($this->htmlOptions['href']) ? $this->htmlOptions['href'] : null;
|
||||
return Html::a($this->getText(), $href, $this->htmlOptions);
|
||||
|
@ -360,9 +360,41 @@ humhub.module('action', function(module, require, $) {
|
||||
this.bindAction(document, 'keydown', '[data-action-keydown]', false);
|
||||
}
|
||||
|
||||
// Handles data-action-confirm non action based links links
|
||||
$(document).on('click', '[href][data-action-confirm]', function(evt) {
|
||||
var $this = $(this);
|
||||
|
||||
// Make sure we are not intercepting an action based link
|
||||
var data = $this.data();
|
||||
for(var key in data) {
|
||||
if(string.startsWith(key, 'action') && !string.startsWith(key, 'actionConfirm') && !string.startsWith(key, 'actionMethod')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
evt.preventDefault();
|
||||
|
||||
modal.confirm($this).then(function(confirmed) {
|
||||
if(confirmed) {
|
||||
var client = require('client');
|
||||
var url = $this.attr('href');
|
||||
var method = $this.data('action-method') || 'GET';
|
||||
if(method.toLocaleUpperCase() === 'POST') {
|
||||
return $this.is('[data-pjax-prevent]') ? client.submit({url:url}) : client.pjax.post({url: url}) ;
|
||||
} else {
|
||||
return $this.is('[data-pjax-prevent]') ? (document.location = url) : client.pjax.redirect(url);
|
||||
}
|
||||
|
||||
}
|
||||
}).finally(function() {
|
||||
loader.reset($this);
|
||||
});
|
||||
});
|
||||
|
||||
updateBindings();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Registers a given handler with the given id.
|
||||
*
|
||||
|
@ -101,6 +101,13 @@ humhub.module('client', function (module, require, $) {
|
||||
} else if (cfg instanceof $.Event) {
|
||||
originalEvent = cfg;
|
||||
cfg = {};
|
||||
} else if($form.url) {
|
||||
// Create a post form
|
||||
$form = $('<form>', {
|
||||
action: $form.url,
|
||||
method: 'post'
|
||||
});
|
||||
$form.appendTo('body');
|
||||
}
|
||||
|
||||
cfg = cfg || {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user