mirror of https://github.com/jumpserver/jumpserver
资产修改功能强化,日志功能添加
parent
173f520929
commit
a8991bfb14
|
@ -12,8 +12,13 @@ class IDC(models.Model):
|
|||
|
||||
|
||||
class BisGroup(models.Model):
|
||||
GROUP_TYPE = (
|
||||
('P', 'PRIVATE'),
|
||||
('A', 'ASSET'),
|
||||
)
|
||||
name = models.CharField(max_length=80, unique=True)
|
||||
comment = models.CharField(max_length=160, blank=True, null=True)
|
||||
type = models.CharField(max_length=1, choices=GROUP_TYPE, default='P')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
|
|
@ -13,7 +13,8 @@ urlpatterns = patterns('',
|
|||
url(r'^group_add/$', jadd_group),
|
||||
url(r'^group_list/$', jlist_group),
|
||||
url(r'^group_del/(\d+)/$', group_del),
|
||||
url(r'^host_del/(\d+.\d+.\d+.\d+)/$', host_del),
|
||||
url(r'^host_edit/(\d+.\d+.\d+.\d+)/$', host_edit),
|
||||
url(r'^host_del/(\d+)/$', host_del),
|
||||
url(r'^host_edit/(\d+)$', host_edit),
|
||||
url(r'^host_edit/batch/$', batch_host_edit),
|
||||
url(r'^test/$', test),
|
||||
)
|
|
@ -7,7 +7,7 @@ from django.core.paginator import Paginator, EmptyPage
|
|||
from models import IDC, Asset, BisGroup
|
||||
from juser.models import UserGroup
|
||||
from connect import PyCrypt, KEY
|
||||
from jpermission.models import Permission
|
||||
from jumpserver.views import jasset_group_add, jasset_host_edit
|
||||
|
||||
cryptor = PyCrypt(KEY)
|
||||
|
||||
|
@ -21,7 +21,7 @@ def jadd_host(request):
|
|||
header_title, path1, path2 = u'添加主机 | Add Host', u'资产管理', u'添加主机'
|
||||
groups = []
|
||||
eidc = IDC.objects.all()
|
||||
egroup = BisGroup.objects.all()
|
||||
egroup = BisGroup.objects.filter(type='A')
|
||||
eusergroup = UserGroup.objects.all()
|
||||
|
||||
if request.method == 'POST':
|
||||
|
@ -60,13 +60,39 @@ def jadd_host(request):
|
|||
login_type=j_type, idc=j_idc,
|
||||
is_active=int(j_active),
|
||||
comment=j_comment)
|
||||
jasset_group_add(j_ip, j_ip, 'P')
|
||||
a.save()
|
||||
print 'ok'
|
||||
a.bis_group = groups
|
||||
a.save()
|
||||
smg = u'主机 %s 添加成功' %j_ip
|
||||
return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
def batch_host_edit(request):
|
||||
if request.method == 'POST':
|
||||
len_table = request.POST.get('len_table')
|
||||
print len_table
|
||||
for i in range(int(len_table)):
|
||||
j_ip = "editable["+str(i)+"][j_ip]"
|
||||
j_port = "editable["+str(i)+"][j_port]"
|
||||
j_idc = "editable["+str(i)+"][j_idc]"
|
||||
j_type = "editable["+str(i)+"][j_type]"
|
||||
j_group = "editable["+str(i)+"][j_group]"
|
||||
j_active = "editable["+str(i)+"][j_active]"
|
||||
j_comment = "editable["+str(i)+"][j_comment]"
|
||||
|
||||
j_ip = request.POST.get(j_ip).strip()
|
||||
j_port = request.POST.get(j_port).strip()
|
||||
j_idc = request.POST.get(j_idc).strip()
|
||||
j_type = request.POST.get(j_type).strip()
|
||||
j_group = request.POST.getlist(j_group)
|
||||
j_active = request.POST.get(j_active).strip()
|
||||
j_comment = request.POST.get(j_comment).strip()
|
||||
print j_ip
|
||||
|
||||
jasset_host_edit(j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment)
|
||||
|
||||
return render_to_response('jasset/host_list.html')
|
||||
|
||||
|
||||
def jlist_host(request):
|
||||
header_title, path1, path2 = u'查看主机 | List Host', u'资产管理', u'查看主机'
|
||||
|
@ -87,7 +113,13 @@ def jlist_host(request):
|
|||
return render_to_response('jasset/host_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
def host_del(request, offset):
|
||||
Asset.objects.filter(ip=str(offset)).delete()
|
||||
len_list = request.POST.get("len_list")
|
||||
for i in range(int(len_list)):
|
||||
key = "id_list["+str(i)+"]"
|
||||
print key
|
||||
jid = request.POST.get(key)
|
||||
print jid
|
||||
Asset.objects.filter(id=jid).delete()
|
||||
return HttpResponseRedirect('/jasset/host_list/')
|
||||
|
||||
def host_edit(request, offset):
|
||||
|
@ -96,10 +128,10 @@ def host_edit(request, offset):
|
|||
header_title, path1, path2 = u'修改主机 | Edit Host', u'资产管理', u'修改主机'
|
||||
groups, e_group = [], []
|
||||
eidc = IDC.objects.all()
|
||||
egroup = BisGroup.objects.all()
|
||||
for g in Asset.objects.get(ip=offset).bis_group.all():
|
||||
egroup = BisGroup.objects.filter(type='A')
|
||||
for g in Asset.objects.get(id=int(offset)).bis_group.all():
|
||||
e_group.append(g)
|
||||
post = Asset.objects.get(ip = str(offset))
|
||||
post = Asset.objects.get(id = int(offset))
|
||||
if request.method == 'POST':
|
||||
j_ip = request.POST.get('j_ip')
|
||||
j_idc = request.POST.get('j_idc')
|
||||
|
@ -113,7 +145,7 @@ def host_edit(request, offset):
|
|||
c = BisGroup.objects.get(name=group)
|
||||
groups.append(c)
|
||||
|
||||
a = Asset.objects.get(ip=str(offset))
|
||||
a = Asset.objects.get(ip=int(offset))
|
||||
|
||||
if j_type == 'M':
|
||||
j_user = request.POST.get('j_user')
|
||||
|
@ -180,24 +212,24 @@ def idc_del(request, offset):
|
|||
return HttpResponseRedirect('/jasset/idc_list/')
|
||||
|
||||
def jadd_group(request):
|
||||
header_title, path1, path2 = u'添加业务组 | Add Group', u'资产管理', u'添加业务组'
|
||||
header_title, path1, path2 = u'添加主机组 | Add Group', u'资产管理', u'添加主机组'
|
||||
if request.method == 'POST':
|
||||
j_group = request.POST.get('j_group')
|
||||
j_comment = request.POST.get('j_comment')
|
||||
|
||||
if BisGroup.objects.filter(name=j_group):
|
||||
emg = u'该业务组已存在!'
|
||||
emg = u'该主机组已存在!'
|
||||
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
|
||||
else:
|
||||
smg = u'业务组%s添加成功' %j_group
|
||||
BisGroup.objects.create(name=j_group, comment=j_comment)
|
||||
smg = u'主机组%s添加成功' %j_group
|
||||
BisGroup.objects.create(name=j_group, comment=j_comment, type='A')
|
||||
|
||||
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def jlist_group(request):
|
||||
header_title, path1, path2 = u'查看业务组 | Add Group', u'资产管理', u'查看业务组'
|
||||
posts = BisGroup.objects.all().order_by('id')
|
||||
posts = BisGroup.objects.filter(type='A').order_by('id')
|
||||
return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
def group_del(request, offset):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#coding: utf-8
|
||||
|
||||
from django.http import HttpResponse
|
||||
from connect import PyCrypt, KEY
|
||||
from jasset.models import Asset, BisGroup, IDC
|
||||
from django.shortcuts import render_to_response
|
||||
|
||||
|
||||
|
@ -12,3 +12,43 @@ def skin_config(request):
|
|||
return render_to_response('skin_config.html')
|
||||
|
||||
|
||||
def jasset_group_add(name, comment, type):
|
||||
if BisGroup.objects.filter(name=name):
|
||||
emg = u'该业务组已存在!'
|
||||
else:
|
||||
BisGroup.objects.create(name=name, comment=comment, type=type)
|
||||
smg = u'业务组%s添加成功' %name
|
||||
|
||||
def jasset_host_edit(j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment):
|
||||
groups = []
|
||||
is_active = {u'是': '1', u'否': '2'}
|
||||
login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
|
||||
for group in j_group:
|
||||
c = BisGroup.objects.get(name=group.strip())
|
||||
groups.append(c)
|
||||
j_type = login_types[j_type]
|
||||
j_idc = IDC.objects.get(name=j_idc)
|
||||
a = Asset.objects.get(ip=str(j_ip))
|
||||
|
||||
if j_type == 'M':
|
||||
a.ip = j_ip
|
||||
a.port = j_port
|
||||
a.login_type = j_type
|
||||
a.idc = j_idc
|
||||
a.is_active = j_active
|
||||
a.comment = j_comment
|
||||
a.username_common = j_user
|
||||
a.password_common = j_password
|
||||
a.username_super = j_root
|
||||
a.password_super = j_passwd
|
||||
else:
|
||||
a.ip = j_ip
|
||||
a.port = j_port
|
||||
a.idc = j_idc
|
||||
a.login_type = j_type
|
||||
a.is_active = is_active[j_active]
|
||||
a.comment = j_comment
|
||||
|
||||
a.save()
|
||||
a.bis_group = groups
|
||||
a.save()
|
|
@ -0,0 +1,13 @@
|
|||
Last login: Mon Jan 26 23:43:44 2015 from 192.168.8.59
|
||||
PS1='[\u@192.168.8.63 \W]\$ '
|
||||
clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m'
|
||||
[halcyon@hadoop03 ~]$ PS1='[\u@192.168.8.63 \W]\$ '
|
||||
[halcyon@192.168.8.63 ~]$ clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m'
|
||||
[H[J[32mLogin 192.168.8.63 done. Enjoy it.[0m
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ pwd
|
||||
/home/halcyon
|
||||
[halcyon@192.168.8.63 ~]$
|
|
@ -0,0 +1,158 @@
|
|||
Last login: Wed Jan 28 22:40:12 2015 from 192.168.8.59
|
||||
PS1='[\u@192.168.8.63 \W]\$ '
|
||||
clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m'
|
||||
[halcyon@hadoop03 ~]$ PS1='[\u@192.168.8.63 \W]\$ '
|
||||
[halcyon@192.168.8.63 ~]$ clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m'
|
||||
[H[J[32mLogin 192.168.8.63 done. Enjoy it.[0m
|
||||
[halcyon@192.168.8.63 ~]$ ifconfig
|
||||
eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19
|
||||
inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0
|
||||
inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link
|
||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||
RX packets:4942926 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:11998 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:1000
|
||||
RX bytes:375187346 (357.8 MiB) TX bytes:2185924 (2.0 MiB)
|
||||
|
||||
lo Link encap:Local Loopback
|
||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||
inet6 addr: ::1/128 Scope:Host
|
||||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||||
RX packets:1446 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:0
|
||||
RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB)
|
||||
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ pwd
|
||||
/home/halcyon
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ ifconfig
|
||||
eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19
|
||||
inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0
|
||||
inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link
|
||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||
RX packets:4942977 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:12020 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:1000
|
||||
RX bytes:375191826 (357.8 MiB) TX bytes:2188600 (2.0 MiB)
|
||||
|
||||
lo Link encap:Local Loopback
|
||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||
inet6 addr: ::1/128 Scope:Host
|
||||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||||
RX packets:1446 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:0
|
||||
RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB)
|
||||
|
||||
[halcyon@192.168.8.63 ~]$ ifconfig
|
||||
eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19
|
||||
inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0
|
||||
inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link
|
||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||
RX packets:4942990 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:12027 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:1000
|
||||
RX bytes:375192932 (357.8 MiB) TX bytes:2189322 (2.0 MiB)
|
||||
|
||||
lo Link encap:Local Loopback
|
||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||
inet6 addr: ::1/128 Scope:Host
|
||||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||||
RX packets:1446 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:0
|
||||
RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB)
|
||||
|
||||
[halcyon@192.168.8.63 ~]$ ifconfig
|
||||
eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19
|
||||
inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0
|
||||
inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link
|
||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||
RX packets:4942999 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:12033 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:1000
|
||||
RX bytes:375193748 (357.8 MiB) TX bytes:2189926 (2.0 MiB)
|
||||
|
||||
lo Link encap:Local Loopback
|
||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||
inet6 addr: ::1/128 Scope:Host
|
||||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||||
RX packets:1446 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:0
|
||||
RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB)
|
||||
|
||||
[halcyon@192.168.8.63 ~]$ ifconfig
|
||||
eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19
|
||||
inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0
|
||||
inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link
|
||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||
RX packets:4943007 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:12039 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:1000
|
||||
RX bytes:375194484 (357.8 MiB) TX bytes:2190498 (2.0 MiB)
|
||||
|
||||
lo Link encap:Local Loopback
|
||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||
inet6 addr: ::1/128 Scope:Host
|
||||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||||
RX packets:1446 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:0
|
||||
RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB)
|
||||
|
||||
[halcyon@192.168.8.63 ~]$ ifconfig
|
||||
eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19
|
||||
inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0
|
||||
inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link
|
||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||
RX packets:4943015 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:12044 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:1000
|
||||
RX bytes:375195234 (357.8 MiB) TX bytes:2190984 (2.0 MiB)
|
||||
|
||||
lo Link encap:Local Loopback
|
||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||
inet6 addr: ::1/128 Scope:Host
|
||||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||||
RX packets:1446 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:0
|
||||
RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB)
|
||||
|
||||
[halcyon@192.168.8.63 ~]$ ifconfig
|
||||
eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19
|
||||
inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0
|
||||
inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link
|
||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||
RX packets:4945950 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:12071 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:1000
|
||||
RX bytes:375405180 (358.0 MiB) TX bytes:2192946 (2.0 MiB)
|
||||
|
||||
lo Link encap:Local Loopback
|
||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||
inet6 addr: ::1/128 Scope:Host
|
||||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||||
RX packets:1448 errors:0 dropped:0 overruns:0 frame:0
|
||||
TX packets:1448 errors:0 dropped:0 overruns:0 carrier:0
|
||||
collisions:0 txqueuelen:0
|
||||
RX bytes:78192 (76.3 KiB) TX bytes:78192 (76.3 KiB)
|
||||
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ pwd
|
||||
/home/halcyon
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$ ll
|
||||
total 0
|
||||
[halcyon@192.168.8.63 ~]$
|
|
@ -0,0 +1,61 @@
|
|||
//jumpserver 自定义js 2015-01-29
|
||||
|
||||
//此函数用于checkbox的全选和反选
|
||||
var checked=false;
|
||||
function check_all(form) {
|
||||
var checkboxes = document.getElementById(form);
|
||||
if (checked == false) {
|
||||
checked = true
|
||||
} else {
|
||||
checked = false
|
||||
}
|
||||
for (var i = 0; i < checkboxes.elements.length; i++) {
|
||||
if (checkboxes.elements[i].type == "checkbox") {
|
||||
checkboxes.elements[i].checked = checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//提取指定行的数据,JSON格式
|
||||
function GetRowData(row){
|
||||
var rowData = {};
|
||||
for(var j=0;j<row.cells.length; j++) {
|
||||
name = row.parentNode.rows[0].cells[j].getAttribute("Name");
|
||||
if (name) {
|
||||
var value = row.cells[j].getAttribute("Value");
|
||||
if (!value) {
|
||||
value = row.cells[j].innerHTML;
|
||||
}
|
||||
rowData[name] = value;
|
||||
}
|
||||
}
|
||||
return rowData;
|
||||
}
|
||||
|
||||
//此函数用于在多选提交时至少要选择一行
|
||||
function GetTableDataBox() {
|
||||
var tabProduct = document.getElementById("editable");
|
||||
var tableData = new Array();
|
||||
var returnData = new Array();
|
||||
var checkboxes = document.getElementById("contents_form");
|
||||
var id_list = new Array();
|
||||
len = checkboxes.elements.length;
|
||||
for (var i=0; i < len; i++) {
|
||||
if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked == true && checkboxes.elements[i].value != "checkall") {
|
||||
id_list.push(i);
|
||||
}
|
||||
}
|
||||
console.log(id_list);
|
||||
for (i in id_list) {
|
||||
console.log(tabProduct);
|
||||
tableData.push(GetRowData(tabProduct.rows[id_list[i]]));
|
||||
}
|
||||
|
||||
if (id_list.length == 0){
|
||||
alert('请至少选择一行!');
|
||||
}
|
||||
returnData.push(tableData);
|
||||
returnData.push(id_list.length);
|
||||
return returnData;
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
/*global $, window*/
|
||||
$.fn.editableTableWidget = function (options) {
|
||||
'use strict';
|
||||
return $(this).each(function () {
|
||||
var buildDefaultOptions = function () {
|
||||
var opts = $.extend({}, $.fn.editableTableWidget.defaultOptions);
|
||||
opts.editor = opts.editor.clone();
|
||||
return opts;
|
||||
},
|
||||
activeOptions = $.extend(buildDefaultOptions(), options),
|
||||
ARROW_LEFT = 37, ARROW_UP = 38, ARROW_RIGHT = 39, ARROW_DOWN = 40, ENTER = 13, ESC = 27, TAB = 9,
|
||||
element = $(this),
|
||||
editor = activeOptions.editor.css('position', 'absolute').hide().appendTo(element.parent()),
|
||||
active,
|
||||
showEditor = function (select) {
|
||||
active = element.find('td:focus');
|
||||
if (active.length) {
|
||||
editor.val(active.text())
|
||||
.removeClass('error')
|
||||
.show()
|
||||
.offset(active.offset())
|
||||
.css(active.css(activeOptions.cloneProperties))
|
||||
.width(active.width())
|
||||
.height(active.height())
|
||||
.focus();
|
||||
if (select) {
|
||||
editor.select();
|
||||
}
|
||||
}
|
||||
},
|
||||
setActiveText = function () {
|
||||
var text = editor.val(),
|
||||
evt = $.Event('change'),
|
||||
originalContent;
|
||||
if (active.text() === text || editor.hasClass('error')) {
|
||||
return true;
|
||||
}
|
||||
originalContent = active.html();
|
||||
active.text(text).trigger(evt, text);
|
||||
if (evt.result === false) {
|
||||
active.html(originalContent);
|
||||
}
|
||||
},
|
||||
movement = function (element, keycode) {
|
||||
if (keycode === ARROW_RIGHT) {
|
||||
return element.next('td');
|
||||
} else if (keycode === ARROW_LEFT) {
|
||||
return element.prev('td');
|
||||
} else if (keycode === ARROW_UP) {
|
||||
return element.parent().prev().children().eq(element.index());
|
||||
} else if (keycode === ARROW_DOWN) {
|
||||
return element.parent().next().children().eq(element.index());
|
||||
}
|
||||
return [];
|
||||
};
|
||||
editor.blur(function () {
|
||||
setActiveText();
|
||||
editor.hide();
|
||||
}).keydown(function (e) {
|
||||
if (e.which === ENTER) {
|
||||
setActiveText();
|
||||
editor.hide();
|
||||
active.focus();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
} else if (e.which === ESC) {
|
||||
editor.val(active.text());
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
editor.hide();
|
||||
active.focus();
|
||||
} else if (e.which === TAB) {
|
||||
active.focus();
|
||||
} else if (this.selectionEnd - this.selectionStart === this.value.length) {
|
||||
var possibleMove = movement(active, e.which);
|
||||
if (possibleMove.length > 0) {
|
||||
possibleMove.focus();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
})
|
||||
.on('input paste', function () {
|
||||
var evt = $.Event('validate');
|
||||
active.trigger(evt, editor.val());
|
||||
if (evt.result === false) {
|
||||
editor.addClass('error');
|
||||
} else {
|
||||
editor.removeClass('error');
|
||||
}
|
||||
});
|
||||
//element.on('click keypress dblclick', showEditor)
|
||||
element.find("td:not([data-editable='false'])").on('click keypress dblclick', showEditor)
|
||||
.css('cursor', 'pointer')
|
||||
.keydown(function (e) {
|
||||
var prevent = true,
|
||||
possibleMove = movement($(e.target), e.which);
|
||||
if (possibleMove.length > 0) {
|
||||
possibleMove.focus();
|
||||
} else if (e.which === ENTER) {
|
||||
showEditor(false);
|
||||
} else if (e.which === 17 || e.which === 91 || e.which === 93) {
|
||||
showEditor(true);
|
||||
prevent = false;
|
||||
} else {
|
||||
prevent = false;
|
||||
}
|
||||
if (prevent) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
//element.find('td').prop('tabindex', 1);
|
||||
element.find("td:not([data-editable='false'])").prop('tabindex', 1);
|
||||
|
||||
$(window).on('resize', function () {
|
||||
if (editor.is(':visible')) {
|
||||
editor.offset(active.offset())
|
||||
.width(active.width())
|
||||
.height(active.height());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
$.fn.editableTableWidget.defaultOptions = {
|
||||
cloneProperties: ['padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right',
|
||||
'text-align', 'font', 'font-size', 'font-family', 'font-weight',
|
||||
'border', 'border-top', 'border-bottom', 'border-left', 'border-right'],
|
||||
editor: $('<input>')
|
||||
};
|
||||
|
|
@ -4,13 +4,13 @@
|
|||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-10">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="text-center">
|
||||
<span>请选择添加内容: </span>
|
||||
<a href="#" class="btn btn-xs btn-primary" id="addhost">添加主机</a>
|
||||
<a href="#" class="btn btn-xs btn-primary" id="addidc">添加IDC</a>
|
||||
<a href="#" class="btn btn-xs btn-primary" id="addbis">添加业务组</a>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<span>请选择添加内容: </span>
|
||||
<a href="#" class="btn btn-xs btn-primary" onclick='change("addhost")'>添加主机</a>
|
||||
<a href="#" class="btn btn-xs btn-primary" onclick='change("addidc")'>添加IDC</a>
|
||||
<a href="#" class="btn btn-xs btn-primary" onclick='change("addgroup")'>添加业务组</a>
|
||||
</div>
|
||||
<div id="add_asset" class="ibox float-e-margins">
|
||||
<div id="ibox-content" class="ibox-title">
|
||||
<h5> 填写主机基本信息 </h5>
|
||||
<div class="ibox-tools">
|
||||
|
@ -150,6 +150,18 @@
|
|||
else{
|
||||
document.getElementById("a1").style.display="none";
|
||||
}};
|
||||
|
||||
function change(type){
|
||||
if (type == 'addhost') {
|
||||
var data = $('#add_asset');
|
||||
} else if (type == 'addidc') {
|
||||
var data = $('#addidc');
|
||||
} else {
|
||||
var data = $('addgroup');
|
||||
}
|
||||
$("#add_asset").html(data);
|
||||
}
|
||||
|
||||
$('#assetForm').validator({
|
||||
timely: 2,
|
||||
theme: "yellow_right_effect",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox float-e-margins" id="all">
|
||||
<div class="ibox-title">
|
||||
<h5> 主机详细信息列表 </h5>
|
||||
<div class="ibox-tools">
|
||||
|
@ -33,39 +33,38 @@
|
|||
<a target="_blank" href="/jasset/host_add" class="btn btn-sm btn-primary "> 添加 </a>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-bordered table-hover " id="editable" >
|
||||
<form id="contents_form" name="contents_form">
|
||||
<table class="table table-striped table-bordered table-hover " id="editable" name="editable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center"><input type="checkbox" class="i-checks" name=""></th>
|
||||
<th class="text-center"> IP地址 </th>
|
||||
<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>
|
||||
<th class="text-center" name="j_ip"> IP地址 </th>
|
||||
<th class="text-center"> 端口号 </th>
|
||||
<th class="text-center"> 登录方式 </th>
|
||||
<th class="text-center"> 所属IDC </th>
|
||||
<th class="text-center" name="j_type"> 登录方式 </th>
|
||||
<th class="text-center" name="j_idc"> 所属IDC </th>
|
||||
<th class="text-center"> 所属业务组 </th>
|
||||
<th class="text-center"> 添加时间 </th>
|
||||
<th class="text-center"> 备注 </th>
|
||||
<th class="text-center"> 是否激活 </th>
|
||||
<th class="text-center" name="j_time"> 添加时间 </th>
|
||||
<th class="text-center" name="j_comment"> 备注 </th>
|
||||
<th class="text-center"> 操作 </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for post in contacts.object_list %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"><input type="checkbox" class="i-checks" name=""></td>
|
||||
<td class="text-center"> {{ post.ip }} </td>
|
||||
<td class="text-center"> {{ post.port }} </td>
|
||||
<td class="text-center"> {{ login_types|get_item:post.login_type }} </td>
|
||||
<td class="text-center"> {{ post.idc.name }} </td>
|
||||
<td class="text-center">
|
||||
{% for group in post.bis_group.all %}
|
||||
{{ group }}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="text-center" data-editable='false'><input name="id" value="{{ post.id }}" type="checkbox" class="i-checks"></td>
|
||||
<td class="text-center" name="j_ip"> {{ post.ip }} </td>
|
||||
<td class="text-center" name="j_port"> {{ post.port }} </td>
|
||||
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
|
||||
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
|
||||
<td class="text-center" name="j_group">{% for group in post.bis_group.all %} {{ group }} {% endfor %}</td>
|
||||
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
|
||||
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
|
||||
<td class="text-center"> {{ post.comment }} </td>
|
||||
<td class="text-center">
|
||||
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
|
||||
<td class="text-center" data-editable='false'>
|
||||
<a href="/jasset/{{ post.ip }}/" class="iframe btn btn-xs btn-primary">详情</a>
|
||||
<a href="/jasset/host_edit/{{ post.ip }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="/jasset/host_del/{{ post.ip }}" class="btn btn-xs btn-danger">删除</a>
|
||||
<a href="/jasset/host_edit/{{ post.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="/jasset/host_del/{{ post.id }}" class="btn btn-xs btn-danger">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -73,9 +72,8 @@
|
|||
</table>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
|
||||
Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
|
||||
</div>
|
||||
<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')" />
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="dataTables_paginate paging_simple_numbers" id="editable_paginate">
|
||||
|
@ -99,6 +97,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -108,7 +107,45 @@
|
|||
<script>
|
||||
$(document).ready(function(){
|
||||
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
|
||||
$('#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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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/host_del/",
|
||||
data: {"id_list": id_list, "len_list": j},
|
||||
success: function (data) {
|
||||
window.open("/jasset/host_list/", "_self");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
|
@ -4,6 +4,8 @@
|
|||
<script src="/static/js/plugins/metisMenu/jquery.metisMenu.js"></script>
|
||||
<script src="/static/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
|
||||
<script src="/static/js/bootstrap-dialog.js"></script>
|
||||
<script src="/static/js/mindmup-editabletable.js"></script>
|
||||
<script src="/static/js/base.js"></script>
|
||||
|
||||
<!-- Peity -->
|
||||
<script src="/static/js/plugins/peity/jquery.peity.min.js"></script>
|
||||
|
|
Loading…
Reference in New Issue