#!/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 prewikka import utils
from prewikka.templates.ClassicLayout import ClassicLayout

##################################################
## 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__ = 1313541190.989898
__CHEETAH_genTimestamp__ = 'Tue Aug 16 18:33:10 2011'
__CHEETAH_src__ = 'prewikka/templates/FilterEdition.tmpl'
__CHEETAH_srcLastModified__ = 'Tue May  5 08:55:59 2009'
__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 FilterEdition(ClassicLayout):

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


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

        super(FilterEdition, 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 main_content(self, **KWS):



        ## CHEETAH: generated from #block main_content at line 4, 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(u'''
<script type="text/javascript"><!--
function newFilterElement(name, object, operator, object_value) {
\tobjects = new Array(''')
        _v = VFFSL(SL,"objects",True) # u'$objects' on line 8, col 22
        if _v is not None: write(_filter(_v, rawExpr=u'$objects')) # from line 8, col 22.
        write(u''')
\toperators = new Array(''')
        _v = VFFSL(SL,"operators",True) # u'$operators' on line 9, col 24
        if _v is not None: write(_filter(_v, rawExpr=u'$operators')) # from line 9, col 24.
        write(u''')

\ttable = document.getElementById("elements")

\tif ( ! name ) {
\t\tif ( table.lastChild.nodeName == "TR" ) {
\t\t\tchild = table.lastChild.firstChild.firstChild
\t\t\tname = new String(child.nodeValue)
\t\t\tif ( name.charAt(name.length - 1) == "Z" ) {
\t\t\t\tname = name.concat("A")
\t\t\t} else {
\t\t\t\tname = name.substr(0, name.length - 1) +
\t\t\t\t\t\t   String.fromCharCode(name.charCodeAt(name.length - 1) + 1)
\t\t\t}
\t\t} else {
\t\t\tname = "A"
\t\t}
\t}

\trow = document.createElement("tr")
\ttable.appendChild(row)

\tfield = document.createElement("td")
\trow.appendChild(field)
\tvalue = document.createTextNode(name)
\tfield.appendChild(value)

\tfield = document.createElement("td")
\trow.appendChild(field)
\tselect = document.createElement("select")
\tfield.appendChild(select)
\tselect.setAttribute("name", "object_" + name)
\tfor ( var i = 0; i < objects.length; i++ ) {
\t\toption = document.createElement("option")
\t\tif ( object == objects[i] ) {
\t\t\toption.setAttribute("selected", "true")
\t\t}
\t\toption.setAttribute("value", objects[i])
\t\tselect.appendChild(option)
\t\tvalue = document.createTextNode(objects[i])
\t\toption.appendChild(value)
\t}

\tfield = document.createElement("td")
\trow.appendChild(field)
\tselect = document.createElement("select")
\tfield.appendChild(select)
\tselect.setAttribute("name", "operator_" + name)
\tfor ( var i = 0; i < operators.length; i++ ) {
\t\t/* NB: setting selected to true before adding option to select is mandatory,
                   if it is done after, it won\'t work  */
\t\toption = document.createElement("option")
\t\tif ( operator == operators[i] ) {
\t\t\toption.setAttribute("selected", "true")
\t\t}
\t\tselect.appendChild(option)
\t\toption.setAttribute("value", operators[i])
\t\tvalue = document.createTextNode(operators[i])
\t\toption.appendChild(value)
\t}

\tfield = document.createElement("td")
\trow.appendChild(field)
\tinput = document.createElement("input")
\tfield.appendChild(input)
\t/* NB: if type=text is set before value=something, the value won\'t be displayed */
\t/*input.setAttribute("type", "text")*/
\tinput.setAttribute("name", "value_" + name)
\tinput.setAttribute("value", object_value)

\tfield = document.createElement("td")
\trow.appendChild(field)
\tlink = document.createElement("a")
\tlink.setAttribute("href", "#")
\tfield.appendChild(link)
\tlink.onclick = function() { this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode) }
\tlink.setAttribute("style", "position: relative; float: right;")
\tvalue = document.createTextNode("-")
\tlink.appendChild(value)
}
//--></script>


