From fb7fa04e3b173e12fd152435472f3ef5a915d0df Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 31 Aug 2017 17:17:54 +0800 Subject: [PATCH] MDL-59759 core_calendar: Use SAVE_CANCEL modal for delete dialog * Plus reorganise the code to make it a little tidier. --- calendar/amd/build/summary_modal.min.js | Bin 2130 -> 2241 bytes calendar/amd/src/summary_modal.js | 66 +++++++++++++++--------- calendar/tests/behat/calendar.feature | 2 +- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/calendar/amd/build/summary_modal.min.js b/calendar/amd/build/summary_modal.min.js index 358bad067ad394052b3e754687b0c2f366f8569b..0a9f53a95bbb873988d0df2cdcb370391321b7e6 100644 GIT binary patch delta 596 zcmZut%W4!s6s6}8f)G)H7!hLINT`BJnJk^87fBdF5F^PTXbhpI>-J33-BnHX?Ma52 zW`4kh+92Y>pKvRPzmPxh2VA&vY4wb8<>qqgaL&DT&gG5oH{br8g@p<*(#nmAWI!h) zVcgI^nZz*ecoGsofDtJ4SfJBPD+@bbAQDhg7_VdtVW3qQnRKpPnEtP4nJ^;lKzYhy zU-ALm!*0F(i6oRIe%~^9mZOQ(ASWSZY4x?WcKvwoMfdDr@7Y23X~|^uqqREQ5&V1z ziX<$h9BXtHg!Jne2Cy*71)c-;B20kvPqt1en-lw5j_rH<>U}ImuwNi*)q@NCr?h`L z(i#cnT9F~ot&07!K6?{x(bB{hm6iDx3#)ewxp3&c)?jns2UK{Gqw)ru^veut&K-G{lnv#U{uIHw%+^v}CIK)qHFXk6NBJ zyl%a6SasR1nLA7Fa!ha-6T(c>*C{rcf F`2&wg%8vj5 delta 502 zcmZ8eO-my|5M@jemkJt73y{h`L`uySk@6s^T&0cG3-_Ocl3lk?V z&uZJIs;WNLb~bX>*9sMm`oOr71?mAurCYh5m%nR6Co9kEO{2)`6NCTMt$L+#VEM+T z!MzH9ukg>tso|Gh&+z;1H#e~ENqOh2&yFrXp0=+praq>kU|qmt$N=GRfT$#)lwk^z zBm>D&7$Tx$4LH!U8QJD5rI1i&9#S@f!hh|fV`~w$UVc3pg2Z-AXdqZzIaCaBqVmha z?qzgM=K)d?1EEtE2^kYBrnKYn5P9ld6VBk4L*E8@+u}!W6hV3C+JVm->m3xBfk%Vn z-5{KfIV%7URXifqEH`GwLUxH~ww(x_gN;1T>iLG$aKpn4WE^VG4=J5K{c~r|T5mET f3DeLO1%f6y`~3COiMi3k;?9ye@E-N^DGmMuOdzUn diff --git a/calendar/amd/src/summary_modal.js b/calendar/amd/src/summary_modal.js index 4a668bea679..da138c3101c 100644 --- a/calendar/amd/src/summary_modal.js +++ b/calendar/amd/src/summary_modal.js @@ -118,33 +118,11 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even // Apply parent event listeners. Modal.prototype.registerEventListeners.call(this); - var confirmPromise = ModalFactory.create( - { - type: ModalFactory.types.CONFIRM - }, - this.getDeleteButton() - ).then(function(modal) { - modal.getRoot().on(ModalEvents.yes, function() { - var eventId = this.getEventId(); - - CalendarRepository.deleteEvent(eventId) - .then(function() { - $('body').trigger(CalendarEvents.deleted, [eventId]); - this.hide(); - }.bind(this)) - .catch(Notification.exception); - }.bind(this)); - - return modal; - }.bind(this)); - // We have to wait for the modal to finish rendering in order to ensure that // the data-event-title property is available to use as the modal title. this.getRoot().on(ModalEvents.bodyRendered, function() { var eventTitle = this.getBody().find(SELECTORS.ROOT).attr('data-event-title'); - confirmPromise.then(function(modal) { - modal.setBody(Str.get_string('confirmeventdelete', 'core_calendar', eventTitle)); - }); + prepareDeleteAction(this, eventTitle); }.bind(this)); CustomEvents.define(this.getEditButton(), [ @@ -173,6 +151,48 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even }.bind(this)); }; + /** + * Prepares the action for the summary modal's delete action. + * + * @param {ModalEventSummary} summaryModal The summary modal instance. + * @param {string} eventTitle The event title. + */ + function prepareDeleteAction(summaryModal, eventTitle) { + var deleteStrings = [ + { + key: 'deleteevent', + component: 'calendar' + }, + { + key: 'confirmeventdelete', + component: 'calendar', + param: eventTitle + } + ]; + var eventId = summaryModal.getEventId(); + var stringsPromise = Str.get_strings(deleteStrings); + var deletePromise = ModalFactory.create( + { + type: ModalFactory.types.SAVE_CANCEL + }, + summaryModal.getDeleteButton() + ); + + $.when(stringsPromise, deletePromise).then(function(strings, deleteModal) { + deleteModal.setTitle(strings[0]); + deleteModal.setBody(strings[1]); + deleteModal.setSaveButtonText(strings[0]); + deleteModal.getRoot().on(ModalEvents.save, function() { + CalendarRepository.deleteEvent(eventId).then(function() { + $('body').trigger(CalendarEvents.deleted, [eventId]); + summaryModal.hide(); + return; + }).catch(Notification.exception); + }); + return deleteModal; + }).fail(Notification.exception); + } + // Automatically register with the modal registry the first time this module is imported so that you can create modals // of this type using the modal factory. if (!registered) { diff --git a/calendar/tests/behat/calendar.feature b/calendar/tests/behat/calendar.feature index 5f2cf5e26c2..45e964f60f1 100644 --- a/calendar/tests/behat/calendar.feature +++ b/calendar/tests/behat/calendar.feature @@ -104,7 +104,7 @@ Feature: Perform basic calendar functionality When I follow "This month" And I click on "Really awesome event!" "link" And I click on "Delete" "button" - And I click on "Yes" "button" + And I click on "Delete event" "button" And I wait to be redirected Then I should not see "Really awesome event!" -- 2.43.0