changeset 585:83eeed69793f

new annotator layer for images.
author casties
date Tue, 13 Nov 2012 17:33:34 +0100
parents 011905457a5f
children 230ba358da3c
files SrvTxtUtils.py documentViewer.py zpt/layer_images_annotator.zpt zpt/viewer_images.zpt zpt/viewer_text.zpt
diffstat 5 files changed, 159 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/SrvTxtUtils.py	Mon Nov 12 18:13:33 2012 +0100
+++ b/SrvTxtUtils.py	Tue Nov 13 17:33:34 2012 +0100
@@ -11,7 +11,7 @@
 import logging
 
 
-srvTxtUtilsVersion = "1.5.1"
+srvTxtUtilsVersion = "1.6"
 
 def getInt(number, default=0):
     """returns always an int (0 in case of problems)"""
@@ -132,3 +132,32 @@
     # call original method
     return ImageFile.index_html(self, REQUEST, RESPONSE)
 
+
+def getBrowserType(self):
+    """check the browsers request to find out the browser type"""
+    bt = {}
+    ua = self.REQUEST.get_header("HTTP_USER_AGENT")
+    bt['ua'] = ua
+    bt['isIE'] = False
+    bt['isN4'] = False
+    if string.find(ua, 'MSIE') > -1:
+        bt['isIE'] = True
+    else:
+        bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1)
+        
+    try:
+        nav = ua[string.find(ua, '('):]
+        ie = string.split(nav, "; ")[1]
+        if string.find(ie, "MSIE") > -1:
+            bt['versIE'] = string.split(ie, " ")[1]
+    except: pass
+    
+    bt['isMac'] = string.find(ua, 'Macintosh') > -1
+    bt['isWin'] = string.find(ua, 'Windows') > -1
+    bt['isIEWin'] = bt['isIE'] and bt['isWin']
+    bt['isIEMac'] = bt['isIE'] and bt['isMac']
+    bt['staticHTML'] = False
+
+    return bt
+
+
--- a/documentViewer.py	Mon Nov 12 18:13:33 2012 +0100
+++ b/documentViewer.py	Tue Nov 13 17:33:34 2012 +0100
@@ -40,67 +40,6 @@
     
     return node
 
-def browserCheck(self):
-    """check the browsers request to find out the browser type"""
-    bt = {}
-    ua = self.REQUEST.get_header("HTTP_USER_AGENT")
-    bt['ua'] = ua
-    bt['isIE'] = False
-    bt['isN4'] = False
-    bt['versFirefox']=""
-    bt['versIE']=""
-    bt['versSafariChrome']=""
-    bt['versOpera']=""
-    
-    if string.find(ua, 'MSIE') > -1:
-        bt['isIE'] = True
-    else:
-        bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1)
-    # Safari oder Chrome identification    
-    try:
-        nav = ua[string.find(ua, '('):]
-        nav1=ua[string.find(ua,')'):]
-        nav2=nav1[string.find(nav1,'('):]
-        nav3=nav2[string.find(nav2,')'):]
-        ie = string.split(nav, "; ")[1]
-        ie1 =string.split(nav1, " ")[2]
-        ie2 =string.split(nav3, " ")[1]
-        ie3 =string.split(nav3, " ")[2]
-        if string.find(ie3, "Safari") >-1:
-            bt['versSafariChrome']=string.split(ie2, "/")[1]
-    except: pass
-    # IE identification
-    try:
-        nav = ua[string.find(ua, '('):]
-        ie = string.split(nav, "; ")[1]
-        if string.find(ie, "MSIE") > -1:
-            bt['versIE'] = string.split(ie, " ")[1]
-    except:pass
-    # Firefox identification
-    try:
-        nav = ua[string.find(ua, '('):]
-        nav1=ua[string.find(ua,')'):]
-        if string.find(ie1, "Firefox") >-1:
-            nav5= string.split(ie1, "/")[1]
-            logging.debug("FIREFOX: %s"%(nav5))
-            bt['versFirefox']=nav5[0:3]                   
-    except:pass
-    #Opera identification
-    try:
-        if string.find(ua,"Opera") >-1:
-            nav = ua[string.find(ua, '('):]
-            nav1=nav[string.find(nav,')'):]
-            bt['versOpera']=string.split(nav1,"/")[2]
-    except:pass
-    
-    bt['isMac'] = string.find(ua, 'Macintosh') > -1
-    bt['isWin'] = string.find(ua, 'Windows') > -1
-    bt['isIEWin'] = bt['isIE'] and bt['isWin']
-    bt['isIEMac'] = bt['isIE'] and bt['isMac']
-    bt['staticHTML'] = False
-
-    return bt
-
 def getParentPath(path, cnt=1):
     """returns pathname shortened by cnt"""
     # make sure path doesn't end with /
