web/htmlwidgets.py
branchtls-sprint
changeset 1698 1311d961ef72
parent 940 15dcdc863965
child 1730 cec526a96535
equal deleted inserted replaced
1697:5dae28906769 1698:1311d961ef72
    57     def append(self, item):
    57     def append(self, item):
    58         self.items.append(item)
    58         self.items.append(item)
    59 
    59 
    60     main_div_class = 'boxContent'
    60     main_div_class = 'boxContent'
    61     listing_class = 'boxListing'
    61     listing_class = 'boxListing'
    62     
    62 
    63     def box_begin_content(self):
    63     def box_begin_content(self):
    64         self.w(u'<div class="%s">\n' % self.main_div_class)
    64         self.w(u'<div class="%s">\n' % self.main_div_class)
    65         if self.islist:
    65         if self.islist:
    66             self.w(u'<ul class="%s">' % self.listing_class)
    66             self.w(u'<ul class="%s">' % self.listing_class)
    67 
    67 
    69         if self.islist:
    69         if self.islist:
    70             self.w(u'</ul>\n')
    70             self.w(u'</ul>\n')
    71         self.w(u'</div>\n')
    71         self.w(u'</div>\n')
    72         if self.shadow:
    72         if self.shadow:
    73             self.w(u'<div class="shadow">&nbsp;</div>')
    73             self.w(u'<div class="shadow">&nbsp;</div>')
    74         
    74 
    75     def _render(self):
    75     def _render(self):
    76         if self.id:
    76         if self.id:
    77             self.w(u'<div class="%s" id="%s">' % (self._class, self.id))
    77             self.w(u'<div class="%s" id="%s">' % (self._class, self.id))
    78         else:
    78         else:
    79             self.w(u'<div class="%s">' % self._class)            
    79             self.w(u'<div class="%s">' % self._class)
    80         if self.title:
    80         if self.title:
    81             if self.escape:
    81             if self.escape:
    82                 title = '<span>%s</span>' % html_escape(self.title)
    82                 title = '<span>%s</span>' % html_escape(self.title)
    83             else:
    83             else:
    84                 title = '<span>%s</span>' % self.title
    84                 title = '<span>%s</span>' % self.title
    98 
    98 
    99     def __init__(self, title, id=None):
    99     def __init__(self, title, id=None):
   100         super(SideBoxWidget, self).__init__(title, id=id, _class='sideBox',
   100         super(SideBoxWidget, self).__init__(title, id=id, _class='sideBox',
   101                                             shadow=False)
   101                                             shadow=False)
   102 
   102 
   103                                             
   103 
   104 class MenuWidget(BoxWidget):
   104 class MenuWidget(BoxWidget):
   105     main_div_class = 'menuContent'
   105     main_div_class = 'menuContent'
   106     listing_class = 'menuListing'
   106     listing_class = 'menuListing'
   107 
   107 
   108     def box_end_content(self):
   108     def box_end_content(self):
   109         if self.islist:
   109         if self.islist:
   110             self.w(u'</ul>\n')
   110             self.w(u'</ul>\n')
   111         self.w(u'</div>\n')
   111         self.w(u'</div>\n')
   112     
   112 
   113 
   113 
   114 class RawBoxItem(HTMLWidget):
   114 class RawBoxItem(HTMLWidget):
   115     """a simpe box item displaying raw data"""
   115     """a simpe box item displaying raw data"""
   116     def __init__(self, label, liclass=None):
   116     def __init__(self, label, liclass=None):
   117         self.label = label
   117         self.label = label
   120     def _start_li(self):
   120     def _start_li(self):
   121         if self.liclass is None:
   121         if self.liclass is None:
   122             return u'<li>'
   122             return u'<li>'
   123         else:
   123         else:
   124             return u'<li class="%s">' % self.liclass
   124             return u'<li class="%s">' % self.liclass
   125         
   125 
   126         return self.label
   126         return self.label
   127     
   127 
   128     def _render(self):
   128     def _render(self):
   129         self.w(u'%s%s</li>' % (self._start_li(), self.label))
   129         self.w(u'%s%s</li>' % (self._start_li(), self.label))
   130 
   130 
   131 
   131 
   132 class BoxMenu(RawBoxItem):
   132 class BoxMenu(RawBoxItem):
   133     """a menu in a box"""
   133     """a menu in a box"""
   134     link_class = 'boxMenu'
   134     link_class = 'boxMenu'
   135     
   135 
   136     def __init__(self, label, items=None, isitem=True, liclass=None, ident=None,
   136     def __init__(self, label, items=None, isitem=True, liclass=None, ident=None,
   137                  link_class=None):
   137                  link_class=None):
   138         super(BoxMenu, self).__init__(label, liclass)
   138         super(BoxMenu, self).__init__(label, liclass)
   139         self.items = items or []
   139         self.items = items or []
   140         self.isitem = isitem
   140         self.isitem = isitem
   141         self.ident = ident or u'boxmenu_%s' % label.replace(' ', '_').replace("'", '')
   141         self.ident = ident or u'boxmenu_%s' % label.replace(' ', '_').replace("'", '')
   142         if link_class:
   142         if link_class:
   143             self.link_class = link_class
   143             self.link_class = link_class
   144             
   144 
   145     def append(self, item):
   145     def append(self, item):
   146         self.items.append(item)
   146         self.items.append(item)
   147 
   147 
   148     def _begin_menu(self, ident):
   148     def _begin_menu(self, ident):
   149         self.w(u'<ul id="%s" class="hidden">' % ident)
   149         self.w(u'<ul id="%s" class="hidden">' % ident)
   150 
   150 
   151     def _end_menu(self):
   151     def _end_menu(self):
   152         self.w(u'</ul>')
   152         self.w(u'</ul>')
   153         
   153 
   154     def _render(self):
   154     def _render(self):
   155         if self.isitem:
   155         if self.isitem:
   156             self.w(self._start_li())
   156             self.w(self._start_li())
   157         ident = self.ident
   157         ident = self.ident
   158         self.w(u'<a href="%s" class="%s">%s</a>' % (
   158         self.w(u'<a href="%s" class="%s">%s</a>' % (
   181 class BoxField(HTMLWidget):
   181 class BoxField(HTMLWidget):
   182     """couples label / value meant to be displayed in a box"""
   182     """couples label / value meant to be displayed in a box"""
   183     def __init__(self, label, value):
   183     def __init__(self, label, value):
   184         self.label = label
   184         self.label = label
   185         self.value = value
   185         self.value = value
   186     
   186 
   187     def _render(self):
   187     def _render(self):
   188         self.w(u'<li><div><span class="label">%s</span>&nbsp;'
   188         self.w(u'<li><div><span class="label">%s</span>&nbsp;'
   189                u'<span class="value">%s</span></div></li>' 
   189                u'<span class="value">%s</span></div></li>'
   190                % (self.label, self.value))
   190                % (self.label, self.value))
   191 
   191 
   192 class BoxSeparator(HTMLWidget):
   192 class BoxSeparator(HTMLWidget):
   193     """a menu separator"""
   193     """a menu separator"""
   194     
   194 
   195     def _render(self):
   195     def _render(self):
   196         self.w(u'</ul><hr class="boxSeparator"/><ul>')
   196         self.w(u'</ul><hr class="boxSeparator"/><ul>')
   197 
   197 
   198 
   198 
   199 class BoxLink(HTMLWidget):
   199 class BoxLink(HTMLWidget):
   247 
   247 
   248 class TableWidget(HTMLWidget):
   248 class TableWidget(HTMLWidget):
   249 
   249 
   250     highlight = "onmouseover=\"addElementClass(this, 'highlighted');\" " \
   250     highlight = "onmouseover=\"addElementClass(this, 'highlighted');\" " \
   251                 "onmouseout=\"removeElementClass(this, 'highlighted');\""
   251                 "onmouseout=\"removeElementClass(this, 'highlighted');\""
   252     
   252 
   253     def __init__(self, model):
   253     def __init__(self, model):
   254         self.model = model
   254         self.model = model
   255         self.columns = []
   255         self.columns = []
   256 
   256 
   257     def append_column(self, column):
   257     def append_column(self, column):