15 |
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
16 |
16 |
|
17 |
17 |
import io
|
|
18 |
import json
|
18 |
19 |
import textwrap
|
19 |
20 |
import time
|
20 |
21 |
import xml.etree.ElementTree as ET
|
... | ... | |
69 |
70 |
return get_publisher().get_backoffice_root().is_global_accessible('workflows')
|
70 |
71 |
|
71 |
72 |
|
|
73 |
def update_order(elements):
|
|
74 |
request = get_request()
|
|
75 |
new_order = request.form['order'].strip(';').split(';')
|
|
76 |
new_elements = []
|
|
77 |
for y in new_order:
|
|
78 |
element = [x for x in elements if x.id == y]
|
|
79 |
if not element:
|
|
80 |
continue
|
|
81 |
new_elements.append(element[0])
|
|
82 |
if {element.id for element in new_elements} != {element.id for element in elements}:
|
|
83 |
return None
|
|
84 |
return new_elements
|
|
85 |
|
|
86 |
|
72 |
87 |
def svg(tag):
|
73 |
88 |
return '{http://www.w3.org/2000/svg}%s' % tag
|
74 |
89 |
|
... | ... | |
623 |
638 |
return form
|
624 |
639 |
|
625 |
640 |
def update_order(self):
|
626 |
|
request = get_request()
|
627 |
|
new_order = request.form['order'].strip(';').split(';')
|
628 |
|
self.status.items = [[x for x in self.status.items if x.id == y][0] for y in new_order]
|
|
641 |
get_response().set_content_type('application/json')
|
|
642 |
reordered_items = update_order(self.status.items)
|
|
643 |
if reordered_items is None:
|
|
644 |
return json.dumps({'err': 1})
|
|
645 |
self.status.items = reordered_items
|
629 |
646 |
self.workflow.store(comment=_('Change in action order'))
|
630 |
|
return 'ok'
|
|
647 |
return json.dumps({'err': 0})
|
631 |
648 |
|
632 |
649 |
def newitem(self):
|
633 |
650 |
form = self.get_new_item_form()
|
... | ... | |
1719 |
1736 |
r += htmltext('</div>')
|
1720 |
1737 |
return r.getvalue()
|
1721 |
1738 |
|
1722 |
|
def _update_order(self, elements):
|
1723 |
|
request = get_request()
|
1724 |
|
new_order = request.form['order'].strip(';').split(';')
|
1725 |
|
new_elements = []
|
1726 |
|
for y in new_order:
|
1727 |
|
status = [x for x in elements if x.id == y]
|
1728 |
|
if not status:
|
1729 |
|
continue
|
1730 |
|
new_elements.append(status[0])
|
1731 |
|
if {s.id for s in new_elements} != {s.id for s in elements}:
|
1732 |
|
return None
|
1733 |
|
return new_elements
|
1734 |
|
|
1735 |
1739 |
def update_order(self):
|
1736 |
|
new_possible_status = self._update_order(self.workflow.possible_status)
|
|
1740 |
get_response().set_content_type('application/json')
|
|
1741 |
new_possible_status = update_order(self.workflow.possible_status)
|
1737 |
1742 |
if new_possible_status is None:
|
1738 |
|
return 'ko'
|
|
1743 |
return json.dumps({'err': 1})
|
1739 |
1744 |
self.workflow.possible_status = new_possible_status
|
1740 |
1745 |
self.workflow.store(comment=_('Change in status order'))
|
1741 |
|
return 'ok'
|
|
1746 |
return json.dumps({'err': 0})
|
1742 |
1747 |
|
1743 |
1748 |
def update_actions_order(self):
|
1744 |
|
new_global_actions = self._update_order(self.workflow.global_actions)
|
|
1749 |
get_response().set_content_type('application/json')
|
|
1750 |
new_global_actions = update_order(self.workflow.global_actions)
|
1745 |
1751 |
if new_global_actions is None:
|
1746 |
|
return 'ko'
|
|
1752 |
return json.dumps({'err': 1})
|
1747 |
1753 |
self.workflow.global_actions = new_global_actions
|
1748 |
1754 |
self.workflow.store(comment=_('Change in global actions order'))
|
1749 |
|
return 'ok'
|
|
1755 |
return json.dumps({'err': 0})
|
1750 |
1756 |
|
1751 |
1757 |
def update_criticality_levels_order(self):
|
1752 |
|
new_criticality_levels = self._update_order(self.workflow.criticality_levels)
|
|
1758 |
get_response().set_content_type('application/json')
|
|
1759 |
new_criticality_levels = update_order(self.workflow.criticality_levels)
|
1753 |
1760 |
if new_criticality_levels is None:
|
1754 |
|
return 'ko'
|
|
1761 |
return json.dumps({'err': 1})
|
1755 |
1762 |
self.workflow.criticality_levels = new_criticality_levels
|
1756 |
1763 |
self.workflow.store(comment=_('Change in criticality levels order'))
|
1757 |
|
return 'ok'
|
|
1764 |
return json.dumps({'err': 0})
|
1758 |
1765 |
|
1759 |
1766 |
def newstatus(self):
|
1760 |
1767 |
form = Form(enctype='multipart/form-data', action='newstatus')
|