#!/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__ = 1225031612.914098
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:32 2008'
__CHEETAH_src__ = 'TreeSelectTemplate.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 TreeSelectTemplate(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 treeselect(self, selectbox, **KWS):



        ## CHEETAH: generated from #def treeselect(selectbox) at line 30, 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
        
        write('''<div>
    <table>
        <tr>
''')
        for select in VFFSL(SL,"selectbox.elementList",True): # generated from line 34, col 1
            if len(VFFSL(SL,"select.options",True)): # generated from line 35, col 1
                write('''            <th>''')
                _v = VFFSL(SL,"select.title",True) # '$select.title' on line 36, col 17
                if _v is not None: write(_filter(_v, rawExpr='$select.title')) # from line 36, col 17.
                write('''</th>
''')
        write('''        </tr>
        <tr>
''')
        optgroup_end = False
        for select in VFFSL(SL,"selectbox.elementList",True): # generated from line 42, col 1
            write('''            <td>
''')
            if len(VFFSL(SL,"select.options",True)): # generated from line 44, col 1
                write('''                <select style="min-width: ''')
                _v = VFFSL(SL,"selectbox.defaultWidth",True) # '${selectbox.defaultWidth}' on line 45, col 43
                if _v is not None: write(_filter(_v, rawExpr='${selectbox.defaultWidth}')) # from line 45, col 43.
                write('''px;" name="''')
                _v = VFFSL(SL,"select.elementName",True) # '$select.elementName' on line 45, col 79
                if _v is not None: write(_filter(_v, rawExpr='$select.elementName')) # from line 45, col 79.
                write('''" onchange="''')
                _v = VFFSL(SL,"select.onchange",True) # '$select.onchange' on line 45, col 110
                if _v is not None: write(_filter(_v, rawExpr='$select.onchange')) # from line 45, col 110.
                write('''" ''')
                _v = VFN(VFFSL(SL,"select",True),"getAttribs",False)() # '$select.getAttribs()' on line 45, col 128
                if _v is not None: write(_filter(_v, rawExpr='$select.getAttribs()')) # from line 45, col 128.
                write('''>
''')
                for option in VFFSL(SL,"select.options",True): # generated from line 46, col 1
                    if VFFSL(SL,"option.optgroup",True): # generated from line 47, col 1
                        if VFFSL(SL,"optgroup_end",True): # generated from line 48, col 1
                            write('''                    </optgroup>
''')
                            optgroup_end = False
                        write('''                    <optgroup label="''')
                        _v = VFFSL(SL,"option.value",True) # '$option.value' on line 52, col 38
                        if _v is not None: write(_filter(_v, rawExpr='$option.value')) # from line 52, col 38.
                        write('''">
''')
                        optgroup_end = True
                    else: # generated from line 54, col 1
                        if VFFSL(SL,"option.selected",True): # generated from line 55, col 1
                            write('''                        <option value="''')
                            _v = VFFSL(SL,"option.value",True) # '$option.value' on line 56, col 40
                            if _v is not None: write(_filter(_v, rawExpr='$option.value')) # from line 56, col 40.
                            write('''" selected>''')
                            _v = VFFSL(SL,"option.text",True) # '$option.text' on line 56, col 64
                            if _v is not None: write(_filter(_v, rawExpr='$option.text')) # from line 56, col 64.
                            write('''</option>
''')
                        elif VFFSL(SL,"option.disabled",True): # generated from line 57, col 1
                            write('''                        <option value="''')
                            _v = VFFSL(SL,"option.value",True) # '$option.value' on line 58, col 40
                            if _v is not None: write(_filter(_v, rawExpr='$option.value')) # from line 58, col 40.
                            write('''" disabled>''')
                            _v = VFFSL(SL,"option.text",True) # '$option.text' on line 58, col 64
                            if _v is not None: write(_filter(_v, rawExpr='$option.text')) # from line 58, col 64.
                            write('''</option>
''')
                        else: # generated from line 59, col 1
                            write('''                        <option value="''')
                            _v = VFFSL(SL,"option.value",True) # '$option.value' on line 60, col 40
                            if _v is not None: write(_filter(_v, rawExpr='$option.value')) # from line 60, col 40.
                            write('''">''')
                            _v = VFFSL(SL,"option.text",True) # '$option.text' on line 60, col 55
                            if _v is not None: write(_filter(_v, rawExpr='$option.text')) # from line 60, col 55.
                            write('''</option>
''')
                write('''                </select>
''')
                _v = VFN(VFFSL(SL,"select",True),"lastKeys",False)() # '$select.lastKeys()' on line 65, col 1
                if _v is not None: write(_filter(_v, rawExpr='$select.lastKeys()')) # from line 65, col 1.
                write('''
''')
            write('''            </td>
''')
        write('''        </tr>
    </table>
</div>
''')
        
        ########################################
        ## 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: TreeSelectTemplate.tmpl 3809 2007-01-19 14:16:23Z jodal $
        #  TreeSelectTemplate.tmpl is used by TreeSelect to render the 
        #  select boxes the template function treeselect() takes a 
        #  TreeSelect.TreeSelect instance as it's argument. For more 
        #  information, see the TreeSelect module
        #   
        #  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
        # 
        # 
        #  Author: 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_TreeSelectTemplate= 'respond'

## END CLASS DEFINITION

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


# 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=TreeSelectTemplate()).run()


