18 from cubicweb.web.htmlwidgets import MenuWidget, PopupBoxMenu, BoxSeparator, BoxLink |
18 from cubicweb.web.htmlwidgets import MenuWidget, PopupBoxMenu, BoxSeparator, BoxLink |
19 from cubicweb.web.component import Component, RelatedObjectsVComponent |
19 from cubicweb.web.component import Component, RelatedObjectsVComponent |
20 |
20 |
21 _ = unicode |
21 _ = unicode |
22 |
22 |
|
23 VISIBLE_PROP_DEF = { |
|
24 _('visible'): dict(type='Boolean', default=False, |
|
25 help=_('display the component or not')), |
|
26 } |
23 |
27 |
24 class RQLInputForm(Component): |
28 class RQLInputForm(Component): |
25 """build the rql input form, usually displayed in the header""" |
29 """build the rql input form, usually displayed in the header""" |
26 id = 'rqlinput' |
30 id = 'rqlinput' |
27 visible = False |
31 property_defs = VISIBLE_PROP_DEF |
28 |
32 |
29 def call(self, view=None): |
33 def call(self, view=None): |
30 if hasattr(view, 'filter_box_context_info'): |
34 if hasattr(view, 'filter_box_context_info'): |
31 rset = view.filter_box_context_info()[0] |
35 rset = view.filter_box_context_info()[0] |
32 else: |
36 else: |
33 rset = self.rset |
37 rset = self.rset |
51 |
55 |
52 |
56 |
53 class ApplLogo(Component): |
57 class ApplLogo(Component): |
54 """build the application logo, usually displayed in the header""" |
58 """build the application logo, usually displayed in the header""" |
55 id = 'logo' |
59 id = 'logo' |
56 site_wide = True # don't want user to hide this component using an eproperty |
60 property_defs = VISIBLE_PROP_DEF |
|
61 # don't want user to hide this component using an cwproperty |
|
62 site_wide = True |
|
63 |
57 def call(self): |
64 def call(self): |
58 self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>' |
65 self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>' |
59 % (self.req.base_url(), self.req.external_resource('LOGO'))) |
66 % (self.req.base_url(), self.req.external_resource('LOGO'))) |
60 |
67 |
61 |
68 |
62 class ApplHelp(Component): |
69 class ApplHelp(Component): |
63 """build the help button, usually displayed in the header""" |
70 """build the help button, usually displayed in the header""" |
64 id = 'help' |
71 id = 'help' |
|
72 property_defs = VISIBLE_PROP_DEF |
65 def call(self): |
73 def call(self): |
66 self.w(u'<a href="%s" class="help" title="%s"> </a>' |
74 self.w(u'<a href="%s" class="help" title="%s"> </a>' |
67 % (self.build_url(_restpath='doc/main'), |
75 % (self.build_url(_restpath='doc/main'), |
68 self.req._(u'help'),)) |
76 self.req._(u'help'),)) |
69 |
77 |
70 |
78 |
71 class UserLink(Component): |
79 class UserLink(Component): |
72 """if the user is the anonymous user, build a link to login |
80 """if the user is the anonymous user, build a link to login |
73 else a link to the connected user object with a loggout link |
81 else a link to the connected user object with a loggout link |
74 """ |
82 """ |
|
83 property_defs = VISIBLE_PROP_DEF |
|
84 # don't want user to hide this component using an cwproperty |
|
85 site_wide = True |
75 id = 'loggeduserlink' |
86 id = 'loggeduserlink' |
76 site_wide = True # don't want user to hide this component using an eproperty |
|
77 |
87 |
78 def call(self): |
88 def call(self): |
79 if not self.req.cnx.anonymous_connection: |
89 if not self.req.cnx.anonymous_connection: |
80 # display useractions and siteactions |
90 # display useractions and siteactions |
81 actions = self.vreg.possible_actions(self.req, self.rset) |
91 actions = self.vreg.possible_actions(self.req, self.rset) |
91 menu.append(BoxLink(action.url(), self.req._(action.title), |
101 menu.append(BoxLink(action.url(), self.req._(action.title), |
92 action.html_class())) |
102 action.html_class())) |
93 box.render(w=self.w) |
103 box.render(w=self.w) |
94 else: |
104 else: |
95 self.anon_user_link() |
105 self.anon_user_link() |
96 |
106 |
97 def anon_user_link(self): |
107 def anon_user_link(self): |
98 if self.config['auth-mode'] == 'cookie': |
108 if self.config['auth-mode'] == 'cookie': |
99 self.w(self.req._('anonymous')) |
109 self.w(self.req._('anonymous')) |
100 self.w(u''' [<a class="logout" href="javascript: popupLoginBox();">%s</a>]''' |
110 self.w(u''' [<a class="logout" href="javascript: popupLoginBox();">%s</a>]''' |
101 % (self.req._('i18n_login_popup'))) |
111 % (self.req._('i18n_login_popup'))) |
114 """display application's messages given using the __message parameter |
124 """display application's messages given using the __message parameter |
115 into a special div section |
125 into a special div section |
116 """ |
126 """ |
117 __select__ = yes() |
127 __select__ = yes() |
118 id = 'applmessages' |
128 id = 'applmessages' |
119 site_wide = True # don't want user to hide this component using an eproperty |
129 property_defs = VISIBLE_PROP_DEF |
|
130 # don't want user to hide this component using an cwproperty |
|
131 site_wide = True |
120 |
132 |
121 def call(self): |
133 def call(self): |
122 msgs = [msg for msg in (self.req.get_shared_data('sources_error', pop=True), |
134 msgs = [msg for msg in (self.req.get_shared_data('sources_error', pop=True), |
123 self.req.message) if msg] |
135 self.req.message) if msg] |
124 self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' % |
136 self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' % |
130 |
142 |
131 |
143 |
132 class ApplicationName(Component): |
144 class ApplicationName(Component): |
133 """display the application name""" |
145 """display the application name""" |
134 id = 'appliname' |
146 id = 'appliname' |
|
147 property_defs = VISIBLE_PROP_DEF |
135 |
148 |
136 def call(self): |
149 def call(self): |
137 self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % (self.req.base_url(), |
150 self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % (self.req.base_url(), |
138 self.req.property_value('ui.site-title'))) |
151 self.req.property_value('ui.site-title'))) |
139 |
152 |
140 |
153 |
141 class SeeAlsoVComponent(RelatedObjectsVComponent): |
154 class SeeAlsoVComponent(RelatedObjectsVComponent): |
142 """display any entity's see also""" |
155 """display any entity's see also""" |
143 id = 'seealso' |
156 id = 'seealso' |
|
157 property_defs = VISIBLE_PROP_DEF |
144 context = 'navcontentbottom' |
158 context = 'navcontentbottom' |
145 rtype = 'see_also' |
159 rtype = 'see_also' |
146 target = 'object' |
160 target = 'object' |
147 order = 40 |
161 order = 40 |
148 # register msg not generated since no entity use see_also in cubicweb itself |
162 # register msg not generated since no entity use see_also in cubicweb itself |
149 title = _('contentnavigation_seealso') |
163 title = _('contentnavigation_seealso') |
150 help = _('contentnavigation_seealso_description') |
164 help = _('contentnavigation_seealso_description') |
151 |
165 |
152 |
166 |
153 class EtypeRestrictionComponent(Component): |
167 class EtypeRestrictionComponent(Component): |
154 """displays the list of entity types contained in the resultset |
168 """displays the list of entity types contained in the resultset |
155 to be able to filter accordingly. |
169 to be able to filter accordingly. |
156 """ |
170 """ |
157 id = 'etypenavigation' |
171 id = 'etypenavigation' |
158 __select__ = two_etypes_rset() | match_form_params('__restrtype', '__restrtypes', |
172 __select__ = two_etypes_rset() | match_form_params('__restrtype', '__restrtypes', |
159 '__restrrql') |
173 '__restrrql') |
|
174 property_defs = VISIBLE_PROP_DEF |
|
175 # don't want user to hide this component using an cwproperty |
|
176 site_wide = True |
160 visible = False # disabled by default |
177 visible = False # disabled by default |
161 |
178 |
162 def call(self): |
179 def call(self): |
163 _ = self.req._ |
180 _ = self.req._ |
164 self.w(u'<div id="etyperestriction">') |
181 self.w(u'<div id="etyperestriction">') |
165 restrtype = self.req.form.get('__restrtype') |
182 restrtype = self.req.form.get('__restrtype') |
166 restrtypes = self.req.form.get('__restrtypes', '').split(',') |
183 restrtypes = self.req.form.get('__restrtypes', '').split(',') |
195 url, _('Any'))) |
212 url, _('Any'))) |
196 else: |
213 else: |
197 html.insert(0, u'<span class="selected">%s</span>' % _('Any')) |
214 html.insert(0, u'<span class="selected">%s</span>' % _('Any')) |
198 self.w(u' | '.join(html)) |
215 self.w(u' | '.join(html)) |
199 self.w(u'</div>') |
216 self.w(u'</div>') |
200 |
217 |
201 |
218 |
202 def registration_callback(vreg): |
219 def registration_callback(vreg): |
203 vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,)) |
220 vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,)) |
204 if 'see_also' in vreg.schema: |
221 if 'see_also' in vreg.schema: |
205 vreg.register(SeeAlsoVComponent) |
222 vreg.register(SeeAlsoVComponent) |