web/htmlwidgets.py
branchstable
changeset 3796 f4e924106fdc
parent 2996 866a2c135c33
child 3797 af9b0e113108
equal deleted inserted replaced
3795:ce6381416a12 3796:f4e924106fdc
    10 """
    10 """
    11 
    11 
    12 from logilab.mtconverter import xml_escape
    12 from logilab.mtconverter import xml_escape
    13 
    13 
    14 from cubicweb.utils import UStringIO
    14 from cubicweb.utils import UStringIO
    15 from cubicweb.common.uilib import toggle_action
    15 from cubicweb.common.uilib import toggle_action, limitsize, htmlescape
       
    16 from cubicweb.web import jsonize
    16 
    17 
    17 # XXX HTMLWidgets should have access to req (for datadir / static urls,
    18 # XXX HTMLWidgets should have access to req (for datadir / static urls,
    18 #     i18n strings, etc.)
    19 #     i18n strings, etc.)
    19 class HTMLWidget(object):
    20 class HTMLWidget(object):
    20 
    21 
   247         # XXX (adim) : why do we need colindex here ?
   248         # XXX (adim) : why do we need colindex here ?
   248         self.cellrenderers.append( (cellvid, colindex) )
   249         self.cellrenderers.append( (cellvid, colindex) )
   249 
   250 
   250     def add_attr(self, attr, value):
   251     def add_attr(self, attr, value):
   251         self.cell_attrs[attr] = value
   252         self.cell_attrs[attr] = value
       
   253 
       
   254 class SimpleTableModel(object):
       
   255     """
       
   256     uses a list of lists as a storage backend
       
   257 
       
   258     NB: the model expectes the cellvid passed to
       
   259     TableColumn.append_renderer to be a callable accepting a single
       
   260     argument and returning a unicode object
       
   261     """
       
   262     def __init__(self, rows):
       
   263         self._rows = rows
       
   264 
       
   265 
       
   266     def get_rows(self):
       
   267         return self._rows
       
   268 
       
   269     def render_cell(self, cellvid, rowindex, colindex, w):
       
   270         value = self._rows[rowindex][colindex]
       
   271         w(cellvid(value))
       
   272 
       
   273     @htmlescape
       
   274     @jsonize
       
   275     def sortvalue(self, rowindex, colindex):
       
   276         value =  self._rows[rowindex][colindex]
       
   277         if value is None:
       
   278             return u''
       
   279         elif isinstance(value, int):
       
   280             return u'%09d'%value
       
   281         else:
       
   282             return unicode(value)
   252 
   283 
   253 
   284 
   254 class TableWidget(HTMLWidget):
   285 class TableWidget(HTMLWidget):
   255 
   286 
   256     highlight = "onmouseover=\"addElementClass(this, 'highlighted');\" " \
   287     highlight = "onmouseover=\"addElementClass(this, 'highlighted');\" " \