Skip to content

Commit 745c39b

Browse files
Replace function Confirm dialog with modal (#17115)
* Replace function Confirm dialog with modal Signed-off-by: Saksham Gupta <shucontech@gmail.com> * Fix failing tests Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev> Co-authored-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 65cc5ed commit 745c39b

6 files changed

Lines changed: 30 additions & 39 deletions

File tree

‎js/src/functions.js‎

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,40 +2391,16 @@ Functions.confirm = function (question, url, callbackFn, openCallback) {
23912391
return true;
23922392
}
23932393

2394-
/**
2395-
* @var button_options Object that stores the options passed to jQueryUI
2396-
* dialog
2397-
*/
2398-
var buttonOptions = [
2399-
{
2400-
text: Messages.strOK,
2401-
'class': 'submitOK',
2402-
click: function () {
2403-
$(this).dialog('close');
2404-
if (typeof callbackFn === 'function') {
2405-
callbackFn.call(this, url);
2406-
}
2407-
}
2408-
},
2409-
{
2410-
text: Messages.strCancel,
2411-
'class': 'submitCancel',
2412-
click: function () {
2413-
$(this).dialog('close');
2414-
}
2394+
$('#functionConfirmModal').modal('show');
2395+
$('#functionConfirmModal').find('.modal-body').first().html(question);
2396+
$('#functionConfirmOkButton').on('click', function () {
2397+
if (typeof callbackFn === 'function') {
2398+
callbackFn.call(this, url);
24152399
}
2416-
];
2417-
2418-
$('<div></div>', { 'id': 'confirm_dialog', 'title': Messages.strConfirm })
2419-
.prepend(question)
2420-
.dialog({
2421-
buttons: buttonOptions,
2422-
close: function () {
2423-
$(this).remove();
2424-
},
2425-
open: openCallback,
2426-
modal: true
2427-
});
2400+
});
2401+
if (typeof openCallback === 'function') {
2402+
openCallback();
2403+
}
24282404
};
24292405
jQuery.fn.confirm = Functions.confirm;
24302406

‎libraries/classes/Controllers/JavaScriptMessagesController.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ private function setMessages(): void
3636

3737
$this->messages = [
3838
/* For confirmations */
39-
'strConfirm' => __('Confirm'),
4039
'strDoYouReally' => __('Do you really want to execute "%s"?'),
4140
'strDropDatabaseStrongWarning' => __('You are about to DESTROY a complete database!'),
4241
'strDatabaseRenameToSameName' => __(

‎templates/footer.twig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{ include('modals/function_confirm.twig') }}
12
{% if not is_ajax %}
23
</div>
34
{% endif %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="modal fade" id="functionConfirmModal" tabindex="-1" aria-labelledby="functionConfirmModalLabel" aria-hidden="true">
2+
<div class="modal-dialog">
3+
<div class="modal-content">
4+
<div class="modal-header">
5+
<h5 class="modal-title" id="functionConfirmModalLabel">{% trans 'Confirm' %}</h5>
6+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans 'Close' %}"></button>
7+
</div>
8+
<div class="modal-body"></div>
9+
<div class="modal-footer">
10+
<button type="button" class="btn btn-secondary" id="functionConfirmOkButton" data-bs-dismiss="modal">{% trans 'Ok' %}</button>
11+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans 'Close' %}</button>
12+
</div>
13+
</div>
14+
</div>
15+
</div>

‎test/classes/Controllers/JavaScriptMessagesControllerTest.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PhpMyAdmin\Controllers\JavaScriptMessagesController;
88
use PHPUnit\Framework\TestCase;
99

10-
use function __;
1110
use function json_decode;
1211
use function ob_end_clean;
1312
use function ob_get_contents;
@@ -39,7 +38,7 @@ public function testIndex(): void
3938
$array = json_decode($json, true);
4039

4140
$this->assertIsArray($array);
42-
$this->assertArrayHasKey('strConfirm', $array);
43-
$this->assertEquals(__('Confirm'), $array['strConfirm']);
41+
$this->assertArrayHasKey('strDoYouReally', $array);
42+
$this->assertEquals('Do you really want to execute "%s"?', $array['strDoYouReally']);
4443
}
4544
}

‎test/classes/FooterTest.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ArrayIterator;
88
use PhpMyAdmin\ErrorHandler;
99
use PhpMyAdmin\Footer;
10+
use PhpMyAdmin\Template;
1011

1112
use function json_encode;
1213

@@ -124,7 +125,7 @@ public function testAjax(): void
124125
$footer = new Footer();
125126
$footer->setAjax(true);
126127
$this->assertEquals(
127-
'',
128+
(new Template())->render('modals/function_confirm') . "\n",
128129
$footer->getDisplay()
129130
);
130131
}
@@ -163,7 +164,7 @@ public function testMinimal(): void
163164
$footer = new Footer();
164165
$footer->setMinimal();
165166
$this->assertEquals(
166-
" </div>\n </body>\n</html>\n",
167+
(new Template())->render('modals/function_confirm') . "\n </div>\n </body>\n</html>\n",
167168
$footer->getDisplay()
168169
);
169170
}

0 commit comments

Comments
 (0)