#!/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
from MaintenanceTemplate import MaintenanceTemplate
import math
import time
from nav.web.templates.TreeSelectTemplate import TreeSelectTemplate

##################################################
## 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__ = 1225031606.5795281
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:26 2008'
__CHEETAH_src__ = 'nav/web/templates/MaintenanceNewTemplate.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 MaintenanceNewTemplate(MaintenanceTemplate):

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


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

        MaintenanceTemplate.__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 tabcontent(self, **KWS):



        ## CHEETAH: generated from #block tabcontent at line 31, 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('''
''')
        #  Print form
        write('''
<form action="" method="post" id="newform">
''')
        edit_taskid = VFFSL(SL,"getVar",False)('edit_taskid', False)
        if VFFSL(SL,"edit_taskid",True): # generated from line 37, col 1
            write('''<input type="hidden" name="edit_taskid" value="''')
            _v = VFFSL(SL,"edit_taskid",True) # '$edit_taskid' on line 38, col 48
            if _v is not None: write(_filter(_v, rawExpr='$edit_taskid')) # from line 38, col 48.
            write('''" />
''')
        write('''
<table class="vertitable">
    <tr>
        <th>Add components</th>
        <td>
''')
        ts = TreeSelectTemplate()
        write('''            ''')
        _v = VFN(VFFSL(SL,"ts",True),"treeselect",False)(VFFSL(SL,"selectbox",True)) # '$ts.treeselect($selectbox)' on line 46, col 13
        if _v is not None: write(_filter(_v, rawExpr='$ts.treeselect($selectbox)')) # from line 46, col 13.
        write('''
''')
        if VFFSL(SL,"selectsubmit.enabled",True): # generated from line 47, col 13
            write('''            <input type="submit" name="''')
            _v = VFFSL(SL,"selectsubmit.control",True) # '$selectsubmit.control' on line 48, col 40
            if _v is not None: write(_filter(_v, rawExpr='$selectsubmit.control')) # from line 48, col 40.
            write('''" value="''')
            _v = VFFSL(SL,"selectsubmit.value",True) # '$selectsubmit.value' on line 48, col 70
            if _v is not None: write(_filter(_v, rawExpr='$selectsubmit.value')) # from line 48, col 70.
            write('''" />
''')
        else: # generated from line 49, col 13
            write('''            <input disabled="disabled" type="submit" name="''')
            _v = VFFSL(SL,"selectsubmit.control",True) # '$selectsubmit.control' on line 50, col 60
            if _v is not None: write(_filter(_v, rawExpr='$selectsubmit.control')) # from line 50, col 60.
            write('''" value="''')
            _v = VFFSL(SL,"selectsubmit.value",True) # '$selectsubmit.value' on line 50, col 90
            if _v is not None: write(_filter(_v, rawExpr='$selectsubmit.value')) # from line 50, col 90.
            write('''" />
''')
        write('''        </td>
    </tr>
    <tr>
        <th>Selected components *</th>
        <td>
            ''')
        _v = VFFSL(SL,"listComponents",False)(VFFSL(SL,"components",True), True) # '$listComponents($components, True)' on line 57, col 13
        if _v is not None: write(_filter(_v, rawExpr='$listComponents($components, True)')) # from line 57, col 13.
        write('''
        </td>
    </tr>
    <tr>
        <th>Start maintenance</th>
        <td>
            <select name="start_year">
''')
        current_year = int(time.strftime('%Y'))
        selected_year = VFFSL(SL,"getVar",False)('start_year', VFFSL(SL,"current_year",True))
        for year in xrange(VFFSL(SL,"current_year",True) - 1, VFFSL(SL,"current_year",True) + 5): # generated from line 66, col 1
            if VFFSL(SL,"year",True) == VFFSL(SL,"selected_year",True): # generated from line 67, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"year",True) # '$year' on line 68, col 32
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 68, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"year",True) # '$year' on line 68, col 59
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 68, col 59.
                write('''</option>
''')
            else: # generated from line 69, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"year",True) # '$year' on line 70, col 32
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 70, col 32.
                write('''">''')
                _v = VFFSL(SL,"year",True) # '$year' on line 70, col 39
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 70, col 39.
                write('''</option>
''')
        write('''            </select>
            <select name="start_month">
''')
        current_month = int(time.strftime('%m'))
        selected_month = VFFSL(SL,"getVar",False)('start_month', VFFSL(SL,"current_month",True))
        for month in xrange(1, 1 + 12): # generated from line 77, col 1
            if VFFSL(SL,"month",True) == VFFSL(SL,"selected_month",True): # generated from line 78, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"month",True) # '$month' on line 79, col 32
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 79, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"month",True) # '$month' on line 79, col 60
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 79, col 60.
                write('''</option>
''')
            else: # generated from line 80, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"month",True) # '$month' on line 81, col 32
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 81, col 32.
                write('''">''')
                _v = VFFSL(SL,"month",True) # '$month' on line 81, col 40
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 81, col 40.
                write('''</option>
''')
        write('''            </select>
            <select name="start_day">
''')
        current_day = int(time.strftime('%d'))
        selected_day = VFFSL(SL,"getVar",False)('start_day', VFFSL(SL,"current_day",True))
        for day in xrange(1, 1 + 31): # generated from line 88, col 1
            if VFFSL(SL,"day",True) == VFFSL(SL,"selected_day",True): # generated from line 89, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"day",True) # '$day' on line 90, col 32
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 90, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"day",True) # '$day' on line 90, col 58
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 90, col 58.
                write('''</option>
''')
            else: # generated from line 91, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"day",True) # '$day' on line 92, col 32
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 92, col 32.
                write('''">''')
                _v = VFFSL(SL,"day",True) # '$day' on line 92, col 38
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 92, col 38.
                write('''</option>
''')
        write('''            </select>
            at
            <select name="start_hour">
''')
        current_hour = int(time.strftime('%H'))
        selected_hour = VFFSL(SL,"getVar",False)('start_hour', VFFSL(SL,"current_hour",True))
        for hour in xrange(0, 24): # generated from line 100, col 1
            if VFFSL(SL,"hour",True) == VFFSL(SL,"selected_hour",True): # generated from line 101, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 102, col 32
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 102, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 102, col 59
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 102, col 59.
                write('''</option>
''')
            else: # generated from line 103, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 104, col 32
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 104, col 32.
                write('''">''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 104, col 39
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 104, col 39.
                write('''</option>
''')
        write('''            </select>
            <select name="start_min">
''')
        current_min = int(math.floor(int(time.strftime('%M')) / 5) * 5)
        selected_min = VFFSL(SL,"getVar",False)('start_min', VFFSL(SL,"current_min",True))
        selected_min = int(math.floor(VFFSL(SL,"selected_min",True) / 5) * 5)
        for min in xrange(0, 60, 5): # generated from line 112, col 1
            if VFFSL(SL,"min",True) == VFFSL(SL,"selected_min",True): # generated from line 113, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"min",True) # '$min' on line 114, col 32
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 114, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"min",True) # '$min' on line 114, col 58
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 114, col 58.
                write('''</option>
''')
            else: # generated from line 115, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"min",True) # '$min' on line 116, col 32
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 116, col 32.
                write('''">''')
                _v = VFFSL(SL,"min",True) # '$min' on line 116, col 38
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 116, col 38.
                write('''</option>
''')
        write('''            </select>        
        </td>
    </tr>
''')
        #  Default to one week into the future
        totime = time.localtime(int(time.time()) + 7*24*60*60)
        write('''    <tr>
        <th>End maintenance</th>
        <td>
            <select name="end_year">
''')
        current_year = int(time.strftime('%Y', VFFSL(SL,"totime",True)))
        selected_year = VFFSL(SL,"getVar",False)('end_year', VFFSL(SL,"current_year",True))
        for year in xrange(VFFSL(SL,"current_year",True) - 1, VFFSL(SL,"current_year",True) + 5): # generated from line 130, col 1
            if VFFSL(SL,"year",True) == VFFSL(SL,"selected_year",True): # generated from line 131, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"year",True) # '$year' on line 132, col 32
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 132, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"year",True) # '$year' on line 132, col 59
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 132, col 59.
                write('''</option>
''')
            else: # generated from line 133, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"year",True) # '$year' on line 134, col 32
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 134, col 32.
                write('''">''')
                _v = VFFSL(SL,"year",True) # '$year' on line 134, col 39
                if _v is not None: write(_filter(_v, rawExpr='$year')) # from line 134, col 39.
                write('''</option>
''')
        write('''            </select>
            <select name="end_month">
''')
        current_month = int(time.strftime('%m', VFFSL(SL,"totime",True)))
        selected_month = VFFSL(SL,"getVar",False)('end_month', VFFSL(SL,"current_month",True))
        for month in xrange(1, 1 + 12): # generated from line 141, col 1
            if VFFSL(SL,"month",True) == VFFSL(SL,"selected_month",True): # generated from line 142, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"month",True) # '$month' on line 143, col 32
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 143, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"month",True) # '$month' on line 143, col 60
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 143, col 60.
                write('''</option>
''')
            else: # generated from line 144, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"month",True) # '$month' on line 145, col 32
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 145, col 32.
                write('''">''')
                _v = VFFSL(SL,"month",True) # '$month' on line 145, col 40
                if _v is not None: write(_filter(_v, rawExpr='$month')) # from line 145, col 40.
                write('''</option>
''')
        write('''            </select>
            <select name="end_day">
''')
        current_day = int(time.strftime('%d', VFFSL(SL,"totime",True)))
        selected_day = VFFSL(SL,"getVar",False)('end_day', VFFSL(SL,"current_day",True))
        for day in xrange(1, 1 + 31): # generated from line 152, col 1
            if VFFSL(SL,"day",True) == VFFSL(SL,"selected_day",True): # generated from line 153, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"day",True) # '$day' on line 154, col 32
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 154, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"day",True) # '$day' on line 154, col 58
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 154, col 58.
                write('''</option>
''')
            else: # generated from line 155, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"day",True) # '$day' on line 156, col 32
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 156, col 32.
                write('''">''')
                _v = VFFSL(SL,"day",True) # '$day' on line 156, col 38
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 156, col 38.
                write('''</option>
''')
        write('''            </select>
            at
            <select name="end_hour">
''')
        current_hour = int(time.strftime('%H', VFFSL(SL,"totime",True)))
        selected_hour = VFFSL(SL,"getVar",False)('end_hour', VFFSL(SL,"current_hour",True))
        for hour in xrange(0, 24): # generated from line 164, col 1
            if VFFSL(SL,"hour",True) == VFFSL(SL,"selected_hour",True): # generated from line 165, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 166, col 32
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 166, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 166, col 59
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 166, col 59.
                write('''</option>
''')
            else: # generated from line 167, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 168, col 32
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 168, col 32.
                write('''">''')
                _v = VFFSL(SL,"hour",True) # '$hour' on line 168, col 39
                if _v is not None: write(_filter(_v, rawExpr='$hour')) # from line 168, col 39.
                write('''</option>
''')
        write('''            </select>
            <select name="end_min">
''')
        current_min = int(math.floor(int(time.strftime('%M', VFFSL(SL,"totime",True))) / 5) * 5)
        selected_min = VFFSL(SL,"getVar",False)('end_min', VFFSL(SL,"current_min",True))
        selected_min = int(math.floor(VFFSL(SL,"selected_min",True) / 5) * 5)
        for min in xrange(0, 60, 5): # generated from line 176, col 1
            if VFFSL(SL,"min",True) == VFFSL(SL,"selected_min",True): # generated from line 177, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"min",True) # '$min' on line 178, col 32
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 178, col 32.
                write('''" selected="selected">''')
                _v = VFFSL(SL,"min",True) # '$min' on line 178, col 58
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 178, col 58.
                write('''</option>
''')
            else: # generated from line 179, col 5
                write('''                <option value="''')
                _v = VFFSL(SL,"min",True) # '$min' on line 180, col 32
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 180, col 32.
                write('''">''')
                _v = VFFSL(SL,"min",True) # '$min' on line 180, col 38
                if _v is not None: write(_filter(_v, rawExpr='$min')) # from line 180, col 38.
                write('''</option>
''')
        write('''            </select>
            (default: one week)
        </td>
    </tr>
    <tr>
        <th>Description *</th>
        <td><textarea name="description" cols="72" rows="5">''')
        _v = VFFSL(SL,"getVar",False)('description', '') # "$getVar('description', '')" on line 189, col 61
        if _v is not None: write(_filter(_v, rawExpr="$getVar('description', '')")) # from line 189, col 61.
        write('''</textarea></td>
    </tr>
    <tr>
        <th></th>
        <td><input type="submit" name="submit_final" value="''')
        _v = VFFSL(SL,"submittext",True) # '$submittext' on line 193, col 61
        if _v is not None: write(_filter(_v, rawExpr='$submittext')) # from line 193, col 61.
        write('''" /></td>
    </tr>
</table>

</form>

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

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        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
        
        #  $Id:$
        # 
        #  Copyright 2006 UNINETT AS
        # 
        #  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: Stein Magnus Jodal <stein.magnus.jodal@uninett.no>
        # 
        write('''

''')
        self.tabcontent(trans=trans)
        
        ########################################
        ## 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_MaintenanceNewTemplate= 'writeBody'

## END CLASS DEFINITION

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


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


