|
12 | 12 | i18n:translate="">You are not allowed to edit queries.</span> |
13 | 13 |
|
14 | 14 | <script language="javascript"> |
15 | | -// This exists solely because I can't figure how to get the & into an |
16 | | -// attributes TALES expression, and so it keeps getting quoted. |
| 15 | +// This allows us to make the delete button an immediate action. |
| 16 | +// The post_to_url function comes from: |
| 17 | +// http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit |
17 | 18 | function retire(qid) { |
18 | | - window.location = 'query'+qid+'?@action=retire&@template=edit'; |
| 19 | + post_to_url('query'+qid, {'@action': 'retire', '@template': 'edit'}); |
| 20 | +} |
| 21 | + |
| 22 | +function restore(qid) { |
| 23 | + post_to_url('query'+qid, {'@action': 'restore', '@template': 'edit'}); |
| 24 | +} |
| 25 | +function post_to_url(path, params, method) { |
| 26 | + method = method || "post"; // Set method to post by default if not specified. |
| 27 | + |
| 28 | + var form = document.createElement("form"); |
| 29 | + form.setAttribute("method", method); |
| 30 | + form.setAttribute("action", path); |
| 31 | + |
| 32 | + for(var key in params) { |
| 33 | + if(params.hasOwnProperty(key)) { |
| 34 | + var hiddenField = document.createElement("input"); |
| 35 | + hiddenField.setAttribute("type", "hidden"); |
| 36 | + hiddenField.setAttribute("name", key); |
| 37 | + hiddenField.setAttribute("value", params[key]); |
| 38 | + |
| 39 | + form.appendChild(hiddenField); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + document.body.appendChild(form); |
| 44 | + form.submit(); |
19 | 45 | } |
20 | 46 | </script> |
21 | 47 |
|
|
29 | 55 | <th i18n:translate="">Include in "Your Queries"</th> |
30 | 56 | <th i18n:translate="">Edit</th> |
31 | 57 | <th i18n:translate="">Private to you?</th> |
32 | | - <th> </th> |
| 58 | + <th i18n:translate="">delete/restore<br> (javascript<br>required)</th> |
| 59 | +</tr> |
| 60 | +<tr> |
| 61 | + <td colspan="5"><b i18n:translate="">Queries I created</b></td> |
33 | 62 | </tr> |
34 | 63 |
|
35 | | -<tr tal:repeat="query mine"> |
36 | | - <tal:block condition="query/is_retired"> |
37 | | - |
| 64 | +<tr tal:define="queries python:db.query.filter(filterspec={'creator': uid})" |
| 65 | + tal:repeat="query queries"> |
| 66 | + <tal:block> |
38 | 67 | <td><a tal:attributes="href string:${query/klass}?${query/url}" |
39 | 68 | tal:content="query/name">query</a></td> |
40 | 69 |
|
|
51 | 80 | </select> |
52 | 81 | </td> |
53 | 82 |
|
54 | | - <td colspan="3" i18n:translate="">[query is retired]</td> |
55 | | - |
56 | | - <!-- <td> maybe offer "restore" some day </td> --> |
57 | | - </tal:block> |
58 | | -</tr> |
59 | | - |
60 | | -<tr tal:repeat="query mine"> |
61 | | - <tal:block condition="not:query/is_retired"> |
62 | | - <td><a tal:attributes="href string:${query/klass}?${query/url}" |
63 | | - tal:content="query/name">query</a></td> |
64 | | - |
65 | | - <td metal:use-macro="template/macros/include" /> |
66 | | - |
67 | 83 | <td><a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a></td> |
68 | 84 |
|
69 | 85 | <td> |
70 | 86 | <select tal:attributes="name string:query${query/id}@private_for"> |
71 | 87 | <option tal:attributes="selected python:query.private_for == uid; |
72 | 88 | value uid" i18n:translate="">yes</option> |
73 | | - <option tal:attributes="selected python:query.private_for == None" |
| 89 | + <option tal:attributes="selected python:not query.private_for" |
74 | 90 | value="-1" i18n:translate="">no</option> |
75 | 91 | </select> |
76 | 92 | </td> |
|
81 | 97 | </td> |
82 | 98 | </tal:block> |
83 | 99 | </tr> |
| 100 | +<tr> |
| 101 | + <td colspan="4"><b i18n:translate="">Queries others created</b></td> |
| 102 | + <td colspan="4"><b i18n:translate="">Owner</b></td> |
| 103 | +</tr> |
84 | 104 |
|
85 | | -<tr tal:define="queries python:db.query.filter(filterspec={'private_for':None})" |
| 105 | +<tr tal:define="queries |
| 106 | + python:db.query.filter(filterspec={'private_for': None})" |
86 | 107 | tal:repeat="query queries"> |
87 | | - <tal:block condition="python: query.creator != uid"> |
| 108 | + <tal:block tal:condition="python:not query.creator == uid"> |
88 | 109 | <td><a tal:attributes="href string:${query/klass}?${query/url}" |
89 | 110 | tal:content="query/name">query</a></td> |
90 | 111 |
|
91 | 112 | <td metal:use-macro="template/macros/include" /> |
92 | 113 |
|
93 | | - <td colspan="3" tal:condition="query/is_edit_ok"> |
94 | | - <a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a> |
95 | | - </td> |
96 | | - <td tal:condition="not:query/is_edit_ok" colspan="3" |
| 114 | + <td colspan="2" tal:condition="not:query/is_edit_ok" |
97 | 115 | i18n:translate="">[not yours to edit]</td> |
| 116 | + <td colspan="2" tal:condition="query/is_edit_ok" |
| 117 | + i18n:translate=""><a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a></td> |
| 118 | + <td colspan="2" |
| 119 | + tal:content="query/creator" i18n:translate="">put query owner here</td> |
| 120 | + </tal:block> |
| 121 | +</tr> |
| 122 | + |
| 123 | +<tr> |
| 124 | + <td colspan="5"><b i18n:translate="">Active retired queries</b></td> |
| 125 | +</tr> |
| 126 | +<tr tal:repeat="query request/user/queries"> |
| 127 | + <tal:block condition="python:path('query/is_retired')"> |
| 128 | + <td><a tal:attributes="href string:${query/klass}?${query/url}" |
| 129 | + tal:content="query/name">query</a></td> |
| 130 | + <tal:block tal:condition="python: not query.creator == uid"> |
| 131 | + <td metal:use-macro="template/macros/include"> </td> |
| 132 | + </tal:block> |
| 133 | + <td colspan="3" i18n:translate="">[query is retired]</td> |
| 134 | + <td tal:condition="python:query.creator == uid"> |
| 135 | + <input type="button" value="Restore" i18n:attributes="value" |
| 136 | + tal:attributes="onClick python:'''restore('%s')'''%query.id"> |
| 137 | + </td> |
98 | 138 | </tal:block> |
99 | 139 | </tr> |
100 | 140 |
|
|
0 commit comments