jenkins-bot has submitted this change and it was merged.

Change subject: Deleting collection: hide dialog when finished, toast on refresh
......................................................................


Deleting collection: hide dialog when finished, toast on refresh

Don't hide spinner, hide DeleteOverlay when done and the page redirected. Show
toast with message after the page redirected.

Added module to deal with "future" toasts (like the future event logging
stuff). Alerts are cleared when ext.gather.init (article page) or when
ext.gather.special (Special:Gather).

Bug: T96294
Change-Id: I1264feb441e3d99fca98e8e5dce2af9484b06895
---
M resources/Resources.php
A resources/ext.gather.alerts/futureToasts.js
A resources/ext.gather.alerts/init.js
M resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
M resources/ext.gather.collection.editor/CollectionEditOverlay.js
5 files changed, 82 insertions(+), 7 deletions(-)

Approvals:
  Jdlrobson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/Resources.php b/resources/Resources.php
index bd9b9a8..8d739fc 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -197,6 +197,7 @@
 
        'ext.gather.init' => $wgGatherResourceFileModuleBoilerplate + array(
                'dependencies' => array(
+                       'ext.gather.alerts.init',
                        'ext.gather.watchstar',
                ),
                'messages' => array(
@@ -265,10 +266,30 @@
                ),
        ),
 
+       'ext.gather.alerts.futureToasts' => 
$wgGatherResourceFileModuleBoilerplate + array(
+               'dependencies' => array(
+                       'mobile.settings',
+                       'mobile.toast',
+               ),
+               'scripts' => array(
+                       'ext.gather.alerts/futureToasts.js',
+               ),
+       ),
+
+       'ext.gather.alerts.init' => $wgGatherResourceFileModuleBoilerplate + 
array(
+               'dependencies' => array(
+                       'ext.gather.alerts.futureToasts',
+               ),
+               'scripts' => array(
+                       'ext.gather.alerts/init.js',
+               ),
+       ),
+
        'ext.gather.collection.delete' => 
$wgGatherResourceFileModuleBoilerplate + array(
                'dependencies' => array(
                        'ext.gather.collection.confirm',
                        'mobile.toast',
+                       'ext.gather.alerts.futureToasts',
                        'ext.gather.api',
                        'mediawiki.util'
                ),
@@ -314,6 +335,7 @@
 
        'ext.gather.special' => $wgGatherMobileSpecialPageResourceBoilerplate + 
array(
                'dependencies' => array(
+                       'ext.gather.alerts.init',
                        'ext.gather.collection.editor',
                        'ext.gather.routes',
                        'ext.gather.collection.flag',
diff --git a/resources/ext.gather.alerts/futureToasts.js 
b/resources/ext.gather.alerts/futureToasts.js
new file mode 100644
index 0000000..f818a04
--- /dev/null
+++ b/resources/ext.gather.alerts/futureToasts.js
@@ -0,0 +1,45 @@
+( function ( M, $ ) {
+
+       var settings = M.require( 'settings' ),
+               toast = M.require( 'toast' ),
+               key = 'future-toasts';
+
+       /**
+        * Get the future toasts to show
+        * @return {Array}
+        */
+       function getToasts() {
+               try {
+                       return JSON.parse( settings.get( key ) ) || [];
+               } catch ( e ) {
+                       return [];
+               }
+       }
+
+       /**
+        * Schedule an alert for the future.
+        * @param {String} msg to show
+        * @param {String} className class to add to element
+        */
+       function addFutureToast( msg, className ) {
+               var toasts = getToasts();
+               toasts.push( [ msg, className ] );
+               settings.save( key, JSON.stringify( toasts ) );
+       }
+
+       /**
+        * Show all pending toasts and clear the queue
+        */
+       function showFutureToasts() {
+               $.each( getToasts(), function ( i, t ) {
+                       toast.show( t[0], t[1] );
+               } );
+               settings.remove( key );
+       }
+
+       M.define( 'ext.gather.alerts/futureToasts', {
+               add: addFutureToast,
+               show: showFutureToasts
+       } );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/ext.gather.alerts/init.js 
b/resources/ext.gather.alerts/init.js
new file mode 100644
index 0000000..b99413e
--- /dev/null
+++ b/resources/ext.gather.alerts/init.js
@@ -0,0 +1,7 @@
+( function ( M ) {
+
+       var futureToasts = M.require( 'ext.gather.alerts/futureToasts' );
+
+       futureToasts.show();
+
+}( mw.mobileFrontend ) );
diff --git a/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js 
b/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
index 95f5703..28e8f2c 100644
--- a/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
+++ b/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
@@ -4,6 +4,7 @@
                SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
                schema = new SchemaGather(),
                toast = M.require( 'toast' ),
+               futureToasts = M.require( 'ext.gather.alerts/futureToasts' ),
                CollectionsApi = M.require( 
'ext.gather.watchstar/CollectionsApi' ),
                ConfirmationOverlay = M.require( 
'ext.gather.confirm/ConfirmationOverlay' );
 
@@ -41,17 +42,16 @@
                        // disable button and inputs
                        this.$( '.confirm, .cancel' ).prop( 'disabled', true );
                        this.api.removeCollection( this.id ).done( function () {
-                               // Show toast
-                               self.$( '.spinner' ).hide();
-                               toast.show( self.options.deleteSuccessMsg, 
'toast' );
-
                                schema.log( {
                                        eventName: 'delete-collection'
                                } ).always( function () {
+                                       self.$( '.spinner' ).hide();
+                                       // Show toast after reloading
+                                       futureToasts.add( 
self.options.deleteSuccessMsg, 'toast' );
+                                       self.hide();
                                        // Go to the collections list page as 
collection will no longer exist
                                        window.location.href = mw.util.getUrl( 
'Special:Gather' );
                                } );
-
                        } ).fail( function ( errMsg ) {
                                toast.show( self.options.deleteFailedError, 
'toast error' );
                                self.hide();
diff --git a/resources/ext.gather.collection.editor/CollectionEditOverlay.js 
b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
index ac169ef..89e9fa4 100644
--- a/resources/ext.gather.collection.editor/CollectionEditOverlay.js
+++ b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
@@ -179,9 +179,10 @@
                 * Event handler when the delete button is clicked.
                 */
                onDeleteActionClick: function () {
-                       this.$el.append( new CollectionDeleteOverlay( {
+                       var deleteOverlay = new CollectionDeleteOverlay( {
                                collection: this.options.collection
-                       } ).$el );
+                       } );
+                       this.$el.append( deleteOverlay.$el );
                },
                /**
                 * Event handler when the back button is clicked on the 
title/edit description pane.

-- 
To view, visit https://gerrit.wikimedia.org/r/205836
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1264feb441e3d99fca98e8e5dce2af9484b06895
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <jhernan...@wikimedia.org>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Jhernandez <jhernan...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to