2015-06-27 22:35:34 +02:00
|
|
|
## -*- coding: utf-8 -*-
|
2015-06-10 22:45:04 +02:00
|
|
|
<%
|
2015-06-10 23:30:16 +02:00
|
|
|
len_attr = len(attributes)
|
|
|
|
switch = len_attr / 2
|
|
|
|
if not switch * 2 == len_attr:
|
|
|
|
switch = switch + 1
|
|
|
|
counter = 1
|
|
|
|
lc1 = []
|
|
|
|
lc2 = []
|
|
|
|
for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']):
|
|
|
|
if counter <= switch:
|
|
|
|
lc1.append(a)
|
|
|
|
else:
|
|
|
|
lc2.append(a)
|
|
|
|
counter = counter + 1
|
2015-06-10 22:45:04 +02:00
|
|
|
%>
|
2015-06-10 23:30:16 +02:00
|
|
|
<%def name="form_col(l)">
|
|
|
|
% for a in l:
|
2015-05-31 22:38:13 +02:00
|
|
|
<% attr = attributes[a] %>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="input-group">
|
2015-06-09 09:19:58 +02:00
|
|
|
<%
|
2015-06-18 23:43:58 +02:00
|
|
|
if modify:
|
|
|
|
required = ''
|
|
|
|
else:
|
|
|
|
required = ' required '
|
2015-06-09 09:19:58 +02:00
|
|
|
if not values is None and a in values:
|
2015-06-18 23:43:58 +02:00
|
|
|
if type(values[a]) is list:
|
|
|
|
tmp = values[a][0]
|
|
|
|
else:
|
|
|
|
tmp = values[a]
|
|
|
|
value = ' value="'+ tmp + '"'
|
|
|
|
value2 = '<option>'+ tmp +'</option>'
|
2015-06-09 09:19:58 +02:00
|
|
|
else:
|
|
|
|
value = ''
|
|
|
|
value2 = ''
|
|
|
|
%>
|
2015-06-18 23:43:58 +02:00
|
|
|
|
2015-07-05 17:50:42 +02:00
|
|
|
<span class="input-group-addon" id="basic-addon-${a}">${attr['display_name']}</span>
|
2015-06-25 02:08:30 +02:00
|
|
|
% if modify and a == keyattr:
|
2015-07-08 00:43:58 +02:00
|
|
|
<input type="hidden" id="attr.${a}" name="attr.${a}" class="form-control" aria-describedby="basic-addon-${a}" ${required} ${value}>
|
2015-07-05 17:50:42 +02:00
|
|
|
<span class="form-control" aria-describedby="basic-addon-${a}">${tmp}</span>
|
2015-06-25 02:08:30 +02:00
|
|
|
% elif attr['type'] == 'string':
|
2015-07-08 00:43:58 +02:00
|
|
|
<input type="text" id="attr.${a}" name="attr.${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon-${a}" ${required} ${value}>
|
2015-05-31 22:38:13 +02:00
|
|
|
% elif attr['type'] == 'email':
|
2015-07-08 00:43:58 +02:00
|
|
|
<input type="email" id="attr.${a}" name="attr.${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon-${a}" ${required} ${value} data-error="email address is invalid">
|
2015-05-31 22:38:13 +02:00
|
|
|
% elif attr['type'] == 'int':
|
2015-07-08 00:43:58 +02:00
|
|
|
<input type="number" id="attr.${a}" name="attr.${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon-${a}" ${required} ${value}>
|
2015-05-31 22:38:13 +02:00
|
|
|
% elif attr['type'] == 'fix':
|
2015-07-08 00:43:58 +02:00
|
|
|
<input type="hidden" id="attr.${a}" name="attr.${a}" class="form-control" aria-describedby="basic-addon-${a}" ${required} value="${attr['value']}">
|
2015-07-05 17:50:42 +02:00
|
|
|
<span class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon-${a}">${attr['value']}</span>
|
2015-05-31 22:38:13 +02:00
|
|
|
% elif attr['type'] == 'stringlist':
|
2015-07-08 00:43:58 +02:00
|
|
|
<select class="form-control" id="attr.${a}" name="attr.${a}">
|
2015-06-09 09:19:58 +02:00
|
|
|
${value2}
|
2015-06-02 08:33:46 +02:00
|
|
|
%for val in attr['values']:
|
|
|
|
<option>${val}</option>
|
|
|
|
%endfor
|
|
|
|
</select>
|
2015-05-31 22:38:13 +02:00
|
|
|
% elif attr['type'] == 'password':
|
2015-11-02 23:25:01 +01:00
|
|
|
<input type="password" class="form-control" data-ppolicy="ppolicy" name="attr.${a}1" id="${a}1" placeholder="${attr['description']}" ${required}>
|
2015-07-05 17:50:42 +02:00
|
|
|
<span class="input-group-addon" id="basic-addon-${a}2">Retype ${attr['display_name']}</span>
|
2015-06-30 23:19:07 +02:00
|
|
|
<input type="password" class="form-control" data-match="#${a}1" data-match-error="Passwords don't match" name="attr.${a}2" id="#${a}2" placeholder="Confirm" ${required}>
|
2015-05-31 22:38:13 +02:00
|
|
|
% endif
|
|
|
|
</div>
|
2015-06-30 23:19:07 +02:00
|
|
|
<div class="help-block with-errors"></div>
|
2015-05-31 22:38:13 +02:00
|
|
|
</div>
|
2015-06-10 23:30:16 +02:00
|
|
|
% endfor
|
|
|
|
</%def>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6 column">
|
|
|
|
${form_col(lc1)}
|
2015-06-10 22:45:04 +02:00
|
|
|
</div>
|
|
|
|
<div class="col-md-6 column">
|
2015-06-10 23:30:16 +02:00
|
|
|
${form_col(lc2)}
|
2015-06-10 22:45:04 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-07-10 20:11:07 +02:00
|
|
|
% if autofill:
|
2015-07-08 00:43:58 +02:00
|
|
|
<%
|
|
|
|
from sets import Set
|
|
|
|
attr_set = Set([])
|
|
|
|
attr_events = {}
|
|
|
|
functions = {}
|
|
|
|
for attrid in attributes:
|
|
|
|
attr = attributes[attrid]
|
|
|
|
field = 'attr.' + attrid
|
|
|
|
attr_set.add(field)
|
|
|
|
if 'autofill' in attr:
|
|
|
|
function = attr['autofill']['function']
|
|
|
|
tuple = (field, function)
|
|
|
|
if not tuple in functions:
|
|
|
|
functions[tuple] = []
|
|
|
|
for arg in attr['autofill']['args']:
|
|
|
|
if arg[0] == '$':
|
|
|
|
field_arg = 'attr.' + arg[1:]
|
|
|
|
attr_set.add(field_arg)
|
|
|
|
functions[tuple].append("fields['" + field_arg + "'].value")
|
|
|
|
if not field_arg in attr_events:
|
|
|
|
attr_events[field_arg] = []
|
|
|
|
attr_events[field_arg].append(tuple)
|
|
|
|
else:
|
|
|
|
value = arg
|
|
|
|
functions[tuple].append("'" + value + "'")
|
|
|
|
%>
|
|
|
|
<script>
|
|
|
|
var fields = new Object();
|
|
|
|
% for attr in attr_set:
|
|
|
|
fields['${attr}'] = document.getElementById('${attr}');
|
|
|
|
% endfor
|
|
|
|
|
|
|
|
% for attrid in attr_events:
|
|
|
|
if (fields['${attrid}'] != null) {
|
2015-07-08 00:57:03 +02:00
|
|
|
fields['${attrid}'].onchange = function () {
|
2015-07-08 00:43:58 +02:00
|
|
|
% for tuple in attr_events[attrid]:
|
|
|
|
if (typeof(${tuple[1]}) == "function") {
|
|
|
|
fields['${tuple[0]}'].value = ${tuple[1]}(${', '.join(functions[tuple])});
|
|
|
|
}
|
|
|
|
% endfor
|
|
|
|
};
|
|
|
|
};
|
|
|
|
% endfor
|
|
|
|
</script>
|
2015-07-10 20:11:07 +02:00
|
|
|
% endif
|