-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeans.html
138 lines (123 loc) · 4.84 KB
/
beans.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{% if query|length > 0 %}
{% set title = beantype ~ ': search results for "' ~ query ~ '"' %}
{% else %}
{% set title = beantype %}
{% endif %}
{% extends "admin/base.html" %}
{% block content %}
<h1 class="page-header">{{ beantype }}{% if query|length > 0 %}: search results for "{{ query }}"{% endif %}</h1>
<div class="row">
<div class="col-md-4">
<p>{{ description }}<br /><br /></p>
</div>
<div class="col-md-4 text-center">
<form class="form-inline" method="get" action="{{ page_url }}">
<div class="form-group">
<input type="text" class="form-control" name="*has" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Search</button>
</form>
</div>
<div class="col-md-4">
<a href="{{ path_for('addbean', { 'beantype': beantype }) }}" class="btn btn-primary pull-right">Add new {{ beantype }}</a>
</div>
</div>
{% if search.result|length > 0 %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>{{ properties[0].description }}</th>
<th>{{ properties[1].description }}</th>
<th>{{ properties[2].description }}</th>
{% if position %}
<th>{{ position.description }}</th>
{% endif %}
<th width="50">Remove</th>
<th width="50">Edit</th>
</tr>
</thead>
<tbody>
{% for bean in search.result %}
<tr>
<td><a href="{{ path_for('getbean', { 'beantype': beantype, 'id': bean.id }) }}">{{ bean[properties[0].name]|striptags[:75] }}</a></td>
<td>{{ bean[properties[1].name]|striptags[:75] }}</td>
<td>{{ bean[properties[2].name]|striptags[:75] }}</td>
{% if position %}
<td>
<div class="btn-group">
<!-- top -->
<span class="btn btn-default btn-xs move" data-action="{{ path_for('putbean', { 'beantype': beantype, 'id': bean.id }) }}" data-{{ position.name }}="0">↑↑</span>
<!-- up 1 -->
<span class="btn btn-default btn-xs move" data-action="{{ path_for('putbean', { 'beantype': beantype, 'id': bean.id }) }}" data-{{ position.name }}="{{ bean[position.name] - 1 }}">↑</span>
<!-- down 1 -->
<span class="btn btn-default btn-xs move" data-action="{{ path_for('putbean', { 'beantype': beantype, 'id': bean.id }) }}" data-{{ position.name }}="{{ bean[position.name] + 1 }}">↓</span>
<!-- bottom-->
<span class="btn btn-default btn-xs move" data-action="{{ path_for('putbean', { 'beantype': beantype, 'id': bean.id }) }}" data-{{ position.name }}="{{ search.total }}">↓↓</span>
</div>
</td>
{% endif %}
<td width="50">
<form method="post" role="form" enctype="multipart/form-data" action="{{ path_for('deletebean', { 'beantype': beantype, 'id': bean.id }) }}">
<input type="hidden" name="_METHOD" value="delete"/>
<button type="submit" class="btn btn-default btn-xs delete" data-title="{{ bean.title }}">Delete</button>
</form>
</td>
<td width="50"><a href="{{ path_for('getbean', { 'beantype': beantype, 'id': bean.id }) }}" class="btn btn-default btn-xs">Edit</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<hr>
{% if search.query %}
<p class="text-muted text-center">There is no {{ beantype }} matching your search. You can <a href="{{ path_for('addbean', { 'beantype': beantype }) }}">add</a> one.</p>
{% else %}
<p class="text-muted text-center">There is no {{ beantype }} yet. You can <a href="{{ path_for('addbean', { 'beantype': beantype }) }}">add</a> one.</p>
{% endif %}
{% endif %}
{% if search.pages and search.pages > 1 %}
<ul class="pagination">
{% for page in 1..search.pages %}
<li {% if search.page == page-1 %}class="active"{% endif %}>
<a href="{{ page_url }}{% if search.query %}?{{ search.query }}&{% else %}?{% endif %}limit={{ search.limit }}&offset={{ (page - 1) * search.limit }}">{{ page }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock content %}
{% block javascript %}
{{ parent() }}
<script type="text/javascript">
// Create a HTML form and submit it.
// This keeps the code more readbale
$( '.move' ).on( 'click', function(e) {
e.preventDefault();
var newForm = $( '<form>', {
'action': $(this).data('action'),
'method': 'post',
'enctype': 'multipart/form-data'
}).append( $('<input>', {
'name': '_METHOD',
'value': 'put'
})).append( $('<input>', {
'name': '{{ position.name }}',
'value': $(this).data('{{ position.name }}')
})).append( $('<input>', {
'name': 'submit',
'value': 'saveandclose',
'type': 'submit',
'id': 'submit'
}));
newForm.hide().appendTo('body');
$('#submit').click(); // Do it this way because submit button also has value.
});
$( '.delete' ).on( 'click', function(e) {
e.preventDefault();
if( confirm( 'Are you sure you want to delete "' + $(this).data('title') + '"?' ) ) {
$(this).parent().submit();
}
});
</script>
{% endblock javascript %}