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
26 return len(self.headers)
29 paginator = self.table_id + "_paginator"
30 classname = "paginationcallback-%s" % paginator
31 classname += " max-pages-%d" % self.max_pages
32 classname += " paginate-%d" % self.pagesize
33 # instantiate paginator callback
34 table_id = self.table_id
36 <script type="text/javascript">
37 function %(paginator)s (opts) { plekit_table_paginator (opts,"%(table_id)s)"; }
40 <table id="%(table_id)s" cellpadding="0" cellspacing="0" border="0"
41 class="plekit_table sortable-onload-self.sort_column rowstyle-alt colstyle-alt no-arrow %(classname)s">
45 if self.pagesize_area:
46 print self.pagesize_area_html ()
48 print self.search_area_html ()
51 print "<caption> %s </caption>" % self.caption
53 for (label,type) in self.headers.iteritems():
56 elif type == "string" or type == "int" or type == "float":
58 elif type.find ("date-") == 0:
59 classpart="sortable-" + type
61 classpart="sortable-sort" + type
62 print '<th class="%(classpart)s plekit_table">%(label)s</th>'%locals()
64 print """</tr></thead><tbody>\n"""
67 ## unlike the php version there is no support for last-minute options, pass them all to the constructor
69 print self.bottom_html()
71 print self.notes_area_html()
74 def pagesize_area_html (self):
75 width=len(self.headers)
76 pagesize_text_id = self.table_id + "_pagesize"
78 <tr class='pagesize_area'><td class='pagesize_area' colspan='%(width)s'>
79 <form class='pagesize' action='satisfy_xhtml_validator'><fieldset>
80 <input class='pagesize_input' type='text' id="%(pagesize_text_id)s" value='self.pagesize'
81 onkeyup='plekit_pagesize_set("self.table_id","%(pagesize_text_id)s", self.pagesize);'
82 size='3' maxlength='3' />
83 <label class='pagesize_label'> items/page </label>
84 <img class='reset' src="/planetlab/icons/clear.png" alt="reset visible size"
85 onmousedown='plekit_pagesize_reset("self.table_id","%(pagesize_text_id)s",self.pagesize_def);' />
86 </fieldset></form></td></tr>
91 def search_area_html (self):
92 width = len(self.headers)
93 search_text_id = self.table_id + "_search"
94 search_reset_id = self.table_id + "_search_reset"
95 search_and_id = self.table_id + "_search_and"
97 <tr class='search_area'><td class='search_area' colspan='%(width)s'>
98 <div class='search'><fieldset>
99 <label class='search_label'> Search </label>
100 <input class='search_input' type='text' id='%(search_text_id)s'
101 onkeyup='plekit_table_filter("self.table_id","%(search_text_id)s","%(search_and_id)s");'
102 size='self.search_width' maxlength='256' />
104 <input id='%(search_and_id)s' class='search_and'
105 type='checkbox' checked='checked'
106 onchange='plekit_table_filter("self.table_id","%(search_text_id)s","%(search_and_id)s");' />
107 <img class='reset' src="/planetlab/icons/clear.png" alt="reset search"
108 onmousedown='plekit_table_filter_reset("self.table_id","%(search_text_id)s","%(search_and_id)s");' />
109 </fieldset></div></td></tr>
114 ## start a <tfoot> section
115 def tfoot_start (self): print self.tfoot_start_html()
116 def tfoot_start_html (self):
118 return "</tbody><tfoot>"
121 def bottom_html (self):
127 result += "</table>\n"
132 "Enter & or | in the search area to switch between <span class='bold'>AND</span> and <span class='bold'>OR</span> search modes",
133 "Hold down the shift key to select multiple columns to sort" ]
135 def notes_area_html (self):
140 notes = notes + self.default_notes
142 result += "<p class='table_note'> <span class='table_note_title'>Notes</span>\n"
144 result += "<br/>%s\n" % note
149 def row_start (self, id=None, classpart=None):
151 if id: print " id='%s'" % id
152 if classpart: print ' class="%s"' % classpart
159 ## supported options:
160 ## (*) only-if : if set and false, then print 'n/a' instead of (presumably void) $text
165 def cell (self, text,only_if=True, classpart=None, columns=None, hfill=None, align=None):
166 print self.cell_html (text, only_if, classpart, columns, hfill, align)
167 def cell_html (self, text, only_if=True, classpart=None, columns=None, hfill=None, align=None):
172 if classpart: html += " class='%s'" % classpart
173 if columns: html += " colspan='%d'" % columns
174 elif hfill: html += " colspan='%d'" % self.columns()
175 if align: html += " style='text-align:%s'" % align
176 html += ">%s</td>" % text