backoffice: fix display of mass actions set to functions with dashes (#36734)

Function slugs are used in data attributes but those are normalized,

  The name of a custom data attribute in JavaScript is the name of the
  same HTML attribute but in camelCase and with no dashes, dots, etc.

  -- https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/dataset

Prevent that by turning all dashes into underscores.
This commit is contained in:
Frédéric Péters 2019-10-08 09:48:20 +02:00
parent cf9a14411f
commit d3eb54b88c
3 changed files with 7 additions and 3 deletions

View File

@ -1374,7 +1374,9 @@ class FormPage(Directory):
attrs = {}
if action.get('functions'):
for function in action.get('functions'):
attrs['data-visible_for_%s' % function] = 'true'
# dashes are replaced by underscores to prevent HTML5
# normalization to CamelCase.
attrs['data-visible_for_%s' % function.replace('-', '_')] = 'true'
else:
attrs['data-visible_for_all'] = 'true'
multi_form.add_submit('button-action-%s' % action['action'].id, action['action'].name, attrs=attrs)

View File

@ -259,7 +259,9 @@ class FormDefUI(object):
workflow_roles.update(filled.workflow_roles)
for function_key, function_value in workflow_roles.items():
if function_value in user.get_roles():
r += htmltext(' data-is-%s="true" ' % function_key)
# dashes are replaced by underscores to prevent HTML5
# normalization to CamelCase.
r += htmltext(' data-is_%s="true" ' % function_key.replace('-', '_'))
r += htmltext('/></td>')
for i, f in enumerate(fields):
field_value = filled.get_field_view_value(f, max_length=30)

View File

@ -73,7 +73,7 @@ function prepare_row_links() {
visible = true;
break;
}
if ($('input[type=checkbox][data-is-' + key.substr(12) + ']:checked').length) {
if ($('input[type=checkbox][data-is_' + key.substr(12) + ']:checked').length) {
visible = true;
break;
}