#!/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__ = 1447321436.671606
__CHEETAH_genTimestamp__ = 'Thu Nov 12 18:43:56 2015'
__CHEETAH_src__ = '/home/knuth/openpli-oe-core/build/tmp/work/fusionhd-oe-linux/enigma2-plugin-extensions-openwebif/1+gitAUTOINC+5837c87afc-r0/git/plugin/controllers/views/ajax/edittimer.tmpl'
__CHEETAH_srcLastModified__ = 'Thu Nov 12 18:43:41 2015'
__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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['name'] # u"$tstrings['name']" on line 6, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['name']")) # from line 6, col 33.
        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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['description'] # u"$tstrings['description']" on line 11, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['description']")) # from line 11, col 33.
        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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['channel'] # u"$tstrings['channel']" on line 16, col 32
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['channel']")) # from line 16, col 32.
        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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['start'] # u"$tstrings['start']" on line 25, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['start']")) # from line 25, col 33.
        write(u''':</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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['end'] # u"$tstrings['end']" on line 32, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['end']")) # from line 32, col 33.
        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 class="timerlist_row_l" style="block: inline;">''')
        _v = VFFSL(SL,"tstrings",True)['enabled'] # u"$tstrings['enabled']" on line 39, col 56
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['enabled']")) # from line 39, col 56.
        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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['just_play'] # u"$tstrings['just_play']" on line 46, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['just_play']")) # from line 46, col 33.
        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<div class="timerlist_row" id="always_zap1">
\t\t<span class="timerlist_row_l">Record+ZAP:</span>
\t\t<span style="margin: 5px;">
\t\t\t<input type="checkbox" name="always_zap" id="always_zap" value="0" />
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['repeated'] # u"$tstrings['repeated']" on line 60, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['repeated']")) # from line 60, col 33.
        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 63, 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 65, col 50
            if _v is not None: write(_filter(_v, rawExpr=u'$i')) # from line 65, col 50.
            write(u'''" value="''')
            _v = VFFSL(SL,"value",True) # u'$value' on line 65, col 61
            if _v is not None: write(_filter(_v, rawExpr=u'$value')) # from line 65, col 61.
            write(u'''" /><label for="day''')
            _v = VFFSL(SL,"i",True) # u'$i' on line 65, col 86
            if _v is not None: write(_filter(_v, rawExpr=u'$i')) # from line 65, col 86.
            write(u'''">''')
            _v = VFFSL(SL,"day",True) # u'$day' on line 65, col 90
            if _v is not None: write(_filter(_v, rawExpr=u'$day')) # from line 65, 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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['location'] # u"$tstrings['location']" on line 72, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['location']")) # from line 72, col 33.
        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 75, col 25
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['default']")) # from line 75, col 25.
        write(u'''</option>
\t\t</select>
\t\t</span>
\t</div>
\t
\t<div class="timerlist_row">
\t\t<span class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['tags'] # u"$tstrings['tags']" on line 81, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['tags']")) # from line 81, col 33.
        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 class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['after_event'] # u"$tstrings['after_event']" on line 87, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['after_event']")) # from line 87, col 33.
        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 90, col 22
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['nothing']")) # from line 90, col 22.
        write(u'''</option>
\t\t\t<option value="1">''')
        _v = VFFSL(SL,"tstrings",True)['standby'] # u"$tstrings['standby']" on line 91, col 22
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['standby']")) # from line 91, col 22.
        write(u'''</option>
\t\t\t<option value="2">''')
        _v = VFFSL(SL,"tstrings",True)['shutdown'] # u"$tstrings['shutdown']" on line 92, col 22
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['shutdown']")) # from line 92, col 22.
        write(u'''</option>
\t\t\t<option value="3" selected="">''')
        _v = VFFSL(SL,"tstrings",True)['auto'] # u"$tstrings['auto']" on line 93, col 34
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['auto']")) # from line 93, col 34.
        write(u'''</option>
\t\t</select>
\t\t</span>
\t</div>
\t<div class="timerlist_row" id="has_vpsplugin1">
\t\t<span class="timerlist_row_l">''')
        _v = VFFSL(SL,"tstrings",True)['vps'] # u"$tstrings['vps']" on line 98, col 33
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['vps']")) # from line 98, col 33.
        write(u''':</span>
\t\t<span style="margin: 5px;">
\t\t\t<input type="checkbox" name="vpsplugin_enabled" id="vpsplugin_enabled" value="0" />
\t\t</span>
\t\t<span id="has_vpsplugin2" class="timerlist_row_r">''')
        _v = VFFSL(SL,"tstrings",True)['safe_mode'] # u"$tstrings['safe_mode']" on line 102, col 53
        if _v is not None: write(_filter(_v, rawExpr=u"$tstrings['safe_mode']")) # from line 102, col 53.
        write(u''':</span>
\t\t<span style="margin: 5px;">
\t\t\t<input type="checkbox" name="vpsplugin_safemode" id="vpsplugin_safemode" value="0" />
\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-ui-timepicker-addon.min.js"></script>

<script type="text/javascript">


initTimerEditBegin();

$(\'#vpsplugin_enabled\').click(function() { checkVPS();});

$(\'#always_zap\').click(function() {
\t$(\'#justplay\').prop("disabled",$(\'#always_zap\').is(\':checked\'));
});

$(\'#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 (!timeredit_begindestroy && $(\'#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: 480,
\twidth: 650,
\tmodal: true,
\tbuttons: [
\t\t\t{text: tstr_save,
\t\t\tclick: function() {
\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\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\tafterevent: $(\'#afterevent\').val(),
\t\t\t\t\ttags: tags,
\t\t\t\t\trepeated: repeated };
\t\t\t\t
\t\t\t\tif($(\'#always_zap\').is(\':checked\')) {
\t\t\t\t\turldata["always_zap"] = "1";
\t\t\t\t\turldata["justplay"] = "0";
\t\t\t\t}
\t\t\t\telse
\t\t\t\t\turldata["justplay"] = $(\'#justplay\').is(\':checked\')?"1":"0";
\t\t\t\t
\t\t\t\tif ($(\'#dirname\').val() != \'None\')
\t\t\t\t\turldata["dirname"] = $(\'#dirname\').val();
\t\t\t\tif (!$(\'#has_vpsplugin1\').is(\':hidden\'))
\t\t\t\t{
\t\t\t\t\turldata["vpsplugin_enabled"] = ($(\'#vpsplugin_enabled\').is(\':checked\')?"1":"0");
\t\t\t\t\turldata["vpsplugin_overwrite"] = ($(\'#vpsplugin_safemode\').is(\':checked\')?"0":"1");
\t\t\t\t}
\t\t\t\tif (!timeredit_begindestroy) {
\t\t\t\t\tvar begindate = new Date($(\'#timerbegin\').datetimepicker(\'getDate\'));
\t\t\t\t\turldata["begin"] = Math.round(begindate.getTime() / 1000);
\t\t\t\t}
\t\t\t\telse
\t\t\t\t\turldata["begin"] = Math.round(current_begin);
\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) load_maincontent("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}
});

checkVPS();


</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()


