changeset 121:f6ce62994858

text_x_arnica: initial setup for css. DataBrowserWidget.format replaced by an internal method because of nesting form elements which don't validate for html4.01 function getCacheUrl added that points to cache of filename on page pagename
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 28 Jun 2008 13:35:41 +0200
parents 65c46d7d48f1
children 8b0eee98ac28
files data/plugin/parser/text_x_arnica.py htdocs/modern/css/text_x_arnica.css
diffstat 2 files changed, 281 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Fri Jun 27 20:15:25 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Sat Jun 28 13:35:41 2008 +0200
@@ -34,6 +34,101 @@
 
 parser_name = __name__.split('.')[-1]
 
+class _DataBrowserWidget(DataBrowserWidget):
+    """ we have to remove the used form in format otherwise the needed form elements
+        becomes a nested form and this do raise lot's of strict html4.01 errors"""
+    def format(self):
+        fmt = self.request.formatter
+
+        result = []
+        #result.append(fmt.div(1))
+
+        havefilters = False
+        for col in self.data.columns:
+            if col.autofilter:
+                havefilters = True
+                break
+        if havefilters:
+            result.append(fmt.rawHTML('<input type="submit" value="%s" %s>' % (self._filter, self._name('submit'))))
+
+        result.append(fmt.table(1, id='%stable' % self.data_id))
+
+        # add header line
+        if self._show_header:
+            result.append(fmt.table_row(1))
+            for idx in range(len(self.data.columns)):
+                col = self.data.columns[idx]
+                if col.hidden:
+                    continue
+                result.append(fmt.table_cell(1))
+                result.append(fmt.strong(1))
+                result.append(col.label or col.name)
+                result.append(fmt.strong(0))
+
+                if col.autofilter:
+                    result.append(fmt.linebreak(False))
+                    select = '<select %s onchange="dbw_update_search(\'%s\');">%s</select>' % (
+                                      self._name('filter%d' % idx),
+                                      self.data_id,
+                                      self._filteroptions(idx))
+                    result.append(fmt.rawHTML(select))
+
+                result.append(fmt.table_cell(0))
+            result.append(fmt.table_row(0))
+
+        # add data
+        self.data.reset()
+        row = self.data.next()
+        if row is not None:
+            filters = [None] * len(row)
+
+            if havefilters:
+                for idx in range(len(row)):
+                    name = '%sfilter%d' % (self.data_id, idx)
+                    if name in self.request.form:
+                        filters[idx] = self.request.form[name][0]
+                        if filters[idx] == self._all:
+                            filters[idx] = None
+
+        while row:
+            hidden = False
+
+            if havefilters:
+                # check if row needs to be hidden due to filtering
+                for idx in range(len(row)):
+                    if filters[idx]:
+                        if isinstance(row[idx], tuple):
+                            data = unicode(row[idx][1])
+                        else:
+                            data = unicode(row[idx])
+                        if data != '' and filters[idx] == self._notempty:
+                            continue
+                        if data == '' and filters[idx] == self._empty:
+                            continue
+                        if data != filters[idx]:
+                            hidden = True
+                            break
+
+            if not hidden:
+                result.append(fmt.table_row(1))
+                for idx in range(len(row)):
+                    if self.data.columns[idx].hidden:
+                        continue
+                    if isinstance(row[idx], tuple):
+                        result.append(fmt.table_cell(1, abbr=unicode(row[idx][1])))
+                        result.append(unicode(row[idx][0]))
+                    else:
+                        result.append(fmt.table_cell(1))
+                        result.append(unicode(row[idx]))
+                    result.append(fmt.table_cell(0))
+                result.append(fmt.table_row(0))
+
+            row = self.data.next()
+
+        result.append(fmt.table(0))
+        #result.append(fmt.div(0))
+        return ''.join(result)
+
 def macro_arnica(target_page=u'', columns=4, file_regex=u'.',
                  image_for_webnail=False,
                  show_text=True, show_date=True, show_tools=True,
@@ -84,7 +179,6 @@
             webnail_width = '%g%s' % webnail_width
 
     return locals()
-
 # ToDo may be move to wikiutil
 def get_exif_info(file_name):
     """ gets exif info from image file
@@ -108,6 +202,13 @@
                  if wikiutil.isPicture(fn) and not fn.startswith('tmp.')]
     return files
 
+def getCacheUrl(base_url, pagename, filename):
+    """ Get URL that points to cache of `filename` on page `pagename`. """
+    url = "%(base_url)s/%(pagename)s?action=arnica_slides&do=view&target=%(filename)s" % {'base_url': base_url,
+                                                                                          'pagename': pagename,
+                                                                                          'filename': filename}
+    return wikiutil.escape(url)
+
 class Parser:
     """ arnica parser """
     extensions = '*.jpg'
@@ -150,31 +251,33 @@
         if not self.request.user.may.delete(self.pagename):
             return ''
 
-        return '''\
+        return '''
+    <div class="html_show_tools_restricted">
         <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
-          <td%(style)s>
-            <input type="hidden" name="action" value="arnica_slides">
-            <input type="hidden" name="do" value="rotate_left">
-            <input type="hidden" name="target" value="%(this_target)s">
-            <input type="image" value="submit" src="%(htdocs)s/common/arnica/arnica_rotate_to_left.png" title="rotate to left">
-          </td>
+            <div class="rotate_to_left">
+                <input type="hidden" name="action" value="arnica_slides">
+                <input type="hidden" name="do" value="rotate_left">
+                <input type="hidden" name="target" value="%(this_target)s">
+                <input type="image" value="submit" src="%(htdocs)s/common/arnica/arnica_rotate_to_left.png" title="rotate to left">
+            </div>
         </form>
         <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
-          <td%(style)s>
-            <input type="hidden" name="action" value="arnica_slides">
-            <input type="hidden" name="do" value="rotate_right">
-            <input type="hidden" name="target" value="%(this_target)s">
-            <input type="image"  value="submit" src="%(htdocs)s/common/arnica/arnica_rotate_to_right.png" title="rotate to right">
-          </td>
+            <div class="rotate_to_right">
+                <input type="hidden" name="action" value="arnica_slides">
+                <input type="hidden" name="do" value="rotate_right">
+                 <input type="hidden" name="target" value="%(this_target)s">
+                <input type="image"  value="submit" src="%(htdocs)s/common/arnica/arnica_rotate_to_right.png" title="rotate to right">
+            </div>
         </form>
         <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
-          <td%(style)s>
-            <input type="hidden" name="action" value="arnica_slides">
-            <input type="hidden" name="do" value="delete">
-            <input type="hidden" name="target" value="%(this_target)s">
-            <input type="image" value="submit" src="%(htdocs)s/common/arnica/arnica_remove_image.png" title="move to bak">
-           </td>
-        </form>''' % {
+             <div class="delete_image">
+                 <input type="hidden" name="action" value="arnica_slides">
+                 <input type="hidden" name="do" value="delete">
+                 <input type="hidden" name="target" value="%(this_target)s">
+                 <input type="image" value="submit" src="%(htdocs)s/common/arnica/arnica_remove_image.png" title="move to bak">
+             </div>
+        </form>
+     </div>''' % {
             'baseurl': self.request.getScriptname(),
             'style': self.td_style,
             'htdocs': self.request.cfg.url_prefix_static,
@@ -186,33 +289,28 @@
         @param idx: index postion of corresponding data
         """
         this_image = self.full[idx]
-        text = '''\
-            <table align="center" width="%(thumbnail_width)s"%(tablestyle)s>
-                <tr>
-                    <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
-                        <td%(style)s>
-                            <input type="hidden" name="action" value="AttachFile">
-                            <input type="hidden" name="do" value="get">
-                            <input type="hidden" name="target" value="%(this_target)s">
-                            <input type="image" value="submit" src="%(htdocs)s/common/arnica/arnica_full_image.png" title="load image">
-                        </td>
-                    </form>
-                    <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
-                        <td%(style)s>
-                            <input type="hidden" name="action" value="arnica_slides">
-                            <input type="hidden" name="do" value="slide_show">
-                            <input type="hidden" name="alias" value="%(description)s">
-                            <input type="hidden" name="target" value="%(target)s">
-                            <input type="hidden" name="pagename" value="%(pagename)s">
-                            <input type="hidden" name="images" value="%(images)s">
-                            <input type="hidden" name="exif_date" value="%(exif_date)s">
-                            <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
-                            <input type="image" value="submit" title="slide show" src="%(htdocs)s/common/arnica/arnica_load_slide_show.png">
-                       </td>
-                    </form>
-                    %(html_show_tools_restricted)s
-                </tr>
-            </table>'''   % {
+        text = '''
+        <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
+            <div class="get_image">
+                <input type="hidden" name="action" value="AttachFile">
+                <input type="hidden" name="do" value="get">
+                <input type="hidden" name="target" value="%(this_target)s">
+                <input type="image" value="submit" src="%(htdocs)s/common/arnica/arnica_full_image.png" title="load image">
+            </div>
+        </form>
+        <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
+            <div class="slide_show">
+                <input type="hidden" name="action" value="arnica_slides">
+                <input type="hidden" name="do" value="slide_show">
+                <input type="hidden" name="alias" value="%(description)s">
+                <input type="hidden" name="target" value="%(target)s">
+                <input type="hidden" name="pagename" value="%(pagename)s">
+                <input type="hidden" name="images" value="%(images)s">
+                <input type="hidden" name="exif_date" value="%(exif_date)s">
+                <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
+                <input type="image" value="submit" title="slide show" src="%(htdocs)s/common/arnica/arnica_load_slide_show.png">
+            </div>
+        </form> %(html_show_tools_restricted)s''' % {
             "baseurl": self.request.getScriptname(),
             "pagename": wikiutil.quoteWikinameURL(self.pagename),
             "htdocs": self.request.cfg.url_prefix_static,
@@ -234,7 +332,7 @@
         """ shows toolbox """
         text = ''
         if self.show_tools:
-            text = "<tr><td align=""center""%(style)s>%(tools)s</td></tr>" % {
+            text = '<div class="html_show_tools">%(tools)s</div>' % {
                 "style": self.td_style,
                 "tools": self.html_tools(idx)}
         return text
@@ -243,8 +341,7 @@
         """ shows date """
         text = ''
         if self.show_date:
-            text = '<tr><td%(style)s>%(this_exif_date)s</td></tr>' % {
-                "style": self.td_style,
+            text = '<div class="html_show_date">%(this_exif_date)s</div>' % {
                 "this_exif_date": self.exif_date[idx]}
         return text
 
@@ -252,9 +349,7 @@
         """ view mode 1 alias text below image """
         text = ''
         if self.show_text:
-            text = '<tr><td width="%(thumbnail_width)s" %(style)s> %(this_alias)s</td></tr>' % {
-                    "thumbnail_width": self.thumbnail_width,
-                    "style": ' align="left" style="padding:0em; margin:2px 2px; border-style:none"',
+            text = '<div class="html_show_alias"> %(this_alias)s</div>' % {
                     "this_alias": self.to_wikitext(self.description[idx])}
         return text
 
@@ -262,30 +357,27 @@
         """ defines arrangement of thumbnail, text, date and tools """
         title = ""
         if self.album:
-            title = "%(n)d images (%(album_title)s)" % {"n": len(self.full),
+            title = '<div class="title">%(n)d images (%(album_title)s)</div>' % {"n": len(self.full),
                                                         "album_title": self.album_title or self.pagename}
-        text = '''\
-    <table width="%(thumbnail_width)s" align="center" valign="center"%(style)s>
-    <tr align="center" valign="center">
-        <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
-            <td valign="middle" width="%(thumbnail_width)s" %(tdstyle)s>
-                %(title)s
-                <input type="hidden" name="action" value="arnica_slides">
-                <input type="hidden" name="do" value="slide_show">
-                <input type="hidden" name="alias" value="%(description)s">
-                <input type="hidden" name="target" value="%(target)s">
-                <input type="hidden" name="pagename" value="%(pagename)s">
-                <input type="hidden" name="images" value="%(images)s">
-                <input type="hidden" name="exif_date" value="%(exif_date)s">
-                <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
-                <input type="image" value="submit" title="slide show" src="%(baseurl)s/%(pagename)s?action=arnica_slides&do=view&target=%(thumbnail)s">
-            </td>
-        </form>
-    </tr>
-      %(alias_html)s
-      %(date_html)s
-      %(html_tools)s
-</table>'''% {
+        text = '''
+<div class="arrange_thumbnails">
+    <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
+        <div class="image"> %(title)s
+             <input type="hidden" name="action" value="arnica_slides">
+             <input type="hidden" name="do" value="slide_show">
+             <input type="hidden" name="alias" value="%(description)s">
+             <input type="hidden" name="target" value="%(target)s">
+             <input type="hidden" name="pagename" value="%(pagename)s">
+             <input type="hidden" name="images" value="%(images)s">
+             <input type="hidden" name="exif_date" value="%(exif_date)s">
+             <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
+             <input type="image" value="submit" title="slide show" src="%(thumbnail)s">
+        </div>
+    </form>
+    %(alias_html)s
+    %(date_html)s
+    %(html_tools)s
+</div>'''% {
      "title": title,
      "tdstyle": self.td_style,
      "style": self.inner_table_style,
@@ -296,7 +388,7 @@
      "image_for_webnail": self.image_for_webnail,
      "target": self.webimg[idx],
      "images": packLine([self.webimg[idx]] + self.webimg),
-     "thumbnail": self.thumb[idx],
+     "thumbnail": getCacheUrl(self.request.getScriptname(), wikiutil.quoteWikinameURL(self.pagename), self.thumb[idx]),
      "thumbnail_width": self.thumbnail_width,
      "html_tools": self.html_show_tools(idx),
      "date_html": self.html_show_date(idx),
@@ -538,17 +630,20 @@
         # adds the last row if it is not filled up
         if result:
             data.addRow(tuple(result))
-        browser = DataBrowserWidget(self.request, show_header=False)
+        browser = _DataBrowserWidget(self.request, show_header=False)
         browser.setData(data)
 
         text = browser.format()
         # XXX browser.format needs to get configurable for choosing the method
         # ugly workaroound
         # if this is not POST the slide_show actioon does send it's data by GET
-        return text.replace('method="GET"', 'method="POST"')
+        text = text.replace('method="GET"', 'method="POST"')
+        return text
 
     def format(self, formatter):
         """ parser output """
         # checks if initializing of all attributes in __init__ was done
         if self.init_settings:
+            self.request.write('<div class="arnica">')
             self.request.write(self.render(formatter))
+            self.request.write('</div>')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/modern/css/text_x_arnica.css	Sat Jun 28 13:35:41 2008 +0200
@@ -0,0 +1,106 @@
+/*
+arnica_slides styles 
+
+copyright © 2008 MoinMoin:ReimarBauer
+license: GNU GPL, see COPYING for details
+*/
+
+html { height: 100%; background: #fff; }
+
+body { min-height: 100%; position: relative; }
+
+div.arnica {
+    position: relative;
+    display: block;
+    text-align: center;
+    margin: 0em;
+}
+
+.arnica table, .arnica td {
+    border: none;
+}
+
+div.arrange_thumbnails {
+    position: relative;
+    display: block;
+    text-align: center;
+    margin: 0em;
+    border-style: outset;
+}
+
+.arnica .title {
+    text-align: center;
+    padding: 0.2em;
+    line-height: 1.2;
+    font-size: 90%;
+ }
+.arnica .image {
+    text-align: center;
+    vertical-align: middle;
+    margin: 0.2em;
+}
+
+.arnica .html_show_alias {
+    text-align: left;
+    padding: 0.2em;
+    line-height: 1.2;
+    font-size: 90%;
+}
+
+.arnica .html_show_date {
+    text-align: center;
+    padding: 0.2em;
+    line-height: 1.2;
+    font-size: 90%;
+ }
+ 
+.arnica .html_show_tools {
+    position: relative;
+    text-align: center;
+    vertical-align: middle;
+    margin: 0em;
+}
+
+.arnica .html_show_tools_restricted {
+    position: relative;
+    text-align: center;
+    vertical-align: middle;
+    margin: 0em;
+}
+
+.arnica .get_image {
+    position: absolute;
+    margin: 0.25em;
+    top: 0%;
+    left: 0%;
+    vertical-align: middle;
+}
+
+.arnica .slide_show {
+    position: absolute;
+    margin: 0.25em;
+    top: 0;
+    left: 10%;
+    vertical-align: middle;
+}
+
+.arnica .rotate_to_left {
+    position: absolute;
+    margin: 0.25em;
+    top: 0;
+    left: 60%;
+    vertical-align: middle;
+}
+
+.arnica .rotate_to_right {
+    position: absolute;
+    margin: 0.25em;
+    top: 0;
+    left: 80%;
+    vertical-align: middle;
+}
+
+.arnica .delete_image {
+    vertical-align: middle;
+    
+}