From b7c3cc5532c0108b0b2559703bf3b4f5f475868f Mon Sep 17 00:00:00 2001
From: halcyon <864072399@qq.com>
Date: Fri, 13 Nov 2015 00:03:51 +0800
Subject: [PATCH] add idc

---
 jasset/forms.py                  |   8 ++
 jasset/models.py                 |   2 +-
 jasset/urls.py                   |  10 +-
 jasset/views.py                  |  77 ++++++++++-
 templates/jasset/asset_list.html |   2 +-
 templates/jasset/idc_add.html    |  95 +++++++++++++
 templates/jasset/idc_detail.html | 229 +++++++++++++++++++++++++++++++
 templates/jasset/idc_edit.html   |  99 +++++++++++++
 templates/jasset/idc_list.html   | 115 ++++++++++++++++
 templates/nav.html               |   2 +
 10 files changed, 632 insertions(+), 7 deletions(-)
 create mode 100644 templates/jasset/idc_add.html
 create mode 100644 templates/jasset/idc_detail.html
 create mode 100644 templates/jasset/idc_edit.html
 create mode 100644 templates/jasset/idc_list.html

diff --git a/jasset/forms.py b/jasset/forms.py
index 10c1e9d09..f9af4d499 100644
--- a/jasset/forms.py
+++ b/jasset/forms.py
@@ -22,3 +22,11 @@ class AssetGroupForm(forms.ModelForm):
         fields = [
             "name", "comment"
         ]
+
+
+class IdcForm(forms.ModelForm):
+    class Meta:
+        model = IDC
+        fields = ['name', "bandwidth", "operator", 'linkman', 'phone', 'address', 'network', 'comment']
+
+
diff --git a/jasset/models.py b/jasset/models.py
index ea3af02e0..020caf431 100644
--- a/jasset/models.py
+++ b/jasset/models.py
@@ -43,7 +43,7 @@ class IDC(models.Model):
     network = models.TextField(blank=True, null=True, verbose_name=u"IP地址段")
     date_added = models.DateField(auto_now=True, default=datetime.datetime.now(), null=True)
     operator = models.IntegerField(max_length=32, blank=True, null=True, verbose_name=u"运营商")
-    comment = models.TextField(blank=True, null=True, verbose_name=u"备注")
+    comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"备注")
 
     def __unicode__(self):
         return self.name
