1 """Views/forms and actions for the CubicWeb web client |
1 """Views/forms and actions for the CubicWeb web client |
2 |
2 |
3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 from rql import nodes |
9 from rql import nodes |
65 if req.search_state[0] == 'normal': |
65 if req.search_state[0] == 'normal': |
66 return 'primary' |
66 return 'primary' |
67 return 'outofcontext-search' |
67 return 'outofcontext-search' |
68 return 'list' |
68 return 'list' |
69 return 'table' |
69 return 'table' |
70 |
|
71 def linksearch_match(req, rset): |
|
72 """when searching an entity to create a relation, return True if entities in |
|
73 the given rset may be used as relation end |
|
74 """ |
|
75 try: |
|
76 searchedtype = req.search_state[1][-1] |
|
77 except IndexError: |
|
78 return 0 # no searching for association |
|
79 for etype in rset.column_types(0): |
|
80 if etype != searchedtype: |
|
81 return 0 |
|
82 return 1 |
|
83 |
70 |
84 def linksearch_select_url(req, rset): |
71 def linksearch_select_url(req, rset): |
85 """when searching an entity to create a relation, return an url to select |
72 """when searching an entity to create a relation, return an url to select |
86 entities in the given rset |
73 entities in the given rset |
87 """ |
74 """ |
88 req.add_js( ('cubicweb.ajax.js', 'cubicweb.edition.js') ) |
75 req.add_js( ('cubicweb.ajax.js', 'cubicweb.edition.js') ) |
89 target, link_eid, r_type, searchedtype = req.search_state[1] |
76 target, eid, r_type, searchedtype = req.search_state[1] |
90 if target == 'subject': |
77 if target == 'subject': |
91 id_fmt = '%s:%s:%%s' % (link_eid, r_type) |
78 id_fmt = '%s:%s:%%s' % (eid, r_type) |
92 else: |
79 else: |
93 id_fmt = '%%s:%s:%s' % (r_type, link_eid) |
80 id_fmt = '%%s:%s:%s' % (r_type, eid) |
94 triplets = '-'.join(id_fmt % row[0] for row in rset.rows) |
81 triplets = '-'.join(id_fmt % row[0] for row in rset.rows) |
95 return "javascript: selectForAssociation('%s', '%s');" % (triplets, |
82 return "javascript: selectForAssociation('%s', '%s');" % (triplets, eid) |
96 link_eid) |
|