From: Aaron Schulz Date: Thu, 15 Mar 2007 02:52:28 +0000 (+0000) Subject: *Add nifty JS function to grey out cascade option when it will not apply X-Git-Tag: 1.31.0-rc.0~53722 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=11ef493f49931a22ca6149ffdd7121fa57cda9ac;p=lhc%2Fweb%2Fwiklou.git *Add nifty JS function to grey out cascade option when it will not apply --- diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 9ebacd8340..662b1df779 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -323,8 +323,17 @@ class ProtectionForm { } function buildCleanupScript() { - return ''; + global $wgRestrictionLevels, $wgGroupPermissions; + $script = 'var wgCascadeableLevels='; + $CascadeableLevels = array(); + foreach( $wgRestrictionLevels as $key ) { + if ( isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect'] ) { + $CascadeableLevels[]="'" . wfEscapeJsString($key) . "'"; + } + } + $script .= "[" . implode(',',$CascadeableLevels) . "];\n"; + $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")'; + return ''; } /** diff --git a/skins/common/protect.js b/skins/common/protect.js index 8968607371..f10c810a16 100644 --- a/skins/common/protect.js +++ b/skins/common/protect.js @@ -33,16 +33,36 @@ function protectInitialize(tableId, labelText) { check.checked = true; protectEnable(true); } + + allowCascade(); return true; } return false; } +function allowCascade() { + var pr_types = document.getElementsByTagName("select"); + for (var i = 0; i < pr_types.length; i++) { + if (pr_types[i].id.match(/^mwProtect-level-/)) { + var selected_level = pr_types[i].getElementsByTagName("option")[pr_types[i].selectedIndex].value; + for (var k=0; k < wgCascadeableLevels.length; k++) { + if ( wgCascadeableLevels[k] != selected_level ) { + document.getElementById('mwProtect-cascade').disabled=true; + return false; + } + } + } + } + document.getElementById('mwProtect-cascade').disabled=false; + return true; +} + function protectLevelsUpdate(source) { if (!protectUnchained()) { protectUpdateAll(source.selectedIndex); } + allowCascade(); } function protectChainUpdate() {