dept.html 2.7 KB
Newer Older
1 2 3 4 5 6 7
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>部门</title>
    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
8 9 10 11 12
    <style>
        #dept td, #dept th {
            text-align: center;
        }
    </style>
13 14 15 16 17 18 19 20 21
</head>
<body>
<div class="container">
    <div class="row clearfix">
		<div class="col-md-12 column">
			<h3>部门信息</h3>
            <hr>
		</div>
	</div>
22

23 24 25 26 27 28 29 30
    <div class="row clearfix">
        <div class="col-md-8 column">
            <table id="dept" class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>部门编号</th>
                    <th>部门名称</th>
                    <th>部门所在地</th>
31
                    <th>是否优秀</th>
32 33 34 35 36 37 38 39
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                    {% for dept in dept_list %}
                    <tr>
                        <td>{{ dept.no }}</td>
                        <td>
40
                            <!-- 写代码时要尽量避免使用硬编码(hard code) -->
41
                            <a href="{% url 'empsindept' dept.no %}">{{ dept.name }}</a>
42 43 44
                        </td>
                        <td>{{ dept.location }}</td>
                        <td>
45 46 47 48 49 50 51
                            {% if dept.excellent %}
                                <span style="color: green;"></span>
                            {% else %}
                                <span style="color: red;">×</span>
                            {% endif %}
                        </td>
                        <td>
52
                            <a id="{{ dept.no }}" href="javascript:void(0);" class="btn btn-xs btn-warning">删除</a>
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        <div class="col-md-4 column">
        </div>
    </div>
</div>
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script>
    $(function() {
        $('#dept tbody tr:even').addClass('info');
        $('#dept tbody tr:odd').addClass('warning');
69 70 71 72 73 74 75 76 77 78 79 80
        $('#dept a[id]').on('click', function(evt) {
            var a = $(evt.target);
            if (confirm('确定要删除吗?')) {
                $.getJSON('/hrs/deldept/' + a.attr('id'), function(json) {
                    if (json.code == 200) {
                        a.parent().parent().remove();
                        $('#dept tbody tr:even').addClass('info');
                        $('#dept tbody tr:odd').addClass('warning');
                    }
                });
            }
        });
81 82 83 84
    });
</script>
</body>
</html>