Enable/disable Special:Block widgets according to block parameters
authorThalia <thalia.e.chan@googlemail.com>
Tue, 2 Apr 2019 14:52:23 +0000 (15:52 +0100)
committerThalia <thalia.e.chan@googlemail.com>
Fri, 5 Apr 2019 14:41:16 +0000 (15:41 +0100)
Different block options are available depending on the block parameters
currently enetered in the form at a given time. Use enable/disable for
these options instead of hide/show, and uncheck any disabled options.

Bug: T212391
Change-Id: Ie715ae570641ad0af4008b9aa7f9ed8f2cda8fb8

resources/src/mediawiki.special.block.js

index 1767411..58657db 100644 (file)
@@ -11,8 +11,8 @@
        }
 
        $( function () {
-               var blockTargetWidget, anonOnlyField, enableAutoblockField, hideUserWidget, hideUserField,
-                       watchUserField, expiryWidget, editingWidget, editingRestrictionWidget, preventTalkPageEditWidget,
+               var blockTargetWidget, anonOnlyWidget, enableAutoblockWidget, hideUserWidget, watchUserWidget,
+                       expiryWidget, editingWidget, editingRestrictionWidget, preventTalkPageEditWidget,
                        pageRestrictionsWidget, namespaceRestrictionsWidget, createAccountWidget, data,
                        enablePartialBlocks, blockAllowsUTEdit, userChangedCreateAccount, updatingBlockOptions;
 
                                editingIsSelected = editingWidget.isSelected(),
                                isSitewide = editingIsSelected && editingRestrictionValue === 'sitewide';
 
-                       enableAutoblockField.toggle( !isNonEmptyIp );
-                       anonOnlyField.toggle( isIp || isEmpty );
+                       enableAutoblockWidget.setDisabled( isNonEmptyIp );
+                       if ( enableAutoblockWidget.isDisabled() ) {
+                               enableAutoblockWidget.setSelected( false );
+                       }
+
+                       anonOnlyWidget.setDisabled( !isIp && !isEmpty );
+                       if ( anonOnlyWidget.isDisabled() ) {
+                               anonOnlyWidget.setSelected( false );
+                       }
 
-                       if ( hideUserField ) {
-                               hideUserField.toggle( !isNonEmptyIp && isIndefinite && isSitewide );
-                               if ( !hideUserField.isVisible() ) {
+                       if ( hideUserWidget ) {
+                               hideUserWidget.setDisabled( isNonEmptyIp || !isIndefinite || !isSitewide );
+                               if ( hideUserWidget.isDisabled() ) {
                                        hideUserWidget.setSelected( false );
                                }
                        }
 
-                       if ( watchUserField ) {
-                               watchUserField.toggle( !isIpRange || isEmpty );
+                       if ( watchUserWidget ) {
+                               watchUserWidget.setDisabled( isIpRange && !isEmpty );
+                               if ( watchUserWidget.isDisabled() ) {
+                                       watchUserWidget.setSelected( false );
+                               }
                        }
 
                        if ( enablePartialBlocks ) {
@@ -84,8 +94,8 @@
                        editingWidget = OO.ui.infuse( $( '#mw-input-wpEditing' ) );
                        expiryWidget = OO.ui.infuse( $( '#mw-input-wpExpiry' ) );
                        createAccountWidget = OO.ui.infuse( $( '#mw-input-wpCreateAccount' ) );
-                       enableAutoblockField = OO.ui.infuse( $( '#mw-input-wpAutoBlock' ).closest( '.oo-ui-fieldLayout' ) );
-                       anonOnlyField = OO.ui.infuse( $( '#mw-input-wpHardBlock' ).closest( '.oo-ui-fieldLayout' ) );
+                       enableAutoblockWidget = OO.ui.infuse( $( '#mw-input-wpAutoBlock' ) );
+                       anonOnlyWidget = OO.ui.infuse( $( '#mw-input-wpHardBlock' ) );
                        blockTargetWidget.on( 'change', updateBlockOptions );
                        editingWidget.on( 'change', updateBlockOptions );
                        expiryWidget.on( 'change', updateBlockOptions );
                        } );
 
                        // Present for certain rights
-                       watchUserField = infuseIfExists( $( '#mw-input-wpWatch' ).closest( '.oo-ui-fieldLayout' ) );
-                       hideUserField = infuseIfExists( $( '#mw-input-wpHideUser' ).closest( '.oo-ui-fieldLayout' ) );
+                       watchUserWidget = infuseIfExists( $( '#mw-input-wpWatch' ) );
                        hideUserWidget = infuseIfExists( $( '#mw-input-wpHideUser' ) );
 
                        // Present for certain global configs