Widget:Duty officer powers

This widget provides a user-friendly solution for displaying duty officer common powers when using Form:Duty officer.

It will not function correctly on other pages.

Using this widget
It takes no parameters and is used as follows:. It is, however, only designed for use on Form:Duty officer.         </li> </li> </li> </li> </li> </li> </ol> <script type="text/javascript"> /* Attaches the function that attempts to retrieve the appropriate common powers to the change event of the appropriate form fields. */ function attachPowerInputEvents { attachPowerEventsToInput( 'Doffpage[spec]' ); }

/* Attaches the function that attempts to retrieve the appropriate common powers to the form input elements having the given name. */ function attachPowerEventsToInput( name ) { inputs = document.getElementsByName( name );

for ( var i = 0; i < inputs.length; ++i ) {   inputs[i].addEventListener( 'change', getCommonPowers, false ); } }

/* Updates the power list. */ function getCommonPowers( e ) { var spec = getSpec;

for ( var i = 1; i < 14; ++i ) {   var target = document.getElementById( 'doff-common-power-' + i ); if ( spec != "" ) {     var source = document.getElementById( 'doff-common-power-' + spec + i ); if ( source !== null && source !== target ) target.innerHTML = source.innerHTML; else target.innerHTML = ''; }   else target.innerHTML = '';

if ( target.innerHTML != '' ) target.style.display = ''; else target.style.display = 'none'; } }

/* Gets the specialization name in the specialization input. */ function getSpec { return document.getElementsByName( 'Doffpage[spec]' )[0].value.replace(/ /g, '-'); }

RLQ.push( function { $(document).ready( attachPowerInputEvents );  $(document).ready( getCommonPowers ); } );