@@ -108,6 +47,7 @@
     # split by /, shorten, and reassemble
     return '/'.join(path.split('/')[0:-cnt])
 
+
 ##
 ## documentViewer class
 ##
@@ -144,6 +84,7 @@
     layer_text_annotator = PageTemplateFile('zpt/layer_text_annotator', globals())
     layer_text_gis = PageTemplateFile('zpt/layer_text_gis', globals())
     layer_text_pundit = PageTemplateFile('zpt/layer_text_pundit', globals())
+    layer_images_annotator = PageTemplateFile('zpt/layer_images_annotator', globals())
     layer_index_extended = PageTemplateFile('zpt/layer_index_extended', globals())
     # toc templates
     toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals())
@@ -160,7 +101,7 @@
     docuviewer_css.index_html = refreshingImageFileIndexHtml
     docuviewer_ie_css = ImageFile('css/docuviewer_ie.css',globals())
     # make docuviewer_ie_css refreshable for development
-    docuviewer_ie_css.index_html = refreshingImageFileIndexHtml
+    #docuviewer_ie_css.index_html = refreshingImageFileIndexHtml
     jquery_js = ImageFile('js/jquery.js',globals())
     
     
@@ -346,12 +287,6 @@
         """returns dict with list of available layers per viewMode"""
         return self.availableLayers
     
-    def getBrowser(self):
-        """getBrowser the version of browser """
-        bt = browserCheck(self)
-        logging.debug("BROWSER VERSION: %s"%(bt))
-        return bt
-        
     def findDigilibUrl(self):
         """try to get the digilib URL from zogilib"""
         url = self.template.zogilib.getDLBaseUrl()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/layer_images_annotator.zpt	Tue Nov 13 17:33:34 2012 +0100
