<!-- -*- mode: python-*- -->
<red:code xmlns:red="http://redfoot.sourceforge.net/2001/06/">

  from redfootlib.util import *

  <red:module name="Generic">

    <red:sub-module instance="editor"
                    class="Editor"
                    from="redmodules.editor"/>

    <red:sub-module instance="neighbours"
                    class="Neighbours"
                    from="redmodules.neighbours"/>

    def __getattr__(self, name):
        if name=="rednode": # default rednode to self.app.rednode
            self.set_rednode(self.app.rednode)
            return self.rednode
        else:
            raise AttributeError
        
    # TODO: does anything in generic/editor/viewer require a rednode
    # or just a TripleStoreIO
    def set_rednode(self, rednode):
        self.rednode = rednode
        self.editor.set_rednode(rednode)
        self.neighbours.set_rednode(rednode)        

    <red:facet name="/">
      <red:exec>
        depth = self.app.remaining_path_info.count("/")
        relative_path = '../' * depth
      </red:exec>
    
      <HTML>
        <HEAD>
          <TITLE>Generic Viewer</TITLE>
          <STYLE>
            body {
              margin:      10px;
              font-family: "Trebuchet MS", sans-serif;
              font-size:   10pt;
              color:       #000;
              background:  #FFF;
            }

            h1 {
              font-family: "Trebuchet MS", sans-serif;
              background:  #900;
              font-weight: normal;
              color:       #FFF;
              padding:     5px 10px;
              margin:      -10px -10px 10px -10px;
            }

            h2 {
              font-family: "Trebuchet MS", sans-serif;
              color: #900;
            }

            p.MENUBAR {
              margin: -10px -10px 10px -10px;
              padding: 3px 20px;
              background:  #000;
              color:       #CCC;
            }

            p.MENUBAR a {
              color:       #CCC;
              text-decoration: none;
              font-weight: bold;
            }

            p.MENUBAR a:visited {
              color:       #CCC;
            }

            p.MENUBAR a:hover {
              color:       #FFF;
            }

            p.MENUBAR2 a {
              color:       #000;
              text-decoration: none;
              font-weight: bold;
              border-top: 1px solid #CCC;
              border-left: 1px solid #CCC;
              border-right: 1px solid #000;
              border-bottom: 1px solid #000;
              padding: 3px;
            }

            p.MENUBAR2 a:visited {
              color:       #000;
            }

            p.MENUBAR2 a:hover {
              background:  #CCC;
            }

            .CLASS {
              font-weight: bold;
            }

            TD {
              font-size:   10pt;
              background:  #EEE;
            }

            INPUT, SELECT {
              font-size:   10pt;
              font-family: "Trebuchet MS", sans-serif;
            }

          </STYLE>
        </HEAD>
        <BODY>

          <H1>Generic Viewer</H1>
          <P CLASS="MENUBAR">
            <A HREF="{relative_path}class_list">
              Class List</A> |
            <A HREF="{relative_path}full_subclass_tree">
              Full Sub-Class Tree</A> |
            <A HREF="{relative_path}partial_subclass_tree">
              Partial Sub-Class Tree</A>
          </P>  
          <P CLASS="MENUBAR">
            <A HREF="{relative_path}add">Add External Resource</A> |
            <A HREF="{relative_path}edit">Create an Abstract Resource</A>
          </P>  
          <P CLASS="MENUBAR">
            <!--
              TODO: make the absolute path configureable via the modules rdf
              -->
            <A HREF="/output">RDF (local only)</A> |
            <A HREF="{relative_path}neighbours/">Add Read-Only Neighbour</A>            
          </P>  
          <red:exec>subject = self.app.request.get_parameter('subject', None)</red:exec>
          <red:if test="subject">
            <P CLASS="MENUBAR2">
              <A HREF='{relative_path}view?subject={encode_URI(subject)}'>View</A>
              <A HREF='{relative_path}edit?subject={encode_URI(subject)}'>Full Edit</A>
              <A HREF='{relative_path}edit_subject?subject={encode_URI(subject)}'>Edit Subject</A>              
            </P>
          </red:if>

          <red:apply/>

        </BODY>

      </HTML>
    </red:facet>

    <red:facet name="/output"
               content-type="text/rdf" >
      <red:exec>
        self.rednode.output(self.app.response)
      </red:exec>
    </red:facet>

  </red:module>

</red:code>
