source: package_branches/invirt-web/cherrypy/code/templates/functions.mako @ 2725

Last change on this file since 2725 was 2448, checked in by quentin, 15 years ago

Apply javascript quoting after URL-escaping

File size: 1.8 KB
RevLine 
[2401]1<%page expression_filter="h"/>
[2393]2<%def name="databaseList(lst, default, onchange, name, id, valueattr, descattr)">
[2406]3<select name="${name}" id="${id}" \
[2393]4% if onchange:
5onchange="${onchange}"\
6% endif
7>
8  <option ${'' if default else 'selected'} value="">None</option>
9  %for item in lst:
10  <option ${'selected' if default == getattr(item, valueattr) else ''} value="${getattr(item, valueattr)}">
11    ${getattr(item, descattr)}
12  </option>
13  % endfor
14</select>
15</%def>
16
17<%def name="cdromList(default='', onchange=None)">
18${databaseList(sorted(database.CDROM.query(), key=lambda x: x.description),
[2401]19               default, onchange, 'cdrom', 'cdromlist', 'cdrom_id', 'description')|n}
[2393]20</%def>
21
22<%def name="autoList(default='', onchange=None)">
23${databaseList(sorted(database.Autoinstall.query(), key=lambda x: x.description),
[2401]24               default, onchange, 'autoinstall', 'autoinstalllist', 'autoinstall_id', 'description')|n}
[2393]25</%def>
26
27<%def name="vmTypeList(default=None)">
28% for vmtype in (('linux-hvm', 'HVM'), ('linux', 'ParaVM'), ):
29<label>
30   <input ${'checked="checked"' if default == vmtype[0] else ''} type="radio" name="vmtype" id="vmtype-${vmtype[0]}" value="${vmtype[0]}">${vmtype[1]}</input>
31</label>
32% endfor
33</%def>
34
35<%def name="errorRow(value, err)">
36% if err and err.err_field == value:
37<tr>
38<td class="error" colspan="2">${str(err)}</td>
39</tr>
40% endif
41</%def>
[2400]42
43<%!
44def jquote(string):
45    return "'" + string.replace('\\', '\\\\').replace("'", "\\'").replace('\n', '\\n') + "'"
[2416]46
47def nl2br(string):
48    return string.replace('\n', '<br/>')
[2400]49%>
50
51<%def name="helppopup(subj)">
52## Return HTML code for a (?) link to a specified help topic
[2448]53<span class="helplink"><a href="help?simple=true;subject=${subj | u}" target="_blank" onclick="return helppopup(${subj | u,jquote})">(?)</a></span>
[2400]54</%def>
Note: See TracBrowser for help on using the repository browser.