@@ -0,0 +1,83 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<metal:block metal:define-macro="html_head" tal:condition="python:'annotator' in viewLayers">
+  <!--  annotator for digilib -->
+  <script type="text/javascript" tal:attributes="src string:$dlBaseUrl/jquery/showdown.js"></script>
+  <script type="text/javascript" tal:attributes="src string:$dlBaseUrl/jquery/annotator-dl.js"></script>
+  <script type="text/javascript" tal:attributes="src string:$dlBaseUrl/jquery/jquery.digilib.annotator.js"></script>
+  <link rel="stylesheet" type="text/css" tal:attributes="href string:$dlBaseUrl/jquery/annotator.min.css"/>
+
+  <script type="text/javascript" 
+    tal:define="global annServerUrl string:http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator;
+    global annTokenUrl string:$viewerUrl/template/token/getLoginToken;
+    annUrl python:'http://echo.mpiwg-berlin.mpg.de/documents%s?pn=%s'%(docinfo['documentPath'],pageinfo['pn']);
+    resUrl python:'http://echo.mpiwg-berlin.mpg.de/documents%s'%(docinfo['documentPath']);
+    global annUser python:here.getAuthenticatedUser(anon='anonymous');
+    global annGroup python:request.get('annotator_group', None);
+    permUser python:test(annGroup, 'group:%s'%annGroup, annUser);"
+    tal:content="structure string:
+    dlOpts.digilibFrontendPath='/jquery/digilib-ann.html';
+    dlOpts.annotationServerUrl='$annServerUrl';
+    dlOpts.annotationTokenUrl='$annTokenUrl';
+    dlOpts.annotationUser='$annUser';
+    dlOpts.annotatorPlugins=['Auth','Permissions','Store','Markdown','DigilibIntegrator'];
+    dlOpts.annotatorPluginSettings={'Store':{'annotationData':{'uri':'$annUrl','resource':'$resUrl'},'loadFromSearch':{'uri':'$annUrl'}},
+        'Permissions':{'read':[],'update':['$permUser'],'delete':['$permUser'],'admin':['$permUser']}};
+    "></script>
+</metal:block>
+
+</head>
+<body>
+  <!-- right-side options -->
+  <div class="col buttons">
+    <!-- LAYER DISPLAY OPTION  -->
+    <ul>
+      <li metal:define-macro="layer_select_li">
+        <input type="checkbox" class="autosubmit" name="viewLayer" value="annotator"
+          tal:attributes="checked python:'annotator' in viewLayers" /> Annotator
+      </li>
+    </ul>
+  </div>
+
+  <metal:block metal:define-macro="options_box" tal:condition="python:'annotator' in viewLayers">
+    <!-- BEGIN ANNOTATIONS -->
+    <div class="options">
+      <h4>Annotator</h4>
+      <ul>
+        <li><a href="javascript:$digilib.digilib('setAnnotationMark')"> <img tal:condition="exists:here/template/annotation-mark.png"
+            tal:attributes="src here/template/annotation-mark.png/absolute_url" /> annotate point
+        </a></li>
+        <li><a href="javascript:$digilib.digilib('setAnnotationRegion')"> <img tal:condition="exists:here/template/annotation-region.png"
+            tal:attributes="src here/template/annotation-region.png/absolute_url" /> annotate region
+        </a></li>
+      </ul>
+      <p>
+        User "<span tal:replace="annUser" />"<span tal:condition="annGroup" tal:content="string: ($annGroup)"/>.
+      </p>
+      <!-- TODO: login button -->
+      <form class="autosubmit" tal:attributes="action viewerUrl">
+        <input type="hidden" tal:define="params python:here.getParams(params={'annotator_group':None});" tal:repeat="param params"
+          tal:attributes="name param; value python:params[param]" />
+        <p>
+          In group
+          <select class="autosubmit" name="annotator_group">
+            <option value="" tal:attributes="selected not:annGroup;"> </option>
+            <option
+              tal:repeat="group python:here.getAnnotatorGroupsForUser(user=annUser,annotationServerUrl=annServerUrl)"
+              tal:attributes="value group/id; selected python:group['id']==annGroup;" tal:content="group/name" />
+          </select> <br /> 
+          <input type="submit" value="Go!" />
+        </p>
+      </form>
+      <p tal:define="std modules/Products.PythonScripts.standard">
+        <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">log in</a>
+      </p>
+    </div>
+    <!-- END ANNOTATIONS -->
+  </metal:block>
+
+</body>
+
+</html>
--- a/zpt/viewer_images.zpt	Mon Nov 12 18:13:33 2012 +0100
+++ b/zpt/viewer_images.zpt	Tue Nov 13 17:33:34 2012 +0100
@@ -2,6 +2,8 @@
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
   tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode;
+              viewLayer pageinfo/viewLayer; viewLayers pageinfo/viewLayers;
+              availableLayers python:here.getAvailableLayers().get('images', None);
               tocMode pageinfo/tocMode; viewerUrl docinfo/viewerUrl;
               numPages docinfo/numPages | nothing; dlBaseUrl docinfo/digilibBaseUrl | nothing;">
 <head>
