1 | ##parameters=REQUEST, cluster=None |
---|
2 | # $Id: waeup_edit_ajax.py 2017 2007-07-16 12:32:00Z 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 | |
---|
13 | doc = context.getContent() |
---|
14 | res = doc.renderEditDetailed(request=REQUEST, proxy=context, cluster=cluster) |
---|
15 | layout, is_valid = str(res[0]), res[1] |
---|
16 | |
---|
17 | # AJAX tries to change the doc and just needs to know if there were errors |
---|
18 | # for feedback without a new form rendering. |
---|
19 | # XXX TODO: avoid here an extra HTML rendering |
---|
20 | # by calling renderEditDetailed() with the right parameters |
---|
21 | |
---|
22 | # At this time we do XML-RPC answers. |
---|
23 | # We'll see later how to automate it to avoid a manual serialization here. |
---|
24 | #from Products.zdb import set_trace |
---|
25 | #set_trace() |
---|
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 |
---|