[gen] Improvements in the rendering of buttons throughout the web UI. [gen] Ref field and Search: added param 'showActions' allowing to show or not the range of icons and buttons below or besides every tied or queried object.

This commit is contained in:
Gaetan Delannay 2015-01-19 15:44:09 +01:00
parent a905aaa139
commit 34cafcdbc1
10 changed files with 171 additions and 163 deletions

View file

@ -121,21 +121,19 @@ class Field:
pxChanges = Px('''
<x if="zobj.hasHistory(name)">
<!-- Button for showing the field version containing changes -->
<input type="button" class="button" if="not showChanges"
var="label=_('changes_show')" value=":label"
style=":'%s; %s' % (url('changes', bg=True), \
ztool.getButtonWidth(label))"
<input if="not showChanges"
var2="label=_('changes_show');
css=ztool.getButtonCss(label)" type="button" class=":css"
value=":label" style=":url('changes', bg=True)"
onclick=":'askField(%s,%s,%s,null,%s)' % \
(q(tagId), q(obj.url), q('view'), q('True'))"/>
<!-- Button for showing the field version without changes -->
<input type="button" class="button" if="showChanges"
var="label=_('changes_hide')" value=":label"
style=":'%s; %s' % (url('changesNo', bg=True), \
ztool.getButtonWidth(label))"
<input if="showChanges"
var2="label=_('changes_hide');
css=ztool.getButtonCss(label)" type="button" class=":css"
value=":label" style=":url('changesNo', bg=True)"
onclick=":'askField(%s,%s,%s,null,%s)' % \
(q(tagId), q(obj.url), q('view'), q('False'))"/>
</x>''')
(q(tagId), q(obj.url), q('view'), q('False'))"/></x>''')
def __init__(self, validator, multiplicity, default, show, page, group,
layouts, move, indexed, mustIndex, searchable,

View file

@ -30,9 +30,8 @@ class Action(Field):
<form var="formId='%s_%s_form' % (zobj.id, name);
label=_(field.labelId);
descr=field.hasDescr and _(field.descrId) or None;
buttonWidth=ztool.getButtonWidth(label);
smallButtons=smallButtons|False;
css=smallButtons and 'buttonSmall button' or 'button'"
css=ztool.getButtonCss(label, smallButtons)"
id=":formId" action=":zobj.absolute_url() + '/onExecuteAction'"
style="display:inline">
<input type="hidden" name="fieldName" value=":name"/>
@ -40,13 +39,11 @@ class Action(Field):
<input if="field.confirm" type="button" class=":css" title=":descr"
var="labelConfirm=_(field.labelId + '_confirm');
commentParam=(field.confirm == 'text') and 'true' or 'false'"
value=":label"
style=":'%s; %s' % (url(field.icon, bg=True), buttonWidth)"
value=":label" style=":url(field.icon, bg=True)"
onclick=":'askConfirm(%s,%s,%s,%s)' % (q('form'), q(formId), \
q(labelConfirm), commentParam)"/>
<input if="not field.confirm" type="submit" class=":css" name="do"
value=":label" title=":descr"
style=":'%s; %s' % (url(field.icon, bg=True), buttonWidth)"/>
value=":label" title=":descr" style=":url(field.icon, bg=True)"/>
</form>''')
# It is not possible to edit an action, not to search it

View file

@ -51,33 +51,36 @@ class Ref(Field):
# This PX displays buttons for triggering global actions on several linked
# objects (delete many, unlink many,...)
pxGlobalActions = Px('''
<!-- Insert several objects (if in pick list) -->
<input if="inPickList" type="button" class="button"
var2="action='link'; label=_('object_link_many')" value=":label"
onclick=":'onLinkMany(%s,%s)' % (q(action), q(ajaxHookId))"
style=":'%s; %s' % (url('linkMany', bg=True), \
ztool.getButtonWidth(label))"/>
<!-- Unlink several objects -->
<input if="mayUnlink"
var2="imgName=linkList and 'unlinkManyUp' or 'unlinkMany';
action='unlink'; label=_('object_unlink_many')"
type="button" class="button" value=":label"
onclick=":'onLinkMany(%s,%s)' % (q(action), q(ajaxHookId))"
style=":'%s; %s' % (url(imgName, bg=True), \
ztool.getButtonWidth(label))"/>
<!-- Delete several objects -->
<input if="mayEdit and field.delete"
var2="action='delete'; label=_('object_delete_many')"
type="button" class="button" value=":label"
onclick=":'onLinkMany(%s,%s)' % (q(action), q(ajaxHookId))"
style=":'%s; %s' % (url('deleteMany', bg=True), \
ztool.getButtonWidth(label))"/>
''')
<div class="globalActions">
<!-- Insert several objects (if in pick list) -->
<input if="inPickList"
var2="action='link'; label=_('object_link_many');
css=ztool.getButtonCss(label)"
type="button" class=":css" value=":label"
onclick=":'onLinkMany(%s,%s)' % (q(action), q(ajaxHookId))"
style=":url('linkMany', bg=True)"/>
<!-- Unlink several objects -->
<input if="mayUnlink"
var2="imgName=linkList and 'unlinkManyUp' or 'unlinkMany';
action='unlink'; label=_('object_unlink_many');
css=ztool.getButtonCss(label)"
type="button" class=":css" value=":label"
onclick=":'onLinkMany(%s,%s)' % (q(action), q(ajaxHookId))"
style=":url(imgName, bg=True)"/>
<!-- Delete several objects -->
<input if="mayEdit and field.delete"
var2="action='delete'; label=_('object_delete_many');
css=ztool.getButtonCss(label)"
type="button" class=":css" value=":label"
onclick=":'onLinkMany(%s,%s)' % (q(action), q(ajaxHookId))"
style=":url('deleteMany', bg=True)"/>
</div>''')
# This PX displays icons for triggering actions on a given referenced object
# (edit, delete, etc).
pxObjectActions = Px('''
<div>
<div if="field.showActions"
style=":'display:%s; margin-bottom:2px' % field.showActions">
<!-- Arrows for moving objects up or down -->
<x if="(totalNumber &gt;1) and changeOrder and not inPickList \
and not inMenu"
@ -143,26 +146,24 @@ class Ref(Field):
# Displays the button allowing to add a new object through a Ref field, if
# it has been declared as addable and if multiplicities allow it.
pxAdd = Px('''
<form if="mayAdd and not inPickList"
class=":inMenu and 'addFormMenu' or 'addForm'"
var2="formName='%s_%s_add' % (zobj.id, field.name)"
name=":formName" id=":formName" target=":target.target"
action=":'%s/do' % folder.absolute_url()">
<input type="hidden" name="action" value="Create"/>
<input type="hidden" name="className" value=":tiedClassName"/>
<input type="hidden" name="nav"
value=":field.getNavInfo(zobj, 0, totalNumber)"/>
<input type="hidden" name="popup"
value=":(inPopup or (target.target != '_self')) and '1' or '0'"/>
<input
type=":(field.addConfirm or field.noForm) and 'button' or 'submit'"
class="buttonSmall button"
var="label=_('add_ref')" value=":label"
style=":'%s; %s' % (url('add', bg=True), \
ztool.getButtonWidth(label))"
onclick=":field.getOnAdd(q, formName, addConfirmMsg, target, \
navBaseCall, startNumber)"/>
</form>''')
<form if="mayAdd and not inPickList"
class=":inMenu and 'addFormMenu' or 'addForm'"
var2="formName='%s_%s_add' % (zobj.id, field.name)"
name=":formName" id=":formName" target=":target.target"
action=":'%s/do' % folder.absolute_url()">
<input type="hidden" name="action" value="Create"/>
<input type="hidden" name="className" value=":tiedClassName"/>
<input type="hidden" name="nav"
value=":field.getNavInfo(zobj, 0, totalNumber)"/>
<input type="hidden" name="popup"
value=":(inPopup or (target.target != '_self')) and '1' or '0'"/>
<input
type=":(field.addConfirm or field.noForm) and 'button' or 'submit'"
var="label=_('add_ref'); css=ztool.getButtonCss(label)" class=":css"
value=":label" style=":url('add', bg=True)"
onclick=":field.getOnAdd(q, formName, addConfirmMsg, target, \
navBaseCall, startNumber)"/>
</form>''')
# Displays the button allowing to select from a popup objects to be linked
# via the Ref field.
@ -173,12 +174,13 @@ class Ref(Field):
href=":'%s/query?className=%s&amp;search=%s:%s:%s&amp;popup=1' % \
(ztool.absolute_url(), tiedClassName, obj.uid, field.name, \
popupMode)">
<input type="button" class="buttonSmall button"
<input type="button"
var="labelId= (popupMode=='repl') and 'search_button' or 'add_ref';
icon= (popupMode=='repl') and 'search' or 'add';
label=_(labelId)" value=":label"
style=":'%s;%s' % (url(icon,bg=True), ztool.getButtonWidth(label))"
onclick="openPopup('iframePopup')"/>
label=_(labelId);
css=ztool.getButtonCss(label)"
value=":label" class=":css"
style=":url(icon, bg=True)" onclick="openPopup('iframePopup')"/>
</a>''')
# This PX displays, in a cell header from a ref table, icons for sorting the
@ -233,10 +235,8 @@ class Ref(Field):
var2="popupMode='add'">:field.pxLink</x>
<!-- The search button if field is queryable -->
<input if="objects and field.queryable" type="button"
class="buttonSmall button"
var2="label=_('search_button')" value=":label"
style=":'%s; %s' % (url('search', bg=True), \
ztool.getButtonWidth(label))"
var2="label=_('search_button'); css=ztool.getButtonCss(label)"
value=":label" class=":css" style=":url('search', bg=True)"
onclick=":'goto(%s)' % \
q('%s/search?className=%s&amp;ref=%s:%s' % \
(ztool.absolute_url(), tiedClassName, zobj.id, field.name))"/>
@ -286,7 +286,7 @@ class Ref(Field):
<x if="refField.name == 'title'">
<x if="mayView">
<x>:field.pxObjectTitle</x>
<div if="tied.o.mayAct()">:field.pxObjectActions</div>
<x if="tied.o.mayAct()">:field.pxObjectActions</x>
</x>
<div if="not mayView">
<img src=":url('fake')" style="margin-right: 5px"/>
@ -303,7 +303,7 @@ class Ref(Field):
</table>
<!-- Global actions -->
<div if="mayEdit and checkboxes">:field.pxGlobalActions</div>
<x if="mayEdit and checkboxes">:field.pxGlobalActions</x>
<!-- (Bottom) navigation -->
<x>:tool.pxNavigate</x>
@ -392,7 +392,7 @@ class Ref(Field):
href=":field.getMenuUrl(zobj, tied)">:tied.title</a>
<!-- Show standard pxObjectTitle else -->
<x if="not field.menuUrlMethod">:field.pxObjectTitle</x>
<div if="tied.o.mayAct()">:field.pxObjectActions</div>
<x if="tied.o.mayAct()">:field.pxObjectActions</x>
</div>
</div>
</div>
@ -531,7 +531,8 @@ class Ref(Field):
checkboxes=True, checkboxesDefault=None, sdefault='',
scolspan=1, swidth=None, sheight=None, sselect=None,
persist=True, render='list', menuIdMethod=None,
menuInfoMethod=None, menuUrlMethod=None, view=None, xml=None):
menuInfoMethod=None, menuUrlMethod=None, view=None, xml=None,
showActions=True):
self.klass = klass
self.attribute = attribute
# May the user add new objects through this ref ? "add" may also contain
@ -712,6 +713,13 @@ class Ref(Field):
# "menuUrlMethod" is an optional method that allows to compute an
# alternative URL for the tied object that is shown within the menu.
self.menuUrlMethod = menuUrlMethod
# "showActions" determines if we must show or not actions on every tied
# object. Values can be: True, False or "inline". If True, actions will
# appear in a "div" tag, below the object title; if "inline", they will
# appear besides it, producing a more compact list of results.
self.showActions = showActions
if showActions == True: self.showActions = 'block'
# Call the base constructor
Field.__init__(self, validator, multiplicity, default, show, page,
group, layouts, move, indexed, mustIndex, searchable,
specificReadPermission, specificWritePermission, width,

View file

@ -26,8 +26,8 @@ class Search:
'''Used for specifying a search for a given class.'''
def __init__(self, name=None, group=None, sortBy='', sortOrder='asc',
maxPerPage=30, default=False, colspan=1, translated=None,
show=True, translatedDescr=None, checkboxes=False,
checkboxesDefault=True, **fields):
show=True, showActions=True, translatedDescr=None,
checkboxes=False, checkboxesDefault=True, **fields):
# "name" is mandatory, excepted in some special cases (ie, when used as
# "select" param for a Ref field).
self.name = name
@ -46,6 +46,11 @@ class Search:
self.translatedDescr = translatedDescr
# Condition for showing or not this search
self.show = show
# Condition for showing or not actions on every result of this search.
# Can be: True, False or "inline". If True, actions will appear in a
# "div" tag, below the object title; if "inline", they will appear
# besides it, producing a more compact list of results.
self.showActions = showActions
# In the dict below, keys are indexed field names or names of standard
# indexes, and values are search values.
self.fields = fields
@ -175,6 +180,10 @@ class UiSearch:
self.name = search.name
self.type = 'search'
self.colspan = search.colspan
# Property "display" of the div tag containing actions for every search
# result.
self.showActions = search.showActions
if search.showActions == True: self.showActions = 'block'
if search.translated:
self.translated = search.translated
self.translatedDescr = search.translatedDescr

View file

@ -463,22 +463,18 @@ class Transition:
class UiTransition:
'''Represents a widget that displays a transition.'''
pxView = Px('''<x var="buttonCss = (buttonsMode == 'small') and \
'buttonSmall button' or 'button'">
pxView = Px('''
<x var="label=transition.title;
css=ztool.getButtonCss(label, buttonsMode == 'small')">
<!-- Real button -->
<input if="transition.mayTrigger" type="button" class=":buttonCss"
var2="label=transition.title"
style=":'%s; %s' % (url(transition.icon, bg=True), \
ztool.getButtonWidth(label))"
value=":label"
<input if="transition.mayTrigger" type="button" class=":css"
style=":url(transition.icon, bg=True)" value=":label"
onclick=":'triggerTransition(%s,%s,%s)' % (q(formId), \
q(transition.name), q(transition.confirm))"/>
<!-- Fake button, explaining why the transition can't be triggered -->
<input if="not transition.mayTrigger" type="button"
class=":'fake ' + buttonCss" var2="label=transition.title"
style=":'%s; %s' % (url('fake', bg=True),
ztool.getButtonWidth(label))"
class=":'fake %s' % css" style=":url('fake', bg=True)"
value=":label" title=":transition.reason"/></x>''')
def __init__(self, name, transition, obj, mayTrigger, ):