This page describes the rules to make action dialogs.
Table of Contents
Rules¶
- Your action should use object_action category, and have an action name in English.
- The action must use an intermediate dialog, where the user can enter parameters.
- This dialog must comply to naming conventions, for example Document_viewDoThisActionDialog.
- This form must use form_dialog page template. Fields inside this dialog must use your_ prefix (except listbox).
- It is allowed to use required fields in dialog.
- The title of this dialog must be the same as the action name, it's what will be shown on the button and on the browser title bar.
- The action script must be named something like Document_doThisAction. It's usually a python script. This script must redirect to the selected tab, by accepting form_id parameter, it should use Base_redirect utility script to redirect and keep all required request parameters. When redirecting, a portal_status_message must be passed, this will be the status message for the next page. This message must be in English, ending with a period and using spaces to separate words (some old scripts might still be using "%20" or "+", this is obsolete). It's this script responsibility to translate the message before redirecting. Here's an example of such a script, setting the description of the context document from a "user_value", that would be your_user_value field in Document_viewDoThisActionDialog.
## Script (Python) "Document_doThisAction"
##parameters=user_value, form_id='view'
##
from Products.ERP5Type.Message import translateString
context.setDescription(user_value)
return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=str(translateString('Action done.'))))
Note: you may find that using field_your_user_value instead of user_value looks working, but this is a mistake. field_your_user_value is the raw value, whereas user_value is the value after validation by the form. For example, in the case of float fields user_value will be converted to float, field_your_user_value will just be a string.
- The dialog can also have a "Update action". This action is used when you have to update some fields values from the values of other fields.
- From a module view, dialogs can be used to update a list of object selected by the user. The action script should then act on the selected object in background using activity.
## Script (Python) "DocumentModule_doThisAction"
##parameters=user_value, selection_name, form_id='view'
##
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
# get selected objects
selection_uid_list = portal.portal_selections.getSelectionCheckedUidsFor(
selection_name)
if not selection_uid_list:
return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=str(translateString('No object selected.'))))
for brain in portal.portal_catalog(uid=selection_uid_list):
brain.getObject().activate().setDescription(user_value)
# unselect objects
portal.portal_selections.setSelectionCheckedUidsFor(selection_name, [])
return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=str(translateString('Action done.'))))
Related Articles¶