From a4a2ff7d2444fe24bf13f022b9748ddb961a095c Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Tue, 29 Oct 2019 18:34:39 +0530 Subject: [PATCH 01/16] Fixed issue when esacpe key is pressed to close prompt --- .../Ui/view/base/web/js/modal/prompt.js | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 13b4d55ea2787..396497868e14f 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -11,10 +11,11 @@ define([ 'underscore', 'mage/template', 'text!ui/template/modal/modal-prompt-content.html', + 'Magento_Ui/js/lib/key-codes', 'jquery-ui-modules/widget', 'Magento_Ui/js/modal/modal', 'mage/translate' -], function ($, _, template, promptContentTmpl) { +], function ($, _, template, promptContentTmpl, keyCodes) { 'use strict'; $.widget('mage.prompt', $.mage.modal, { @@ -64,13 +65,31 @@ define([ click: function () { this.closeModal(true); } - }] + }], + keyEventHandlers: { + + /** + * Escape key press handler, + * close modal window + * @param {Object} event - event + */ + escapeKey: function (event) { + if (this.options.isOpen && this.modal.find(document.activeElement).length || + this.options.isOpen && this.modal[0] === document.activeElement) { + this._close(); + } + } + } }, /** * Create widget. */ _create: function () { + _.bindAll( + this, + 'keyEventSwitcher' + ); this.options.focus = this.options.promptField; this.options.validation = this.options.validation && this.options.validationRules.length; this._super(); @@ -118,6 +137,18 @@ define([ return formTemplate; }, + /** + * Listener key events. + * Call handler function if it exists + */ + keyEventSwitcher: function (event) { + var key = keyCodes[event.keyCode]; + + if (this.options.keyEventHandlers.hasOwnProperty(key)) { + this.options.keyEventHandlers[key].apply(this, arguments); + } + }, + /** * Remove widget */ @@ -177,3 +208,4 @@ define([ return $('
').html(config.content).prompt(config); }; }); + From c42d48a44829ad91024e2c61f14fa9d5e9fe9731 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Tue, 5 Nov 2019 23:59:31 +0530 Subject: [PATCH 02/16] Fixed static test --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 396497868e14f..de7efe5103d5b 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -73,7 +73,7 @@ define([ * close modal window * @param {Object} event - event */ - escapeKey: function (event) { + escapeKey: function () { if (this.options.isOpen && this.modal.find(document.activeElement).length || this.options.isOpen && this.modal[0] === document.activeElement) { this._close(); From b8e0c42cba3db9a4b5005fe7e0d078891ad5b0ce Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Mon, 11 Nov 2019 12:01:21 +0000 Subject: [PATCH 03/16] magento/magento2#25349: Fixed static tests --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index de7efe5103d5b..4a73a3454bc07 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -71,7 +71,6 @@ define([ /** * Escape key press handler, * close modal window - * @param {Object} event - event */ escapeKey: function () { if (this.options.isOpen && this.modal.find(document.activeElement).length || From d6995f7595363e896415f06c1228ffc2f2f719ff Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Thu, 14 Nov 2019 23:41:50 +0530 Subject: [PATCH 04/16] Fixed issue with prompt closed on pressing escape key instead of hiding --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index de7efe5103d5b..8679ebd7de6cc 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -73,10 +73,10 @@ define([ * close modal window * @param {Object} event - event */ - escapeKey: function () { - if (this.options.isOpen && this.modal.find(document.activeElement).length || - this.options.isOpen && this.modal[0] === document.activeElement) { - this._close(); + escapeKey: function (event) { + if (this.modal.find(document.activeElement).length || + this.modal[0] === document.activeElement) { + this.closeModal(); } } } From 240fc19617589cecc528799824ad1b8378558dd4 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Fri, 15 Nov 2019 00:24:14 +0530 Subject: [PATCH 05/16] Fixed static build test --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 799f6323f0b87..0a03ea759d071 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -72,7 +72,7 @@ define([ * Escape key press handler, * close modal window */ - escapeKey: function (event) { + escapeKey: function () { if (this.modal.find(document.activeElement).length || this.modal[0] === document.activeElement) { this.closeModal(); From da6b3612ff51e52caf4bcf7dccf7690cd79d9cd4 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Tue, 26 Nov 2019 22:37:53 +0530 Subject: [PATCH 06/16] Reverted changes fix for modal and fixed the e.stopImmediatePropagation issue --- .../Checkout/view/frontend/web/js/sidebar.js | 4 ++- .../Ui/view/base/web/js/modal/modal.js | 5 ++- .../Ui/view/base/web/js/modal/prompt.js | 31 +------------------ 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js index 6fc5ef9d2a574..0545ccf29248c 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js @@ -98,7 +98,9 @@ define([ /** @inheritdoc */ always: function (e) { - e.stopImmediatePropagation(); + if (e) { + e.stopImmediatePropagation(); + } } } }); diff --git a/app/code/Magento/Ui/view/base/web/js/modal/modal.js b/app/code/Magento/Ui/view/base/web/js/modal/modal.js index a8a76206bcd2b..b72e7bc49f2f0 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/modal.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/modal.js @@ -104,12 +104,11 @@ define([ /** * Escape key press handler, * close modal window - * @param {Object} event - event */ - escapeKey: function (event) { + escapeKey: function () { if (this.options.isOpen && this.modal.find(document.activeElement).length || this.options.isOpen && this.modal[0] === document.activeElement) { - this.closeModal(event); + this.closeModal(); } } } diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 0a03ea759d071..54a2b4a894df9 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -65,30 +65,13 @@ define([ click: function () { this.closeModal(true); } - }], - keyEventHandlers: { - - /** - * Escape key press handler, - * close modal window - */ - escapeKey: function () { - if (this.modal.find(document.activeElement).length || - this.modal[0] === document.activeElement) { - this.closeModal(); - } - } - } + }] }, /** * Create widget. */ _create: function () { - _.bindAll( - this, - 'keyEventSwitcher' - ); this.options.focus = this.options.promptField; this.options.validation = this.options.validation && this.options.validationRules.length; this._super(); @@ -136,18 +119,6 @@ define([ return formTemplate; }, - /** - * Listener key events. - * Call handler function if it exists - */ - keyEventSwitcher: function (event) { - var key = keyCodes[event.keyCode]; - - if (this.options.keyEventHandlers.hasOwnProperty(key)) { - this.options.keyEventHandlers[key].apply(this, arguments); - } - }, - /** * Remove widget */ From db51191275245123b84d772a80820454a2cb5631 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Tue, 26 Nov 2019 23:53:33 +0530 Subject: [PATCH 07/16] Fixed static test --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 54a2b4a894df9..151ce2e4efca2 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -11,11 +11,10 @@ define([ 'underscore', 'mage/template', 'text!ui/template/modal/modal-prompt-content.html', - 'Magento_Ui/js/lib/key-codes', 'jquery-ui-modules/widget', 'Magento_Ui/js/modal/modal', 'mage/translate' -], function ($, _, template, promptContentTmpl, keyCodes) { +], function ($, _, template, promptContentTmpl) { 'use strict'; $.widget('mage.prompt', $.mage.modal, { From 3e25bd1385e9287f0ba5d5c6579a2f65ade3d2b4 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sat, 30 Nov 2019 09:32:50 +0530 Subject: [PATCH 08/16] Fixed always function issue --- app/code/Magento/Checkout/view/frontend/web/js/sidebar.js | 4 +--- app/code/Magento/Ui/view/base/web/js/modal/modal.js | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js index 0545ccf29248c..6fc5ef9d2a574 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js @@ -98,9 +98,7 @@ define([ /** @inheritdoc */ always: function (e) { - if (e) { - e.stopImmediatePropagation(); - } + e.stopImmediatePropagation(); } } }); diff --git a/app/code/Magento/Ui/view/base/web/js/modal/modal.js b/app/code/Magento/Ui/view/base/web/js/modal/modal.js index b72e7bc49f2f0..5a96184294571 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/modal.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/modal.js @@ -105,10 +105,10 @@ define([ * Escape key press handler, * close modal window */ - escapeKey: function () { + escapeKey: function (event) { if (this.options.isOpen && this.modal.find(document.activeElement).length || this.options.isOpen && this.modal[0] === document.activeElement) { - this.closeModal(); + this.closeModal(event); } } } @@ -177,7 +177,7 @@ define([ var key = keyCodes[event.keyCode]; if (this.options.keyEventHandlers.hasOwnProperty(key)) { - this.options.keyEventHandlers[key].apply(this, arguments); + this.options.keyEventHandlers[key].apply(this, arguments, event); } }, From 633ea172803d6d81b823f8791226bf1d0e516957 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Tue, 3 Dec 2019 23:26:05 +0530 Subject: [PATCH 09/16] Added missing parameter description --- app/code/Magento/Ui/view/base/web/js/modal/modal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/modal.js b/app/code/Magento/Ui/view/base/web/js/modal/modal.js index 5a96184294571..49abbb5c7d0b0 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/modal.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/modal.js @@ -104,6 +104,7 @@ define([ /** * Escape key press handler, * close modal window + * @param {Object} event - event */ escapeKey: function (event) { if (this.options.isOpen && this.modal.find(document.activeElement).length || From 997959f2f081f844b798ccae31cc54fa0833ca60 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Tue, 17 Dec 2019 20:48:02 +0530 Subject: [PATCH 10/16] Fixed prompt issue with latest updates --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 151ce2e4efca2..9e5df49e6e8b3 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -154,8 +154,7 @@ define([ */ closeModal: function (result) { var value; - - if (result) { + if (result && !(result instanceof $.Event)) { if (this.options.validation && !this.validate()) { return false; } From 65b2afeeea0801291a924eb64618650faa8d2e93 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sun, 26 Jan 2020 11:14:54 +0530 Subject: [PATCH 11/16] Feedback changes --- app/code/Magento/Ui/view/base/web/js/modal/modal.js | 4 ++-- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/modal.js b/app/code/Magento/Ui/view/base/web/js/modal/modal.js index fcfb86877663c..79dee43ada257 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/modal.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/modal.js @@ -182,7 +182,7 @@ define([ var key = keyCodes[event.keyCode]; if (this.options.keyEventHandlers.hasOwnProperty(key)) { - this.options.keyEventHandlers[key].apply(this, arguments, event); + this.options.keyEventHandlers[key].apply(this, arguments); } }, @@ -308,7 +308,7 @@ define([ * Close modal. * * @return {Element} - current element. */ - closeModal: function () { + closeModal: function (event, result) { var that = this; this._removeKeyListener(); diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 9e5df49e6e8b3..3b0485903424b 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -51,8 +51,8 @@ define([ /** * Click handler. */ - click: function () { - this.closeModal(); + click: function (event) { + this.closeModal(event); } }, { text: $.mage.__('OK'), @@ -61,8 +61,8 @@ define([ /** * Click handler. */ - click: function () { - this.closeModal(true); + click: function (event) { + this.closeModal(event); } }] }, @@ -152,7 +152,7 @@ define([ /** * Close modal window */ - closeModal: function (result) { + closeModal: function (event, result) { var value; if (result && !(result instanceof $.Event)) { if (this.options.validation && !this.validate()) { From b41ea13a925eda843277dc9960071f00207b329e Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sat, 8 Feb 2020 00:17:32 +0530 Subject: [PATCH 12/16] Feedback changes --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 3b0485903424b..f681eb28aca9e 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -62,7 +62,7 @@ define([ * Click handler. */ click: function (event) { - this.closeModal(event); + this.closeModal(event, true); } }] }, @@ -75,7 +75,7 @@ define([ this.options.validation = this.options.validation && this.options.validationRules.length; this._super(); this.modal.find(this.options.modalContent).append(this.getFormTemplate()); - this.modal.find(this.options.modalCloseBtn).off().on('click', _.bind(this.closeModal, this, false)); + this.modal.find(this.options.modalCloseBtn).off().on('click', _.bind(this.closeModal, this)); if (this.options.validation) { this.setValidationClasses(); @@ -154,7 +154,9 @@ define([ */ closeModal: function (event, result) { var value; - if (result && !(result instanceof $.Event)) { + result = result || false; + + if (result) { if (this.options.validation && !this.validate()) { return false; } From 552eaafd5029a982c5243670e71d618467602319 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sat, 8 Feb 2020 00:24:05 +0530 Subject: [PATCH 13/16] event is used in the closeModal body --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index f681eb28aca9e..740b4e5ef0b87 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -162,9 +162,9 @@ define([ } value = this.modal.find(this.options.promptField).val(); - this.options.actions.confirm.call(this, value); + this.options.actions.confirm.call(event, value); } else { - this.options.actions.cancel.call(this, result); + this.options.actions.cancel.call(event, result); } this.options.actions.always(); From ce6614ef0e813e2d2ae8226c715d8d0a5cfb4d1a Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sat, 8 Feb 2020 00:44:34 +0530 Subject: [PATCH 14/16] event is passed to the always method --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 740b4e5ef0b87..098951af2f175 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -167,7 +167,7 @@ define([ this.options.actions.cancel.call(event, result); } - this.options.actions.always(); + this.options.actions.always(event); this.element.bind('promptclosed', _.bind(this._remove, this)); return this._super(); From b1ab6a97c8354b3ef1c80aac379140fe356898e4 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Tue, 18 Feb 2020 14:32:01 +0200 Subject: [PATCH 15/16] static test fix --- app/code/Magento/Ui/view/base/web/js/modal/modal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/modal.js b/app/code/Magento/Ui/view/base/web/js/modal/modal.js index c15fd156af803..2e797a09d225f 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/modal.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/modal.js @@ -308,7 +308,7 @@ define([ * Close modal. * * @return {Element} - current element. */ - closeModal: function (event, result) { + closeModal: function (event, result) {//eslint-disable-line no-unused-vars var that = this; this._removeKeyListener(); From 437fab3b783eb68460d283214f41f6b9d9fcb49f Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Tue, 18 Feb 2020 14:36:32 +0200 Subject: [PATCH 16/16] static test fix --- app/code/Magento/Ui/view/base/web/js/modal/prompt.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 098951af2f175..d5a8654249612 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -154,6 +154,7 @@ define([ */ closeModal: function (event, result) { var value; + result = result || false; if (result) {