mirror of
https://github.com/RobbieHan/sandboxMP.git
synced 2026-02-11 14:44:55 +08:00
network asset
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
from django import forms
|
||||
|
||||
from .models import Code, DeviceInfo, ConnectionInfo, DeviceFile
|
||||
from .models import Code, DeviceInfo, ConnectionInfo, DeviceFile, NetworkAsset
|
||||
|
||||
|
||||
class CodeCreateForm(forms.ModelForm):
|
||||
@@ -100,4 +100,31 @@ class ConnectionInfoForm(forms.ModelForm):
|
||||
class DeviceFileUploadForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = DeviceFile
|
||||
fields = '__all__'
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class NetworkAssetCreateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = NetworkAsset
|
||||
fields = '__all__'
|
||||
error_messages = {
|
||||
'name': {'required': '请填写网络资产名称'},
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(NetworkAssetCreateForm, self).clean()
|
||||
ip_address = cleaned_data.get('ip_address')
|
||||
|
||||
if NetworkAsset.objects.filter(ip_address=ip_address).count():
|
||||
raise forms.ValidationError('资产地址已存在:{}已存在'.format(ip_address))
|
||||
|
||||
|
||||
class NetworkAssetUpdateForm(NetworkAssetCreateForm):
|
||||
def clean(self):
|
||||
cleaned_data = self.cleaned_data
|
||||
ip_address = cleaned_data.get('ip_address')
|
||||
|
||||
if self.instance:
|
||||
matching_asset = NetworkAsset.objects.exclude(pk=self.instance.pk)
|
||||
if matching_asset.filter(ip_address=ip_address).exists():
|
||||
raise forms.ValidationError('资产地址已存在:{}已存在'.format(ip_address))
|
||||
@@ -137,6 +137,9 @@ class NetworkAsset(models.Model):
|
||||
management = models.CharField(max_length=100, blank=True, default='', verbose_name='管理地址')
|
||||
show_on_top = models.BooleanField(default=False, verbose_name='首页展示')
|
||||
provider = models.ForeignKey('Supplier', blank=True, null=True, on_delete=models.SET_NULL, verbose_name='服务商')
|
||||
state = models.BooleanField(default=True, verbose_name='状态')
|
||||
buyDate = models.DateField(default=datetime.now, blank=True, null=True, verbose_name='购买日期')
|
||||
warrantyDate = models.DateField(default=datetime.now, blank=True, null=True, verbose_name='到保日期')
|
||||
desc = models.TextField(blank=True, default='', verbose_name='备注信息')
|
||||
|
||||
class Meta:
|
||||
@@ -144,6 +147,19 @@ class NetworkAsset(models.Model):
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class NatRule(models.Model):
|
||||
internet_ip = models.CharField(max_length=80, blank=True, default='', verbose_name='互联网IP')
|
||||
src_port = models.IntegerField(blank=True, default='', verbose_name='源端口')
|
||||
lan_ip = models.CharField(max_length=80, blank=True, default='', verbose_name='内网IP')
|
||||
dest_port = models.IntegerField(blank=True, default='', verbose_name='目的端口')
|
||||
state = models.BooleanField(default=True, verbose_name='状态')
|
||||
desc = models.TextField(blank=True, default='', verbose_name='备注信息')
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'NAT规则'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class DomainName(AbstractMode):
|
||||
dn_type_choices = (('1', '主域名'),('2', '二级域名'))
|
||||
domain = models.CharField(max_length=200, verbose_name='域名')
|
||||
@@ -165,14 +181,3 @@ class DomainName(AbstractMode):
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class NatRule(models.Model):
|
||||
internet_ip = models.CharField(max_length=80, blank=True, default='', verbose_name='互联网IP')
|
||||
src_port = models.IntegerField(blank=True, default='', verbose_name='源端口')
|
||||
lan_ip = models.CharField(max_length=80, blank=True, default='', verbose_name='内网IP')
|
||||
dest_port = models.IntegerField(blank=True, default='', verbose_name='目的端口')
|
||||
state = models.BooleanField(default=True, verbose_name='状态')
|
||||
desc = models.TextField(blank=True, default='', verbose_name='备注信息')
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'NAT规则'
|
||||
verbose_name_plural = verbose_name
|
||||
@@ -44,4 +44,10 @@ urlpatterns = [
|
||||
path('eam/supplier/update/', views_eam.SupplierUpdateView.as_view(), name='eam-supplier-update'),
|
||||
path('eam/supplier/list/', views_eam.SupplierListView.as_view(), name='eam-supplier-list'),
|
||||
path('eam/supplier/delete/', views_eam.SupplierDeleteView.as_view(), name='eam-supplier-delete'),
|
||||
|
||||
path('eam/network_asset/', views_eam.NetworkAssetView.as_view(), name='eam-network_asset'),
|
||||
path('eam/network_asset/create/', views_eam.NetworkAssetCreateView.as_view(), name='eam-network_asset-create'),
|
||||
path('eam/network_asset/update/', views_eam.NetworkAssetUpdateView.as_view(), name='eam-network_asset-update'),
|
||||
path('eam/network_asset/list/', views_eam.NetworkAssetListView.as_view(), name='eam-network_asset-list'),
|
||||
path('eam/network_asset/delete/', views_eam.NetworkAssetDeleteView.as_view(), name='eam-network_asset-delete'),
|
||||
]
|
||||
|
||||
@@ -11,8 +11,9 @@ from system.mixin import LoginRequiredMixin
|
||||
from custom import (BreadcrumbMixin, SandboxDeleteView,
|
||||
SandboxListView, SandboxUpdateView, SandboxCreateView)
|
||||
from .models import (Cabinet, DeviceInfo, Code, ConnectionInfo, DeviceFile,
|
||||
Supplier)
|
||||
from .forms import DeviceCreateForm, DeviceUpdateForm, ConnectionInfoForm, DeviceFileUploadForm
|
||||
Supplier, NetworkAsset)
|
||||
from .forms import (DeviceCreateForm, DeviceUpdateForm, ConnectionInfoForm,
|
||||
DeviceFileUploadForm, NetworkAssetCreateForm, NetworkAssetUpdateForm)
|
||||
from utils.db_utils import MongodbDriver
|
||||
from utils.sandbox_utils import LoginExecution
|
||||
|
||||
@@ -108,6 +109,8 @@ class DeviceListView(SandboxListView):
|
||||
device['service_type'] = get_object_or_404(Code, pk=int(service_type)).value if service_type else ''
|
||||
device['dev_cabinet'] = get_object_or_404(Cabinet, pk=int(dev_cabinet)).number if dev_cabinet else ''
|
||||
return context_data
|
||||
|
||||
|
||||
class DeviceCreateView(SandboxCreateView):
|
||||
model = DeviceInfo
|
||||
form_class = DeviceCreateForm
|
||||
@@ -115,7 +118,6 @@ class DeviceCreateView(SandboxCreateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
public_data = get_device_public()
|
||||
kwargs.update(public_data)
|
||||
print(public_data)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
@@ -257,17 +259,58 @@ class SupplierUpdateView(SandboxUpdateView):
|
||||
|
||||
class SupplierListView(SandboxListView):
|
||||
model = Supplier
|
||||
fields = '__all__'
|
||||
fields = ['id', 'firm', 'contact_details', 'desc']
|
||||
|
||||
def get_filters(self):
|
||||
data = self.request.GET
|
||||
filters = {}
|
||||
if 'number' in data and data['number']:
|
||||
filters['number__icontains'] = data['number']
|
||||
if 'position' in data and data['position']:
|
||||
filters['position__icontains'] = data['position']
|
||||
if 'firm' in data and data['firm']:
|
||||
filters['firm__icontains'] = data['firm']
|
||||
if 'contact_details' in data and data['contact_details']:
|
||||
filters['contact_deatils__icontains'] = data['contact_details']
|
||||
return filters
|
||||
|
||||
|
||||
class SupplierDeleteView(SandboxDeleteView):
|
||||
model = Supplier
|
||||
model = Supplier
|
||||
|
||||
|
||||
class NetworkAssetView(LoginRequiredMixin, BreadcrumbMixin, TemplateView):
|
||||
template_name = 'cmdb/network_asset.html'
|
||||
|
||||
|
||||
class NetworkAssetCreateView(SandboxCreateView):
|
||||
model = NetworkAsset
|
||||
form_class = NetworkAssetCreateForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['all_provider'] = Supplier.objects.all()
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class NetworkAssetUpdateView(SandboxUpdateView):
|
||||
model = NetworkAsset
|
||||
form_class = NetworkAssetUpdateForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['all_provider'] = Supplier.objects.all()
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class NetworkAssetListView(SandboxListView):
|
||||
model = NetworkAsset
|
||||
fields = ['id', 'name', 'ip_address', 'management', 'provider__firm', 'buyDate', 'warrantyDate', 'state']
|
||||
|
||||
def get_filters(self):
|
||||
data = self.request.GET
|
||||
filters = {}
|
||||
if 'name' in data and data['name']:
|
||||
filters['name__icontains'] = data['name']
|
||||
if 'ip_address' in data and data['ip_address']:
|
||||
filters['ip_address__icontains'] = data['ip_address']
|
||||
return filters
|
||||
|
||||
|
||||
class NetworkAssetDeleteView(SandboxDeleteView):
|
||||
model = NetworkAsset
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert("操作失败", {icon: 2});
|
||||
layer.alert("没有权限", {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -253,7 +253,7 @@
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert('删除失败', {icon: 2});
|
||||
layer.alert('没有权限', {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert("操作失败", {icon: 2});
|
||||
layer.alert("没有权限", {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -261,7 +261,7 @@
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert('删除失败', {icon: 2});
|
||||
layer.alert('没有权限', {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
306
templates/cmdb/network_asset.html
Normal file
306
templates/cmdb/network_asset.html
Normal file
@@ -0,0 +1,306 @@
|
||||
{% extends "base-left.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'plugins/datatables/jquery.dataTables.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div id="devlist">
|
||||
<div class="box box-primary" id="liebiao">
|
||||
<div class="box-header">
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnRefresh" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-repeat"></i>刷新
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnCreate" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-plus"></i>新增
|
||||
</button>
|
||||
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnDelete" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-trash"></i>删除
|
||||
</button>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<form class="form-inline" id="queryForm">
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>资产名称:</label>
|
||||
<input type="text" name="name" class="form-control inputText" id="name">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>IP地址:</label>
|
||||
<input type="text" name="ip_address" class="form-control inputText" id="ip_address">
|
||||
</div>
|
||||
<button type="button" id="btnSearch" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-search"></i>查询
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box-body">
|
||||
<table id="dtbList" class="display" cellspacing="0" width="100%">
|
||||
<thead>
|
||||
<tr valign="middle">
|
||||
<th><input type="checkbox" id="checkAll"></th>
|
||||
<th>ID</th>
|
||||
<th>资产名称</th>
|
||||
<th>IP地址</th>
|
||||
<th>管理地址</th>
|
||||
<th>服务商</th>
|
||||
<th>购买日期</th>
|
||||
<th>到期时间</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<br> <br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<!-- /.content -->
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block javascripts %}
|
||||
|
||||
<script src="{% static 'plugins/datatables/jquery.dataTables.min.js' %}"></script>
|
||||
<script src="{% static 'plugins/datatables/dataTables.const-1.js' %}"></script>
|
||||
<script src="{% static 'js/plugins/layer/layer.js' %}"></script>
|
||||
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
// 菜单选中高亮
|
||||
$(function () {
|
||||
$('#CMDB-EAM').addClass('active');
|
||||
$('#CMDB-EAM-NETWORK_ASSET').addClass('active');
|
||||
|
||||
});
|
||||
|
||||
// datatables 初始化配置
|
||||
var oDataTable = null;
|
||||
$(function () {
|
||||
oDataTable = initTable();
|
||||
|
||||
function initTable() {
|
||||
var oTable = $('#dtbList').DataTable($.extend(true, {},
|
||||
DATATABLES_CONSTANT.DATA_TABLES.SERVER_SIDE_OPTION,
|
||||
|
||||
{
|
||||
ajax: {
|
||||
"url": "{% url 'cmdb:eam-network_asset-list' %}",
|
||||
"data": function (d) {
|
||||
d.number = $("#name").val();
|
||||
d.position = $("#ip_address").val();
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
DATATABLES_CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,
|
||||
{
|
||||
data: "id",
|
||||
width: "5%",
|
||||
},
|
||||
{
|
||||
data: "name",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "ip_address",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "management",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "provider__firm",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "buyDate",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "warrantyDate",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "state",
|
||||
render : function(data, type, row, meta) {
|
||||
if (data=true) {
|
||||
var ret="<button class='btn btn-success btn-xs'>在用</button>";
|
||||
return ret;
|
||||
}if (data=false) {
|
||||
var ret="<button class='btn btn-warning btn-xs'>停用</button>";
|
||||
return ret;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
data: "id",
|
||||
width: "10%",
|
||||
bSortable: "false",
|
||||
render: function (data, type, row, meta) {
|
||||
var ret = "";
|
||||
var ret = "<button title='详情-修改' onclick='doUpdate("
|
||||
+ data + ")'><i class='glyphicon glyphicon-pencil'></i></button>";
|
||||
ret = ret + "<button title='删除' onclick='doDelete("
|
||||
+ data + ")'><i class='glyphicon glyphicon-trash'></i></button>";
|
||||
return ret;
|
||||
}
|
||||
}],
|
||||
}));
|
||||
return oTable;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// 刷新数据
|
||||
$("#btnRefresh").click(function () {
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
//新建数据
|
||||
$("#btnCreate").click(function () {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '550px'],
|
||||
content: "{% url 'cmdb:eam-network_asset-create' %}",
|
||||
end: function () {
|
||||
//关闭时做的事情
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//修改数据
|
||||
function doUpdate(id) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '编辑',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '550px'],
|
||||
content: ["{% url 'cmdb:eam-network_asset-update' %}" + '?id=' + id, 'no'],
|
||||
end: function () {
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//checkbox全选
|
||||
$("#checkAll").on("click", function () {
|
||||
if ($(this).prop("checked") === true) {
|
||||
$("input[name='checkList']").prop("checked", $(this).prop("checked"));
|
||||
$('#example tbody tr').addClass('selected');
|
||||
} else {
|
||||
$("input[name='checkList']").prop("checked", false);
|
||||
$('#example tbody tr').removeClass('selected');
|
||||
}
|
||||
});
|
||||
|
||||
//批量删除
|
||||
$("#btnDelete").click(function () {
|
||||
if ($("input[name='checkList']:checked").length == 0) {
|
||||
layer.msg("请选择要删除的记录");
|
||||
return;
|
||||
}
|
||||
|
||||
var arrId = new Array();
|
||||
$("input[name='checkList']:checked").each(function () {
|
||||
//alert($(this).val());
|
||||
arrId.push($(this).val());
|
||||
});
|
||||
|
||||
sId = arrId.join(',');
|
||||
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-network_asset-delete' %}",
|
||||
data: {"id": sId, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert("操作成功", {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert("没有权限", {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//删除单个数据
|
||||
function doDelete(id) {
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-network_asset-delete' %}",
|
||||
data: {"id": id, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('删除成功', {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert('没有权限', {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//select2
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
$("#btnSearch").click(function(){
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
172
templates/cmdb/networkasset_form.html
Normal file
172
templates/cmdb/networkasset_form.html
Normal file
@@ -0,0 +1,172 @@
|
||||
{% extends 'base-layer.html' %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{%static 'plugins/select2/select2.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap-datetimepicker.min.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="box box-danger">
|
||||
<form class="form-horizontal" id="addForm" method="post">
|
||||
<input type="hidden" name='id' value="{{ networkasset.id }}" />
|
||||
{% csrf_token %}
|
||||
<div class="box-body">
|
||||
<fieldset>
|
||||
<legend>
|
||||
</legend>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">资产名称</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="name" type="text" value="{{ networkasset.name }}" />
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">IP地址</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="ip_address" type="text" value="{{ networkasset.ip_address }}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">购买日期</label>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" class="form-control pull-right form_datetime" name="buyDate"
|
||||
value="{{ networkasset.buyDate | date:'Y-m-d' }}" readonly/>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">质保日期</label>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" class="form-control pull-right form_datetime" name="warrantyDate"
|
||||
value="{{ networkasset.warrantyDate | date:'Y-m-d' }}" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">管理地址</label>
|
||||
<div class="col-sm-8">
|
||||
<input class="form-control" name="management" type="text" value="{{ networkasset.management }}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">服务商</label>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control select2" style="width:100%;" name="provider">
|
||||
<option {% ifequal networkasset.provider '' %}selected="selected"{% endifequal %}></option>
|
||||
{% for provider in all_provider %}
|
||||
<option value="{{ provider.id }}" {% ifequal networkasset.provider_id provider.id %}selected="selected"{% endifequal %}>
|
||||
{{ provider.firm }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">状态</label>
|
||||
<div class="col-sm-3">
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="state" value="True"
|
||||
{% ifequal networkasset.state True %}checked{% endifequal %}
|
||||
{% if not networkasset %}checked{% endif %}> 在用
|
||||
</label>
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="state" value="False"
|
||||
{% ifequal networkasset.state False %}checked{% endifequal %}> 停用
|
||||
</label>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">首页展示</label>
|
||||
<div class="col-sm-3">
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="show_on_top" value="True"
|
||||
{% ifequal networkasset.show_on_top True %}checked{% endifequal %}> 是
|
||||
</label>
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="show_on_top" value="False"
|
||||
{% ifequal networkasset.show_on_top False %}checked{% endifequal %}
|
||||
{% if not networkasset %}checked{% endif %}> 否
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">备注信息</label>
|
||||
<div class="col-sm-8">
|
||||
<textarea class="form-control" name="desc" rows="5" >{{ deviceinfo.desc }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="box-footer ">
|
||||
<div class="row span7 text-center ">
|
||||
<button type="button" id="btnCancel" class="btn btn-default margin-right " >重置</button>
|
||||
<button type="button" id="btnSave" class="btn btn-info margin-right " >保存</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
|
||||
<script src="{% static 'bootstrap/js/bootstrap-datetimepicker.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function getUrl() {
|
||||
if ($("input[name='id']").val()) {
|
||||
var url = "{% url 'cmdb:eam-network_asset-update' %}";
|
||||
} else {
|
||||
var url = "{% url 'cmdb:eam-network_asset-create' %}";
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
$("#btnSave").click(function () {
|
||||
var data = $("#addForm").serialize();
|
||||
$.ajax({
|
||||
type: $("#addForm").attr('method'),
|
||||
url: getUrl(),
|
||||
data: data,
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('数据保存成功!', {icon: 1}, function (index) {
|
||||
parent.layer.closeAll(); //关闭所有弹窗
|
||||
});
|
||||
} else {
|
||||
layer.alert(msg.error, {icon: 5});
|
||||
//$('errorMessage').html(msg.message)
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*点取消刷新新页面*/
|
||||
$("#btnCancel").click(function () {
|
||||
window.location.reload();
|
||||
|
||||
})
|
||||
|
||||
|
||||
/*input 时间输入选择*/
|
||||
$(".form_datetime").datetimepicker({
|
||||
language: 'zh',
|
||||
minView: 'month', //选择范围知道日期,不选择时分
|
||||
//weekStart: 1,
|
||||
//todayBtn: 1,
|
||||
autoclose: 1,
|
||||
todayHighlight: 1,
|
||||
//startView: 2,
|
||||
forceParse: 0,
|
||||
showMeridian: 1,
|
||||
format: 'yyyy-mm-dd'
|
||||
}).on('changeDate', function (ev) {
|
||||
$(this).datetimepicker('hide');
|
||||
});
|
||||
|
||||
// select2
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
276
templates/cmdb/supplier.html
Normal file
276
templates/cmdb/supplier.html
Normal file
@@ -0,0 +1,276 @@
|
||||
{% extends "base-left.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'plugins/datatables/jquery.dataTables.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div id="devlist">
|
||||
<div class="box box-primary" id="liebiao">
|
||||
<div class="box-header">
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnRefresh" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-repeat"></i>刷新
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnCreate" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-plus"></i>新增
|
||||
</button>
|
||||
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnDelete" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-trash"></i>删除
|
||||
</button>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<form class="form-inline" id="queryForm">
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>供应商:</label>
|
||||
<input type="text" name="firm" class="form-control inputText" id="firm">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>联系信息:</label>
|
||||
<input type="text" name="contact_details" class="form-control inputText" id="contact_details">
|
||||
</div>
|
||||
<button type="button" id="btnSearch" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-search"></i>查询
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box-body">
|
||||
<table id="dtbList" class="display" cellspacing="0" width="100%">
|
||||
<thead>
|
||||
<tr valign="middle">
|
||||
<th><input type="checkbox" id="checkAll"></th>
|
||||
<th>ID</th>
|
||||
<th>供应商</th>
|
||||
<th>联系信息</th>
|
||||
<th>备注信息</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<br> <br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<!-- /.content -->
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block javascripts %}
|
||||
|
||||
<script src="{% static 'plugins/datatables/jquery.dataTables.min.js' %}"></script>
|
||||
<script src="{% static 'plugins/datatables/dataTables.const-1.js' %}"></script>
|
||||
<script src="{% static 'js/plugins/layer/layer.js' %}"></script>
|
||||
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
// 菜单选中高亮
|
||||
$(function () {
|
||||
$('#CMDB-EAM').addClass('active');
|
||||
$('#CMDB-EAM-SUPPLIER').addClass('active');
|
||||
|
||||
});
|
||||
|
||||
// datatables 初始化配置
|
||||
var oDataTable = null;
|
||||
$(function () {
|
||||
oDataTable = initTable();
|
||||
|
||||
function initTable() {
|
||||
var oTable = $('#dtbList').DataTable($.extend(true, {},
|
||||
DATATABLES_CONSTANT.DATA_TABLES.SERVER_SIDE_OPTION,
|
||||
|
||||
{
|
||||
ajax: {
|
||||
"url": "{% url 'cmdb:eam-supplier-list' %}",
|
||||
"data": function (d) {
|
||||
d.number = $("#firm").val();
|
||||
d.position = $("#contact_details").val();
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
DATATABLES_CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,
|
||||
{
|
||||
data: "id",
|
||||
width: "5%",
|
||||
},
|
||||
{
|
||||
data: "firm",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "contact_details",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "desc",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "id",
|
||||
width: "10%",
|
||||
bSortable: "false",
|
||||
render: function (data, type, row, meta) {
|
||||
var ret = "";
|
||||
var ret = "<button title='详情-修改' onclick='doUpdate("
|
||||
+ data + ")'><i class='glyphicon glyphicon-pencil'></i></button>";
|
||||
ret = ret + "<button title='删除' onclick='doDelete("
|
||||
+ data + ")'><i class='glyphicon glyphicon-trash'></i></button>";
|
||||
return ret;
|
||||
}
|
||||
}],
|
||||
}));
|
||||
return oTable;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// 刷新数据
|
||||
$("#btnRefresh").click(function () {
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
//新建数据
|
||||
$("#btnCreate").click(function () {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '400px'],
|
||||
content: "{% url 'cmdb:eam-supplier-create' %}",
|
||||
end: function () {
|
||||
//关闭时做的事情
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//修改数据
|
||||
function doUpdate(id) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '编辑',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '400px'],
|
||||
content: ["{% url 'cmdb:eam-supplier-update' %}" + '?id=' + id, 'no'],
|
||||
end: function () {
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//checkbox全选
|
||||
$("#checkAll").on("click", function () {
|
||||
if ($(this).prop("checked") === true) {
|
||||
$("input[name='checkList']").prop("checked", $(this).prop("checked"));
|
||||
$('#example tbody tr').addClass('selected');
|
||||
} else {
|
||||
$("input[name='checkList']").prop("checked", false);
|
||||
$('#example tbody tr').removeClass('selected');
|
||||
}
|
||||
});
|
||||
|
||||
//批量删除
|
||||
$("#btnDelete").click(function () {
|
||||
if ($("input[name='checkList']:checked").length == 0) {
|
||||
layer.msg("请选择要删除的记录");
|
||||
return;
|
||||
}
|
||||
|
||||
var arrId = new Array();
|
||||
$("input[name='checkList']:checked").each(function () {
|
||||
//alert($(this).val());
|
||||
arrId.push($(this).val());
|
||||
});
|
||||
|
||||
sId = arrId.join(',');
|
||||
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-supplier-delete' %}",
|
||||
data: {"id": sId, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert("操作成功", {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert("没有权限", {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//删除单个数据
|
||||
function doDelete(id) {
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-supplier-delete' %}",
|
||||
data: {"id": id, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('删除成功', {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert('没有权限', {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//select2
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
$("#btnSearch").click(function(){
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
99
templates/cmdb/supplier_form.html
Normal file
99
templates/cmdb/supplier_form.html
Normal file
@@ -0,0 +1,99 @@
|
||||
{% extends 'base-layer.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">
|
||||
<!-- iCheck for checkboxes and radio inputs -->
|
||||
{% endblock %}
|
||||
{% block main %}
|
||||
<div class="box box-danger">
|
||||
<form class="form-horizontal" id="addForm" method="post">
|
||||
<input type="hidden" name='id' value="{{ supplier.id }}" />
|
||||
{% csrf_token %}
|
||||
<div class="box-body">
|
||||
<fieldset>
|
||||
<legend>
|
||||
<h4></h4>
|
||||
</legend>
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">供应商</label>
|
||||
<div class="col-sm-8">
|
||||
<input class="form-control" name="firm" type="text" value="{{ supplier.firm }}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">联系信息</label>
|
||||
<div class="col-sm-8">
|
||||
<input class="form-control" name="contact_details" type="text" value="{{ supplier.contact_details}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">描述信息</label>
|
||||
<div class="col-sm-8">
|
||||
<input class="form-control" id="desc" name="desc" type="text" value="{{ supplier.desc }}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="box-footer ">
|
||||
<div class="row span7 text-center ">
|
||||
<button type="button" id="btnCancel" class="btn btn-default margin-right ">重置</button>
|
||||
<button type="button" id="btnSave" class="btn btn-info margin-right ">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function getUrl() {
|
||||
if ($("input[name='id']").val()) {
|
||||
var url = "{% url 'cmdb:eam-supplier-update' %}";
|
||||
} else {
|
||||
var url = "{% url 'cmdb:eam-supplier-create' %}";
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
$("#btnSave").click(function () {
|
||||
var data = $("#addForm").serialize();
|
||||
$.ajax({
|
||||
type: $("#addForm").attr('method'),
|
||||
url: getUrl(),
|
||||
data: data,
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('数据保存成功!', {icon: 1}, function (index) {
|
||||
parent.layer.closeAll(); //关闭所有弹窗
|
||||
});
|
||||
} else {
|
||||
layer.alert(msg.error, {icon: 5});
|
||||
//$('errorMessage').html(msg.message)
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/*点取消刷新新页面*/
|
||||
$("#btnCancel").click(function () {
|
||||
window.location.reload();
|
||||
|
||||
});
|
||||
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user