From dcf90f2b94526025bee23e71d2b2c8529c81eea1 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 23 Sep 2014 18:38:55 +0200 Subject: [PATCH] [gen] Created method mixin.getListTitle that is responsible for displaying an object's title in the various lists (queries, refs). --- fields/ref.py | 19 +++++++------------ gen/mixins/__init__.py | 38 +++++++++++++++++++++++++++++++++++++ gen/wrappers/ToolWrapper.py | 17 ++++++----------- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/fields/ref.py b/fields/ref.py index 23d05c5..2df23f7 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -38,21 +38,16 @@ class Ref(Field): # defined. If we are on a forward reference, the "nav" parameter is added to # the URL for allowing to navigate from one object to the next/previous one. pxObjectTitle = Px(''' - + pageName=field.isBack and field.back.pageName or 'main'"> ::tied.o.getSupTitle(navInfo) - :(not includeShownInfo) and \ - tied.o.getShownValue('title') or field.getReferenceLabel(tied) - ::tied.o.getSubTitle()''') + ::tied.o.getListTitle(nav=navInfo, target=target, page=pageName, \ + inPopup=inPopup) + ::sub + ''') # This PX displays buttons for triggering global actions on several linked # objects (delete many, unlink many,...) diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index 11b6186..9a3c6da 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -951,6 +951,44 @@ class BaseMixin: if hasattr(obj, 'getSubBreadCrumb'): return obj.getSubBreadCrumb() return '' + def getListTitle(self, mode='link', nav='', target=None, page='main', + inPopup=False, selectJs=None): + '''Gets the title as it must appear in lists of objects (ie in lists of + tied objects in a Ref, in query results...). + + In most cases, a title must appear as a link that leads to the object + view layout. In this case (p_mode == "link"): + * p_nav is the navigation parameter allowing navigation between + this object and others; + * p_target specifies if the link must be opened in the popup or not; + * p_page specifies which page to show on the target object view; + * p_inPopup indicates if we are already in the popup or not. + + Another p_mode is "select". In this case, we are in a popup for + selecting objects: every title must not be a link, but clicking on it + must trigger Javascript code (in p_selectJs) that will select this + object. + + The last p_mode is "text". In this case, we simply show the object + title but with no tied action (link, select). + ''' + # Compute common parts + cssClass = self.getCssFor('title') + title = self.getShownValue('title') + if mode == 'link': + inPopup = inPopup or (target.target != '_self') + url = self.getUrl(page=page, nav=nav, inPopup=inPopup) + onClick = target.openPopup and \ + (' onclick="%s"' % target.openPopup) or '' + res = '%s' % \ + (url, cssClass, target.target, onClick, title) + elif mode == 'select': + res = '%s' % \ + (cssClass, selectJs, title) + elif mode == 'text': + res = '%s' % (cssClass, title) + return res + # Workflow methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def initializeWorkflow(self): '''Called when an object is created, be it temp or not, for initializing diff --git a/gen/wrappers/ToolWrapper.py b/gen/wrappers/ToolWrapper.py index d99934e..929a9f7 100644 --- a/gen/wrappers/ToolWrapper.py +++ b/gen/wrappers/ToolWrapper.py @@ -317,17 +317,13 @@ class ToolWrapper(AbstractWrapper): + titleMode=inPopup and 'select' or 'link'; + pageName=zobj.getDefaultViewPage(); + selectJs=inPopup and 'onSelectObject(%s,%s,%s)' % (q(cbId), \ + q(rootHookId), q(uiSearch.initiator.url))"> ::sup - :zobj.getShownValue('title') - :obj.title + ::zobj.getListTitle(mode=titleMode, nav=navInfo, target=target, \ + page=pageName, inPopup=inPopup, selectJs=selectJs) ::sub @@ -478,7 +474,6 @@ class ToolWrapper(AbstractWrapper): (q(ajaxHookId), q(ztool.absolute_url()), q(className), \ q(searchName),int(inPopup)); showNewSearch=showNewSearch|True; - enableLinks=enableLinks|not inPopup; newSearchUrl='%s/search?className=%s%s' % \ (ztool.absolute_url(), className, refUrlPart); showSubTitles=req.get('showSubTitles', 'true') == 'true';