11 |
11 |
12 from logilab.common.decorators import cached |
12 from logilab.common.decorators import cached |
13 |
13 |
14 from cubicweb.common.utils import UStringIO |
14 from cubicweb.common.utils import UStringIO |
15 from cubicweb.common.view import AnyRsetView, StartupView, EntityView |
15 from cubicweb.common.view import AnyRsetView, StartupView, EntityView |
16 from cubicweb.common.uilib import (html_traceback, rest_traceback, html_escape, |
16 from cubicweb.common.uilib import html_traceback, rest_traceback |
17 toggle_link) |
|
18 from cubicweb.common.selectors import (yes, one_line_rset, |
17 from cubicweb.common.selectors import (yes, one_line_rset, |
19 accept_rset, none_rset, |
18 accept_rset, none_rset, |
20 chainfirst, chainall) |
19 chainfirst, chainall) |
21 from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, stdmsgs |
20 from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, stdmsgs |
22 from cubicweb.web.widgets import StaticComboBoxWidget |
21 from cubicweb.web.widgets import StaticComboBoxWidget |
23 from cubicweb.web.form import FormMixIn |
22 from cubicweb.web.form import FormMixIn |
24 |
23 |
25 _ = unicode |
24 _ = unicode |
282 _('actions') |
281 _('actions') |
283 _('boxes') |
282 _('boxes') |
284 _('components') |
283 _('components') |
285 _('contentnavigation') |
284 _('contentnavigation') |
286 |
285 |
|
286 |
|
287 def make_togglable_link(nodeid, label, cookiename, cookievalue): |
|
288 """builds a HTML link that switches the visibility & remembers it""" |
|
289 action = u"javascript: toggle_and_remember_visibility('%s', '%s', '%s')" % \ |
|
290 (nodeid, cookiename, cookievalue) |
|
291 return u'<a href="%s">%s</a>' % (action, label) |
|
292 |
287 class SystemEpropertiesForm(FormMixIn, StartupView): |
293 class SystemEpropertiesForm(FormMixIn, StartupView): |
288 controller = 'edit' |
294 controller = 'edit' |
289 id = 'systemepropertiesform' |
295 id = 'systemepropertiesform' |
290 title = _('site configuration') |
296 title = _('site configuration') |
291 require_groups = ('managers',) |
297 require_groups = ('managers',) |
296 |
302 |
297 def url(self): |
303 def url(self): |
298 """return the url associated with this view. We can omit rql here""" |
304 """return the url associated with this view. We can omit rql here""" |
299 return self.build_url('view', vid=self.id) |
305 return self.build_url('view', vid=self.id) |
300 |
306 |
|
307 def _cookie_name_from_group(self, group): |
|
308 return str('%s_property_%s' % (self.config.appid, group)) |
|
309 |
|
310 def _group_status(self, group, default=u'hidden'): |
|
311 cookies = self.req.get_cookie() |
|
312 cookiename = self._cookie_name_from_group(group) |
|
313 cookie = cookies.get(cookiename) |
|
314 if cookie is None: |
|
315 cookies[cookiename] = default |
|
316 self.req.set_cookie(cookies, cookiename, maxage=None) |
|
317 status = default |
|
318 else: |
|
319 status = cookie.value |
|
320 return status |
|
321 |
301 def call(self, **kwargs): |
322 def call(self, **kwargs): |
302 """The default view representing the application's index""" |
323 """The default view representing the application's index""" |
303 self.req.add_js('cubicweb.edition.js') |
324 self.req.add_js(('cubicweb.edition.js', 'cubicweb.preferences.js')) |
304 self.req.add_css('cubicweb.preferences.css') |
325 self.req.add_css('cubicweb.preferences.css') |
305 vreg = self.vreg |
326 vreg = self.vreg |
306 values = self.defined_keys |
327 values = self.defined_keys |
307 groupedopts = {} |
328 groupedopts = {} |
308 mainopts = {} |
329 mainopts = {} |
328 _ = req._ |
349 _ = req._ |
329 w(u'<h1>%s</h1>\n' % _(self.title)) |
350 w(u'<h1>%s</h1>\n' % _(self.title)) |
330 w(self.error_message()) |
351 w(self.error_message()) |
331 for label, group, form in sorted((_(g), g, f) |
352 for label, group, form in sorted((_(g), g, f) |
332 for g, f in mainopts.iteritems()): |
353 for g, f in mainopts.iteritems()): |
|
354 status = self._group_status(group) #hidden, or not ? |
333 w(u'<h2 class="propertiesform">%s</h2>\n' % |
355 w(u'<h2 class="propertiesform">%s</h2>\n' % |
334 (toggle_link('fieldset_' + group, label))) |
356 (make_togglable_link('fieldset_' + group, label, |
335 w(u'<div id="fieldset_%s" class="hidden">' % group) |
357 self._cookie_name_from_group(group), status))) |
|
358 statusclass = status and 'class="%s"' % status or '' |
|
359 w(u'<div id="fieldset_%s" %s>' % (group, statusclass)) |
336 w(u'<fieldset class="subentity">') |
360 w(u'<fieldset class="subentity">') |
337 w(form) |
361 w(form) |
338 w(u'</fieldset></div>') |
362 w(u'</fieldset></div>') |
339 for label, group, objects in sorted((_(g), g, o) |
363 for label, group, objects in sorted((_(g), g, o) |
340 for g, o in groupedopts.iteritems()): |
364 for g, o in groupedopts.iteritems()): |
|
365 status = self._group_status(group) |
341 w(u'<h2 class="propertiesform">%s</h2>\n' % |
366 w(u'<h2 class="propertiesform">%s</h2>\n' % |
342 (toggle_link('fieldset_' + group, label))) |
367 (make_togglable_link('fieldset_' + group, label, |
343 w(u'<div id="fieldset_%s" class="hidden">' % group) |
368 self._cookie_name_from_group(group), status))) |
|
369 statusclass = status and 'class="%s"' % status or '' |
|
370 w(u'<div id="fieldset_%s" %s>' % (group, statusclass)) |
344 for label, oid, form in sorted((self.req.__('%s_%s' % (group, o)), o, f) |
371 for label, oid, form in sorted((self.req.__('%s_%s' % (group, o)), o, f) |
345 for o, f in objects.iteritems()): |
372 for o, f in objects.iteritems()): |
346 w(u'<fieldset class="subentity">') |
373 w(u'<fieldset class="subentity">') |
347 w(u'<legend class="componentTitle">%s</legend>\n' % label) |
374 w(u'<legend class="componentTitle">%s</legend>\n' % label) |
348 docmsgid = '%s_%s_description' % (group, oid) |
375 docmsgid = '%s_%s_description' % (group, oid) |