Commit b4c4b405 by Qiang Xue

Fixes #3511: Dropped `yii.allowAction()` and modified `yii.confirm()` in…

Fixes #3511: Dropped `yii.allowAction()` and modified `yii.confirm()` in `yii.js` to support callbacks
parent 1a8dd259
...@@ -225,6 +225,7 @@ Yii Framework 2 Change Log ...@@ -225,6 +225,7 @@ Yii Framework 2 Change Log
- Chg #3175: InvalidCallException, InvalidParamException, UnknownMethodException are now extended from SPL BadMethodCallException (samdark) - Chg #3175: InvalidCallException, InvalidParamException, UnknownMethodException are now extended from SPL BadMethodCallException (samdark)
- Chg #3358: Removed automatic CSRF meta tag generation by `View`. Added `Html::csrfMetaTags()` and its call to main layout files (qiangxue) - Chg #3358: Removed automatic CSRF meta tag generation by `View`. Added `Html::csrfMetaTags()` and its call to main layout files (qiangxue)
- Chg #3383: Added `$type` parameter to `IdentityInterface::findIdentityByAccessToken()` (qiangxue) - Chg #3383: Added `$type` parameter to `IdentityInterface::findIdentityByAccessToken()` (qiangxue)
- Chg #3511: Dropped `yii.allowAction()` and modified `yii.confirm()` in `yii.js` to support callbacks (tanakahisateru)
- Chg #3531: \yii\grid\GridView now allows any character (except ":") in the attribute part of the shorthand syntax for columns (rawtaz) - Chg #3531: \yii\grid\GridView now allows any character (except ":") in the attribute part of the shorthand syntax for columns (rawtaz)
- Chg #3544: Added `$key` as a parameter to the callable specified via `yii\grid\DataColumn::value` (mdmunir) - Chg #3544: Added `$key` as a parameter to the callable specified via `yii\grid\DataColumn::value` (mdmunir)
- Chg #3611: Query caching is refactored. (qiangxue) - Chg #3611: Query caching is refactored. (qiangxue)
......
...@@ -98,23 +98,15 @@ yii = (function ($) { ...@@ -98,23 +98,15 @@ yii = (function ($) {
* The default implementation simply displays a js confirmation dialog. * The default implementation simply displays a js confirmation dialog.
* You may override this by setting `yii.confirm`. * You may override this by setting `yii.confirm`.
* @param message the confirmation message. * @param message the confirmation message.
* @return boolean whether the user confirms with the message in the dialog * @param ok a callback to be called when the user confirms the message
* @param cancel a callback to be called when the user cancels the confirmation
*/ */
confirm: function (message) { confirm: function (message, ok, cancel) {
return confirm(message); if (confirm(message)) {
}, !ok || ok();
} else {
/** !cancel || cancel();
* Returns a value indicating whether to allow executing the action defined for the specified element. }
* This method recognizes the `data-confirm` attribute of the element and uses it
* as the message in a confirmation dialog. The method will return true if this special attribute
* is not defined or if the user confirms the message.
* @param $e the jQuery representation of the element
* @return boolean whether to allow executing the action defined for the specified element.
*/
allowAction: function ($e) {
var message = $e.data('confirm');
return message === undefined || pub.confirm(message);
}, },
/** /**
...@@ -126,15 +118,14 @@ yii = (function ($) { ...@@ -126,15 +118,14 @@ yii = (function ($) {
* For other elements, either the containing form action or the current page URL will be used * For other elements, either the containing form action or the current page URL will be used
* as the form action URL. * as the form action URL.
* *
* If the `data-method` attribute is not defined, the default element action will be performed. * If the `data-method` attribute is not defined, nothing will be done.
* *
* @param $e the jQuery representation of the element * @param $e the jQuery representation of the element
* @return boolean whether to execute the default action for the element.
*/ */
handleAction: function ($e) { handleAction: function ($e) {
var method = $e.data('method'); var method = $e.data('method');
if (method === undefined) { if (method === undefined) {
return true; return;
} }
var $form = $e.closest('form'); var $form = $e.closest('form');
...@@ -178,8 +169,6 @@ yii = (function ($) { ...@@ -178,8 +169,6 @@ yii = (function ($) {
if (newForm) { if (newForm) {
$form.remove(); $form.remove();
} }
return false;
}, },
getQueryParams: function (url) { getQueryParams: function (url) {
...@@ -237,28 +226,27 @@ yii = (function ($) { ...@@ -237,28 +226,27 @@ yii = (function ($) {
} }
function initDataMethods() { function initDataMethods() {
var $document = $(document); var handler = function (event) {
// handle data-confirm and data-method for clickable elements
$document.on('click.yii', pub.clickableSelector, function (event) {
var $this = $(this); var $this = $(this);
if (pub.allowAction($this)) { // data-confirm requires data-method
return pub.handleAction($this); if ($this.data('method') === undefined) {
} else { return true;
event.stopImmediatePropagation();
return false;
} }
var message = $this.data('confirm');
if (message !== undefined) {
pub.confirm(message, function () {
pub.handleAction($this);
}); });
// handle data-confirm and data-method for changeable elements
$document.on('change.yii', pub.changeableSelector, function (event) {
var $this = $(this);
if (pub.allowAction($this)) {
return pub.handleAction($this);
} else { } else {
pub.handleAction($this);
}
event.stopImmediatePropagation(); event.stopImmediatePropagation();
return false; return false;
} };
});
// handle data-confirm and data-method for clickable and changeable elements
$(document).on('click.yii', pub.clickableSelector, handler)
.on('change.yii', pub.changeableSelector, handler);
} }
function initScriptFilter() { function initScriptFilter() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment