source: trunk/packages/invirt-web/code/templates/functions.mako @ 2804

Last change on this file since 2804 was 2792, checked in by broder, 15 years ago

The <input /> tag is always empty, so having a separate closing
</input> tag is meaningless.

File size: 1.8 KB
RevLine 
[2667]1<%page expression_filter="h"/>
2<%def name="databaseList(lst, default, onchange, name, id, valueattr, descattr)">
3<select name="${name}" id="${id}" \
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),
19               default, onchange, 'cdrom', 'cdromlist', 'cdrom_id', 'description')|n}
20</%def>
21
22<%def name="autoList(default='', onchange=None)">
23${databaseList(sorted(database.Autoinstall.query(), key=lambda x: x.description),
24               default, onchange, 'autoinstall', 'autoinstalllist', 'autoinstall_id', 'description')|n}
25</%def>
26
27<%def name="vmTypeList(default=None)">
28% for vmtype in (('linux-hvm', 'HVM'), ('linux', 'ParaVM'), ):
29<label>
[2792]30   <input ${'checked="checked"' if default == vmtype[0] else '' | n} type="radio" name="vmtype" id="vmtype-${vmtype[0]}" value="${vmtype[0]}" />${vmtype[1]}
[2667]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>
[2672]42
43<%!
44def jquote(string):
45    return "'" + string.replace('\\', '\\\\').replace("'", "\\'").replace('\n', '\\n') + "'"
[2682]46
47def nl2br(string):
48    return string.replace('\n', '<br/>')
[2672]49%>
50
51<%def name="helppopup(subj)">
52## Return HTML code for a (?) link to a specified help topic
53<span class="helplink"><a href="help?simple=true;subject=${subj | u}" target="_blank" onclick="return helppopup(${subj | u,jquote})">(?)</a></span>
54</%def>
Note: See TracBrowser for help on using the repository browser.