1 | ##parameters=REQUEST, cluster=None |
---|
2 | # $Id: waeup_edit_ajax.py 2020 2007-07-16 14:17:45Z joachim $ |
---|
3 | """ |
---|
4 | Called when a document form is posted for AJAX validation. |
---|
5 | |
---|
6 | Returns the validation result and the rendered page in an XML-RPC response. |
---|
7 | """ |
---|
8 | from Products.CPSDocument.utils import cleanAjaxParams |
---|
9 | |
---|
10 | # cleaning incoming params |
---|
11 | cleanAjaxParams(REQUEST) |
---|
12 | # from Products.zdb import set_trace |
---|
13 | # set_trace() |
---|
14 | |
---|
15 | doc = context.getContent() |
---|
16 | res = doc.renderEditDetailed(request=REQUEST, proxy=context, cluster=cluster) |
---|
17 | layout, is_valid = str(res[0]), res[1] |
---|
18 | |
---|
19 | # AJAX tries to change the doc and just needs to know if there were errors |
---|
20 | # for feedback without a new form rendering. |
---|
21 | # XXX TODO: avoid here an extra HTML rendering |
---|
22 | # by calling renderEditDetailed() with the right parameters |
---|
23 | |
---|
24 | # At this time we do XML-RPC answers. |
---|
25 | # We'll see later how to automate it to avoid a manual serialization here. |
---|
26 | |
---|
27 | if is_valid: |
---|
28 | comments = REQUEST.get('comments') |
---|
29 | context.cpsdocument_notify_modification(comments=comments) |
---|
30 | |
---|
31 | if is_valid and 'cpsdocument_edit_and_view_button' in REQUEST: |
---|
32 | action = 'view' |
---|
33 | else: |
---|
34 | action = '' |
---|
35 | |
---|
36 | |
---|
37 | REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml') |
---|
38 | REQUEST.RESPONSE.setHeader('Cache-Control', 'no-cache') |
---|
39 | response = '<?xml version="1.0" encoding="utf-8" ?>' |
---|
40 | response += '<ajax-response>' |
---|
41 | response += '<result>%s</result>' % str(bool(is_valid)) |
---|
42 | response += '<layout><![CDATA[%s]]></layout>' % layout |
---|
43 | response += '<action>%s</action>' % action |
---|
44 | response += '</ajax-response>' |
---|
45 | |
---|
46 | return response |
---|