Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204002

Change subject: Untested refactor of JS code to hide / show collections
......................................................................

Untested refactor of JS code to hide / show collections

* Combine showCollection / hideCollection in a single method, setVisible. This
  makes the interface consistent with setPrivacy.

Change-Id: Ifb508f155a358eff06cd1fd3fff534412fc651bb
---
M resources/ext.gather.lists/init.js
M resources/ext.gather.watchstar/CollectionsApi.js
2 files changed, 16 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather 
refs/changes/02/204002/1

diff --git a/resources/ext.gather.lists/init.js 
b/resources/ext.gather.lists/init.js
index e319d11..8ee836c 100644
--- a/resources/ext.gather.lists/init.js
+++ b/resources/ext.gather.lists/init.js
@@ -15,34 +15,18 @@
         * @param {jQuery.Event} ev
         */
        function onModerateCollection( ev ) {
-               var $btn = $( ev.currentTarget ),
-                       $row = $btn.closest( 'li' ),
-                       id = $btn.data( 'id' ),
-                       label = $btn.data( 'label' ),
-                       owner = $btn.data( 'owner' ),
-                       action = $btn.data( 'action' ),
-                       msgKey = action === 'hide' ? 
'gather-lists-hide-collection' : 'gather-lists-show-collection',
-                       message = mw.msg( msgKey, label, owner );
+               var $button = $( ev.currentTarget ),
+                       data = $button.data(),
+                       key = 'gather-lists-' + data.action + '-collection';
 
-               if ( action === 'hide' && window.confirm( message ) ) {
-                       api.hideCollection( id ).done( function () {
-                               $row.fadeOut( function () {
-                                       $row.remove();
-                                       toast.show( mw.msg( 
'gather-lists-hide-success-toast', label ), 'toast' );
-                               } );
-                       } ).fail( function () {
-                               toast.show( mw.msg( 
'gather-lists-hide-failure-toast', label ), 'toast fail' );
-                       } );
-               }
-
-               if ( action === 'show' && window.confirm( message ) ) {
-                       api.showCollection( id ).done( function () {
-                               $row.fadeOut( function () {
-                                       $row.remove();
-                                       toast.show( mw.msg( 
'gather-lists-show-success-toast', label ), 'toast' );
-                               } );
-                       } ).fail( function () {
-                               toast.show( mw.msg( 
'gather-lists-show-failure-toast', label ), 'toast fail' );
+               if ( confirm( mw.msg( key, data.label, data.owner ) ) ) {
+                       api.setVisible( data.id, data.action === 'show' ).then( 
function () {
+                               $button.closest( 'li' ).remove();
+                               key = 'gather-lists-' + data.action + 
'-success-toast';
+                               toast.show( mw.msg( key, data.label ), 'toast' 
);
+                       }, function () {
+                               key = 'gather-lists-' + data.action + 
'-failure-toast';
+                               toast.show( mw.msg( key, data.label ), 'toast 
fail' );
                        } );
                }
        }
diff --git a/resources/ext.gather.watchstar/CollectionsApi.js 
b/resources/ext.gather.watchstar/CollectionsApi.js
index f9c2f31..1c0c558 100644
--- a/resources/ext.gather.watchstar/CollectionsApi.js
+++ b/resources/ext.gather.watchstar/CollectionsApi.js
@@ -145,7 +145,7 @@
                 * @param {Boolean} isPrivate private or not
                 * @return {jQuery.Deferred}
                 */
-               setPrivacy: function ( id, isPrivate ) {
+               setPrivate: function ( id, isPrivate ) {
                        return this.postWithToken( 'watch', {
                                action: 'editlist',
                                id: id,
@@ -153,29 +153,17 @@
                        } );
                },
                /**
-                * Hide list (moderation purposes)
+                * Show or hide a list (for moderation purposes)
                 * @method
                 * @param {Number} id unique identifier of collection
                 * @return {jQuery.Deferred}
                 */
-               hideCollection: function ( id ) {
+               setVisibile: function ( id, isVisible ) {
+                       var mode = isVisible ? 'showlist' : 'hidelist';
                        return this.postWithToken( 'watch', {
                                action: 'editlist',
                                id: id,
-                               mode: 'hidelist'
-                       } );
-               },
-               /**
-                * Show list (moderation purposes)
-                * @method
-                * @param {Number} id unique identifier of collection
-                * @return {jQuery.Deferred}
-                */
-               showCollection: function ( id ) {
-                       return this.postWithToken( 'watch', {
-                               action: 'editlist',
-                               id: id,
-                               mode: 'showlist'
+                               mode: isVisible ? 'showlist' : 'hidelist'
                        } );
                }
        } );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb508f155a358eff06cd1fd3fff534412fc651bb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to