[gen] Ref field: added a confirmation popup when the user wants to sort the ref. Indeed, most users think it is like sorting query results: they are not conscious it is a permanent change in the database, with effect for all users.

This commit is contained in:
Gaetan Delannay 2014-10-07 15:03:07 +02:00
parent c2676c9cf8
commit a16871f4b5
11 changed files with 57 additions and 17 deletions

View file

@ -328,8 +328,9 @@ class Field:
return self.indexed and not self.isMultiValued() and not \
((self.type == 'String') and self.isSelection())
elif usage == 'ref':
return self.type in ('Integer', 'Float', 'Boolean', 'Date') or \
((self.type == 'String') and (self.format == 0))
if self.type in ('Integer', 'Float', 'Boolean', 'Date'): return True
elif self.type == 'String':
return (self.format == 0) and not self.isMultilingual(None,True)
def isShowable(self, obj, layoutType):
'''When displaying p_obj on a given p_layoutType, must we show this

View file

@ -189,9 +189,13 @@ class Ref(Field):
(q(startNumber), q('sort'), q('sortKey'), q(refField.name), \
q('reverse'), q('**v**')))">
<img class="clickable" src=":url('sortAsc')"
onclick=":ajaxBaseCall.replace('**v**', 'False')"/>
var="js=ajaxBaseCall.replace('**v**', 'False')"
onclick=":'askConfirm(%s,%s,%s)' % (q('script'), q(js,False), \
q(sortConfirm))"/>
<img class="clickable" src=":url('sortDesc')"
onclick=":ajaxBaseCall.replace('**v**', 'True')"/>
var="js=ajaxBaseCall.replace('**v**', 'True')"
onclick=":'askConfirm(%s,%s,%s)' % (q('script'), q(js,False), \
q(sortConfirm))"/>
</x>''')
# Shows the object number in a numbered list of tied objects.
@ -430,6 +434,7 @@ class Ref(Field):
navBaseCall='askRefField(%s,%s,%s,**v**)' % \
(q(ajaxHookId), q(zobj.absolute_url()), q(innerRef));
changeOrder=mayEdit and field.getAttribute(zobj, 'changeOrder');
sortConfirm=changeOrder and _('sort_confirm');
numbered=field.isNumbered(zobj);
changeNumber=not inPickList and numbered and changeOrder and \
(totalNumber &gt; 3);

View file

@ -476,10 +476,12 @@ class String(Field):
res = False
return res
def isMultilingual(self, obj):
'''Is this field multilingual ?.'''
def isMultilingual(self, obj, dontKnow=False):
'''Is this field multilingual ? If we don't know, say p_dontKnow.'''
# In the following case, impossible to know: we say no.
if not obj and callable(self.languages): return
if not obj:
if callable(self.languages): return dontKnow
else: return len(self.languages) > 1
return len(self.getAttribute(obj, 'languages')) > 1
def getDefaultLayouts(self):