9 _ = unicode |
9 _ = unicode |
10 |
10 |
11 from simplejson import dumps |
11 from simplejson import dumps |
12 |
12 |
13 from logilab.common.decorators import cached |
13 from logilab.common.decorators import cached |
14 from logilab.mtconverter import html_escape |
14 from logilab.mtconverter import xml_escape |
15 |
15 |
16 from cubicweb import typed_eid |
16 from cubicweb import typed_eid |
17 from cubicweb.view import EntityView |
17 from cubicweb.view import EntityView |
18 from cubicweb.selectors import (one_line_rset, non_final_entity, |
18 from cubicweb.selectors import (one_line_rset, non_final_entity, |
19 match_search_state, match_form_params) |
19 match_search_state, match_form_params) |
62 def cell_call(self, row, col): |
62 def cell_call(self, row, col): |
63 entity = self.entity(row, col) |
63 entity = self.entity(row, col) |
64 erset = entity.as_rset() |
64 erset = entity.as_rset() |
65 if self.req.match_search_state(erset): |
65 if self.req.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 html_escape(linksearch_select_url(self.req, erset)), |
67 xml_escape(linksearch_select_url(self.req, erset)), |
68 self.req._('select this entity'), |
68 self.req._('select this entity'), |
69 html_escape(entity.view('textoutofcontext')), |
69 xml_escape(entity.view('textoutofcontext')), |
70 html_escape(entity.absolute_url(vid='primary')), |
70 xml_escape(entity.absolute_url(vid='primary')), |
71 self.req._('view detail for this entity'))) |
71 self.req._('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 |
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> |
112 </div> |
112 </div> |
113 """ % (hidden and 'hidden' or '', divid, selectid, |
113 """ % (hidden and 'hidden' or '', divid, selectid, |
114 html_escape(dumps(entity.eid)), is_cell and 'true' or 'null', relname, |
114 xml_escape(dumps(entity.eid)), is_cell and 'true' or 'null', relname, |
115 '\n'.join(options)) |
115 '\n'.join(options)) |
116 |
116 |
117 def _get_select_options(self, entity, rschema, target): |
117 def _get_select_options(self, entity, rschema, target): |
118 """add options to search among all entities of each possible type""" |
118 """add options to search among all entities of each possible type""" |
119 options = [] |
119 options = [] |
124 field = form.field_by_name(rschema, target, entity.e_schema) |
124 field = form.field_by_name(rschema, target, entity.e_schema) |
125 limit = self.req.property_value('navigation.combobox-limit') |
125 limit = self.req.property_value('navigation.combobox-limit') |
126 for eview, reid in form.form_field_vocabulary(field, limit): |
126 for eview, reid in form.form_field_vocabulary(field, limit): |
127 if reid is None: |
127 if reid is None: |
128 options.append('<option class="separator">-- %s --</option>' |
128 options.append('<option class="separator">-- %s --</option>' |
129 % html_escape(eview)) |
129 % xml_escape(eview)) |
130 else: |
130 else: |
131 optionid = relation_id(eid, rtype, target, reid) |
131 optionid = relation_id(eid, rtype, target, reid) |
132 if optionid not in pending_inserts: |
132 if optionid not in pending_inserts: |
133 # prefix option's id with letters to make valid XHTML wise |
133 # prefix option's id with letters to make valid XHTML wise |
134 options.append('<option id="id%s" value="%s">%s</option>' % |
134 options.append('<option id="id%s" value="%s">%s</option>' % |
135 (optionid, reid, html_escape(eview))) |
135 (optionid, reid, xml_escape(eview))) |
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 = [] |
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.req), |
147 '<option value="%s">%s %s</option>' % ( |
147 '<option value="%s">%s %s</option>' % ( |
148 html_escape(url), _('Search for'), eschema.display_name(self.req)))) |
148 xml_escape(url), _('Search for'), eschema.display_name(self.req)))) |
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.req._ |
155 for basketeid, basketname in self._get_basket_links(self.req.user.eid, |
155 for basketeid, basketname in self._get_basket_links(self.req.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'), html_escape(basketname))) |
159 optionid, basketeid, _('link to each item in'), xml_escape(basketname))) |
160 return options |
160 return options |
161 |
161 |
162 def _get_basket_links(self, ueid, target, targettypes): |
162 def _get_basket_links(self, ueid, target, targettypes): |
163 targettypes = set(targettypes) |
163 targettypes = set(targettypes) |
164 for basketeid, basketname, elements in self._get_basket_info(ueid): |
164 for basketeid, basketname, elements in self._get_basket_info(ueid): |