diff libervia/pages/tickets/edit/page_meta.py @ 1143:7bd47d32da87

pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket: there is currently no way to edit XHTML directly inside the browser with Libervia pages, this patch works around this by doing a conversion to/from markdown.
author Goffi <goffi@goffi.org>
date Sat, 19 Jan 2019 11:42:37 +0100
parents 28e3eb3bb217
children 29eb15062416
line wrap: on
line diff
--- a/libervia/pages/tickets/edit/page_meta.py	Fri Jan 11 21:47:10 2019 +0100
+++ b/libervia/pages/tickets/edit/page_meta.py	Sat Jan 19 11:42:37 2019 +0100
@@ -66,6 +66,16 @@
         )
     except KeyError:
         pass
+
+    # for now we don't have XHTML editor, so we'll go with a TextBox and a convertion
+    # to a text friendly syntax using markdown
+    wid = ticket.widgets[u'body']
+    if wid.type == u"xhtmlbox":
+        wid.type = u"textbox"
+        wid.value =  yield self.host.bridgeCall(
+            u"syntaxConvert", wid.value, C.SYNTAX_XHTML, u"markdown",
+            False, profile)
+
     template_data[u"new_ticket_xmlui"] = ticket
 
 
@@ -83,6 +93,14 @@
     except (KeyError, IndexError):
         pass
     profile = self.getProfile(request)
+
+    # we convert back body to XHTML
+    body = yield self.host.bridgeCall(
+        u"syntaxConvert", posted_data[u'body'][0], u"markdown", C.SYNTAX_XHTML,
+        False, profile)
+    posted_data[u'body'] = [u'<div xmlns="{ns}">{body}</div>'.format(ns=C.NS_XHTML,
+                                                                     body=body)]
+
     yield self.host.bridgeCall(
         "ticketSet", service.full(), node, posted_data, u"", ticket_id, {}, profile
     )