|
2 | 2 | <head> |
3 | 3 | <link rel="stylesheet" type="text/css" href="_file/style.css"> |
4 | 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8;"> |
| 5 | +<script language="JavaScript" |
| 6 | + tal:condition="python:request.form.has_key('property')" |
| 7 | + tal:content="structure string: |
| 8 | + |
| 9 | +// this is the name of the field in the original form that we're working on |
| 10 | +field = '${request/form/property/value}'; |
| 11 | + |
| 12 | +function listClose() { |
| 13 | + window.close(); |
| 14 | +} |
| 15 | + |
| 16 | +function listClear() { |
| 17 | + window.opener.document.itemSynopsis[field].value = ''; |
| 18 | +} |
| 19 | + |
| 20 | +function pick(opt) { |
| 21 | + if (window.opener && !window.opener.closed) { |
| 22 | + window.opener.document.itemSynopsis[field].value = opt; |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +// add a value to the form field |
| 27 | +function add(opt) { |
| 28 | + val = window.opener.document.itemSynopsis[field].value; |
| 29 | + if (/^\s*$$/.test(val)) { |
| 30 | + newval = opt; // existing is all whitespace, so just replace |
| 31 | + } else { |
| 32 | + newval = val + ', ' + opt; |
| 33 | + } |
| 34 | + pick(newval); |
| 35 | +} |
| 36 | + |
| 37 | +// remove a value from the form field |
| 38 | +function remove(opt) { |
| 39 | + // ((opt(,\s*)?)|(,\s*opt)) |
| 40 | + replaceStr = new String('(('+opt+'(,\\s*)?)|(,\\s*'+opt+'))'); |
| 41 | + re = new RegExp(replaceStr); |
| 42 | + |
| 43 | + str = window.opener.document.itemSynopsis[field].value; |
| 44 | + |
| 45 | + // replace occurences with empty string |
| 46 | + newstr = str.replace(re, ''); |
| 47 | + pick(newstr); |
| 48 | +} |
| 49 | +"> |
| 50 | +</script> |
5 | 51 | </head> |
| 52 | + |
6 | 53 | <body class="body" marginwidth="0" marginheight="0"> |
| 54 | +<form> |
| 55 | +<div style="padding:10px;text-align:center;"> |
| 56 | + <script language="javascript"> |
| 57 | + // put up a 'reset' button if the field has values when we pop up this window |
| 58 | + |
| 59 | + // this is the name of the field in the original form that we're working on |
| 60 | + orig = window.opener.document.itemSynopsis[field].value; |
| 61 | + if (/[^\s]/.test(orig)) { |
| 62 | + reset = '<input type="button" onclick="pick(orig);" ' + |
| 63 | + 'value="Reset to original values" /> | '; |
| 64 | + document.write(reset); |
| 65 | + } |
| 66 | + </script> |
| 67 | + <input type="button" |
| 68 | + tal:attributes="value string:Clear all ${request/form/property/value} values" |
| 69 | + onclick="listClear();" /> | |
| 70 | + <input type="button" onclick="listClose();" value="Close this window" /> |
| 71 | +</div> |
7 | 72 |
|
8 | 73 | <table class="classhelp" |
9 | 74 | tal:define="props python:request.form['properties'].value.split(',')"> |
10 | | -<tr><th tal:repeat="prop props" tal:content="prop"></th></tr> |
| 75 | +<tr> |
| 76 | + <th tal:condition="python:request.form.has_key('property')">add/remove</th> |
| 77 | + <th tal:repeat="prop props" tal:content="prop"></th> |
| 78 | +</tr> |
11 | 79 | <tr tal:repeat="item context/list"> |
| 80 | + <td tal:condition="python:request.form.has_key('property')"> |
| 81 | + <input type="button" tal:define="opt python: item[props[0]]" |
| 82 | + tal:attributes="onclick string:add('${opt}')" value=" + "> |
| 83 | + <input type="button" tal:define="opt python: item[props[0]]" |
| 84 | + tal:attributes="onclick string:remove('${opt}')" value=" - " /> |
| 85 | + </td> |
12 | 86 | <td tal:repeat="prop props" tal:content="structure python:item[prop]"></td> |
13 | 87 | </tr> |
14 | 88 | </table> |
15 | | - |
| 89 | +</form> |
16 | 90 | </body> |
| 91 | +</html> |
0 commit comments