# HG changeset patch # User Aurelien Campeas # Date 1235387803 -3600 # Node ID 65f278630d0ca353dad956353b48c006e36bcb22 # Parent 64962f22df2b4dcd457a0767bf7cc7dbbd32a8ac# Parent 7c184924d49248623b8b3541af9804f910fa62af merge diff -r 64962f22df2b -r 65f278630d0c web/data/cubicweb.widgets.js --- a/web/data/cubicweb.widgets.js Mon Feb 23 11:53:23 2009 +0100 +++ b/web/data/cubicweb.widgets.js Mon Feb 23 12:16:43 2009 +0100 @@ -181,6 +181,14 @@ } } +Widgets.TreeView = defclass("TreeView", null, { + __init__: function(wdgnode) { + jQuery(wdgnode).treeview({toggle: toggleTree, + prerendered: true + }); + } +}); + /* widget based on SIMILE's timeline widget * http://code.google.com/p/simile-widgets/ diff -r 64962f22df2b -r 65f278630d0c web/views/tabs.py --- a/web/views/tabs.py Mon Feb 23 11:53:23 2009 +0100 +++ b/web/views/tabs.py Mon Feb 23 12:16:43 2009 +0100 @@ -33,22 +33,15 @@ });""" % {'event': 'load_%s' % vid, 'vid': vid, 'reloadable' : str(reloadable).lower()}) - def lazyview(self, vid, rql=None, eid=None, rset=None, static=False, - reloadable=False, show_spinbox=True, w=None): + def lazyview(self, vid, eid=None, reloadable=False, show_spinbox=True, w=None): """a lazy version of wview first version only support lazy viewing for an entity at a time """ - assert rql or eid or rset or static, \ - 'lazyview wants at least : rql, or an eid, or an rset -- or call it with static=True' w = w or self.w self.req.add_js('cubicweb.lazy.js') urlparams = {'vid' : vid, 'mode' : 'html'} - if rql: - urlparams['rql'] = rql - elif eid: + if eid: urlparams['rql'] = rql_for_eid(eid) - elif rset: - urlparams['rql'] = rset.printable_rql() w(u'
' % ( vid, html_escape(self.build_url('json', **urlparams)))) if show_spinbox: @@ -72,12 +65,12 @@ return str('%s_active_tab' % self.config.appid) def active_tab(self, tabs, default): - cookies = self.req.get_cookie() + cookie = self.req.get_cookie() cookiename = self.cookie_name - activetab = cookies.get(cookiename) + activetab = cookie.get(cookiename) if activetab is None: - cookies[cookiename] = default - self.req.set_cookie(cookies, cookiename) + cookie[cookiename] = default + self.req.set_cookie(cookie, cookiename) tab = default else: tab = activetab.value @@ -103,7 +96,7 @@ active_tab = self.active_tab(tabs, default) # build the html structure w = self.w - w(u'
' % entity.eid) + w(u'
') w(u'
    ') for tab in tabs: w(u'
  • ') @@ -117,16 +110,15 @@ w(u'
