diff -r cddfbdee0eb3 -r 35133d86970b web/views/eproperties.py
--- a/web/views/eproperties.py Tue Feb 17 20:39:09 2009 +0100
+++ b/web/views/eproperties.py Tue Feb 17 20:56:45 2009 +0100
@@ -7,9 +7,250 @@
"""
__docformat__ = "restructuredtext en"
-from cubicweb.selectors import implements
+from logilab.mtconverter import html_escape
+
+from logilab.common.decorators import cached
+
+from cubicweb.selectors import (one_line_rset, none_rset, implements,
+ match_user_groups, chainfirst, chainall)
+from cubicweb.common.utils import UStringIO
+from cubicweb.common.view import StartupView
+from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, stdmsgs
from cubicweb.web.views import baseviews
+from cubicweb.web.form import FormMixIn
+
+_ = unicode
+
+# some string we want to be internationalizable for nicer display of eproperty
+# groups
+_('navigation')
+_('ui')
+_('actions')
+_('boxes')
+_('components')
+_('contentnavigation')
class EPropertyPrimaryView(baseviews.PrimaryView):
__selectors__ = implements('EProperty')
skip_none = False
+
+
+def make_togglable_link(nodeid, label, cookiename):
+ """builds a HTML link that switches the visibility & remembers it"""
+ action = u"javascript: toggle_and_remember_visibility('%s', '%s')" % \
+ (nodeid, cookiename)
+ return u'%s' % (action, label)
+
+def css_class(someclass):
+ return someclass and 'class="%s"' % someclass or ''
+
+class SystemEPropertiesForm(FormMixIn, StartupView):
+ id = 'systemepropertiesform'
+ __selectors__ = (none_rset, match_user_groups('managers'))
+
+ title = _('site configuration')
+ controller = 'edit'
+ category = 'startupview'
+
+ def linkable(self):
+ return True
+
+ def url(self):
+ """return the url associated with this view. We can omit rql here"""
+ return self.build_url('view', vid=self.id)
+
+ def _cookie_name(self, somestr):
+ return str('%s_property_%s' % (self.config.appid, somestr))
+
+ def _group_status(self, group, default=u'hidden'):
+ cookies = self.req.get_cookie()
+ cookiename = self._cookie_name(group)
+ cookie = cookies.get(cookiename)
+ if cookie is None:
+ cookies[cookiename] = default
+ self.req.set_cookie(cookies, cookiename, maxage=None)
+ status = default
+ else:
+ status = cookie.value
+ return status
+
+ def call(self, **kwargs):
+ """The default view representing the application's index"""
+ self.req.add_js(('cubicweb.edition.js', 'cubicweb.preferences.js'))
+ self.req.add_css('cubicweb.preferences.css')
+ vreg = self.vreg
+ values = self.defined_keys
+ groupedopts = {}
+ mainopts = {}
+ # "self.id=='systemepropertiesform'" to skip site wide properties on
+ # user's preference but not site's configuration
+ for key in vreg.user_property_keys(self.id=='systemepropertiesform'):
+ parts = key.split('.')
+ if parts[0] in vreg:
+ # appobject configuration
+ reg, oid, propid = parts
+ groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key)
+ else:
+ mainopts.setdefault(parts[0], []).append(key)
+ # precompute form to consume error message
+ for group, keys in mainopts.items():
+ mainopts[group] = self.form(keys, False)
+ for group, objects in groupedopts.items():
+ for oid, keys in objects.items():
+ groupedopts[group][oid] = self.form(keys, True)
+
+ w = self.w
+ req = self.req
+ _ = req._
+ w(u'
%s
\n' % _(self.title))
+ w(self.error_message())
+ for label, group, form in sorted((_(g), g, f)
+ for g, f in mainopts.iteritems()):
+ status = css_class(self._group_status(group)) #'hidden' (collapsed), or '' (open) ?
+ w(u'