Index: trunk/phase3/includes/Xml.php |
— | — | @@ -309,7 +309,7 @@ |
310 | 310 | 'type' => 'hidden', |
311 | 311 | 'value' => $value ) + $attribs ); |
312 | 312 | } |
313 | | - |
| 313 | + |
314 | 314 | /** |
315 | 315 | * Convenience function to build an HTML drop-down list item. |
316 | 316 | * @param $text String: text for this item |
— | — | @@ -330,6 +330,51 @@ |
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
| 334 | + * Build a drop-down box for selecting a reason for an action |
| 335 | + * |
| 336 | + * @param mixed $other Text for the "Other reasons" option |
| 337 | + * @param mixed $list Correctly formatted text to be used to generate the options |
| 338 | + * @param mixed $selected Option which should be pre-selected |
| 339 | + * @return string |
| 340 | + */ |
| 341 | + public static function reasonDropDown( $other = '', $list = '', $selected = '' ) { |
| 342 | + $options = ''; |
| 343 | + $optgroup = false; |
| 344 | + |
| 345 | + $options = self::option( $other, 'other', $selected === 'other' ); |
| 346 | + |
| 347 | + foreach ( explode( "\n", $list ) as $option) { |
| 348 | + $value = trim( htmlspecialchars($option) ); |
| 349 | + if ( $value == '' ) { |
| 350 | + continue; |
| 351 | + } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) { |
| 352 | + // A new group is starting ... |
| 353 | + $value = trim( substr( $value, 1 ) ); |
| 354 | + if( $optgroup ) $options .= self::closeElement('optgroup'); |
| 355 | + $options .= self::openElement( 'optgroup', array( 'label' => $value ) ); |
| 356 | + $optgroup = true; |
| 357 | + } elseif ( substr( $value, 0, 2) == '**' ) { |
| 358 | + // groupmember |
| 359 | + $value = trim( substr( $value, 2 ) ); |
| 360 | + $options .= self::option( $value, $value, $selected === $value ); |
| 361 | + } else { |
| 362 | + // groupless reason list |
| 363 | + if( $optgroup ) $options .= self::closeElement('optgroup'); |
| 364 | + $options .= self::option( $value, $value, $selected === $value ); |
| 365 | + $optgroup = false; |
| 366 | + } |
| 367 | + } |
| 368 | + if( $optgroup ) $options .= self::closeElement('optgroup'); |
| 369 | + |
| 370 | + return Xml::openElement( 'select', array( 'id' => 'wpReasonDropDown', 'name' => 'wpReasonDropDown', |
| 371 | + 'class' => 'wpReasonDropDown' ) ) |
| 372 | + . "\n" |
| 373 | + . $options |
| 374 | + . "\n" |
| 375 | + . Xml::closeElement( 'select' ); |
| 376 | + } |
| 377 | + |
| 378 | + /** |
334 | 379 | * Returns an escaped string suitable for inclusion in a string literal |
335 | 380 | * for JavaScript source code. |
336 | 381 | * Illegal control characters are assumed not to be present. |