') for tab in tabs: w(u'
' % tab) - self.lazyview(tab, eid=entity.eid) + self.lazyview(tab, entity.eid) w(u'
') # call the set_tab() JS function *after* each tab is generated # because the callback binding needs to be done before self.req.html_headers.add_onload(u""" - jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s }); + jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); set_tab('%(vid)s', '%(cookiename)s'); """ % {'tabindex' : tabs.index(active_tab), 'vid' : active_tab, - 'eeid' : entity.eid, 'cookiename' : self.cookie_name}) @@ -146,10 +138,11 @@ vid = 'gallery' __selectors__ = EntityRelationView.__selectors__ + (one_line_rset,) + This is the view we want to have in a tab, only if there is something to show. Then, just define as below, and declare this being the tab content : - class ProjectScreenshotTab(EntityRelatedTab, ProjectScreenshotsView): + class ProjectScreenshotTab(DataDependantTab, ProjectScreenshotsView): id = 'screenshots_tab' """ __selectors__ = EntityView.__selectors__ + (has_related_entities,) diff -r 64962f22df2b -r 65f278630d0c web/views/treeview.py --- a/web/views/treeview.py Mon Feb 23 11:53:23 2009 +0100 +++ b/web/views/treeview.py Mon Feb 23 12:16:43 2009 +0100 @@ -1,32 +1,38 @@ from logilab.mtconverter import html_escape + from cubicweb.interfaces import ITree from cubicweb.common.selectors import implement_interface, yes from cubicweb.common.view import EntityView +from cubicweb.web.views.baseviews import OneLineView + class TreeView(EntityView): id = 'treeview' accepts = ('Any',) itemvid = 'treeitemview' css_classes = 'treeview widget' title = _('tree view') - - def call(self, subvid=None, treeid=None): + + def call(self, subvid=None): if subvid is None and 'subvid' in self.req.form: subvid = self.req.form.pop('subvid') # consume it if subvid is None: subvid = 'oneline' self.req.add_css('jquery.treeview.css') - self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js')) - # XXX find a way, an id is MANDATORY - treeid = 'TREE' #treeid or self.rset.rows[0][0] - self.req.html_headers.add_onload(u""" - $("#tree-%s").treeview({toggle: toggleTree, - prerendered: true});""" % treeid) - self.w(u'
    ' % (treeid, self.css_classes)) + self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js', 'cubicweb.widgets.js')) + # XXX noautoload is a quick hack to avoid treeview to be rebuilt + # after a json query and avoid double toggling bugs. + # Need to find a way to do that cleanly. + if 'noautoload' in self.req.form: + self.w(u'
      ' % self.css_classes) + else: + self.w(u'
        ' + % self.css_classes) for rowidx in xrange(len(self.rset)): self.wview(self.itemvid, self.rset, row=rowidx, col=0, vid=subvid, parentvid=self.id) self.w(u'
      ') + class FileTreeView(TreeView): """specific version of the treeview to display file trees @@ -38,6 +44,8 @@ def call(self, subvid=None): super(FileTreeView, self).call(subvid='filetree-oneline') + + class FileItemInnerView(EntityView): """inner view used by the TreeItemView instead of oneline view @@ -49,10 +57,10 @@ def cell_call(self, row, col): entity = self.entity(row, col) if ITree.is_implemented_by(entity.__class__) and not entity.is_leaf(): - self.w(u'
      %s
      \n' % entity.view('oneline')) + self.w(u'
      %s
      ' % entity.view('oneline')) else: # XXX define specific CSS classes according to mime types - self.w(u'
      %s
      \n' % entity.view('oneline')) + self.w(u'
      %s
      ' % entity.view('oneline')) class DefaultTreeViewItemView(EntityView): @@ -60,7 +68,7 @@ """ id = 'treeitemview' accepts = ('Any',) - + def cell_call(self, row, col, vid='oneline', parentvid='treeview'): entity = self.entity(row, col) itemview = self.view(vid, self.rset, row=row, col=col) @@ -70,14 +78,9 @@ self.w(u'
    • %s
    • ' % itemview) -class TreeStateMixin(object): - - def open_state(self): - raise NotImplementedError - -class TreeViewItemView(EntityView, TreeStateMixin): +class TreeViewItemView(EntityView): """specific treeitem view for entities which implement ITree - + (each item should be exandable if it's not a tree leaf) """ id = 'treeitemview' @@ -85,80 +88,33 @@ # the default treeitem view __selectors__ = (implement_interface, yes) accepts_interfaces = (ITree,) - - def open_state(self): - """implements TreeState mixin""" - return () - + def cell_call(self, row, col, vid='oneline', parentvid='treeview'): - w = self.w entity = self.entity(row, col) - liclasses = [] + cssclasses = [] is_leaf = False - is_open = str(entity.eid) in self.open_state() if row == len(self.rset) - 1: is_leaf = True if not hasattr(entity, 'is_leaf') or entity.is_leaf(): - if is_leaf : liclasses.append('last') - w(u'
    • ' % u' '.join(liclasses)) + if is_leaf : cssclasses.append('last') + self.w(u'
    • ' % u' '.join(cssclasses)) else: rql = entity.children_rql() % {'x': entity.eid} url = html_escape(self.build_url('json', rql=rql, vid=parentvid, pageid=self.req.pageid, subvid=vid, noautoload=True)) - if is_open: - liclasses.append('collapsable') - else: - liclasses.append('expandable') - divclasses = ['hitarea'] - if is_open: - divclasses.append('collapsable-hitarea') - else: - divclasses.append('expandable-hitarea') - if is_leaf: - liclasses.append('lastExpandable') - if not is_open: - divclasses.append('lastExpandable-hitarea') - if is_open: - w(u'
    • ' % u' '.join(liclasses)) - else: - w(u'
    • ' % (url, u' '.join(liclasses))) - if is_leaf: - divtail = '' - else: - divtail = ''' onclick="async_remote_exec('node_clicked', %s)"''' % entity.eid - w(u'
      ' % (u' '.join(divclasses), divtail)) - + cssclasses.append('expandable') + divclasses = ['hitarea expandable-hitarea'] + if is_leaf : + cssclasses.append('lastExpandable') + divclasses.append('lastExpandable-hitarea') + self.w(u'
    • ' % (url, u' '.join(cssclasses))) + self.w(u'
      ' % u' '.join(divclasses)) + # add empty
        because jquery's treeview plugin checks for # sublists presence - if not is_open: - w(u'
        • place holder
        ') - # the local node info + self.w(u'
        • place holder
        ') self.wview(vid, self.rset, row=row, col=col) - if is_open: # recurse if needed - self.wview(parentvid, self.req.execute(rql)) - w(u'') - -from logilab.common.decorators import monkeypatch -from cubicweb.web.views.basecontrollers import JSonController + self.w(u'') -@monkeypatch(JSonController) -def js_node_clicked(self, eid): - """add/remove eid in treestate cookie - XXX this deals with one tree per page - also check the treeid issue above - """ - cookies = self.req.get_cookie() - treestate = cookies.get('treestate') - if treestate is None: - cookies['treestate'] = str(eid) - self.req.set_cookie(cookies, 'treestate') - else: - marked = set(treestate.value.split(';')) - if eid in marked: - marked.remove(eid) - else: - marked.add(eid) - cookies['treestate'] = ';'.join(str(x) for x in marked) - self.req.set_cookie(cookies, 'treestate')