33 |
33 |
34 title = _('search for association') |
34 title = _('search for association') |
35 |
35 |
36 def cell_call(self, row, col): |
36 def cell_call(self, row, col): |
37 rset, vid, divid, paginate = self.filter_box_context_info() |
37 rset, vid, divid, paginate = self.filter_box_context_info() |
38 self.rset = rset |
38 self.cw_rset = rset |
39 self.w(u'<div id="%s">' % divid) |
39 self.w(u'<div id="%s">' % divid) |
40 self.paginate() |
40 self.paginate() |
41 self.wview(vid, rset, 'noresult') |
41 self.wview(vid, rset, 'noresult') |
42 self.w(u'</div>') |
42 self.w(u'</div>') |
43 |
43 |
44 @cached |
44 @cached |
45 def filter_box_context_info(self): |
45 def filter_box_context_info(self): |
46 entity = self.rset.get_entity(0, 0) |
46 entity = self.cw_rset.get_entity(0, 0) |
47 role, eid, rtype, etype = self.req.search_state[1] |
47 role, eid, rtype, etype = self._cw.search_state[1] |
48 assert entity.eid == typed_eid(eid) |
48 assert entity.eid == typed_eid(eid) |
49 # the default behaviour is to fetch all unrelated entities and display |
49 # the default behaviour is to fetch all unrelated entities and display |
50 # them. Use fetch_order and not fetch_unrelated_order as sort method |
50 # them. Use fetch_order and not fetch_unrelated_order as sort method |
51 # since the latter is mainly there to select relevant items in the combo |
51 # since the latter is mainly there to select relevant items in the combo |
52 # box, it doesn't give interesting result in this context |
52 # box, it doesn't give interesting result in this context |
53 rql, args = entity.unrelated_rql(rtype, etype, role, |
53 rql, args = entity.unrelated_rql(rtype, etype, role, |
54 ordermethod='fetch_order', |
54 ordermethod='fetch_order', |
55 vocabconstraints=False) |
55 vocabconstraints=False) |
56 rset = self.req.execute(rql, args, tuple(args)) |
56 rset = self._cw.execute(rql, args, tuple(args)) |
57 return rset, 'list', "search-associate-content", True |
57 return rset, 'list', "search-associate-content", True |
58 |
58 |
59 |
59 |
60 class OutOfContextSearch(EntityView): |
60 class OutOfContextSearch(EntityView): |
61 __regid__ = 'outofcontext-search' |
61 __regid__ = 'outofcontext-search' |
62 def cell_call(self, row, col): |
62 def cell_call(self, row, col): |
63 entity = self.rset.get_entity(row, col) |
63 entity = self.cw_rset.get_entity(row, col) |
64 erset = entity.as_rset() |
64 erset = entity.as_rset() |
65 if self.req.match_search_state(erset): |
65 if self._cw.match_search_state(erset): |
66 self.w(u'<a href="%s" title="%s">%s</a> <a href="%s" title="%s">[...]</a>' % ( |
66 self.w(u'<a href="%s" title="%s">%s</a> <a href="%s" title="%s">[...]</a>' % ( |
67 xml_escape(linksearch_select_url(self.req, erset)), |
67 xml_escape(linksearch_select_url(self._cw, erset)), |
68 self.req._('select this entity'), |
68 self._cw._('select this entity'), |
69 xml_escape(entity.view('textoutofcontext')), |
69 xml_escape(entity.view('textoutofcontext')), |
70 xml_escape(entity.absolute_url(vid='primary')), |
70 xml_escape(entity.absolute_url(vid='primary')), |
71 self.req._('view detail for this entity'))) |
71 self._cw._('view detail for this entity'))) |
72 else: |
72 else: |
73 entity.view('outofcontext', w=self.w) |
73 entity.view('outofcontext', w=self.w) |
74 |
74 |
75 |
75 |
76 class UnrelatedDivs(EntityView): |
76 class UnrelatedDivs(EntityView): |
77 __regid__ = 'unrelateddivs' |
77 __regid__ = 'unrelateddivs' |
78 __select__ = match_form_params('relation') |
78 __select__ = match_form_params('relation') |
79 |
79 |
80 def cell_call(self, row, col): |
80 def cell_call(self, row, col): |
81 entity = self.rset.get_entity(row, col) |
81 entity = self.cw_rset.get_entity(row, col) |
82 relname, target = self.req.form.get('relation').rsplit('_', 1) |
82 relname, target = self._cw.form.get('relation').rsplit('_', 1) |
83 rschema = self.schema.rschema(relname) |
83 rschema = self._cw.schema.rschema(relname) |
84 hidden = 'hidden' in self.req.form |
84 hidden = 'hidden' in self._cw.form |
85 is_cell = 'is_cell' in self.req.form |
85 is_cell = 'is_cell' in self._cw.form |
86 self.w(self.build_unrelated_select_div(entity, rschema, target, |
86 self.w(self.build_unrelated_select_div(entity, rschema, target, |
87 is_cell=is_cell, hidden=hidden)) |
87 is_cell=is_cell, hidden=hidden)) |
88 |
88 |
89 def build_unrelated_select_div(self, entity, rschema, target, |
89 def build_unrelated_select_div(self, entity, rschema, target, |
90 is_cell=False, hidden=True): |
90 is_cell=False, hidden=True): |
91 options = [] |
91 options = [] |
92 divid = 'div%s_%s_%s' % (rschema.type, target, entity.eid) |
92 divid = 'div%s_%s_%s' % (rschema.type, target, entity.eid) |
93 selectid = 'select%s_%s_%s' % (rschema.type, target, entity.eid) |
93 selectid = 'select%s_%s_%s' % (rschema.type, target, entity.eid) |
94 if rschema.symetric or target == 'subject': |
94 if rschema.symetric or target == 'subject': |
95 targettypes = rschema.objects(entity.e_schema) |
95 targettypes = rschema.objects(entity.e_schema) |
96 etypes = '/'.join(sorted(etype.display_name(self.req) for etype in targettypes)) |
96 etypes = '/'.join(sorted(etype.display_name(self._cw) for etype in targettypes)) |
97 else: |
97 else: |
98 targettypes = rschema.subjects(entity.e_schema) |
98 targettypes = rschema.subjects(entity.e_schema) |
99 etypes = '/'.join(sorted(etype.display_name(self.req) for etype in targettypes)) |
99 etypes = '/'.join(sorted(etype.display_name(self._cw) for etype in targettypes)) |
100 etypes = cut(etypes, self.req.property_value('navigation.short-line-size')) |
100 etypes = cut(etypes, self._cw.property_value('navigation.short-line-size')) |
101 options.append('<option>%s %s</option>' % (self.req._('select a'), etypes)) |
101 options.append('<option>%s %s</option>' % (self._cw._('select a'), etypes)) |
102 options += self._get_select_options(entity, rschema, target) |
102 options += self._get_select_options(entity, rschema, target) |
103 options += self._get_search_options(entity, rschema, target, targettypes) |
103 options += self._get_search_options(entity, rschema, target, targettypes) |
104 if 'Basket' in self.schema: # XXX |
104 if 'Basket' in self._cw.schema: # XXX |
105 options += self._get_basket_options(entity, rschema, target, targettypes) |
105 options += self._get_basket_options(entity, rschema, target, targettypes) |
106 relname, target = self.req.form.get('relation').rsplit('_', 1) |
106 relname, target = self._cw.form.get('relation').rsplit('_', 1) |
107 return u"""\ |
107 return u"""\ |
108 <div class="%s" id="%s"> |
108 <div class="%s" id="%s"> |
109 <select id="%s" onchange="javascript: addPendingInsert(this.options[this.selectedIndex], %s, %s, '%s');"> |
109 <select id="%s" onchange="javascript: addPendingInsert(this.options[this.selectedIndex], %s, %s, '%s');"> |
110 %s |
110 %s |
111 </select> |
111 </select> |
136 return options |
136 return options |
137 |
137 |
138 def _get_search_options(self, entity, rschema, target, targettypes): |
138 def _get_search_options(self, entity, rschema, target, targettypes): |
139 """add options to search among all entities of each possible type""" |
139 """add options to search among all entities of each possible type""" |
140 options = [] |
140 options = [] |
141 _ = self.req._ |
141 _ = self._cw._ |
142 for eschema in targettypes: |
142 for eschema in targettypes: |
143 mode = '%s:%s:%s:%s' % (target, entity.eid, rschema.type, eschema) |
143 mode = '%s:%s:%s:%s' % (target, entity.eid, rschema.type, eschema) |
144 url = self.build_url(entity.rest_path(), vid='search-associate', |
144 url = self.build_url(entity.rest_path(), vid='search-associate', |
145 __mode=mode) |
145 __mode=mode) |
146 options.append((eschema.display_name(self.req), |
146 options.append((eschema.display_name(self._cw), |
147 '<option value="%s">%s %s</option>' % ( |
147 '<option value="%s">%s %s</option>' % ( |
148 xml_escape(url), _('Search for'), eschema.display_name(self.req)))) |
148 xml_escape(url), _('Search for'), eschema.display_name(self._cw)))) |
149 return [o for l, o in sorted(options)] |
149 return [o for l, o in sorted(options)] |
150 |
150 |
151 def _get_basket_options(self, entity, rschema, target, targettypes): |
151 def _get_basket_options(self, entity, rschema, target, targettypes): |
152 options = [] |
152 options = [] |
153 rtype = rschema.type |
153 rtype = rschema.type |
154 _ = self.req._ |
154 _ = self._cw._ |
155 for basketeid, basketname in self._get_basket_links(self.req.user.eid, |
155 for basketeid, basketname in self._get_basket_links(self._cw.user.eid, |
156 target, targettypes): |
156 target, targettypes): |
157 optionid = relation_id(entity.eid, rtype, target, basketeid) |
157 optionid = relation_id(entity.eid, rtype, target, basketeid) |
158 options.append('<option id="%s" value="%s">%s %s</option>' % ( |
158 options.append('<option id="%s" value="%s">%s %s</option>' % ( |
159 optionid, basketeid, _('link to each item in'), xml_escape(basketname))) |
159 optionid, basketeid, _('link to each item in'), xml_escape(basketname))) |
160 return options |
160 return options |