backoffice: use a template to render workflow page (#52648)
This commit is contained in:
parent
f3bc4ec278
commit
cfd832ee69
|
@ -34,7 +34,7 @@ from wcs.backoffice.studio import StudioDirectory
|
|||
from wcs.carddef import CardDef
|
||||
from wcs.formdata import Evolution
|
||||
from wcs.formdef import FormDef
|
||||
from wcs.qommon import N_, _, errors, force_str, get_logger, misc
|
||||
from wcs.qommon import N_, _, errors, force_str, get_logger, misc, template
|
||||
from wcs.qommon.admin.menu import command_icon
|
||||
from wcs.qommon.backoffice.menu import html_top
|
||||
from wcs.qommon.form import (
|
||||
|
@ -1526,6 +1526,7 @@ class WorkflowPage(Directory):
|
|||
('logged-errors', 'logged_errors_dir'),
|
||||
('history', 'snapshots_dir'),
|
||||
]
|
||||
do_not_call_in_templates = True
|
||||
|
||||
def __init__(self, component, instance=None):
|
||||
if instance:
|
||||
|
@ -1551,181 +1552,27 @@ class WorkflowPage(Directory):
|
|||
def html_top(self, title):
|
||||
return html_top('workflows', title)
|
||||
|
||||
def last_modification_block(self):
|
||||
return utils.last_modification_block(obj=self.workflow)
|
||||
|
||||
def graphviz(self):
|
||||
return graphviz(self.workflow, include=True)
|
||||
|
||||
def get_workflow_roles(self):
|
||||
workflow_roles = list((self.workflow.roles or {}).items())
|
||||
workflow_roles.sort(key=lambda x: '' if x[0] == '_receiver' else misc.simplify(x[1]))
|
||||
return workflow_roles
|
||||
|
||||
def _q_index(self):
|
||||
self.html_top(title=_('Workflow - %s') % self.workflow.name)
|
||||
r = TemplateIO(html=True)
|
||||
get_response().filter['sidebar'] = self.get_sidebar()
|
||||
get_response().add_javascript(
|
||||
['jquery.js', 'jquery-ui.js', 'biglist.js', 'svg-pan-zoom.js', 'jquery.colourpicker.js']
|
||||
)
|
||||
r += htmltext('<div id="appbar">')
|
||||
r += htmltext('<h2>%s</h2>') % self.workflow.name
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext('<span class="actions">')
|
||||
r += htmltext('<a rel="popup" href="edit">%s</a>') % _('change title')
|
||||
r += htmltext('</span>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
r += utils.last_modification_block(obj=self.workflow)
|
||||
r += get_session().display_message()
|
||||
|
||||
r += htmltext('<div class="splitcontent-left">')
|
||||
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h3>%s</h3>') % _('Possible Status')
|
||||
|
||||
if not self.workflow.possible_status:
|
||||
r += htmltext('<p>%s</p>') % _('There are not yet any status defined in this workflow.')
|
||||
else:
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext('<p class="hint">')
|
||||
r += _('Use drag and drop with the handles to reorder status.')
|
||||
r += htmltext('</p>')
|
||||
r += htmltext('<ul id="status-list" class="biglist sortable">')
|
||||
else:
|
||||
r += htmltext('<ul id="status-list" class="biglist">')
|
||||
for status in self.workflow.possible_status:
|
||||
klass = ['biglistitem']
|
||||
if status.get_visibility_restricted_roles():
|
||||
klass.append('hidden-status')
|
||||
r += htmltext('<li class="%s" id="itemId_%s">') % (' '.join(klass), status.id)
|
||||
attrs = ''
|
||||
if status.colour:
|
||||
attrs = 'style="border-color: #%s"' % status.colour
|
||||
r += htmltext('<a href="status/%s/" %s>' % (status.id, attrs))
|
||||
r += htmltext('%s</a>') % status.name
|
||||
r += htmltext('</li>')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
r += htmltext('</div>') # .splitcontent-left
|
||||
|
||||
r += htmltext('<div class="splitcontent-right">')
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h3>%s') % _('Workflow Functions')
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext(' <span class="change">(<a rel="popup" href="functions/new">%s</a>)</span>') % _(
|
||||
'add function'
|
||||
)
|
||||
r += htmltext('</h3>')
|
||||
r += htmltext('<ul id="roles-list" class="biglist">')
|
||||
workflow_roles = list((self.workflow.roles or {}).items())
|
||||
workflow_roles.sort(key=lambda x: '' if x[0] == '_receiver' else misc.simplify(x[1]))
|
||||
for key, label in workflow_roles:
|
||||
r += htmltext('<li class="biglistitem">')
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext('<a rel="popup" href="functions/%s">%s</a>') % (key[1:], label)
|
||||
else:
|
||||
r += htmltext('<a>%s</a>') % label
|
||||
r += htmltext('</li>')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
if not self.workflow.is_default():
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h3>%s') % _('Workflow Variables')
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext(' <span class="change">(<a href="variables/">%s</a>)</span>') % _('change')
|
||||
r += htmltext('</h3>')
|
||||
if self.workflow.variables_formdef:
|
||||
r += htmltext('<ul class="biglist">')
|
||||
for field in self.workflow.variables_formdef.fields:
|
||||
if field.varname:
|
||||
r += htmltext('<li><a href="variables/fields/%s/">%s') % (field.id, field.label)
|
||||
if '*' not in field.varname:
|
||||
r += htmltext(' <code class="varname">{{form_option_%s}}</code>') % field.varname
|
||||
r += htmltext('</a></li>')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
if not self.workflow.is_default():
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h3>%s') % _('Global Actions')
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext(
|
||||
' <span class="change">(<a rel="popup" href="global-actions/new">%s</a>)</span>'
|
||||
) % _('add global action')
|
||||
r += htmltext('</h3>')
|
||||
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext(
|
||||
'<ul id="status-list" class="biglist sortable" '
|
||||
'data-order-function="update_actions_order">'
|
||||
)
|
||||
else:
|
||||
r += htmltext('<ul class="biglist">')
|
||||
|
||||
for action in self.workflow.global_actions or []:
|
||||
r += htmltext('<li class="biglistitem" id="itemId_%s">' % action.id)
|
||||
r += htmltext('<a href="global-actions/%s/">%s</a>') % (action.id, action.name)
|
||||
r += htmltext('</li>')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
if not self.workflow.is_default():
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h3>%s') % _('Criticality Levels')
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext(
|
||||
' <span class="change">' '(<a rel="popup" href="criticality-levels/new">' '%s</a>)</span>'
|
||||
) % _('add criticality level')
|
||||
r += htmltext('</h3>')
|
||||
r += htmltext(
|
||||
'<ul class="biglist sortable criticality-levels" '
|
||||
'data-order-function="update_criticality_levels_order">'
|
||||
)
|
||||
for level in self.workflow.criticality_levels or []:
|
||||
style = ''
|
||||
if level.colour:
|
||||
style = 'style="border-left-color: #%s"' % level.colour
|
||||
r += htmltext('<li class="biglistitem" id="itemId_%s" %s>' % (level.id, style))
|
||||
r += htmltext('<a rel="popup" href="criticality-levels/%s">%s</a>') % (level.id, level.name)
|
||||
r += htmltext('</li>')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
if not self.workflow.is_default():
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h3>%s') % _('Backoffice Fields')
|
||||
if not self.workflow.is_readonly():
|
||||
r += htmltext(' <span class="change">(<a href="backoffice-fields/">%s</a>)</span></h3>') % _(
|
||||
'change'
|
||||
)
|
||||
if self.workflow.backoffice_fields_formdef:
|
||||
r += htmltext('<ul class="biglist">')
|
||||
for field in self.workflow.backoffice_fields_formdef.fields:
|
||||
r += htmltext('<li><a href="backoffice-fields/fields/%s/">%s') % (field.id, field.label)
|
||||
if field.varname:
|
||||
r += htmltext(' <code class="varname">{{form_var_%s}}</code>') % field.varname
|
||||
r += htmltext('</a></li>')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
r += htmltext('</div>') # .splitcontent-right
|
||||
|
||||
r += htmltext('<br style="clear:both;"/>')
|
||||
|
||||
if self.workflow.possible_status:
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext(graphviz(self.workflow, include=True))
|
||||
r += htmltext('<div class="full-screen-link"><a href="schema.svg">%s</a></div>') % _(
|
||||
'Full Screen'
|
||||
)
|
||||
r += htmltext('</div>') # bo-block
|
||||
|
||||
formdefs = self.workflow.formdefs()
|
||||
if formdefs:
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h3>%s</h3>') % _('Forms')
|
||||
r += htmltext('<p>%s ') % _('This workflow is used for the following forms:')
|
||||
r += htmltext(', ').join(
|
||||
[htmltext('<a href="../../forms/%s/">%s</a>') % (x.id, x.name) for x in formdefs]
|
||||
)
|
||||
r += htmltext('</p>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
get_response().filter['sidebar'] = self.get_sidebar()
|
||||
|
||||
return r.getvalue()
|
||||
return template.QommonTemplateResponse(
|
||||
templates=['wcs/backoffice/workflow.html'],
|
||||
context={'view': self, 'workflow': self.workflow},
|
||||
)
|
||||
|
||||
def get_sidebar(self):
|
||||
r = TemplateIO(html=True)
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
{% extends "wcs/backoffice/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block appbar-title %}{{ workflow.name }}{% endblock %}
|
||||
|
||||
{% block appbar-actions %}
|
||||
{% if not workflow.is_readonly %}
|
||||
<a rel="popup" href="edit">{% trans "change title" %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ view.last_modification_block|safe }}
|
||||
|
||||
<div class="splitcontent-left">
|
||||
<div class="bo-block">
|
||||
<h3>{% trans "Possible Status" %}</h3>
|
||||
{% if not workflow.possible_status %}
|
||||
<p>{% trans "There are not yet any status defined in this workflow." %}</p>
|
||||
{% else %}
|
||||
{% if workflow.is_readonly %}
|
||||
<ul id="status-list" class="biglist">
|
||||
{% else %}
|
||||
<p class="hint">{% trans "Use drag and drop with the handles to reorder status." %}</p>
|
||||
<ul id="status-list" class="biglist sortable">
|
||||
{% endif %}
|
||||
{% spaceless %}
|
||||
{% for status in workflow.possible_status %}
|
||||
<li class="biglistitem {% if status.get_visibility_restricted_roles %}hidden-status{% endif %}"
|
||||
id="itemId_{{ status.id }}">
|
||||
<a href="status/{{ status.id }}/" {% if status.colour %}style="border-color: #{{status.colour}}"{% endif %}
|
||||
>{{ status.name }}</a></li>
|
||||
{% endfor %}
|
||||
{% endspaceless %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="splitcontent-right">
|
||||
<div class="bo-block">
|
||||
<h3>{% trans "Workflow Functions" %}
|
||||
{% if not workflow.is_readonly %}
|
||||
<span class="change">(<a rel="popup" href="functions/new">{% trans "add function" %}</a>)</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
<ul id="roles-list" class="biglist">
|
||||
{% for workflow_role in view.get_workflow_roles %}
|
||||
<li class="biglistitem">
|
||||
{% if not workflow.is_readonly %}
|
||||
<a rel="popup" href="functions/{{ workflow_role.0|slice:"1:" }}">{{ workflow_role.1 }}</a>
|
||||
{% else %}
|
||||
<a>{{ workflow_role.1 }}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% if not workflow.is_default %}
|
||||
<div class="bo-block">
|
||||
<h3>{% trans "Workflow Variables" %}
|
||||
{% if not workflow.is_readonly %}
|
||||
<span class="change">(<a rel="popup" href="variables/">{% trans "change" %}</a>)</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
{% if workflow.variables_formdef %}
|
||||
<ul class="biglist">
|
||||
{% for field in workflow.variables_formdef.fields %}
|
||||
{% if field.varname %}
|
||||
<li><a href="variables/fields/{{ field.id }}">{{ field.label }}
|
||||
{% if '*' not in field.varname %}
|
||||
<code class="varname">{{ "{{" }} form_option_{{ field.varname }} }}</code>
|
||||
{% endif %}
|
||||
</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="bo-block">
|
||||
<h3>{% trans "Global Actions" %}
|
||||
{% if not workflow.is_readonly %}
|
||||
<span class="change">(<a rel="popup" href="global-actions/new">{% trans "add global action" %}</a>)</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
{% if workflow.is_readonly %}
|
||||
<ul class="biglist">
|
||||
{% else %}
|
||||
<ul id="status-list" class="biglist sortable" data-order-function="update_actions_order">
|
||||
{% endif %}
|
||||
{% for action in workflow.global_actions %}
|
||||
<li class="biglistitem" id="itemId_{{ action.id }}"><a href="global-actions/{{ action.id }}/">{{ action.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="bo-block">
|
||||
<h3>{% trans "Criticality Levels" %}
|
||||
{% if not workflow.is_readonly %}
|
||||
<span class="change">(<a rel="popup" href="criticality-levels/new">{% trans "add criticality level" %}</a>)</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
{% if workflow.is_readonly %}
|
||||
<ul class="biglist">
|
||||
{% else %}
|
||||
<ul class="biglist sortable criticality-levels" data-order-function="update_criticality_levels_order">
|
||||
{% endif %}
|
||||
{% spaceless %}
|
||||
{% for level in workflow.criticality_levels %}
|
||||
<li class="biglistitem" id="itemId_{{ level.id }}"
|
||||
{% if level.colour %}style="border-left-color: #{{ level.colour }}"{% endif %}>
|
||||
<a rel="popup" href="criticality-levels/{{ level.id }}">{{ level.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endspaceless %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="bo-block">
|
||||
<h3>{% trans "Backoffice Fields" %}
|
||||
{% if not workflow.is_readonly %}
|
||||
<span class="change">(<a rel="popup" href="backoffice-fields/">{% trans "change" %}</a>)</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
{% if workflow.backoffice_fields_formdef %}
|
||||
<ul class="biglist">
|
||||
{% for field in workflow.backoffice_fields_formdef.fields %}
|
||||
{% if field.varname %}
|
||||
<li><a href="backoffice_fields/fields/{{ field.id }}">{{ field.label }}
|
||||
{% if field.varname %}
|
||||
<code class="varname">{{ "{{" }} form_var_{{ field.varname }} }}</code>
|
||||
{% endif %}
|
||||
</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %} {# not workflow.is_default #}
|
||||
</div>
|
||||
|
||||
<br style="clear:both;"/>
|
||||
|
||||
{% if workflow.possible_status %}
|
||||
<div class="bo-block">
|
||||
{{ view.graphviz|safe }}
|
||||
<div class="full-screen-link"><a href="schema.svg">{% trans "Full Screen" %}</a></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% with formdefs=workflow.formdefs %}
|
||||
{% if formdefs %}
|
||||
<div class="bo-block">
|
||||
<h3>{% trans "Forms" %}</h3>
|
||||
<p>{% trans "This workflow is used for the following forms:" %}
|
||||
{% for formdef in formdefs %}
|
||||
<a href="../../forms/{{ formdef.id }}">{{ formdef.name }}</a>{% if not forloop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue