equal
deleted
inserted
replaced
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
403 back its value in form parameters, and modify the syntax tree |
403 back its value in form parameters, and modify the syntax tree |
404 (`self.rqlst`) accordingly. |
404 (`self.rqlst`) accordingly. |
405 """ |
405 """ |
406 raise NotImplementedError |
406 raise NotImplementedError |
407 |
407 |
|
408 @property |
|
409 def wdgclass(self): |
|
410 raise NotImplementedError |
|
411 |
408 |
412 |
409 class VocabularyFacet(AbstractFacet): |
413 class VocabularyFacet(AbstractFacet): |
410 """This abstract class extend :class:`AbstractFacet` to use the |
414 """This abstract class extend :class:`AbstractFacet` to use the |
411 :class:`FacetVocabularyWidget` as widget, suitable for facets that may |
415 :class:`FacetVocabularyWidget` as widget, suitable for facets that may |
412 restrict values according to a (usually computed) vocabulary. |
416 restrict values according to a (usually computed) vocabulary. |
415 |
419 |
416 .. automethod:: cubicweb.web.facet.VocabularyFacet.vocabulary |
420 .. automethod:: cubicweb.web.facet.VocabularyFacet.vocabulary |
417 .. automethod:: cubicweb.web.facet.VocabularyFacet.possible_values |
421 .. automethod:: cubicweb.web.facet.VocabularyFacet.possible_values |
418 """ |
422 """ |
419 needs_update = True |
423 needs_update = True |
|
424 |
|
425 @property |
|
426 def wdgclass(self): |
|
427 return FacetVocabularyWidget |
420 |
428 |
421 def get_widget(self): |
429 def get_widget(self): |
422 """Return the widget instance to use to display this facet. |
430 """Return the widget instance to use to display this facet. |
423 |
431 |
424 This implementation expects a .vocabulary method on the facet and |
432 This implementation expects a .vocabulary method on the facet and |
425 return a combobox displaying this vocabulary. |
433 return a combobox displaying this vocabulary. |
426 """ |
434 """ |
427 vocab = self.vocabulary() |
435 vocab = self.vocabulary() |
428 if len(vocab) <= 1: |
436 if len(vocab) <= 1: |
429 return None |
437 return None |
430 wdg = FacetVocabularyWidget(self) |
438 wdg = self.wdgclass(self) |
431 selected = frozenset(typed_eid(eid) for eid in self._cw.list_form_param(self.__regid__)) |
439 selected = frozenset(typed_eid(eid) for eid in self._cw.list_form_param(self.__regid__)) |
432 for label, value in vocab: |
440 for label, value in vocab: |
433 if value is None: |
441 if value is None: |
434 wdg.append(FacetSeparator(label)) |
442 wdg.append(FacetSeparator(label)) |
435 else: |
443 else: |
1049 |
1057 |
1050 def __init__(self, facet): |
1058 def __init__(self, facet): |
1051 self.facet = facet |
1059 self.facet = facet |
1052 self.items = [] |
1060 self.items = [] |
1053 |
1061 |
|
1062 def height(self): |
|
1063 return len(self.items) + 1 |
|
1064 |
1054 def append(self, item): |
1065 def append(self, item): |
1055 self.items.append(item) |
1066 self.items.append(item) |
1056 |
1067 |
1057 def _render(self): |
1068 def _render(self): |
1058 title = xml_escape(self.facet.title) |
1069 title = xml_escape(self.facet.title) |
1081 |
1092 |
1082 class FacetStringWidget(HTMLWidget): |
1093 class FacetStringWidget(HTMLWidget): |
1083 def __init__(self, facet): |
1094 def __init__(self, facet): |
1084 self.facet = facet |
1095 self.facet = facet |
1085 self.value = None |
1096 self.value = None |
|
1097 |
|
1098 def height(self): |
|
1099 return 2 |
1086 |
1100 |
1087 def _render(self): |
1101 def _render(self): |
1088 title = xml_escape(self.facet.title) |
1102 title = xml_escape(self.facet.title) |
1089 facetid = xml_escape(self.facet.__regid__) |
1103 facetid = xml_escape(self.facet.__regid__) |
1090 self.w(u'<div id="%s" class="facet">\n' % facetid) |
1104 self.w(u'<div id="%s" class="facet">\n' % facetid) |
1121 #'# make emacs happier |
1135 #'# make emacs happier |
1122 def __init__(self, facet, minvalue, maxvalue): |
1136 def __init__(self, facet, minvalue, maxvalue): |
1123 self.facet = facet |
1137 self.facet = facet |
1124 self.minvalue = minvalue |
1138 self.minvalue = minvalue |
1125 self.maxvalue = maxvalue |
1139 self.maxvalue = maxvalue |
|
1140 |
|
1141 def height(self): |
|
1142 return 3 |
1126 |
1143 |
1127 def _render(self): |
1144 def _render(self): |
1128 facet = self.facet |
1145 facet = self.facet |
1129 facet._cw.add_js('jquery.ui.js') |
1146 facet._cw.add_js('jquery.ui.js') |
1130 facet._cw.add_css('jquery.ui.css') |
1147 facet._cw.add_css('jquery.ui.css') |
1212 self._cw = req |
1229 self._cw = req |
1213 self.facet = facet |
1230 self.facet = facet |
1214 self.value = value |
1231 self.value = value |
1215 self.selected = selected |
1232 self.selected = selected |
1216 |
1233 |
|
1234 def height(self): |
|
1235 return 1 |
|
1236 |
1217 def _render(self): |
1237 def _render(self): |
1218 title = xml_escape(self.facet.title) |
1238 title = xml_escape(self.facet.title) |
1219 facetid = xml_escape(self.facet.__regid__) |
1239 facetid = xml_escape(self.facet.__regid__) |
1220 self.w(u'<div id="%s" class="facet">\n' % facetid) |
1240 self.w(u'<div id="%s" class="facet">\n' % facetid) |
1221 cssclass = 'facetValue facetCheckBox' |
1241 cssclass = 'facetValue facetCheckBox' |