#!/usr/bin/env python
# -*- coding: UTF-8 -*-



##################################################
## DEPENDENCIES
import sys
import os
import os.path
from os.path import getmtime, exists
import time
import types
import __builtin__
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import DummyTransaction
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers

##################################################
## MODULE CONSTANTS
try:
    True, False
except NameError:
    True, False = (1==1), (1==0)
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.0.1'
__CHEETAH_versionTuple__ = (2, 0, 1, 'final', 0)
__CHEETAH_genTime__ = 1225031613.401351
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:33 2008'
__CHEETAH_src__ = 'selectTreeTemplate.tmpl'
__CHEETAH_srcLastModified__ = 'Fri Jan 19 14:16:23 2007'
__CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class selectTreeTemplate(Template):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        Template.__init__(self, *args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def renderLayoutBox(self, layoutBox, **KWS):



        ## CHEETAH: generated from #def renderLayoutBox($layoutBox) at line 27, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        htmlId = ''
        if VFFSL(SL,"layoutBox.htmlId",True): # generated from line 29, col 1
            htmlId = VFFSL(SL,"layoutBox.htmlId",True)
        write('''<table id="''')
        _v = VFFSL(SL,"htmlId",True) # '$htmlId' on line 32, col 12
        if _v is not None: write(_filter(_v, rawExpr='$htmlId')) # from line 32, col 12.
        write('''" cellspacing="10">
''')
        if VFFSL(SL,"layoutBox.showTitles",True): # generated from line 33, col 1
            write('''    <tr>
''')
            if VFFSL(SL,"layoutBox.showTitles",True): # generated from line 35, col 1
                for select in VFFSL(SL,"layoutBox.selectList",True): # generated from line 36, col 1
                    write('''        <th align="left">''')
                    _v = VFFSL(SL,"select.title",True) # '$select.title' on line 37, col 26
                    if _v is not None: write(_filter(_v, rawExpr='$select.title')) # from line 37, col 26.
                    write('''</th>
''')
            write('''    </tr>
''')
        write('''    <tr>
''')
        for select in VFFSL(SL,"layoutBox.selectList",True): # generated from line 43, col 1
            write('''        <td style="height: 100%;">
''')
            show = False
            if len(VFFSL(SL,"select.options",True)): # generated from line 46, col 1
                show = True
            if VFFSL(SL,"layoutBox.showEmptySelects",True): # generated from line 49, col 1
                show = True
            if VFFSL(SL,"show",True): # generated from line 52, col 1
                _v = VFFSL(SL,"renderSelect",False)(VFFSL(SL,"layoutBox",True), VFFSL(SL,"select",True)) # '$renderSelect($layoutBox, $select)' on line 53, col 1
                if _v is not None: write(_filter(_v, rawExpr='$renderSelect($layoutBox, $select)')) # from line 53, col 1.
                write('''
''')
            elif VFFSL(SL,"layoutBox.showHelpTexts",True): # generated from line 54, col 1
                write('''<div style="border: solid 2px; padding: 5px;">
''')
                _v = VFFSL(SL,"layoutBox.emptySelectText",True) # '$layoutBox.emptySelectText' on line 56, col 1
                if _v is not None: write(_filter(_v, rawExpr='$layoutBox.emptySelectText')) # from line 56, col 1.
                write(''' ''')
                _v = VFFSL(SL,"select.prevSelect.title",True) # '$select.prevSelect.title' on line 56, col 28
                if _v is not None: write(_filter(_v, rawExpr='$select.prevSelect.title')) # from line 56, col 28.
                write('''
</div>
''')
            write('''        </td>
''')
        write('''    </tr>
</table>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def renderSelect(self, layoutBox, select, **KWS):



        ## CHEETAH: generated from #def renderSelect($layoutBox,$select) at line 65, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        style = ''
        if VFFSL(SL,"layoutBox.minimumSelectWidth",True): # generated from line 67, col 1
            style += 'min-width: ' + str(VFFSL(SL,"layoutBox.minimumSelectWidth",True)) + 'em;'
        if VFFSL(SL,"layoutBox.exactSelectWidth",True): # generated from line 70, col 1
            width = str(VFFSL(SL,"select.maxOptionTextLength",True))
            style += 'width: ' + VFFSL(SL,"width",True) + 'em;'
        attribs = ''
        if VFFSL(SL,"select.selectMultiple",True): # generated from line 75, col 1
            attribs += 'multiple '
        if VFFSL(SL,"select.multipleHeight",True): # generated from line 78, col 1
            height = str(VFFSL(SL,"select.multipleHeight",True))
            attribs += 'size="' + VFFSL(SL,"height",True) + '" '
        if VFFSL(SL,"select.setOnChange",True): # generated from line 82, col 1
            attribs += 'onchange="' + VFFSL(SL,"select.onChange",True) + '" '
        disabled = ''
        if VFFSL(SL,"select.disabled",True): # generated from line 86, col 1
            disabled = 'disabled="disabled"'
        write('''<select ''')
        _v = VFFSL(SL,"disabled",True) # '$disabled' on line 89, col 9
        if _v is not None: write(_filter(_v, rawExpr='$disabled')) # from line 89, col 9.
        write(''' id="''')
        _v = VFFSL(SL,"select.controlName",True) # '$select.controlName' on line 89, col 23
        if _v is not None: write(_filter(_v, rawExpr='$select.controlName')) # from line 89, col 23.
        write('''" name="''')
        _v = VFFSL(SL,"select.controlName",True) # '$select.controlName' on line 89, col 50
        if _v is not None: write(_filter(_v, rawExpr='$select.controlName')) # from line 89, col 50.
        write('''" ''')
        _v = VFFSL(SL,"attribs",True) # '$attribs' on line 89, col 71
        if _v is not None: write(_filter(_v, rawExpr='$attribs')) # from line 89, col 71.
        write(''' style="''')
        _v = VFFSL(SL,"style",True) # '$style' on line 89, col 87
        if _v is not None: write(_filter(_v, rawExpr='$style')) # from line 89, col 87.
        write('''">
''')
        if len(VFFSL(SL,"select.options",True)) == 0: # generated from line 90, col 1
            #  dummy option to force some browsers to render empty selects
            write('''    <option disabled value=""></option>
''')
        for option in VFFSL(SL,"select.options",True): # generated from line 94, col 1
            if VFFSL(SL,"option.optgroup",True): # generated from line 95, col 1
                write('''    <optgroup label="''')
                _v = VFFSL(SL,"option.text",True) # '$option.text' on line 96, col 22
                if _v is not None: write(_filter(_v, rawExpr='$option.text')) # from line 96, col 22.
                write('''">
''')
            elif VFFSL(SL,"option.optgroupEnd",True): # generated from line 97, col 1
                write('''    </optgroup>
''')
            else: # generated from line 99, col 1
                selected = ''
                if VFFSL(SL,"option.selected",True): # generated from line 101, col 1
                    selected = 'selected="selected"'
                write('''        <option ''')
                _v = VFFSL(SL,"selected",True) # '$selected' on line 104, col 17
                if _v is not None: write(_filter(_v, rawExpr='$selected')) # from line 104, col 17.
                write(''' value="''')
                _v = VFFSL(SL,"option.value",True) # '$option.value' on line 104, col 34
                if _v is not None: write(_filter(_v, rawExpr='$option.value')) # from line 104, col 34.
                write('''">''')
                _v = VFFSL(SL,"option.text",True) # '$option.text' on line 104, col 49
                if _v is not None: write(_filter(_v, rawExpr='$option.text')) # from line 104, col 49.
                write('''</option>
''')
        write('''</select>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def respond(self, trans=None):



        ## CHEETAH: main method generated for this template
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        #  $Id: selectTreeTemplate.tmpl 3809 2007-01-19 14:16:23Z jodal $
        # 
        #  Copyright 2003, 2004 Norwegian University of Science and Technology
        # 
        #  This file is part of Network Administration Visualized (NAV)
        # 
        #  NAV is free software; you can redistribute it and/or modify
        #  it under the terms of the GNU General Public License as published by
        #  the Free Software Foundation; either version 2 of the License, or
        #  (at your option) any later version.
        # 
        #  NAV is distributed in the hope that it will be useful,
        #  but WITHOUT ANY WARRANTY; without even the implied warranty of
        #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        #  GNU General Public License for more details.
        # 
        #  You should have received a copy of the GNU General Public License
        #  along with NAV; if not, write to the Free Software
        #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        # 
        # 
        #  Authors: Hans Jørgen Hoel <hansjorg@orakel.ntnu.no>
        # 
        write('''

''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    _mainCheetahMethod_for_selectTreeTemplate= 'respond'

## END CLASS DEFINITION

if not hasattr(selectTreeTemplate, '_initCheetahAttributes'):
    templateAPIClass = getattr(selectTreeTemplate, '_CHEETAH_templateClass', Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(selectTreeTemplate)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit http://www.CheetahTemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=selectTreeTemplate()).run()