''')
        _orig_filter_93657111 = _filter
        filterName = u'CleanOutput'
        if self._CHEETAH__filters.has_key("CleanOutput"):
            _filter = self._CHEETAH__currentFilter = self._CHEETAH__filters[filterName]
        else:
            _filter = self._CHEETAH__currentFilter = \
			self._CHEETAH__filters[filterName] = getattr(self._CHEETAH__filtersLib, filterName)(self).filter
        write(u'''<div id="fieldset_page" style="display: table-cell;">

<fieldset class="fieldset_heading">
<legend>''')
        if False:
            _("Available filters")
        _v = VFFSL(SL,"_",False)("Available filters") # u'$_("Available filters")' on line 96, col 9
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Available filters")')) # from line 96, col 9.
        write(u'''</legend>
<form action="?" method="post">
  <input type="hidden" name="view" value="filter_edition"/>

  <select style="width: 400px;" name="filter_name">
    <option value="">&nbsp;</option>
''')
        for f in VFFSL(SL,"filters",True): # generated from line 102, col 3
            if VFFSL(SL,"f",True) == VFFSL(SL,"fltr.name",True): # generated from line 103, col 5
                selected = "selected=\"selected\""
            else: # generated from line 105, col 5
                selected = ""
            write(u'''    <option value="''')
            _v = VFFSL(SL,"f",True) # u'$f' on line 108, col 20
            if _v is not None: write(_filter(_v, rawExpr=u'$f')) # from line 108, col 20.
            write(u'''" ''')
            _v = VFFSL(SL,"selected",True) # u'$selected' on line 108, col 24
            if _v is not None: write(_filter(_v, rawExpr=u'$selected')) # from line 108, col 24.
            write(u'''>''')
            _v = VFFSL(SL,"f",True) # u'$f' on line 108, col 34
            if _v is not None: write(_filter(_v, rawExpr=u'$f')) # from line 108, col 34.
            write(u'''</option>
''')
        write(u'''  </select>

  <input type="submit" name="mode" value="''')
        if False:
            _("Load")
        _v = VFFSL(SL,"_",False)("Load") # u'$_("Load")' on line 112, col 43
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Load")')) # from line 112, col 43.
        write(u'''"/>
  <input type="submit" name="mode" value="''')
        if False:
            _("Delete")
        _v = VFFSL(SL,"_",False)("Delete") # u'$_("Delete")' on line 113, col 43
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Delete")')) # from line 113, col 43.
        write(u'''"/>
</form>
</fieldset>

<br/>

<form action="?" method="post">
<input type="hidden" name="view" value="filter_edition"/>

<fieldset>
<legend>''')
        if False:
            _("Edition")
        _v = VFFSL(SL,"_",False)("Edition") # u'$_("Edition")' on line 123, col 9
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Edition")')) # from line 123, col 9.
        write(u'''</legend>
<table>
 <tfoot>
  <tr>
   <td style="text-align: right;" colspan="4">&nbsp;</td>
   <td><a style="text-align: right;" href="javascript:newFilterElement(\'\', \'\', \'\', \'\')">+</a></td>
  </tr>
 </tfoot>
 <tbody id="elements"></tbody>
</table>

''')
        _filter = self._CHEETAH__currentFilter = _orig_filter_93657111
        _orig_filter_50441557 = _filter
        filterName = u'Filter'
        if self._CHEETAH__filters.has_key("Filter"):
            _filter = self._CHEETAH__currentFilter = self._CHEETAH__filters[filterName]
        else:
            _filter = self._CHEETAH__currentFilter = \
			self._CHEETAH__filters[filterName] = getattr(self._CHEETAH__filtersLib, filterName)(self).filter
        write(u'''
<script type="text/javascript"><!--
''')
        for element in VFFSL(SL,"elements",True): # generated from line 138, col 1
            write(u'''\tnewFilterElement("''')
            _v = VFN(VFFSL(SL,"utils",True),"escape_attribute",False)(VFFSL(SL,"element.name",True)) # u'$utils.escape_attribute($element.name)' on line 139, col 20
            if _v is not None: write(_filter(_v, rawExpr=u'$utils.escape_attribute($element.name)')) # from line 139, col 20.
            write(u'''", "''')
            _v = VFN(VFFSL(SL,"utils",True),"escape_attribute",False)(VFFSL(SL,"element.object",True)) # u'$utils.escape_attribute($element.object)' on line 139, col 62
            if _v is not None: write(_filter(_v, rawExpr=u'$utils.escape_attribute($element.object)')) # from line 139, col 62.
            write(u'''", "''')
            _v = VFN(VFFSL(SL,"utils",True),"escape_attribute",False)(VFFSL(SL,"element.operator",True)) # u'$utils.escape_attribute($element.operator)' on line 139, col 106
            if _v is not None: write(_filter(_v, rawExpr=u'$utils.escape_attribute($element.operator)')) # from line 139, col 106.
            write(u'''", "''')
            _v = VFN(VFFSL(SL,"utils",True),"escape_attribute",False)(VFFSL(SL,"element.value",True)) # u'$utils.escape_attribute($element.value)' on line 139, col 152
            if _v is not None: write(_filter(_v, rawExpr=u'$utils.escape_attribute($element.value)')) # from line 139, col 152.
            write(u'''");
''')
        write(u'''//--></script>

''')
        _filter = self._CHEETAH__currentFilter = _orig_filter_50441557
        _orig_filter_51121060 = _filter
        filterName = u'CleanOutput'
        if self._CHEETAH__filters.has_key("CleanOutput"):
            _filter = self._CHEETAH__currentFilter = self._CHEETAH__filters[filterName]
        else:
            _filter = self._CHEETAH__currentFilter = \
			self._CHEETAH__filters[filterName] = getattr(self._CHEETAH__filtersLib, filterName)(self).filter
        write(u'''
<br />


<table>
 <tr>
  <th>''')
        if False:
            _("Formula:")
        _v = VFFSL(SL,"_",False)("Formula:") # u'$_("Formula:")' on line 151, col 7
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Formula:")')) # from line 151, col 7.
        write(u'''</th>
  <td><input style="width: 400px;" type="text" name="formula" value="''')
        _v = VFFSL(SL,"formula",True) # u'$formula' on line 152, col 70
        if _v is not None: write(_filter(_v, rawExpr=u'$formula')) # from line 152, col 70.
        write(u'''"/></td>
 </tr>
 <tr>
  <th>''')
        if False:
            _("Name:")
        _v = VFFSL(SL,"_",False)("Name:") # u'$_("Name:")' on line 155, col 7
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Name:")')) # from line 155, col 7.
        write(u'''</th>
  <td><input style="width: 400px;" type="text" name="save_as" value="''')
        _v = VFFSL(SL,"fltr.name",True) # u'$fltr.name' on line 156, col 70
        if _v is not None: write(_filter(_v, rawExpr=u'$fltr.name')) # from line 156, col 70.
        write(u'''"/></td>
 </tr>
 <tr>
  <th style="vertical-align: top;">''')
        if False:
            _("Comment:")
        _v = VFFSL(SL,"_",False)("Comment:") # u'$_("Comment:")' on line 159, col 36
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Comment:")')) # from line 159, col 36.
        write(u'''</th>
  <td><textarea style="width: 400px;" name="filter_comment" rows="4" cols="55">''')
        _v = VFFSL(SL,"fltr.comment",True) # u'$fltr.comment' on line 160, col 80
        if _v is not None: write(_filter(_v, rawExpr=u'$fltr.comment')) # from line 160, col 80.
        write(u'''</textarea></td>
 </tr>
</table>

<input style="float: right;" type="submit" name="mode" value="''')
        if False:
            _("Save")
        _v = VFFSL(SL,"_",False)("Save") # u'$_("Save")' on line 164, col 63
        if _v is not None: write(_filter(_v, rawExpr=u'$_("Save")')) # from line 164, col 63.
        write(u'''"/> 
</fieldset>
</form>

</div>
''')
        _filter = self._CHEETAH__currentFilter = _orig_filter_51121060
        
        ########################################
        ## 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
        
        write(u'''
''')
        self.main_content(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_FilterEdition= 'writeBody'

## END CLASS DEFINITION

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


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