@@ -27,6 +29,13 @@
             'scalerInsets' : {'x':300, 'y':100}\n
         };\n'''%(dlBaseUrl,docinfo.get('imagePath',''),pageinfo.get('pn','1'))"></script>
 
+<!--  layer headers (rendered always) -->
+<tal:block tal:repeat="layer availableLayers">
+  <tal:block tal:define="mpath string:here/template/layer_images_${layer}/macros/html_head" tal:condition="python:exists(mpath)">
+    <metal:block metal:use-macro="python:path(mpath)" />
+  </tal:block>
+</tal:block>
+
 <script type="text/javascript">
 	// <!--
 	$(document).ready(function() {
@@ -56,7 +65,7 @@
       <div class="col toc">
         <metal:block metal:use-macro="python:path('here/template/toc_%s/macros/main'%tocMode)" />
       </div>
-      <!-- col-main: text page -->
+      <!-- col-main: document page -->
       <div class="col main">
         <div class="ruler top">
           <metal:block metal:use-macro="here/template/common_template/macros/page_ruler" />
@@ -69,7 +78,28 @@
         <!-- /content -->
       </div>
       <!-- /col-main -->
+      
       <div class="col buttons">
+        <!-- layer switcher -->
+        <div class="options" tal:condition="availableLayers">
+          <h4>Image layer</h4>
+          <form tal:attributes="action viewerUrl" class="autosubmit">
+            <input type="hidden" tal:define="params python:here.getParams(params={'viewLayer':None})"
+              tal:repeat="param params" tal:attributes="name param; value python:params[param]" />
+            <ul>
+              <!-- layer select buttons (rendered always) -->
+              <tal:block tal:repeat="layer availableLayers">
+                <tal:block tal:define="mpath string:here/template/layer_images_${layer}/macros/layer_select_li"
+                  tal:condition="python:exists(mpath)">
+                  <li metal:use-macro="python:path(mpath)" />
+                </tal:block>
+              </tal:block>
+            </ul>
+            <input type="submit" value="Go!" />
+          </form>
+        </div>
+
+        <!-- digilib options -->
         <div class="options digilib">
           <ul>
             <li><a href="javascript:$digilib.digilib('zoomBy', 1.4)"> <img tal:condition="exists:here/template/zoom-in.png"
@@ -104,9 +134,17 @@
             </a></li>
           </ul>
         </div>
+
+        <!--  layer option boxes (rendered if active) -->
+        <tal:block tal:repeat="layer availableLayers">
+          <tal:block tal:define="mpath string:here/template/layer_images_${layer}/macros/options_box"
+            tal:condition="python:exists(mpath)">
+            <metal:block metal:use-macro="python:path(mpath)" />
+          </tal:block>
+        </tal:block>
       </div>
-    </div>
-    <!-- page-body -->
+    </div><!-- /page-body -->
+    
     <div class="page-body" tal:condition="python:not here.isAccessible(docinfo)">
       <div class="errortext">Sorry, access to this document is restricted.</div>
     </div>
--- a/zpt/viewer_text.zpt	Mon Nov 12 18:13:33 2012 +0100
+++ b/zpt/viewer_text.zpt	Tue Nov 13 17:33:34 2012 +0100
@@ -73,7 +73,7 @@
 
       <!-- right-side options -->
       <div class="col buttons">
-        <!--"BEGIN TEXT DISPLAY"  -->
+        <!--BEGIN TEXT LAYERS -->
         <div class="options" tal:condition="availableLayers">
           <h4>Text layer</h4>
           <form tal:attributes="action viewerUrl" class="autosubmit">
@@ -91,7 +91,7 @@
             <input type="submit" value="Go!" />
           </form>
         </div>
-        <!--"END TEXT DISPLAY"-->
+        <!--END TEXT LAYERS-->
 
         <!--"BEGIN TEXT SIZE"-->
         <!--  <div class="options">