Source

webwork / src / java / template / archive / simple / doubleselect.vm

`#parse("/$parameters.templateDir/simple/select.vm")
#set ( $startCount = 0)
#if ($parameters.headerKey && $parameters.headerValue)
    #set ( $startCount = $startCount + 1)
#end
#if ($parameters.emptyOption)
    #set ( $startCount = $startCount + 1)
#end

<br/>
<select name="$!webwork.htmlEncode($parameters.doubleName)"
    #if ($parameters.disabled)         disabled="disabled"                                         #end
    #if ($parameters.doubleTabindex)   tabindex="$!webwork.htmlEncode($parameters.doubleTabindex)" #end
    #if ($parameters.doubleId)         id="$!webwork.htmlEncode($parameters.doubleId)"             #end
    #if ($parameters.multiple)         multiple="multiple"                                         #end
    #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"          #end
    #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"          #end
>
</select>
<script type="text/javascript">
#set( $itemCount = $startCount )
var $!webwork.htmlEncode($parameters.name)Group = new Array($!{parameters.listSize} + $startCount);
for (i = 0; i < ($!{parameters.listSize} + $startCount); i++)
$!webwork.htmlEncode($parameters.name)Group[i] = new Array();
#foreach( $item in $items )
    $stack.push($item)
    #if( $parameters.listKey )
        #set( $itemKey = $stack.findValue($parameters.listKey) )
    #else
        #set( $itemKey = $item )
    #end
    #if( $parameters.listValue )
        #set( $itemValue  = $stack.findValue($parameters.listValue) )
    #else
        #set( $itemValue = $item )
    #end
    #set( $doubleItems = $stack.findValue($parameters.doubleList) )
    #set( $doubleItemCount = 0 )
    #if( $doubleItems )
        #foreach( $doubleItem in $doubleItems )
            $stack.push($doubleItem)
            #if( $parameters.doubleListKey )
                #set( $doubleItemKey = $stack.findValue($parameters.doubleListKey) )
            #else
                #set( $doubleItemKey = $doubleItem )
            #end
            #if( $parameters.doubleListValue )
                #set( $doubleItemValue  = $stack.findValue($parameters.doubleListValue) )
            #else
                #set( $doubleItemValue = $doubleItem )
            #end
            $!webwork.htmlEncode($parameters.name)Group[$itemCount][$doubleItemCount] = new Option("$doubleItemKey", "$doubleItemValue");
            #set( $doubleItemCount = $doubleItemCount + 1 )
            #set ($trash = $stack.pop())
        #end
        #set( $itemCount = $itemCount + 1 )
    #end
    #set ($trash = $stack.pop())
#end
var $!webwork.htmlEncode($parameters.name)Temp = document.$!webwork.htmlEncode(${parameters.formName}).$!webwork.htmlEncode(${parameters.doubleName});
#set( $itemCount = $startCount )
#set( $redirectTo = 0 )
#foreach( $item in $items )
    $stack.push($item)
    #if( $parameters.listValue )
        #set( $itemValue  = $stack.findValue($parameters.listValue) )
    #else
        #set( $itemValue = $item )
    #end
    #if( $tag.contains($parameters.nameValue, $itemKey) )
        #set( $redirectTo = $itemCount )
    #end
    #set( $itemCount = $itemCount + 1 )
    #set ($trash = $stack.pop())
#end
$!{webwork.htmlEncode($parameters.name)}Redirect($redirectTo);
function $!{webwork.htmlEncode($parameters.name)}Redirect(x) {
    for (m = $!{webwork.htmlEncode($parameters.name)}Temp.options.length - 1; m >= 0; m--)
        $!{webwork.htmlEncode($parameters.name)}Temp.options[m] = null;

    for (i = 0; i < $!{parameters.name}Group[x].length; i++) {
        $!{webwork.htmlEncode($parameters.name)}Temp.options[i] = new Option($!{webwork.htmlEncode($parameters.name)}Group[x][i].text, $!{webwork.htmlEncode($parameters.name)}Group[x][i].value);
    }

    if ($!{parameters.name}Temp.options.length > 0)
        $!{webwork.htmlEncode($parameters.name)}Temp.options[0].selected = true;
}
</script>