Mercurial > hg > documentViewer
changeset 480:50a28442f21c elementtree
more new template stuff
author | casties |
---|---|
date | Mon, 15 Aug 2011 21:09:08 +0200 |
parents | fe5b0e4ac5f2 |
children | 0a0f7f570f90 |
files | css/docuviewer.css documentViewer.py zpt/head_main.zpt zpt/toc_thumbs.zpt zpt/viewer_text.zpt |
diffstat | 5 files changed, 200 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/css/docuviewer.css Mon Aug 15 11:58:56 2011 +0200 +++ b/css/docuviewer.css Mon Aug 15 21:09:08 2011 +0200 @@ -1,3 +1,14 @@ + +div.page_body { + display: table-row; +} +div.toc { + display: table-cell; +} +div.text { + display: table-cell; +} + .thumb { padding: 3px; }
--- 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')
--- a/zpt/head_main.zpt Mon Aug 15 11:58:56 2011 +0200 +++ b/zpt/head_main.zpt Mon Aug 15 21:09:08 2011 +0200 @@ -1,4 +1,20 @@ -<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo; formattedLabel python:here.metadata.getFormattedLabel(bibdata=docinfo.get('bib',None))"> - <span tal:condition="not:formattedLabel" tal:content="string:(no bibliographical information for ${docinfo/bib_type})"/> - <span tal:condition="formattedLabel" tal:content="structure formattedLabel"/> -</tal:block> +<!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> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +</head> +<body> + <!-- block used for page header content area --> + <metal:block metal:define-macro="main" + tal:define="docpath docinfo/textURLPath | nothing; + query here/REQUEST/query | nothing; + queryType here/REQUEST/queryType | nothing; + bib docinfo/bib | nothing; bibType docinfo/bibType | nothing; + formattedLabel python:here.metadataService.getBibFormattedLabel(bibdata=bib);"> + <span tal:condition="not:formattedLabel" + tal:content="string:(no bibliographical information for ${bibType})" /> + <span tal:condition="formattedLabel" tal:content="structure formattedLabel" /> + </metal:block> +</body> +</html>
--- a/zpt/toc_thumbs.zpt Mon Aug 15 11:58:56 2011 +0200 +++ b/zpt/toc_thumbs.zpt Mon Aug 15 21:09:08 2011 +0200 @@ -1,31 +1,70 @@ -<div tal:define="docinfo options/docinfo; pageinfo options/pageinfo; - start pageinfo/start; end pageinfo/end; rows pageinfo/rows; cols pageinfo/cols; - current pageinfo/current; grpsize pageinfo/groupsize"> +<!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> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +</head> +<body> + <!-- block used for main content area --> + <div class="toc" metal:define-macro="main" + tal:define="start pageinfo/start; + grpsize pageinfo/groupsize; + numgroups pageinfo/numgroups; + pageBatch pageinfo/pageBatch; pageZero pageinfo/pageZero; + left python:test(flowLtr,pageBatch['prevStart'],pageBatch['nextStart']); + right python:test(flowLtr,pageBatch['nextStart'],pageBatch['prevStart']);"> + <ul class="toctype"> + <li class="sel"> + <a tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a> + </li> + <li tal:condition="python:docinfo.get('numTocEntries', None)"> + <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a> + </li> + <li tal:condition="python:docinfo.get('numFigureEntries', None)"> + <a tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a> + </li> + <li> + <a tal:attributes="href python:here.getLink('tocMode','none')">None</a> + </li> + </ul> -<div class="thumbruler"> - <span tal:condition="python:(start>1)"> - <a tal:attributes="href python:here.getLink(param='start',val=max(start-grpsize,1))"><</a> - </span> - <select tal:attributes="onChange python:'location.href=\''+here.getLink(param='start',val=None)+'&start=\'+this.options[this.selectedIndex].value'"> - <option tal:repeat="grp python:range(pageinfo['numgroups'])" - tal:attributes="selected python:(start==grp*grpsize+1); value python:(grp*grpsize+1)" - tal:content="python:(grp*grpsize+1)"/> - </select> - <span tal:condition="python:(start+grpsize<int(docinfo['numPages']))"> - <a tal:attributes="href python:here.getLink(param='start',val=start+grpsize)">></a> - </span> -</div> -<table> - <tr tal:repeat="row python:range(rows)"> - <tal:block tal:repeat="idx python:range(start+row*cols,start+(row+1)*cols)"> - <td align="center" tal:condition="python:(idx<=end)" - tal:attributes="class python:here.getStyle(idx,current,'thumb')"> - <a tal:attributes="href python:here.getLink(param='pn',val=idx)"> - <img class="thumbimg" border="0" tal:attributes="src string:${docinfo/imageURL}&pn=$idx&dw=100&dh=100"/> - <div class="thumbcap" tal:content="idx"/> - </a> - </td> - </tal:block> - </tr> -</table> -</div> + <div class="content"> + <div class="ruler"> + <form class="autosubmit" tal:attributes="action viewerUrl"> + <input type="hidden" tal:define="params python:here.getParams('start',None)" + tal:repeat="param params" + tal:attributes="name param; value python:params[param]" /> + <a tal:condition="left" tal:attributes="href python:here.getLink('start',left)"><</a> + <span tal:condition="not:left"><</span> + <select class="autosubmit" name="start" + tal:define="ofs python:test(pageinfo['pageZero'],0,1)"> + <tal:block tal:repeat="grp python:range(numgroups)"> + <option tal:define="idx python:max(grp*grpsize+ofs,1)" + tal:attributes="selected python:start==idx; value idx;" + tal:content="python:'%s - %s'%(idx,min((grp+1)*grpsize+ofs-1,numPages))" /> + </tal:block> + </select> + <input type="submit" value="Go" /> + <a tal:condition="right" tal:attributes="href python:here.getLink('start',right)">></a> + <span tal:condition="not:right">></span> + </form> + </div> + + <table class="thumbs"> + <tr tal:repeat="row pageBatch/pages"> + <td tal:repeat="thumb row" + tal:attributes="class python:here.getStyle(thumb['idx'],pn,'thumb')"> + <a tal:define="idx thumb/idx" tal:condition="idx" + tal:attributes="href python:here.getLink('pn',idx)"> + <img + tal:attributes="src python:test(docinfo['imageURL'],here.getScalerUrl(pn=idx,dw=100,dh=100,docinfo=docinfo),'images/pic'); + alt idx" /><br/> + <span tal:content="idx" /> + </a> + </td> + </tr> + </table> + </div> <!-- content --> + </div> <!-- toc --> +</body> +</html> \ No newline at end of file
--- a/zpt/viewer_text.zpt Mon Aug 15 11:58:56 2011 +0200 +++ b/zpt/viewer_text.zpt Mon Aug 15 21:09:08 2011 +0200 @@ -1,30 +1,64 @@ <!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" - tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode; tocMode pageinfo/tocMode"> + tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode; + tocMode pageinfo/tocMode; viewType pageinfo/viewType; viewerUrl docinfo/viewerUrl; + numPages docinfo/numPages | nothing;"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="template/docuviewer_css" type="text/css"> </head> -<body tal:condition="docinfo/numPages"> -<div tal:replace="structure python:here.template.head_main(docinfo=docinfo,viewMode=viewMode,pageinfo=pageinfo)"/> -<tal:block tal:condition="python:here.isAccessible(docinfo)"> -<table border="0" width="100%" height="100%"> - <tr> - <td width="300px" valign="top"> - <tal:block tal:replace="structure python:getattr(here.template, 'toc_%s'%tocMode)(docinfo=docinfo,pageinfo=pageinfo)"/> - </td> - <td width="100%" valign="top"> - <tal:block tal:content="structure python:getattr(here.template, 'page_main_%s'%viewMode)(docinfo=docinfo,pageinfo=pageinfo,mk=options['mk'])"/> - </td> - </tr> -</table> -</tal:block> -<tal:block tal:condition="not:python:here.isAccessible(docinfo)"> -<div class="errortext">Sorry, access to this document is restricted.</div> -</tal:block> +<body tal:condition="numPages"> + <tal:block tal:define="docpath docinfo/textURLPath; + pn pageinfo/pn; + flowLtr python:pageinfo.get('pageFlow','ltr')!='rtl'; + prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None); + first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None); + left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev); + leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first); + textPage python:here.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo);"> + <div class="page_head" metal:use-macro="here/template/head_main/macros/main" /> + <div class="page_body" tal:condition="python:here.isAccessible(docinfo)"> + <!--table of contents--> + <div class="toc" + metal:use-macro="python:path('here/template/toc_%s/macros/main'%tocMode)" /> + <!-- text page --> + <div class="text"> + <div class="ruler"> + <form class="autosubmit pageruler" tal:attributes="action viewerUrl"> + <input type="hidden" tal:define="params python:here.getParams('pn', None)" + tal:repeat="param params" tal:attributes="name param; value python:params[param]" /> + page + <a tal:condition="leftest" tal:attributes="href python:here.getLink('pn',leftest)">|<</a> + <span tal:condition="not:leftest">|<</span> + <a tal:condition="left" tal:attributes="href python:here.getLink('pn',left)"><</a> + <span tal:condition="not:left"><</span> + <input class="autosubmit" size="3" type="text" name="pn" tal:attributes="value pn" /> + <tal:block tal:define="originalPage pageinfo/pageNumberOrig | nothing" + tal:condition="python:originalPage!=None"> + (<span tal:replace="originalPage"/><span tal:define="originalPageNorm pageinfo/pageNumberOrigNorm | nothing" tal:condition="python:originalPageNorm!=None">[<span tal:replace="originalPageNorm"/>]</span>) + </tal:block> + <input type="submit" value="Go" /> + of + <span tal:replace="numPages"/> + <a tal:condition="right" tal:attributes="href python:here.getLink('pn',right)">></a> + <span tal:condition="not:right">></span> + <a tal:condition="rightest" tal:attributes="href python:here.getLink('pn',rightest)">>|</a> + <span tal:condition="not:rightest">>|</span> + </form> + </div> + <div class="page"> + <div class="pageHeaderTitle" tal:condition="exists:pageinfo/pageHeaderTitle" tal:content="structure pageinfo/pageHeaderTitle"/> + <tal:block tal:replace="structure textPage"/> + </div> + </div> + </div> + <div class="page_body" tal:condition="python:not here.isAccessible(docinfo)"> + <div class="errortext">Sorry, access to this document is restricted.</div> + </div> + </tal:block> </body> -<body tal:condition="not:docinfo/numPages"> -<div class="errortext">Sorry, document doesn't exist.</div> +<body tal:condition="not:numPages"> + <div class="errortext">Sorry, document doesn't exist.</div> </body> </html>