|
5 | 5 | <span metal:fill-slot="body_title" tal:omit-tag="python:1" |
6 | 6 | i18n:translate="">"Your Queries" Editing</span> |
7 | 7 |
|
8 | | -<td class="content" metal:fill-slot="content"> |
| 8 | +<td class="content" metal:fill-slot="content" |
| 9 | + tal:define="anti_csrf_this_page python:utils.anti_csrf_nonce()" > |
9 | 10 |
|
10 | 11 | <span tal:condition="not:context/is_edit_ok" |
11 | 12 | i18n:translate="">You are not allowed to edit queries.</span> |
12 | 13 |
|
13 | | -<script language="javascript"> |
14 | | -// This exists solely because I can't figure how to get the & into an |
15 | | -// attributes TALES expression, and so it keeps getting quoted. |
16 | | -function retire(qid) { |
17 | | - window.location = 'query'+qid+'?@action=retire&@template=edit'; |
| 14 | +<script tal:attributes="nonce request/client/client_nonce" |
| 15 | + language="javascript" > |
| 16 | +// This allows us to make the delete button an immediate action. |
| 17 | +// The post_to_url function comes from: |
| 18 | +// http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit |
| 19 | +function retire(qid, csrf) { |
| 20 | + post_to_url('query'+qid, {'@action': 'retire', '@template':'edit', |
| 21 | + '@csrf': csrf}); |
18 | 22 | } |
| 23 | + |
| 24 | +function restore(qid, csrf) { |
| 25 | + post_to_url('query'+qid, {'@action': 'restore', '@template': 'edit', |
| 26 | + '@csrf': csrf}); |
| 27 | +} |
| 28 | +function post_to_url(path, params, method) { |
| 29 | + method = method || "post"; // Set method to post by default if not specified. |
| 30 | + |
| 31 | + var form = document.createElement("form"); |
| 32 | + form.setAttribute("method", method); |
| 33 | + form.setAttribute("action", path); |
| 34 | + |
| 35 | + for(var key in params) { |
| 36 | + if(params.hasOwnProperty(key)) { |
| 37 | + var hiddenField = document.createElement("input"); |
| 38 | + hiddenField.setAttribute("type", "hidden"); |
| 39 | + hiddenField.setAttribute("name", key); |
| 40 | + hiddenField.setAttribute("value", params[key]); |
| 41 | + |
| 42 | + form.appendChild(hiddenField); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + document.body.appendChild(form); |
| 47 | + form.submit(); |
| 48 | +} |
| 49 | + |
| 50 | +// note restore() is defined above but not yet used in this template. |
| 51 | +// see classic template and integrate it. |
19 | 52 | </script> |
20 | 53 |
|
21 | 54 | <form method="POST" onSubmit="return submit_once()" action="query" |
|
28 | 61 | <th i18n:translate="">Include in "Your Queries"</th> |
29 | 62 | <th i18n:translate="">Edit</th> |
30 | 63 | <th i18n:translate="">Private to you?</th> |
31 | | - <th> </th> |
| 64 | + <th i18n:translate="">delete/restore<br> (javascript<br>required)</th> |
32 | 65 | </tr> |
33 | 66 |
|
34 | 67 | <tr tal:repeat="query mine"> |
|
76 | 109 |
|
77 | 110 | <td> |
78 | 111 | <input type="button" value="Delete" i18n:attributes="value" |
79 | | - tal:attributes="onClick python:'''retire('%s')'''%query.id"> |
| 112 | + tal:attributes="onClick python:'''retire('%s','%s')'''%(query.id,anti_csrf_this_page)"> |
80 | 113 | </td> |
81 | 114 | </tr> |
82 | 115 |
|
|
97 | 130 |
|
98 | 131 | <tr><td colspan="5"> |
99 | 132 | <input name="@csrf" type="hidden" |
100 | | - tal:attributes="value python:utils.anti_csrf_nonce()"> |
| 133 | + tal:attributes="value anti_csrf_this_page"> |
101 | 134 | <input type="hidden" name="@action" value="edit"> |
102 | 135 | <input type="hidden" name="@template" value="edit"> |
103 | 136 | <input type="submit" value="Save Selection" i18n:attributes="value"> |
|
0 commit comments