5 def __init__ (self, table_id, headers, column_sort,
7 search_area=True, pagesize_area=True, notes_area=True,
8 search_width=40, pagesize=25, pagesize_def=999,
11 self.table_id=table_id
13 self.column_sort =column_sort
15 self.search_area=search_area
16 self.pagesize_area=pagesize_area
17 self.notes_area=notes_area
18 self.search_width =search_width
19 self.pagesize =pagesize
20 self.pagesize_def=pagesize_def
21 self.max_pages=max_pages
25 return len(self.headers)
28 paginator = self.table_id + "_paginator"
29 classname = "paginationcallback-%s" % paginator
30 classname += " max-pages-%d" % self.max_pages
31 classname += " paginate-%d" % self.pagesize
32 # instantiate paginator callback
33 table_id = self.table_id
35 <script type="text/javascript">
36 function %(paginator)s (opts) { plekit_table_paginator (opts,"%(table_id)s)"; }
39 <table id="%(table_id)s" cellpadding="0" cellspacing="0" border="0"
40 class="plekit_table sortable-onload-self.sort_column rowstyle-alt colstyle-alt no-arrow %(classname)s">
44 if self.pagesize_area:
45 print self.pagesize_area_html ()
47 print self.search_area_html ()
50 print "<caption> %s </caption>" % self.caption
52 for (label,type) in self.headers.iteritems():
55 elif type == "string" or type == "int" or type == "float":
57 elif type.find ("date-") == 0:
58 classpart="sortable-" + type
60 classpart="sortable-sort" + type
61 print '<th class="%(classpart)s plekit_table">%(label)s</th>'%locals()
63 print """</tr></thead><tbody>\n"""
66 ## unlike the php version there is no support for last-minute options, pass them all to the constructor
68 print self.bottom_html()
70 print self.notes_area_html()
73 def pagesize_area_html (self):
74 width=len(self.headers)
75 pagesize_text_id = self.table_id + "_pagesize"
77 <tr class='pagesize_area'><td class='pagesize_area' colspan='%(width)s'>
78 <form class='pagesize' action='satisfy_xhtml_validator'><fieldset>
79 <input class='pagesize_input' type='text' id="%(pagesize_text_id)s" value='self.pagesize'
80 onkeyup='plekit_pagesize_set("self.table_id","%(pagesize_text_id)s", self.pagesize);'
81 size='3' maxlength='3' />
82 <label class='pagesize_label'> items/page </label>
83 <img class='reset' src="/planetlab/icons/clear.png" alt="reset visible size"
84 onmousedown='plekit_pagesize_reset("self.table_id","%(pagesize_text_id)s",self.pagesize_def);' />
85 </fieldset></form></td></tr>
90 def search_area_html (self):
91 width = len(self.headers)
92 search_text_id = self.table_id + "_search"
93 search_reset_id = self.table_id + "_search_reset"
94 search_and_id = self.table_id + "_search_and"
96 <tr class='search_area'><td class='search_area' colspan='%(width)s'>
97 <div class='search'><fieldset>
98 <label class='search_label'> Search </label>
99 <input class='search_input' type='text' id='%(search_text_id)s'
100 onkeyup='plekit_table_filter("self.table_id","%(search_text_id)s","%(search_and_id)s");'
101 size='self.search_width' maxlength='256' />
103 <input id='%(search_and_id)s' class='search_and'
104 type='checkbox' checked='checked'
105 onchange='plekit_table_filter("self.table_id","%(search_text_id)s","%(search_and_id)s");' />
106 <img class='reset' src="/planetlab/icons/clear.png" alt="reset search"
107 onmousedown='plekit_table_filter_reset("self.table_id","%(search_text_id)s","%(search_and_id)s");' />
108 </fieldset></div></td></tr>
113 ## start a <tfoot> section
114 def tfoot_start (self): print self.tfoot_start_html()
115 def tfoot_start_html (self):
117 return "</tbody><tfoot>"
120 def bottom_html (self):
126 result += "</table>\n"
131 "Enter & or | in the search area to switch between <span class='bold'>AND</span> and <span class='bold'>OR</span> search modes",
132 "Hold down the shift key to select multiple columns to sort" ]
134 def notes_area_html (self):
139 notes = notes + default_notes
141 result += "<p class='table_note'> <span class='table_note_title'>Notes</span>\n"
143 result += "<br/>%s\n" % note
148 def row_start (self, id=None, classpart=None):
150 if id: print " id='%s'" % id
151 if classpart: print ' class="%s"' % classpart
158 ## supported options:
159 ## (*) only-if : if set and false, then print 'n/a' instead of (presumably void) $text
164 def cell (self, text,only_if=True, classpart=None, columns=None, hfill=None, align=None):
165 print self.cell_html (text, only_if, classpart, columns, hfill, align)
166 def cell_html (self, text, only_if=True, classpart=None, columns=None, hfill=None, align=None):
171 if classpart: html += " class='%s'" % classpart
172 if columns: html += " colspan='%d'" % columns
173 elif hfill: html += " colspan='%d'" % self.columns()
174 if align: html += " style='text-align:%s'" % align
175 html += ">%s</td>" % text