Source

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

Full commit
#parse("/template/xhtml/controlheader.vm")

<select name="$!parameters.name"
    #if ($parameters.size)             size="$parameters.size"                              #end
    #if ($parameters.disabled)         disabled="disabled"                                  #end
    #if ($parameters.tabindex)         tabindex="$parameters.tabindex"                      #end
    #if ($parameters.id)               id="$parameters.id"                                  #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
    onchange="$!{parameters.name}Redirect(this.options.selectedIndex)"
>

#set ( $startCount = 0)
#if ($parameters.headerKey && $parameters.headerValue)
    <option value="$!webwork.htmlEncode($parameters.headerKey)">$!webwork.htmlEncode($parameters.headerValue)</option>
    #set ( $startCount = $startCount + 1)
#end

#if ($parameters.emptyOption)
    <option value=""></option>
    #set ( $startCount = $startCount + 1)
#end

#set( $items = $parameters.list )
#if( $items )
    #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

        <option value="$!webwork.htmlEncode($itemKey)"
            #if( $tag.contains($parameters.nameValue, $itemKey) )selected="selected"#end
        >$!webwork.htmlEncode($itemValue)</option>

        #set ($trash = $stack.pop())
    #end
#end
</select>

<br/>

<select name="$!parameters.doubleName"
    #if ($parameters.doubleTabindex)   tabindex="$parameters.doubleTabindex"                #end
    #if ($parameters.doubleId)         id="$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 $!{parameters.name}Group = new Array($items.size() + $startCount)
for (i = 0; i < ($items.size() + $startCount); i++)
$!{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 )
            #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

            $!{parameters.name}Group[$itemCount][$doubleItemCount] = new Option("$doubleItemKey", "$doubleItemValue")
            #set( $doubleItemCount = $doubleItemCount + 1 )
        #end

        #set( $itemCount = $itemCount + 1 )
    #end

    #set ($trash = $stack.pop())
#end

## CHANGE THE NAME OF YOUR FORM HERE, NEED TO FIX THIS
var $!{parameters.name}Temp = document.$!{parameters.form.name}.$!{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

$!{parameters.name}Redirect($redirectTo)

function $!{parameters.name}Redirect(x) {
    for (m = $!{parameters.name}Temp.options.length - 1; m >= 0; m--)
        $!{parameters.name}Temp.options[m] = null

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

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


#parse("/template/xhtml/controlfooter.vm")