#!/usr/bin/env python




##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
    import builtins as builtin
except ImportError:
    import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from six.moves.urllib.parse import quote
from json import dumps
from Plugins.Extensions.OpenWebif.controllers.i18n import tstrings
import datetime

##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.4.4'
__CHEETAH_versionTuple__ = (2, 4, 4, 'development', 0)
__CHEETAH_genTime__ = 1644596121.268289
__CHEETAH_genTimestamp__ = 'Fri Feb 11 16:15:21 2022'
__CHEETAH_src__ = '/home/nonsolosat/openpli-dreambox-oe-core/build/tmp/work/dm520-oe-linux/enigma2-plugin-extensions-openwebif/gitAUTOINC+81b15e17ab-r0/git/plugin/controllers/views/mobile/timerlist.tmpl'
__CHEETAH_srcLastModified__ = 'Fri Feb 11 15:59:45 2022'
__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 timerlist(Template):

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


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

        super(timerlist, self).__init__(*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 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
        
        write(u'''<body>
\t<div data-role="page">
\t\t<div id="header">
\t\t\t<div class="button" onclick="history.back()">''')
        _v = VFFSL(SL,"tstrings",True)['back'] # u"$tstrings['back']" on line 8, col 49
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['back']")) # from line 8, col 49.
        write(u'''</div>
\t\t\t<!-- <div class="button-bold">+</div> -->
\t\t\t<h1><a style="color:#FFF;text-decoration:none;" href=\'/mobile\'>OpenWebif</a></h1>
\t\t</div>
\t\t<div id="contentContainer">
\t\t\t<div data-role="collapsibleset">
\t\t\t\t<div data-role="collapsible" data-disabled="true" data-collapsed-icon="false" data-theme="b">
\t\t\t\t\t<h2>''')
        _v = VFFSL(SL,"tstrings",True)['timer_list'] # u"$tstrings['timer_list']" on line 15, col 10
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['timer_list']")) # from line 15, col 10.
        write(u'''</h2>
\t\t\t\t</div>
''')
        oldstartdate = ""
        for timer in VFFSL(SL,"timers",True): # generated from line 18, col 5
            duration = VFFSL(SL,"timer.duration",True)/60
            starttime = datetime.datetime.fromtimestamp(VFFSL(SL,"timer.begin",True)).strftime("%H:%M")
            startdate = datetime.datetime.fromtimestamp(VFFSL(SL,"timer.begin",True)).strftime("%d.%m.%Y")
            endtime = datetime.datetime.fromtimestamp(VFFSL(SL,"timer.end",True)).strftime("%H:%M")
            if VFFSL(SL,"startdate",True) != VFFSL(SL,"oldstartdate",True): # generated from line 23, col 5
                if VFFSL(SL,"oldstartdate",True) != "": # generated from line 24, col 5
                    write(u'''\t\t\t\t\t</ul>
\t\t\t\t</div>
\t\t\t\t<div data-role="collapsible">
''')
                else: # generated from line 28, col 5
                    write(u'''\t\t\t\t<div data-role="collapsible" data-collapsed="false">
''')
                write(u'''\t\t\t\t\t<h2>''')
                _v = VFFSL(SL,"startdate",True) # u'$startdate' on line 31, col 10
                if _v is not None: write(_filter(_v, rawExpr=u'$startdate')) # from line 31, col 10.
                write(u'''</h2>
''')
                oldstartdate = VFFSL(SL,"startdate",True)
                write(u'''\t\t\t\t\t<ul data-role="listview" data-inset="false" data-theme="a">
''')
            write(u'''\t\t\t\t\t<li>
''')
            sref = quote(VFFSL(SL,"timer.serviceref",True), safe=' ~@#$&()*!+=:;,.?/\'')
            name = quote(VFFSL(SL,"timer.name",True), safe=' ~@#$&()*!+=:;,.?/\'').replace("'","\\'")
            write(u'''\t\t\t\t\t\t<a href="#">
\t\t\t\t\t\t\t<h2>''')
            _v = VFFSL(SL,"timer.name",True) # u'$timer.name' on line 39, col 12
            if _v is not None: write(_filter(_v, rawExpr=u'$timer.name')) # from line 39, col 12.
            write(u'''</h2>
\t\t\t\t\t\t\t<p><strong>''')
            _v = VFFSL(SL,"timer.servicename",True) # u'$timer.servicename' on line 40, col 19
            if _v is not None: write(_filter(_v, rawExpr=u'$timer.servicename')) # from line 40, col 19.
            write(u''' - ''')
            _v = VFFSL(SL,"starttime",True) # u'$starttime' on line 40, col 40
            if _v is not None: write(_filter(_v, rawExpr=u'$starttime')) # from line 40, col 40.
            write(u''' - ''')
            _v = VFFSL(SL,"endtime",True) # u'$endtime' on line 40, col 53
            if _v is not None: write(_filter(_v, rawExpr=u'$endtime')) # from line 40, col 53.
            write(u''' (''')
            _v = VFFSL(SL,"duration",True) # u'$duration' on line 40, col 63
            if _v is not None: write(_filter(_v, rawExpr=u'$duration')) # from line 40, col 63.
            write(u''' min)</strong></p>
\t\t\t\t\t\t\t<p>''')
            _v = VFFSL(SL,"timer.description",True) # u'$timer.description' on line 41, col 11
            if _v is not None: write(_filter(_v, rawExpr=u'$timer.description')) # from line 41, col 11.
            write(u'''</p>
\t\t\t\t\t\t</a>
\t\t\t\t\t\t<a href="#" onclick="deleteTimer(\'''')
            _v = VFFSL(SL,"sref",True) # u'$sref' on line 43, col 41
            if _v is not None: write(_filter(_v, rawExpr=u'$sref')) # from line 43, col 41.
            write(u"""', '""")
            _v = VFFSL(SL,"timer.begin",True) # u'$timer.begin' on line 43, col 50
            if _v is not None: write(_filter(_v, rawExpr=u'$timer.begin')) # from line 43, col 50.
            write(u"""', '""")
            _v = VFFSL(SL,"timer.end",True) # u'$timer.end' on line 43, col 66
            if _v is not None: write(_filter(_v, rawExpr=u'$timer.end')) # from line 43, col 66.
            write(u"""', '""")
            _v = VFFSL(SL,"name",True) # u'$name' on line 43, col 80
            if _v is not None: write(_filter(_v, rawExpr=u'$name')) # from line 43, col 80.
            write(u'''\');" aria-expanded="false" class="ui-btn ui-btn-icon-notext ui-icon-delete ui-btn-a" title="delete"></a>
\t\t\t\t\t</li>
''')
        write(u'''\t\t\t\t</ul>
\t\t\t</div>
\t\t\t<button onclick="document.location.reload(true)">''')
        _v = VFFSL(SL,"tstrings",True)['refresh'] # u"$tstrings['refresh']" on line 48, col 53
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['refresh']")) # from line 48, col 53.
        write(u'''</button>
\t\t</div>
\t\t<div id="footer">
\t\t\t<p>OpenWebif Mobile</p>
\t\t\t<a onclick="document.location.href=\'/index?mode=fullpage\';return false;" href="#">''')
        _v = VFFSL(SL,"tstrings",True)['show_full_openwebif'] # u"$tstrings['show_full_openwebif']" on line 52, col 86
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['show_full_openwebif']")) # from line 52, col 86.
        write(u'''</a>
\t\t</div>
\t<script>
\tfunction deleteTimer(sRef, begin, end, title) {
\t\tvar t = decodeURIComponent(title);
\t\tif (confirm("''')
        _v = VFFSL(SL,"tstrings",True)['delete_timer_question'] # u"$tstrings['delete_timer_question']" on line 57, col 16
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['delete_timer_question']")) # from line 57, col 16.
        write(u'''" + ": " + t) === true) {
\t\t\t$.ajax({ url: "/api/timerdelete?sRef=" + sRef + "&begin=" + begin + "&end=" + end, cache: false, async: false}).done(function() {
\t\t\t\tlocation.reload(true);
\t\t\t});
\t\t}
\t}
\t</script>
</div>
</body>
</html>
''')
        
        ########################################
        ## 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_timerlist= 'respond'

## END CLASS DEFINITION

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


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