diff --git a/jasset/urls.py b/jasset/urls.py
index 029b82295..da902558a 100644
--- a/jasset/urls.py
+++ b/jasset/urls.py
@@ -5,8 +5,6 @@ from jasset.views import *
 urlpatterns = patterns('',
     url(r'^asset_add/$', asset_add),
     # url(r"^host_add_multi/$", host_add_batch),
-    url(r'^group_add/$', group_add),
-    url(r'^group_list/$', group_list),
     url(r'^group_del/$', group_del),
     url(r'^asset_list/$', asset_list),
     url(r'^asset_del/$', asset_del),
@@ -16,11 +14,17 @@ urlpatterns = patterns('',
     # url(r"^host_detail/$", host_detail),
     # url(r"^dept_host_ajax/$", dept_host_ajax),
     # url(r"^show_all_ajax/$", show_all_ajax),
+    url(r'^group_add/$', group_add),
+    url(r'^group_list/$', group_list),
     url(r'^group_edit/$', group_edit),
     url(r'^group_list/$', group_list),
     url(r'^group_detail/$', group_detail),
     # url(r'^group_del_host/$', group_del_host),
-
     url(r'^asset_edit_batch/$', asset_edit_batch),
     # url(r'^host_edit_common/batch/$', host_edit_common_batch),
+    url(r'^idc_add/$', idc_add),
+    url(r'^idc_list/$', idc_list),
+    url(r'^idc_detail/$', idc_detail),
+    url(r'^idc_edit/$', idc_edit),
+    url(r'^idc_del/$', idc_del),
 )
\ No newline at end of file
diff --git a/jasset/views.py b/jasset/views.py
index bde27c68e..943f27c71 100644
--- a/jasset/views.py
+++ b/jasset/views.py
@@ -3,12 +3,11 @@
 import ast
 
 from django.db.models import Q
-from django.template import RequestContext
 from django.shortcuts import get_object_or_404
 
 from jasset.asset_api import *
 from jumpserver.api import *
-from jasset.forms import AssetForm
+from jasset.forms import AssetForm, IdcForm
 from jasset.models import Asset, IDC, AssetGroup, ASSET_TYPE, ASSET_STATUS
 
 
@@ -328,3 +327,77 @@ def asset_detail(request):
     asset_record = AssetRecord.objects.filter(asset=asset).order_by('-alert_time')
 
     return my_render('jasset/asset_detail.html', locals(), request)
+
+
+@require_role('admin')
+def idc_add(request):
+    """
+    IDC add view
+    """
+    header_title, path1, path2 = u'添加IDC', u'资产管理', u'添加IDC'
+    if request.method == 'POST':
+        idc_form = IdcForm(request.POST)
+        if idc_form.is_valid():
+            idc_name = idc_form.cleaned_data['name']
+
+            if IDC.objects.filter(name=idc_name):
+                emg = u'添加失败, 此IDC %s 已存在!' % idc_name
+                return my_render('jasset/idc_add.html', locals(), request)
+            else:
+                idc_form.save()
+                smg = u'IDC: %s添加成功' % idc_name
+            return HttpResponseRedirect("/jasset/idc_list/")
+    else:
+        idc_form = IdcForm()
+    return render_to_response('jasset/idc_add.html',
+                              locals(),
+                              context_instance=RequestContext(request))
+
+
+@require_role('admin')
+def idc_list(request):
+    header_title, path1, path2 = u'查看IDC', u'资产管理', u'查看IDC'
+    posts = IDC.objects.all()
+    keyword = request.GET.get('keyword', '')
+    if keyword:
+        posts = IDC.objects.filter(Q(name__contains=keyword) | Q(comment__contains=keyword))
+    else:
+        posts = IDC.objects.exclude(name='ALL').order_by('id')
+    contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
+    return render_to_response('jasset/idc_list.html',
+                              locals(),
+                              context_instance=RequestContext(request))
+
+
+@require_role('admin')
+def idc_edit(request):
+    idc_id = request.GET.get('id', '')
+    idc = get_object(IDC, id=idc_id)
+    if request.method == 'POST':
+        idc_form = IdcForm(request.POST, instance=idc)
+        if idc_form.is_valid():
+            idc_form.save()
+            return HttpResponseRedirect("/jasset/idc_list/")
+    else:
+        idc_form = IdcForm(instance=idc)
+        return my_render('jasset/idc_edit.html', locals(), request)
+
+
+@require_role('admin')
+def idc_detail(request):
+    """ IDC详情 """
+    header_title, path1, path2 = u'IDC详情', u'资产管理', u'IDC详情'
+    idc_id = request.GET.get('id', '')
+    idc = get_object(IDC, id=idc_id)
+    posts = Asset.objects.filter(idc=idc).order_by('ip')
+    contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
+
+    return my_render('jasset/idc_detail.html', locals(), request)
+
+
+@require_role('admin')
+def idc_del(request):
+    uuid = request.GET.get('uuid', '')
+    idc = get_object_or_404(IDC, uuid=uuid)
+    idc.delete()
+    return HttpResponseRedirect('/jasset/idc_list/')
diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html
index 731f6f44f..7a7bbf937 100644
--- a/templates/jasset/asset_list.html
+++ b/templates/jasset/asset_list.html
@@ -229,7 +229,7 @@
                 data: {asset_id_all: asset_id_all},
                 url: "/jasset/asset_del/?arg=batch",
                 success: function () {
-                    window.open("/jasset/asset_list/", "_self");
+                    parent.location.reload();
                 }
             });
         }
