diff documentViewer.py @ 480:50a28442f21c elementtree

more new template stuff
author casties
date Mon, 15 Aug 2011 21:09:08 +0200
parents fe5b0e4ac5f2
children 7ca8ac7db06e
line wrap: on
line diff
--- a/documentViewer.py	Mon Aug 15 11:58:56 2011 +0200
+++ b/documentViewer.py	Mon Aug 15 21:09:08 2011 +0200
@@ -1,4 +1,5 @@
 from OFS.Folder import Folder
+from OFS.Image import File
 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 
 from AccessControl import ClassSecurityInfo
@@ -135,8 +136,9 @@
     page_main_xml = PageTemplateFile('zpt/page_main_xml', globals())
     page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', globals())
     head_main = PageTemplateFile('zpt/head_main', globals())
-    docuviewer_css = PageTemplateFile('css/docuviewer.css', globals())
     info_xml = PageTemplateFile('zpt/info_xml', globals())
+    # TODO: can this be nicer?
+    docuviewer_css = File('docuviewer_css','',open(os.path.join(package_home(globals()),'css/docuviewer.css')), content_type='text/css')
     
     
     thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals())
@@ -347,13 +349,32 @@
         """try to get the digilib URL from zogilib"""
         url = self.template.zogilib.getDLBaseUrl()
         return url
+    
+    def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None):
+        """returns URL to digilib Scaler with params"""
+        url = None
+        if docinfo is not None:
+            url = docinfo.get('imageURL', None)
+            
+        if url is None:
+            url = "%s/servlet/Scaler?"%self.digilibBaseUrl
+            if fn is None and docinfo is not None:
+                fn = docinfo.get('imagePath','')
+            
+            url += "fn=%s"%fn
+            
+        if pn:
+            url += "&pn=%s"%pn
+            
+        url += "&dw=%s&dh=%s"%(dw,dh)
+        return url
 
     def getDocumentViewerURL(self):
         """returns the URL of this instance"""
         return self.absolute_url()
     
     def getStyle(self, idx, selected, style=""):
-        """returns a string with the given style and append 'sel' if path == selected."""
+        """returns a string with the given style and append 'sel' if idx == selected."""
         #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style))
         if idx == selected:
             return style + 'sel'
@@ -708,6 +729,7 @@
 
         current = getInt(current)
         pageinfo['current'] = current
+        pageinfo['pn'] = current
         rows = int(rows or self.thumbrows)
         pageinfo['rows'] = rows
         cols = int(cols or self.thumbcols)
@@ -718,14 +740,13 @@
         start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
         # int(current / grpsize) * grpsize +1))
         pageinfo['start'] = start
-        pn = self.REQUEST.get('pn','1')
-        pageinfo['pn'] = pn
+        
         np = int(docinfo.get('numPages', 0))
         if np == 0:
             # numPages unknown - maybe we can get it from text page
             if docinfo.get('textURLPath', None):
                 # cache text page as well
-                pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo)
+                pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=current, docinfo=docinfo, pageinfo=pageinfo)
                 np = int(docinfo.get('numPages', 0))
                 
         pageinfo['numgroups'] = int(np / grpsize)
@@ -737,8 +758,9 @@
         # add zeroth page for two columns
         pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
         pageinfo['pageZero'] = pageZero
-        pageinfo['pageList'] = self.getPageList(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
+        pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
                 
+        # TODO: do we need this here?
         pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
         pageinfo['query'] = self.REQUEST.get('query','') 
         pageinfo['queryType'] = self.REQUEST.get('queryType','')
@@ -764,10 +786,11 @@
         return pageinfo
 
 
-    def getPageList(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
-        """returns array of page informations for one screenfull of thumbnails"""
+    def getPageBatch(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
+        """returns dict with array of page informations for one screenfull of thumbnails"""
+        grpsize = rows * cols
         if maxIdx == 0:
-            maxIdx = start + rows * cols
+            maxIdx = start + grpsize
 
         pages = []
         if pageZero and start == 1:
@@ -792,8 +815,20 @@
                 
             pages.append(row)
             
-        logging.debug("getPageList returns=%s"%(pages))
-        return pages
+        batch = {}
+        if start > 1:
+            batch['prevStart'] = max(start - grpsize, 1)
+        else:
+            batch['prevStart'] = None
+            
+        if start + grpsize < maxIdx:
+            batch['nextStart'] = start + grpsize
+        else:
+            batch['nextStart'] = None
+
+        batch['pages'] = pages
+        #logging.debug("getPageList returns=%s"%(batch))
+        return batch
         
 
     security.declareProtected('View management screens','changeDocumentViewerForm')