-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectlink.html
More file actions
52 lines (48 loc) · 2.14 KB
/
objectlink.html
File metadata and controls
52 lines (48 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<div class="form-group{% if property.required %} required{% endif %}">
<label for="{{ property.name }}[type]" class="col-sm-2 control-label">{{ property.description }}</label>
<div class="col-sm-4">
<select class="form-control select2" id="{{ property.name }}-type" name="{{ property.name }}[type]">
{% for type,link in property.models %}
<option value="{{ type }}"{% if bean[property.name].type == type %} selected="selected"{% endif %}>{{ type }}</option>
{% endfor %}
</select>
</div>
<div class="col-sm-4">
<select class="form-control select2" id="{{ property.name }}-id" name="{{ property.name }}[id]"{% if property.required %} required="required"{% endif %}>
{% for type,link in property.models %}
{% if link != 'single' %}
<option value="" data-type="{{ type }}"{% if bean[property.name].id == '' and bean[property.name].type == type %} selected="selected"{% endif %}>All {{ type }} objects</option>
{% endif %}
{% for object in property.options[type] %}
<option value="{{ object.id }}" data-type="{{ type }}"{% if bean[property.name].id == object.id and bean[property.name].type == type %} selected="selected"{% endif %}>{{ object.title }}</option>
{% endfor %}
{% endfor %}
</select>
</div>
<div class="col-sm-2">
{% if bean[property.name].id %}
<a href="{{ path_for('getbean', { 'beantype': bean[property.name].type, 'id': bean[property.name].id }) }}" class="btn btn-default btn-block">Edit</a>
{% elseif bean[property.name].type %}
<a href="{{ path_for('listbeans', { 'beantype': bean[property.name].type }) }}" class="btn btn-default btn-block">Edit</a>
{% endif %}
</div>
</div>
<script type="text/javascript">
if (typeof showType !== "function") { // Only define function if it doesn't exist yet.
function showType(type) {
$('#{{ property.name }}-id option').hide();
$('#{{ property.name }}-id').find('[data-type="' + type + '"]').show();
}
}
// Init
{% if bean[property.name].type %}
// Existing object
showType('{{ bean[property.name].type }}');
{% else %}
// New object
showType( $('#{{ property.name }}-type').val() );
{% endif %}
$('#{{ property.name }}-type').change(function() {
showType( $(this).val() );
});
</script>