Merge "docs: Fix Doxygen parsing of @var descriptions with $var names"
[lhc/web/wiklou.git] / resources / src / mediawiki.special.block.js
index 58657db..d1bada0 100644 (file)
                        pageRestrictionsWidget, namespaceRestrictionsWidget, createAccountWidget, data,
                        enablePartialBlocks, blockAllowsUTEdit, userChangedCreateAccount, updatingBlockOptions;
 
+               function preserveSelectedStateOnDisable( widget ) {
+                       var widgetWasSelected;
+
+                       if ( !widget ) {
+                               return;
+                       }
+
+                       // 'disable' event fires if disabled state changes
+                       widget.on( 'disable', function ( disabled ) {
+                               if ( disabled ) {
+                                       // Disabling an enabled widget
+                                       // Save selected and set selected to false
+                                       widgetWasSelected = widget.isSelected();
+                                       widget.setSelected( false );
+                               } else {
+                                       // Enabling a disabled widget
+                                       // Set selected to the saved value
+                                       if ( widgetWasSelected !== undefined ) {
+                                               widget.setSelected( widgetWasSelected );
+                                       }
+                                       widgetWasSelected = undefined;
+                               }
+                       } );
+               }
+
                function updateBlockOptions() {
                        var blocktarget = blockTargetWidget.getValue().trim(),
                                isEmpty = blocktarget === '',
                                isSitewide = editingIsSelected && editingRestrictionValue === 'sitewide';
 
                        enableAutoblockWidget.setDisabled( isNonEmptyIp );
-                       if ( enableAutoblockWidget.isDisabled() ) {
-                               enableAutoblockWidget.setSelected( false );
-                       }
 
                        anonOnlyWidget.setDisabled( !isIp && !isEmpty );
-                       if ( anonOnlyWidget.isDisabled() ) {
-                               anonOnlyWidget.setSelected( false );
-                       }
 
                        if ( hideUserWidget ) {
                                hideUserWidget.setDisabled( isNonEmptyIp || !isIndefinite || !isSitewide );
-                               if ( hideUserWidget.isDisabled() ) {
-                                       hideUserWidget.setSelected( false );
-                               }
                        }
 
                        if ( watchUserWidget ) {
                                watchUserWidget.setDisabled( isIpRange && !isEmpty );
-                               if ( watchUserWidget.isDisabled() ) {
-                                       watchUserWidget.setSelected( false );
-                               }
                        }
 
                        if ( enablePartialBlocks ) {
                                pageRestrictionsWidget.setDisabled( !editingIsSelected || isSitewide );
                                namespaceRestrictionsWidget.setDisabled( !editingIsSelected || isSitewide );
                                if ( blockAllowsUTEdit ) {
-                                       // This option is disabled for partial blocks unless a namespace restriction
-                                       // for the User_talk namespace is in place.
+                                       // Disable for partial blocks, unless the block is against the User_talk namespace
                                        preventTalkPageEditWidget.setDisabled(
-                                               editingIsSelected &&
-                                               editingRestrictionValue === 'partial' &&
-                                               namespaceRestrictionsWidget.getValue().indexOf(
-                                                       String( mw.config.get( 'wgNamespaceIds' ).user_talk )
-                                               ) === -1
+                                               // Partial block that doesn't block editing
+                                               !editingIsSelected ||
+                                               // Partial block that blocks editing and doesn't block the User_talk namespace
+                                               (
+                                                       editingRestrictionValue === 'partial' &&
+                                                       namespaceRestrictionsWidget.getValue().indexOf(
+                                                               String( mw.config.get( 'wgNamespaceIds' ).user_talk )
+                                                       ) === -1
+                                               )
                                        );
                                }
                        }
                                preventTalkPageEditWidget = infuseIfExists( $( '#mw-input-wpDisableUTEdit' ) );
                        }
 
+                       // When disabling checkboxes, preserve their selected state in case they are re-enabled
+                       preserveSelectedStateOnDisable( enableAutoblockWidget );
+                       preserveSelectedStateOnDisable( anonOnlyWidget );
+                       preserveSelectedStateOnDisable( watchUserWidget );
+                       preserveSelectedStateOnDisable( hideUserWidget );
+                       preserveSelectedStateOnDisable( preventTalkPageEditWidget );
+
                        updateBlockOptions();
                }
        } );