#!/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 Plugins.Extensions.OpenWebif.local import tstrings

##################################################
## 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__ = 1406885499.332104
__CHEETAH_genTimestamp__ = 'Fri Aug  1 18:31:39 2014'
__CHEETAH_src__ = '/home/wslee2/models/5-wo/force1plus/openpli3.0/build-force1plus/tmp/work/mips32el-oe-linux/enigma2-plugin-extensions-openwebif-1+git5+3c0c4fbdb28d7153bf2140459b553b3d5cdd4149-r0/git/plugin/controllers/views/ajax/edittimer.tmpl'
__CHEETAH_srcLastModified__ = 'Fri Aug  1 18:30:05 2014'
__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 edittimer(Template):

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


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

        super(edittimer, 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'''
<form>
<div>
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['name'] # u"$tstrings['name']" on line 6, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['name']")) # from line 6, col 44.
        write(u''':</span>
\t\t<span><input type="text" name="timername" id="timername" style="width: 450px;" class="text ui-widget-content ui-corner-all" /></span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['description'] # u"$tstrings['description']" on line 11, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['description']")) # from line 11, col 44.
        write(u''':</span>
\t\t<span><textarea name="description" id="description" style="width: 450px; height: 50px;" class="text ui-widget-content ui-corner-all" /></span>
\t</div>
\t
\t<div class="timerlist_row">
\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['channel'] # u"$tstrings['channel']" on line 16, col 43
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['channel']")) # from line 16, col 43.
        write(u''':</span>
\t\t<span>
\t\t<select id="bouquet_select" name="bouquet_select">
\t\t\t<option value="0">''')
        _v = VFFSL(SL,"tstrings",True)['nothing'] # u"$tstrings['nothing']" on line 19, col 22
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['nothing']")) # from line 19, col 22.
        write(u'''</option>
\t\t</select>
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">Start:</span>
\t\t<span>
\t\t<input type="text" name="timerbegin" id="timerbegin" value="" class="text ui-widget-content ui-corner-all" />
\t\t</span>
\t</div>

\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['end'] # u"$tstrings['end']" on line 32, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['end']")) # from line 32, col 44.
        write(u''':</span>
\t\t<span>
\t\t<input type="text" name="timerend" id="timerend" value="" class="text ui-widget-content ui-corner-all" />
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left; block: inline;">''')
        _v = VFFSL(SL,"tstrings",True)['enabled'] # u"$tstrings['enabled']" on line 39, col 59
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['enabled']")) # from line 39, col 59.
        write(u''':</span>
\t\t<span style="margin: 5px;">
\t\t\t<input type="checkbox" name="enabled" id="enabled" value="0" />
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['just_play'] # u"$tstrings['just_play']" on line 46, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['just_play']")) # from line 46, col 44.
        write(u''':</span>
\t\t<span style="margin: 5px;">
\t\t\t<input type="checkbox" name="justplay" id="justplay" value="0" />
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['repeated'] # u"$tstrings['repeated']" on line 53, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['repeated']")) # from line 53, col 44.
        write(u''':</span>
\t\t<span id="repeatdays" style="margin: 5px;">
''')
        i = 0
        for day in [VFFSL(SL,"tstrings",True)['mo'], VFFSL(SL,"tstrings",True)['tu'], VFFSL(SL,"tstrings",True)['we'], VFFSL(SL,"tstrings",True)['th'], VFFSL(SL,"tstrings",True)['fr'], VFFSL(SL,"tstrings",True)['sa'], VFFSL(SL,"tstrings",True)['su']]: # generated from line 56, col 3
            value = 2 ** VFFSL(SL,"i",True)
            write(u'''\t\t\t<input type="checkbox" name="repeated" id="day''')
            _v = VFFSL(SL,"i",True) # u'$i' on line 58, col 50
            if _v is not None: write(_filter(_v, rawExpr=u'$i')) # from line 58, col 50.
            write(u'''" value="''')
            _v = VFFSL(SL,"value",True) # u'$value' on line 58, col 61
            if _v is not None: write(_filter(_v, rawExpr=u'$value')) # from line 58, col 61.
            write(u'''" /><label for="day''')
            _v = VFFSL(SL,"i",True) # u'$i' on line 58, col 86
            if _v is not None: write(_filter(_v, rawExpr=u'$i')) # from line 58, col 86.
            write(u'''">''')
            _v = VFFSL(SL,"day",True) # u'$day' on line 58, col 90
            if _v is not None: write(_filter(_v, rawExpr=u'$day')) # from line 58, col 90.
            write(u'''</label>
''')
            i = VFFSL(SL,"i",True)+1
        write(u'''\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['location'] # u"$tstrings['location']" on line 65, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['location']")) # from line 65, col 44.
        write(u''':</span>
\t\t<span>
\t\t<select id="dirname" name="dirname">
\t\t\t<option value="None">''')
        _v = VFFSL(SL,"tstrings",True)['default'] # u"$tstrings['default']" on line 68, col 25
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['default']")) # from line 68, col 25.
        write(u'''</option>
\t\t</select>
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['tags'] # u"$tstrings['tags']" on line 74, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['tags']")) # from line 74, col 44.
        write(u''':</span>
\t\t<span id="tagsnew" style="margin:5px">
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span style="width: 100px; float: left;">''')
        _v = VFFSL(SL,"tstrings",True)['after_event'] # u"$tstrings['after_event']" on line 80, col 44
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['after_event']")) # from line 80, col 44.
        write(u''':</span>
\t\t<span>
\t\t<select id="afterevent" name="afterevent">
\t\t\t<option value="0">''')
        _v = VFFSL(SL,"tstrings",True)['nothing'] # u"$tstrings['nothing']" on line 83, col 22
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['nothing']")) # from line 83, col 22.
        write(u'''</option>
\t\t\t<option value="1">''')
        _v = VFFSL(SL,"tstrings",True)['standby'] # u"$tstrings['standby']" on line 84, col 22
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['standby']")) # from line 84, col 22.
        write(u'''</option>
\t\t\t<option value="2">''')
        _v = VFFSL(SL,"tstrings",True)['shutdown'] # u"$tstrings['shutdown']" on line 85, col 22
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['shutdown']")) # from line 85, col 22.
        write(u'''</option>
\t\t\t<option value="3" selected="">''')
        _v = VFFSL(SL,"tstrings",True)['auto'] # u"$tstrings['auto']" on line 86, col 34
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['auto']")) # from line 86, col 34.
        write(u'''</option>
\t\t</select>
\t\t</span>
\t</div>
\t<div id="errorbox" class="timerlist_row" style="color: red;">
\t\t<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"> 
\t\t\t<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> 
\t\t\t<span id="error"></span>
\t\t</div>
\t</div>
</div>
</form>

<script src="/js/jquery.timerpicker.js"></script>

<script type="text/javascript">


$(\'#timerbegin\').datetimepicker({
\t
\ttimeText: tstr_time,
\thourText: tstr_hour,
\tminuteText: tstr_minute,
\tcurrentText: tstr_now,
\tcloseText: tstr_done,
\tmonthNames: [tstr_january, tstr_february, tstr_march, tstr_april, tstr_may, tstr_june, tstr_july, tstr_august, tstr_september, tstr_october, tstr_november, tstr_december],
\tdayNames: [tstr_sunday, tstr_monday, tstr_tuesday, tstr_wednesday, tstr_thursday, tstr_friday, tstr_saturday, tstr_sunday],
\tdayNamesMin: [tstr_su, tstr_mo, tstr_tu, tstr_we, tstr_th, tstr_fr, tstr_sa, tstr_su],
\t
\tdateFormat: \'dd.mm.yy\',
\ttimeFormat: \'hh:mm\',
\tonClose: function(dateText, inst) {
\t\tif ($(\'#timerend\').val() != \'\' &&
\t\t\t$(this).datetimepicker(\'getDate\') > $(\'#timerend\').datetimepicker(\'getDate\')) {
\t\t\t\t$(\'#error\').text(tstr_start_after_end);
\t\t\t\t$(\'#errorbox\').show();
\t\t}
\t\telse
\t\t\t$(\'#errorbox\').hide();
\t}
});
$(\'#timerend\').datetimepicker({
\t
\ttimeText: tstr_time,
\thourText: tstr_hour,
\tminuteText: tstr_minute,
\tcurrentText: tstr_now,
\tcloseText: tstr_done,
\tmonthNames: [tstr_january, tstr_february, tstr_march, tstr_april, tstr_may, tstr_june, tstr_july, tstr_august, tstr_september, tstr_october, tstr_november, tstr_december],
\tdayNames: [tstr_sunday, tstr_monday, tstr_tuesday, tstr_wednesday, tstr_thursday, tstr_friday, tstr_saturday, tstr_sunday],
\tdayNamesMin: [tstr_su, tstr_mo, tstr_tu, tstr_we, tstr_th, tstr_fr, tstr_sa, tstr_su],
\t
\tdateFormat: \'dd.mm.yy\',
\ttimeFormat: \'hh:mm\',
\tonClose: function(dateText, inst) {
\t\tif ($(\'#timerbegin\').val() != \'\' &&\t
\t\t\t$(\'#timerbegin\').datetimepicker(\'getDate\') > $(this).datetimepicker(\'getDate\')) {
\t\t\t\t$(\'#error\').text(tstr_start_after_end);
\t\t\t\t$(\'#errorbox\').show();
\t\t}
\t\telse
\t\t\t$(\'#errorbox\').hide();
\t}
});

$(\'#repeatdays\').buttonset();

$(\'#editTimerForm\').dialog({
\tautoOpen: false,
\theight: 455,
\twidth: 600,
\tmodal: true,
\tbuttons: [
\t\t\t{text: tstr_save,
\t\t\tclick: function() {
\t\t\t\tvar begindate = new Date($(\'#timerbegin\').datetimepicker(\'getDate\'));
\t\t\t\tvar enddate = new Date($(\'#timerend\').datetimepicker(\'getDate\'));

\t\t\t\tvar repeated = 0;
\t\t\t\t$(\'[name="repeated"]:checked\').each(function() {
\t\t\t\t\trepeated += parseInt($(this).val());
\t\t\t\t});
\t\t\t\tvar tags = "";
\t\t\t\t$(\'[name="tagsnew"]:checked\').each(function() {
\t\t\t\t\tif(tags!="")
\t\t\t\t\t\ttags+=" ";
\t\t\t\t\ttags += $(this).val();
\t\t\t\t\t
\t\t\t\t});
\t\t\t\tvar urldata = { sRef: $(\'#bouquet_select\').val(),
\t\t\t\t\tbegin: Math.round(begindate.getTime() / 1000),
\t\t\t\t\tend: Math.round(enddate.getTime() / 1000),
\t\t\t\t\tname: $(\'#timername\').val(),
\t\t\t\t\tdescription: $(\'#description\').val(),
\t\t\t\t\tdisabled: ($(\'#enabled\').is(\':checked\')?"0":"1"),
\t\t\t\t\tjustplay: ($(\'#justplay\').is(\':checked\')?"1":"0"),
\t\t\t\t\tafterevent: $(\'#afterevent\').val(),
\t\t\t\t\tdirname: $(\'#dirname\').val(),
\t\t\t\t\ttags: tags,
\t\t\t\t\trepeated: repeated };
\t\t\t\t
\t\t\t\tvar canclose = false;
\t\t\t\tif (current_serviceref == "") {
\t\t\t\t\t$.ajax({
\t\t\t\t\t\tasync: false,
\t\t\t\t\t\turl: "/api/timeradd?",
\t\t\t\t\t\tdata: urldata,
\t\t\t\t\t\tsuccess: function(data) {
\t\t\t\t\t\t\tresult = $.parseJSON(data);
\t\t\t\t\t\t\tif (result.result) {
\t\t\t\t\t\t\t\tcanclose = true;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t\telse {
\t\t\t\t\t\t\t\t$("#error").text(result.message);
\t\t\t\t\t\t\t\t$("#errorbox").show();
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t});
\t\t\t\t}
\t\t\t\telse {
\t\t\t\t\turldata[\'channelOld\'] = current_serviceref;
\t\t\t\t\turldata[\'beginOld\'] = Math.round(current_begin);
\t\t\t\t\turldata[\'endOld\'] = Math.round(current_end);
\t\t\t\t\t$.ajax({
\t\t\t\t\t\tasync: false,
\t\t\t\t\t\turl: "/api/timerchange?",
\t\t\t\t\t\tdata: urldata,
\t\t\t\t\t\tsuccess: function(data) {
\t\t\t\t\t\t\tresult = $.parseJSON(data);
\t\t\t\t\t\t\tif (result.result) {
\t\t\t\t\t\t\t\tcanclose = true;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t\telse {
\t\t\t\t\t\t\t\t$("#error").text(result.message);
\t\t\t\t\t\t\t\t$("#errorbox").show();
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t});
\t\t\t\t}
\t\t\t\t
\t\t\t\tif (canclose) {
\t\t\t\t\tif (reloadTimers) $("#content_container").load("/ajax/timers");
\t\t\t\t\t$(this).dialog("close");
\t\t\t\t}
\t\t\t}
\t\t},
\t\t{
\t\t\ttext: tstr_close,
\t\t\tclick: function() {
\t\t\t\t$(this).dialog("close");
\t\t\t}
\t\t}
\t],
\tclose: function() {
\t\treturn;
\t}
});


</script>
''')
        
        ########################################
        ## 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_edittimer= 'respond'

## END CLASS DEFINITION

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


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