diff --git a/templates/jasset/idc_add.html b/templates/jasset/idc_add.html
new file mode 100644
index 000000000..a093254d0
--- /dev/null
+++ b/templates/jasset/idc_add.html
@@ -0,0 +1,95 @@
+{% extends 'base.html' %}
+{% block content %}
+{% load bootstrap %}
+{% include 'nav_cat_bar.html' %}
+<div class="wrapper wrapper-content animated fadeInRight">
+    <div class="row">
+        <div class="col-lg-10">
+            <div class="ibox float-e-margins">
+                <div id="ibox-content" class="ibox-title">
+                    <h5> 填写IDC基本信息 </h5>
+                    <div class="ibox-tools">
+                        <a class="collapse-link">
+                            <i class="fa fa-chevron-up"></i>
+                        </a>
+                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+                            <i class="fa fa-wrench"></i>
+                        </a>
+                        <ul class="dropdown-menu dropdown-user">
+                        </ul>
+                        <a class="close-link">
+                            <i class="fa fa-times"></i>
+                        </a>
+                    </div>
+                </div>
+
+                <div class="ibox-content">
+                    {% if emg %}
+                        <div class="alert alert-warning text-center">{{ emg }}</div>
+                    {% endif %}
+                    {% if smg %}
+                        <div class="alert alert-success text-center">{{ smg }}</div>
+                    {% endif %}
+                    <form id="assetForm" method="post" class="form-horizontal">
+                        {{ idc_form.name|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.bandwidth|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.operator|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.linkman|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.phone|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.address|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.network|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.comment|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        <div class="form-group">
+                            <div class="col-sm-4 col-sm-offset-5">
+                                <button class="btn btn-white" type="submit"> 重置 </button>
+                                <button class="btn btn-primary" type="sumbit"> 提交 </button>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    var required_fields = ["id_name"];
+    required_fields.forEach(function(field) {
+        $('label[for="' + field + '"]').parent().addClass("required");
+    });
+
+    $('#assetForm').validator({
+        timely: 2,
+        theme: "yellow_right_effect",
+        fields: {
+            "j_idc": {
+                rule: "required",
+                tip: "输入IDC名",
+                ok: "",
+                msg: {required: "IDC名必须填写!"},
+                data: {'data-ok':"主机名可以使用", 'data-msg-required': '主机名已正确'}
+            }
+        },
+        valid: function(form) {
+            form.submit();
+        }
+    });
+</script>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/jasset/idc_detail.html b/templates/jasset/idc_detail.html
new file mode 100644
index 000000000..0d61dfa1c
--- /dev/null
+++ b/templates/jasset/idc_detail.html
@@ -0,0 +1,229 @@
+{% extends 'base.html' %}
+{% load mytags %}
+{% block content %}
+{% include 'nav_cat_bar.html' %}
+
+<div class="wrapper wrapper-content animated fadeInRight">
+    <div class="row">
+        <div class="col-lg-12">
+            <div class="ibox float-e-margins" id="all">
+                <div class="ibox-title">
+                    <h5> IDC<span class="text-info"> {{ idc.name }} </span>详细信息列表 </h5>
+                    <div class="ibox-tools">
+                        <a class="collapse-link">
+                            <i class="fa fa-chevron-up"></i>
+                        </a>
+                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+                            <i class="fa fa-wrench"></i>
+                        </a>
+                        <ul class="dropdown-menu dropdown-user">
+                            <li><a href="#">未启用 1</a>
+                            </li>
+                            <li><a href="#">未启用 2</a>
+                            </li>
+                        </ul>
+                        <a class="close-link">
+                            <i class="fa fa-times"></i>
+                        </a>
+                    </div>
+                </div>
+
+                <div class="ibox-content">
+                    {% if emg %}
+                        <div class="alert alert-warning text-center">{{ emg }}</div>
+                    {% endif %}
+                    {% if smg %}
+                        <div class="alert alert-success text-center">{{ smg }}</div>
+                    {% endif %}
+                    <div class="">
+                    <a target="_blank" href="/jasset/host_add" class="btn btn-sm btn-primary "> 添加主机 </a>
+                    </div>
+
+                    <form id="asset_form" name="asset_form">
+                    <table class="table table-striped table-bordered table-hover " id="editable" name="editable">
+                        <thead>
+                            <tr>
+                                <th class="text-center">
+                                    <input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('asset_form')">
+                                </th>
+                                <th class="text-center" name="ip"> IP地址 </th>
+                                <th class="text-center"> 主机名 </th>
+                                <th class="text-center"> IDC </th>
+                                <th class="text-center"> 所属主机组 </th>
+                                <th class="text-center"> 配置信息 </th>
+                                <th class="text-center"> 使用默认管理 </th>
+                                <th class="text-center"> 操作 </th>
+                            </tr>
+                        </thead>
+                        <tbody>
+                        {% for asset in contact_list %}
+                            <tr class="gradeX">
+                                <td class="text-center" name="id" value="{{ asset.id }}" data-editable='false'>
+                                    <input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks">
+                                </td>
+                                <td class="text-center"> {{ asset.ip }} </td>
+                                <td class="text-center"> {{ asset.hostname }} </td>
+                                <td class="text-center"> {{ asset.idc.name }} </td>
+                                <td class="text-center">{{ asset.group.all|group_str2 }}</td>
+                                <td class="text-center">{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}</td>
+                                <td class="text-center"> {{ asset.use_default_auth|bool2str }} </td>
+                                <td class="text-center" data-editable='false'>
+                                    <a href="/jasset/asset_detail/?id={{ asset.id }}" class="btn btn-xs btn-primary">详情</a>
+                                    {% ifnotequal session_role_id 0 %}
+                                        <a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</a>
+                                        <a value="/jasset/asset_del/?id={{ asset.id }}" class="btn btn-xs btn-danger asset_del">删除</a>
+                                    {% endifnotequal %}
+                                </td>
+                            </tr>
+                        {% endfor %}
+                        </tbody>
+                    </table>
+                    <div class="row">
+                        <div class="col-sm-6">
+                            <input type="button" id="asset_del" class="btn btn-danger btn-sm"  name="del_button" value="删除" />
+                            <a value="/jasset/asset_edit_batch/" type="button" class="btn btn-sm btn-warning iframe">修改</a>
+                        </div>
+                        <div class="col-sm-6">
+                            <div class="dataTables_paginate paging_simple_numbers" id="editable_paginate">
+                                <ul class="pagination" style="margin-top: 0; float: right">
+                                {% if keyword %}
+                                    {% if contacts.has_previous %}
+                                        <li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
+                                            <a href="?keyword={{ keyword }}&page={{ contacts.previous_page_number }}">Previous</a>
+                                        </li>
+                                    {% else %}
+                                        <li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
+                                             <a href="#">Previous</a>
+                                        </li>
+                                    {% endif %}
+                                    {% ifequal show_first 1 %}
+                                        <li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page=1&id={{ idc.id }}"  title="第1页">1...</a></li>
+                                    {% endifequal %}
+                                    {% for page in page_range %}
+                                        {% ifequal current_page page %}
+                                            <li class="paginate_button active"  aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page={{ page }}&id={{ idc.id }}"  title="第{{ page }}页">{{ page }}</a></li>
+                                        {% else %}
+                                            <li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page={{ page }}&id={{ idc.id }}"  title="第{{ page }}页">{{ page }}</a></li>
+                                        {% endifequal %}
+                                    {% endfor %}
+                                    {% ifequal show_end 1 %}
+                                        <li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page={{ p.num_pages }}&id={{ idc.id }}"  title="第{{ page }}页">...{{ p.num_pages }}</a></li>
+                                    {% endifequal %}
+                                    {% if contacts.has_next %}
+                                        <li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
+                                            <a href="?keyword={{ keyword }}&page={{ contacts.next_page_number }}&id={{ idc.id }}">Next</a>
+                                        </li>
+                                    {% else %}
+                                        <li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
+                                            <a href="#">Next</a>
+                                        </li>
+                                    {% endif %}
+
+                                {% else %}
+                                    {% if contacts.has_previous %}
+                                        <li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
+                                            <a href="?page={{ contacts.previous_page_number }}&id={{ idc.id }}">Previous</a>
+                                        </li>
+                                    {% else %}
+                                        <li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
+                                             <a href="#">Previous</a>
+                                        </li>
+                                    {% endif %}
+                                    {% ifequal show_first 1 %}
+                                        <li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page=1&id={{ idc.id }}"  title="第1页">1...</a></li>
+                                    {% endifequal %}
+                                    {% for page in page_range %}
+                                        {% ifequal current_page page %}
+                                            <li class="paginate_button active"  aria-controls="editable" tabindex="0"><a href="?page={{ page }}&id={{ idc.id }}"  title="第{{ page }}页">{{ page }}</a></li>
+                                        {% else %}
+                                            <li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ page }}&id={{ idc.id }}"  title="第{{ page }}页">{{ page }}</a></li>
+                                        {% endifequal %}
+                                    {% endfor %}
+                                    {% ifequal show_end 1 %}
+                                        <li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ p.num_pages }}&id={{ idc.id }}"  title="第{{ page }}页">...{{ p.num_pages }}</a></li>
+                                    {% endifequal %}
+                                    {% if contacts.has_next %}
+                                        <li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
+                                            <a href="?page={{ contacts.next_page_number }}&id={{ idc.id }}">Next</a>
+                                        </li>
+                                    {% else %}
+                                        <li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
+                                            <a href="#">Next</a>
+                                        </li>
+                                    {% endif %}
+                                {% endif %}
+                                </ul>
+                            </div>
+                        </div>
+                    </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    $(document).ready(function(){
+        $('#editable').editableTableWidget();
+    });
+
+    function alter(form) {
+        selectData = GetTableDataBox();
+        if (selectData[1] != 0) {
+            $.ajax({
+                type: "post",
+                url: "/jasset/host_edit/batch/",
+                data: {"editable": selectData[0], "len_table": selectData[1]},
+                success: function (data) {
+                    alert("修改成功");
+                    window.open("/jasset/host_list/", "_self");
+                }
+            });
+        }
+    }
+
+    $(".iframe").on('click', function(){
+        var ids = getIDall();
+        if (ids == ''){
+            alert("请至少选择一行!");
+            return false;
+        }
+        var url= $(this).attr("value") + '?id=' + ids;
+            index = $.layer({
+                type: 2,
+                title: 'JumpServer - 批量修改主机',
+                maxmin: true,
+                shift: 'top',
+                border: [2, 0.3, '#1AB394'],
+                shade: [0.5, '#000000'],
+                shadeClose: true,
+                area : ['800px' , '600px'],
+                iframe: {src: url},
+                close: function(){
+                    location.replace(location.href);
+                }
+            });
+    });
+
+     $('#asset_del').click(function () {
+        var asset_id_all = getIDall();
+        console.log(asset_id_all);
+        if (asset_id_all == ''){
+            alert("请至少选择一行!");
+            return false;
+        }
+        if (confirm("确定删除")) {
+            $.ajax({
+                type: "post",
+                data: {asset_id_all: asset_id_all},
+                url: "/jasset/asset_del/?arg=batch",
+                success: function () {
+                    parent.location.reload();
+                }
+            });
+        }
+     });
+</script>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/jasset/idc_edit.html b/templates/jasset/idc_edit.html
new file mode 100644
index 000000000..b4db0c424
--- /dev/null
+++ b/templates/jasset/idc_edit.html
@@ -0,0 +1,99 @@
+{% extends 'base.html' %}
+{% block content %}
+{% load bootstrap %}
+{% include 'nav_cat_bar.html' %}
+<div class="wrapper wrapper-content animated fadeInRight">
+    <div class="row">
+        <div class="col-lg-10">
+            <div class="ibox float-e-margins">
+                <div id="ibox-content" class="ibox-title">
+                    <h5> 填写IDC基本信息 </h5>
+                    <div class="ibox-tools">
+                        <a class="collapse-link">
+                            <i class="fa fa-chevron-up"></i>
+                        </a>
+                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+                            <i class="fa fa-wrench"></i>
+                        </a>
+                        <ul class="dropdown-menu dropdown-user">
+                            <li><a href="#">未启用 1</a>
+                            </li>
+                            <li><a href="#">未启用 2</a>
+                            </li>
+                        </ul>
+                        <a class="close-link">
+                            <i class="fa fa-times"></i>
+                        </a>
+                    </div>
+                </div>
+
+                <div class="ibox-content">
+                    {% if emg %}
+                        <div class="alert alert-warning text-center">{{ emg }}</div>
+                    {% endif %}
+                    {% if smg %}
+                        <div class="alert alert-success text-center">{{ smg }}</div>
+                    {% endif %}
+                    <form id="assetForm" method="post" class="form-horizontal">
+                        {{ idc_form.name|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.bandwidth|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.operator|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.linkman|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.phone|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.address|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.network|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        {{ idc_form.comment|bootstrap_horizontal }}
+
+                        <div class="hr-line-dashed"></div>
+                        <div class="form-group">
+                            <div class="col-sm-4 col-sm-offset-5">
+                                <button class="btn btn-white" type="submit"> 重置 </button>
+                                <button class="btn btn-primary" type="sumbit"> 提交 </button>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    var required_fields = ["id_name"];
+    required_fields.forEach(function(field) {
+        $('label[for="' + field + '"]').parent().addClass("required");
+    });
+
+    $('#assetForm').validator({
+        timely: 2,
+        theme: "yellow_right_effect",
+        fields: {
+            "j_idc": {
+                rule: "required",
+                tip: "输入IDC名",
+                ok: "",
+                msg: {required: "IDC名必须填写!"},
+                data: {'data-ok':"主机名可以使用", 'data-msg-required': '主机名已正确'}
+            }
+        },
+        valid: function(form) {
+            form.submit();
+        }
+    });
+</script>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/jasset/idc_list.html b/templates/jasset/idc_list.html
new file mode 100644
index 000000000..85a409ea2
--- /dev/null
+++ b/templates/jasset/idc_list.html
@@ -0,0 +1,115 @@
+{% extends 'base.html' %}
+{% load mytags %}
+{% block content %}
+{% include 'nav_cat_bar.html' %}
+
+<div class="wrapper wrapper-content animated fadeInRight">
+    <div class="row">
+        <div class="col-lg-10">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <h5> IDC详细信息列表</h5>
+                    <div class="ibox-tools">
+                        <a class="collapse-link">
+                            <i class="fa fa-chevron-up"></i>
+                        </a>
+                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+                            <i class="fa fa-wrench"></i>
+                        </a>
+                        <ul class="dropdown-menu dropdown-user">
+                            <li><a href="#">未启用 1</a>
+                            </li>
+                            <li><a href="#">未启用 2</a>
+                            </li>
+                        </ul>
+                        <a class="close-link">
+                            <i class="fa fa-times"></i>
+                        </a>
+                    </div>
+                </div>
+                <div class="ibox-content">
+                    <div class="">
+                    <a target="_blank" href="/jasset/idc_add" class="btn btn-sm btn-primary "> 添加IDC </a>
+                    <form id="search_form" method="get" action="" class="pull-right mail-search">
+                        <div class="input-group">
+                            <input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
+                            <input type="text" style="display: none">
+                            <div class="input-group-btn">
+                                <button id='search_btn' type="submit" class="btn btn-sm btn-primary">
+                                    Search
+                                </button>
+                            </div>
+                        </div>
+                    </form>
+                    </div>
+
+                    <form id="contents_form" name="contents_form">
+                    <table class="table table-striped table-bordered table-hover " id="editable" >
+                        <thead>
+                            <tr>
+                                {% ifequal session_role_id 2 %}
+                                    <th class="text-center"><input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')"></th>
+                                {% endifequal %}
+                                <th class="text-center"> 机房名 </th>
+                                <th class="text-center"> 主机数量 </th>
+                                <th class="text-center"> 备注 </th>
+                                <th class="text-center"> 操作 </th>
+                            </tr>
+                        </thead>
+                        <tbody>
+                        {% for post in contacts.object_list  %}
+                            <tr class="gradeX">
+                                    <td class="text-center" name="j_id" value="{{ post.id }}" data-editable='false'><input name="id" value="{{ post.id }}" type="checkbox" class="i-checks"></td>
+                                <td class="text-center"> {{ post.name }} </td>
+                                    <td class="text-center"> <a href="/jasset/idc_detail/?id={{ post.id }}">{{ post.asset_set.count }}</a> </td>
+                                <td class="text-center"> {{ post.comment }} </td>
+                                <td class="text-center">
+                                    <a href="/jasset/idc_detail/?id={{ post.id }}" class="iframe btn btn-xs btn-primary">详情</a>
+                                        <a href="/jasset/idc_edit/?id={{ post.id }}" class="btn btn-xs btn-info">编辑</a>
+                                        <a href="/jasset/idc_del/?id={{ post.id }}" class="btn btn-xs btn-danger">删除</a>
+                                </td>
+                            </tr>
+                        {% endfor %}
+                        </tbody>
+                    </table>
+                   <div class="row">
+                        <div class="col-sm-6">
+                            {% ifequal session_role_id 2 %}
+                                <input type="button" id="del_button" class="btn btn-danger btn-sm"  name="del_button" value="删除" onclick="del('contents_form')" />
+                                <!--<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />-->
+                            {% endifequal %}
+                        </div>
+                        {% include 'paginator.html' %}
+                    </div>
+                   </form>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    function del(form) {
+    var checkboxes = document.getElementById(form);
+    var id_list = {};
+    var j = 0;
+    for (var i = 0; i < checkboxes.elements.length; i++) {
+        if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked == true && checkboxes.elements[i].value != "checkall") {
+            id_list[j] = checkboxes.elements[i].value;
+            j++;
+        }
+    }
+    if (confirm("确定删除")) {
+        $.ajax({
+            type: "POST",
+            url: "/jasset/idc_del/?id=multi",
+            data: {"id_list": id_list, "len_list": j},
+            success: function (data) {
+                window.open("/jasset/idc_list/", "_self");
+            }
+        });
+    }
+    }
+</script>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/nav.html b/templates/nav.html
index ee268ee25..77d9f9664 100644
--- a/templates/nav.html
+++ b/templates/nav.html
@@ -22,6 +22,8 @@
                     <li class="group_list group_detail group_edit"><a href="/jasset/group_list/">查看资产组</a></li>
                     <li class="asset_add asset_add_multi"><a href="/jasset/asset_add/">添加资产</a></li>
                     <li class="asset_list asset_detail asset_edit"><a href="/jasset/asset_list/">查看资产<span class="label label-info pull-right">{{ host_active_num }}/{{ host_total_num}}</span></a></li>
+                    <li class="idc_add"><a href="/jasset/idc_add/">添加机房</a></li>
+                    <li class="idc_list idc_detail idc_edit"><a href="/jasset/idc_list/">查看机房</a></li>
                 </ul>
             </li>
             <li id="jperm">