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"
77 result_dict = locals()
78 result_dict.update(self.__dict__)
80 <tr class='pagesize_area'><td class='pagesize_area' colspan='%(width)s'>
81 <form class='pagesize' action='satisfy_xhtml_validator'><fieldset>
82 <input class='pagesize_input' type='text' id="%(pagesize_text_id)s" value='%(pagesize)s'
83 onkeyup='plekit_pagesize_set("%(table_id)s","%(pagesize_text_id)s", %(pagesize)s);'
84 size='3' maxlength='3' />
85 <label class='pagesize_label'> items/page </label>
86 <img class='reset' src="/planetlab/icons/clear.png" alt="reset visible size"
87 onmousedown='plekit_pagesize_reset("%(table_id)s","%(pagesize_text_id)s",%(pagesize_def)s);' />
88 </fieldset></form></td></tr>
93 def search_area_html (self):
94 width = len(self.headers)
95 search_text_id = self.table_id + "_search"
96 search_reset_id = self.table_id + "_search_reset"
97 search_and_id = self.table_id + "_search_and"
98 result_dict = locals()
99 result_dict.update(self.__dict__)
101 <tr class='search_area'><td class='search_area' colspan='%(width)s'>
102 <div class='search'><fieldset>
103 <label class='search_label'> Search </label>
104 <input class='search_input' type='text' id='%(search_text_id)s'
105 onkeyup='plekit_table_filter("%(table_id)s","%(search_text_id)s","%(search_and_id)s");'
106 size='%(search_width)s' maxlength='256' />
108 <input id='%(search_and_id)s' class='search_and'
109 type='checkbox' checked='checked'
110 onchange='plekit_table_filter("%(table_id)s","%(search_text_id)s","%(search_and_id)s");' />
111 <img class='reset' src="/planetlab/icons/clear.png" alt="reset search"
112 onmousedown='plekit_table_filter_reset("%(table_id)s","%(search_text_id)s","%(search_and_id)s");' />
113 </fieldset></div></td></tr>
118 ## start a <tfoot> section
119 def tfoot_start (self): print self.tfoot_start_html()
120 def tfoot_start_html (self):
122 return "</tbody><tfoot>"
125 def bottom_html (self):
131 result += "</table>\n"
136 "Enter & or | in the search area to switch between <span class='bold'>AND</span> and <span class='bold'>OR</span> search modes",
137 "Hold down the shift key to select multiple columns to sort" ]
139 def notes_area_html (self):
144 notes = notes + self.default_notes
146 result += "<p class='table_note'> <span class='table_note_title'>Notes</span>\n"
148 result += "<br/>%s\n" % note
153 def row_start (self, id=None, classpart=None):
155 if id: print " id='%s'" % id
156 if classpart: print ' class="%s"' % classpart
163 ## supported options:
164 ## (*) only-if : if set and false, then print 'n/a' instead of (presumably void) $text
169 def cell (self, text,only_if=True, classpart=None, columns=None, hfill=None, align=None):
170 print self.cell_html (text, only_if, classpart, columns, hfill, align)
171 def cell_html (self, text, only_if=True, classpart=None, columns=None, hfill=None, align=None):
176 if classpart: html += " class='%s'" % classpart
177 if columns: html += " colspan='%d'" % columns
178 elif hfill: html += " colspan='%d'" % self.columns()
179 if align: html += " style='text-align:%s'" % align
180 html += ">%s</td>" % text