[309] | 1 | ## Script (Python) "cpsdocument_edit_ajax" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST, cluster=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: cpsdocument_edit_ajax.py 45956 2006-05-26 15:14:03Z tziade $ |
---|
| 11 | """ |
---|
| 12 | Called when a document form is posted for AJAX validation. |
---|
| 13 | |
---|
| 14 | Returns the validation result and the rendered page in an XML-RPC response. |
---|
| 15 | """ |
---|
| 16 | from Products.CPSDocument.utils import cleanAjaxParams |
---|
| 17 | |
---|
| 18 | # cleaning incoming params |
---|
| 19 | cleanAjaxParams(REQUEST) |
---|
| 20 | |
---|
| 21 | doc = context.getContent() |
---|
| 22 | res = doc.renderEditDetailed(request=REQUEST, proxy=context, cluster=cluster) |
---|
| 23 | layout, is_valid = str(res[0]), res[1] |
---|
| 24 | |
---|
| 25 | # AJAX tries to change the doc and just needs to know if there were errors |
---|
| 26 | # for feedback without a new form rendering. |
---|
| 27 | # XXX TODO: avoid here an extra HTML rendering |
---|
| 28 | # by calling renderEditDetailed() with the right parameters |
---|
| 29 | |
---|
| 30 | # At this time we do XML-RPC answers. |
---|
| 31 | # We'll see later how to automate it to avoid a manual serialization here. |
---|
| 32 | if is_valid and 'cpsdocument_edit_and_view_button' in REQUEST: |
---|
| 33 | action = 'view' |
---|
| 34 | else: |
---|
| 35 | action = '' |
---|
| 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 |
---|