[gen] Ref.select can now hold a Search instance; began implementation of Ref.link == 'popup'.

This commit is contained in:
Gaetan Delannay 2014-07-18 16:54:11 +02:00
parent a466513fb3
commit b2a2aa5210
7 changed files with 102 additions and 37 deletions

View file

@ -73,13 +73,15 @@ class ToolMixin(BaseMixin):
url = self.goto('%s/home' % self.absolute_url())
return url
def getHomeObject(self):
def getHomeObject(self, inPopup=False):
'''The concept of "home object" is the object where the user must "be",
even if he is "nowhere". For example, if the user is on a search
screen, there is no contextual object. In this case, if we have a
home object for him, we will use it as contextual object, and its
portlet menu will nevertheless appear: the user will not have the
feeling of being lost.'''
# If we are in the popup, we do not want any home object in the way.
if inPopup: return
# If the app defines a method "getHomeObject", call it.
try:
return self.appy().getHomeObject()
@ -727,6 +729,10 @@ class ToolMixin(BaseMixin):
# It is a custom search whose parameters are in the session.
fields = self.REQUEST.SESSION['searchCriteria']
res = Search('customSearch', **fields)
elif ':' in name:
# The search is defined in a Ref field with link=popup
refClass, ref = name.split(':')
res = getattr(self.getAppyClass(refClass), ref).select
elif name:
appyClass = self.getAppyClass(className)
# Search among static searches

View file

@ -210,11 +210,11 @@ function askAjaxChunk(hook,mode,url,px,params,beforeSend,onGet) {
/* The functions below wrap askAjaxChunk for getting specific content through
an Ajax request. */
function askQueryResult(hookId, objectUrl, className, searchName,
function askQueryResult(hookId, objectUrl, className, searchName, popup,
startNumber, sortKey, sortOrder, filterKey) {
// Sends an Ajax request for getting the result of a query.
var params = {'className': className, 'search': searchName,
'startNumber': startNumber};
'startNumber': startNumber, 'popup': popup};
if (sortKey) params['sortKey'] = sortKey;
if (sortOrder) params['sortOrder'] = sortOrder;
if (filterKey) {
@ -725,15 +725,24 @@ function openPopup(popupId, msg, width, height) {
}
// Open the popup
var popup = document.getElementById(popupId);
// Put it at the right place on the screen
// Put it at the right place on the screen and give it the right dimensions
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || 0;
popup.style.top = (scrollTop + 150) + 'px';
if (width) popup.style.width = width + 'px';
if (height) popup.style.height = height + 'px';
if (popupId == 'iframePopup') {
// Initialize iframe's width.
var iframe = document.getElementById('appyIFrame');
if (!width) width = window.innerWidth - 200;
if (!height) {
height = window.innerHeight - 200;
popup.style.top = ((window.innerHeight - height) / 2).toFixed() + 'px';
}
popup.style.left = ((window.innerWidth - width) / 2).toFixed() + 'px';
popup.style.width = width + 'px';
iframe.style.width = (width-20) + 'px';
if (height) iframe.style.height = height + 'px';
popup.style.height = height + 'px';
iframe.style.height = (height-20) + 'px';
}
popup.style.display = 'block';
}

View file

@ -431,9 +431,9 @@ class ToolWrapper(AbstractWrapper):
batchSize=queryResult.batchSize;
batchNumber=len(zobjects);
ajaxHookId='queryResult';
navBaseCall='askQueryResult(%s,%s,%s,%s,**v**)' % \
navBaseCall='askQueryResult(%s,%s,%s,%s,%s,**v**)' % \
(q(ajaxHookId), q(ztool.absolute_url()), q(className), \
q(searchName));
q(searchName),int(inPopup));
showNewSearch=showNewSearch|True;
enableLinks=enableLinks|True;
newSearchUrl='%s/search?className=%s%s' % \
@ -446,7 +446,7 @@ class ToolWrapper(AbstractWrapper):
<!-- Display here POD templates if required. -->
<table var="fields=ztool.getResultPodFields(className);
layoutType='view'"
if="zobjects and fields" align=":dright">
if="not inPopup and zobjects and fields" align=":dright">
<tr>
<td var="zobj=zobjects[0]; obj=zobj.appy()"
for="field in fields"
@ -455,7 +455,7 @@ class ToolWrapper(AbstractWrapper):
</table>
<!-- The title of the search -->
<p>
<p if="not inPopup">
<x>::uiSearch.translated</x> (<span class="discreet">:totalNumber</span>)
<x if="showNewSearch and (searchName == 'customSearch')">&nbsp;&mdash;
&nbsp;<i><a href=":newSearchUrl">:_('search_new')</a></i>

View file

@ -6,6 +6,7 @@ from appy.gen import utils as gutils
# ------------------------------------------------------------------------------
class UserWrapper(AbstractWrapper):
workflow = WorkflowOwner
specialUsers = ('system', 'anon', 'admin')
def showLogin(self):
'''When must we show the login field?'''
@ -42,7 +43,7 @@ class UserWrapper(AbstractWrapper):
if not self.login or (login != self.login):
# A new p_login is requested. Check if it is valid and free.
# Some logins are not allowed.
if login in ('admin', 'anon', 'system'):
if login in self.specialUsers:
return self.translate('login_reserved')
# Check that no user or group already uses this login.
if self.count('User', noSecurity=True, login=login) or \
@ -219,7 +220,7 @@ class UserWrapper(AbstractWrapper):
def mayEdit(self):
'''No one can edit users "system" and "anon".'''
if self.o.id in ('system', 'anon'): return
if self.o.id in ('anon', 'system'): return
# Call custom "mayEdit" when present.
custom = self._getCustomMethod('mayEdit')
if custom: return self._callCustom('mayEdit')
@ -227,7 +228,7 @@ class UserWrapper(AbstractWrapper):
def mayDelete(self):
'''No one can delete users "system", "anon" and "admin".'''
if self.o.id in ('system', 'anon', 'admin'): return
if self.o.id in self.specialUsers: return
# Call custom "mayDelete" when present.
custom = self._getCustomMethod('mayDelete')
if custom: return self._callCustom('mayDelete')

View file

@ -75,16 +75,16 @@ class AbstractWrapper(object):
# The template PX for all pages.
pxTemplate = Px('''
<html var="ztool=tool.o; user=tool.user;
obj=obj or ztool.getHomeObject();
req=ztool.REQUEST; resp=req.RESPONSE;
inPopup=req.get('popup') == '1';
obj=obj or ztool.getHomeObject(inPopup);
zobj=obj and obj.o or None;
isAnon=user.login=='anon'; app=ztool.getApp();
appFolder=app.data; url = ztool.getIncludeUrl;
appName=ztool.getAppName(); _=ztool.translate;
req=ztool.REQUEST; resp=req.RESPONSE;
dummy=setattr(req, 'pxContext', _ctx_);
lang=ztool.getUserLanguage(); q=ztool.quote;
layoutType=ztool.getLayoutType();
inPopup=req.get('popup') == '1';
showPortlet=not inPopup and ztool.showPortlet(obj, layoutType);
dir=ztool.getLanguageDirection(lang);
cfg=ztool.getProductConfig(True);