Commit f88c1490 authored by 江世峰's avatar 江世峰

asset:add assets_bulk

parent cdb1602e
...@@ -52,7 +52,6 @@ class AssetCreateForm(forms.ModelForm): ...@@ -52,7 +52,6 @@ class AssetCreateForm(forms.ModelForm):
'groups': forms.SelectMultiple(attrs={'class': 'select2', 'groups': forms.SelectMultiple(attrs={'class': 'select2',
'data-placeholder': _('Select asset groups')}), 'data-placeholder': _('Select asset groups')}),
'tags': forms.SelectMultiple(attrs={'class': 'select2', 'tags': forms.SelectMultiple(attrs={'class': 'select2',
'id':'tags',
'data-placeholder': _('Select asset tags')}), 'data-placeholder': _('Select asset tags')}),
'system_users': forms.SelectMultiple(attrs={'class': 'select2', 'system_users': forms.SelectMultiple(attrs={'class': 'select2',
'data-placeholder': _('Select asset system users')}), 'data-placeholder': _('Select asset system users')}),
......
...@@ -42,10 +42,10 @@ ...@@ -42,10 +42,10 @@
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$('.select2').select2(); $('.select2').select2();
$("#tags").select2({ $("#id_tags").select2({
tags: true, tags: true,
maximumSelectionLength: 8, //最多能够选择的个数 maximumSelectionLength: 8, //最多能够选择的个数
closeOnSelect: false //closeOnSelect: false
}); });
}) })
......
...@@ -18,48 +18,29 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -18,48 +18,29 @@ div.dataTables_wrapper div.dataTables_filter,
.custom{ .custom{
/*float:left;*/ /*float:left;*/
margin-right:5px; margin-right:5px;
} }
#modal .modal-body { max-height: 200px; } #modal .modal-body { max-height: 200px; }
</style> </style>
{% endblock %} {% endblock %}
{% block content_left_head %} {% block content_left_head %}{% endblock %}
{% endblock %} {% block table_search %}{% endblock %}
{% block table_search %}
{% endblock %}
{% block tags_list %} {% block tags_list %}
<div class="ydxbd" id="ydxbd" style="display: none;"> <div class="ydxbd" id="ydxbd" style="display: none;">
<div> <div class="tagBtnList">
<p id="tags_p">
{% for tag in tag_list %} {% for tag in tag_list %}
<a href="{% url 'assets:asset-tags' tag_id=tag.0 %}"
<a href="{% url 'assets:asset-tags' tag_id=tag.0 %}">
<span
{% if tag.0|IntToStr == tag_id %} {% if tag.0|IntToStr == tag_id %}
class="label label-warning" name="tag_on" class="tagBtn2 label label-warning" name="tag_on">
{% else %} {% else %}
class="label label-default" class="tagBtn2 label label-default">
{% endif %} {% endif %}
>{{ tag.1}}({{ tag.2 }})</span> {{ tag.1}}({{ tag.2 }})
</a> </a>
{# <a href="{% url 'assets:asset-tags' tag_id=tag.0 %}"#}
{# {% if tag.0|IntToStr == tag_id %}#}
{# class="fa fa-tag btn btn-sm btn-warning btn-rounded mar-j" name="tag_on">#}
{# {% else %}#}
{# class="fa fa-tag btn btn-sm btn-default btn-rounded mar-j">#}
{# {% endif %}#}
{# <span class="mar">#}
{# <strong>{{ tag.1}}</strong>({{ tag.2 }})#}
{# </span></a>#}
{% endfor %} {% endfor %}
{# <a href="{% url 'assets:asset-list' %}" class="btn btn-sm btn-rounded btn-default ">移除选择</a>#} <a href="{% url 'assets:asset-list' %}" class="tagBtn2 label label-default" >移除选择</a>
<a href="{% url 'assets:asset-list' %}" ><span class="label label-default">移除选择</span></a>
</p>
</div>
</div> </div>
</div>
{% endblock %} {% endblock %}
{% block table_head %} {% block table_head %}
...@@ -139,10 +120,8 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -139,10 +120,8 @@ div.dataTables_wrapper div.dataTables_filter,
if(tag_on.length > 0){ if(tag_on.length > 0){
oDiv.style.display = "block"; oDiv.style.display = "block";
} }
}; };
function tagShow() { function tagShow() {
var oDiv = document.getElementById("ydxbd"); var oDiv = document.getElementById("ydxbd");
if (oDiv.style.display == 'none'){ if (oDiv.style.display == 'none'){
...@@ -152,11 +131,7 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -152,11 +131,7 @@ div.dataTables_wrapper div.dataTables_filter,
} }
};//onload; };//onload;
$(document).ready(function(){ $(document).ready(function(){
$('#modal').modal({ $('#modal').modal({
show: false, show: false,
backdrop: 'static', backdrop: 'static',
...@@ -164,18 +139,16 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -164,18 +139,16 @@ div.dataTables_wrapper div.dataTables_filter,
remote:"{% url 'assets:asset-modal-update' %}", remote:"{% url 'assets:asset-modal-update' %}",
}); });
//$('#modal').on('shown.bs.modal',function(){
$('#asset_bulk_update_modal').on('shown.bs.modal',function(){ $('#asset_bulk_update_modal').on('shown.bs.modal',function(){
//alert('当弹窗完全加载完后,再触发;') //alert('当弹窗完全加载完后,再触发;')
$('.select2').select2(); $('.select2').select2();
$("#tags").select2({ $("#id_tags").select2({
tags: true, tags: true,
maximumSelectionLength: 8, //最多能够选择的个数 maximumSelectionLength: 8, //最多能够选择的个数
closeOnSelect: false //closeOnSelect: false
}); });
}); });
$('#asset_bulk_update_modal').modal({ $('#asset_bulk_update_modal').modal({
show: false, show: false,
backdrop: 'static', backdrop: 'static',
...@@ -220,9 +193,7 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -220,9 +193,7 @@ div.dataTables_wrapper div.dataTables_filter,
}; };
}); });
$('#btn_bulk_update').on('click',function(){ $('#btn_bulk_update').on('click',function(){
// alert( table.rows('.selected').data().length +' row(s) selected' );
var column2 = table.rows('.selected').data(); var column2 = table.rows('.selected').data();
var id_list = []; var id_list = [];
var plain_id_list = []; var plain_id_list = [];
...@@ -259,9 +230,9 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -259,9 +230,9 @@ div.dataTables_wrapper div.dataTables_filter,
}; };
function doUpdate() { function doUpdate() {
$('#asset_bulk_update_modal').modal('show'); // alert(plain_id_list);
// $('#modal').modal('show'); // $('#asset_bulk_update_modal').modal('show');
// alert(JSON.stringify(id_list)); window.location.href="{% url 'assets:asset-modal-update' %}?plain_id_lists="+plain_id_list
}; };
var action = $('#slct_bulk_update option:selected').val(); var action = $('#slct_bulk_update option:selected').val();
...@@ -295,14 +266,8 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -295,14 +266,8 @@ div.dataTables_wrapper div.dataTables_filter,
});//button });//button
}); //$(document).ready }); //$(document).ready
var bCheck = 1; var bCheck = 1;
function checkAll(){ function checkAll(){
if(bCheck){ if(bCheck){
...@@ -324,18 +289,5 @@ div.dataTables_wrapper div.dataTables_filter, ...@@ -324,18 +289,5 @@ div.dataTables_wrapper div.dataTables_filter,
}; };
}; };
</script> </script>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -5,61 +5,173 @@ ...@@ -5,61 +5,173 @@
{% block form %} {% block form %}
<div class="hr-line-dashed"></div> <div style="display:none" id="ridd">
<div class="ydxbd" id="ydxbd" style="display: block;">
<div>
<p id="tags_p">
<a>
</a>
{% for f in form %}
<span class="label label-default">{{ f.hostname }}</span>
{% endfor %}
<a href="{% url 'assets:asset-list' %}" ><span class="label label-default">移除选择</span></a>
</p>
</div>
</div>
<div class="hr-line-dashed"></div>
<form action="" method="post" class="form-horizontal">
{% csrf_token %}
<div class="hr-line-dashed"></div>
{{ form.hostname|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.port|bootstrap_horizontal }} {{ form.port|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }} {{ form.type|bootstrap_horizontal }}
{{ form.idc|bootstrap_horizontal }} {{ form.idc|bootstrap_horizontal }}
{{ form.groups|bootstrap_horizontal }} {{ form.groups|bootstrap_horizontal }}
{{ form.admin_user|bootstrap_horizontal }} {{ form.admin_user|bootstrap_horizontal }}
{{ form.system_users|bootstrap_horizontal }} {{ form.system_users|bootstrap_horizontal }}
{{ form.brand|bootstrap_horizontal }}
{{ form.cpu|bootstrap_horizontal }}
{{ form.memory|bootstrap_horizontal }}
{{ form.disk|bootstrap_horizontal }}
{{ form.os|bootstrap_horizontal }}
{{ form.cabinet_no|bootstrap_horizontal }}
{{ form.cabinet_pos|bootstrap_horizontal }}
{{ form.status|bootstrap_horizontal }}
{{ form.env|bootstrap_horizontal }}
{{ form.tags|bootstrap_horizontal }} {{ form.tags|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }} {{ form.comment|bootstrap_horizontal }}
</div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<form action="" class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " id="asset_on_count">已选主机({{ assets_count }})</label>
<div class="col-sm-9" id="asset_sed">
<div class="form-asset-on" id="add_asset">
<p id="asset_on_p">
{% for asset in assets_on_list %}
<button name='asset_hostname' title='{{ asset.ip }}' type='button' class='btn btn-default btn-xs'>{{ asset.hostname }}</button>
{% endfor %}
</p>
</div>
</div>
</div>
</form>
<div class="hr-line-dashed"></div>
<div class="ydxbd" id="formlists" style="display: block;">
<p id="tags_p" class="mgl-5 c02">选择属性</p>
<div class="tagBtnList">
<a onclick="AddAllForm(this)" class="tagBtn2 label label-primary" id="changeall">全选</a>
<a onclick="AddForm(this,'id_port')" class="tagBtn2 label label-default" name="changebtn">端口</a>
<a onclick="AddForm(this,'id_type')" class="tagBtn2 label label-default" name="changebtn">系统类型</a>
<a onclick="AddForm(this,'id_idc')" class="tagBtn2 label label-default" name="changebtn">机房</a>
<a onclick="AddForm(this,'id_groups')" class="tagBtn2 label label-default" name="changebtn">用户组</a>
<a onclick="AddForm(this,'id_admin_user')" class="tagBtn2 label label-default" name="changebtn">管理用户</a>
<a onclick="AddForm(this,'id_system_users')" class="tagBtn2 label label-default" name="changebtn">系统用户</a>
<a onclick="AddForm(this,'id_brand')" class="tagBtn2 label label-default" name="changebtn">品牌</a>
<a onclick="AddForm(this,'id_cpu')" class="tagBtn2 label label-default" name="changebtn">CPU</a>
<a onclick="AddForm(this,'id_memory')" class="tagBtn2 label label-default" name="changebtn">内存</a>
<a onclick="AddForm(this,'id_disk')" class="tagBtn2 label label-default" name="changebtn">硬盘</a>
<a onclick="AddForm(this,'id_os')" class="tagBtn2 label label-default" name="changebtn">操作系统</a>
<a onclick="AddForm(this,'id_cabinet_no')" class="tagBtn2 label label-default" name="changebtn">机柜编号</a>
<a onclick="AddForm(this,'id_cabinet_pos')" class="tagBtn2 label label-default" name="changebtn">机柜层号</a>
<a onclick="AddForm(this,'id_status')" class="tagBtn2 label label-default" name="changebtn">资产状态</a>
<a onclick="AddForm(this,'id_env')" class="tagBtn2 label label-default" name="changebtn">资产环境</a>
<a onclick="AddForm(this,'id_tags')" class="tagBtn2 label label-default" name="changebtn">标签</a>
<a onclick="AddForm(this,'id_comment')" class="tagBtn2 label label-default" name="changebtn">备注</a>
</div>
</div>
<div class="hr-line-dashed"></div>
<form action="" method="post" class="form-horizontal" id="add_form">
{% csrf_token %}
<div class="form-group" name="formbtn" id="formbtn">
<div class="col-sm-4 col-sm-offset-2"> <div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">{% trans 'Reset' %}</button> <button class="btn btn-white" type="reset">{% trans 'Reset' %}</button>
<button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button> <button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
</div> </div>
</div> </div>
</form> </form>
<!-- 模态框(Modal) -->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content" id="box">
<!--此部分为主体内容,将远程加载进来-->
</div>
</div>
</div>
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <script>
$(document).ready(function () {
$('#add_asset').on('click',function(){
$('#modal').modal('show');
});
$('#modal').modal({
show: false,
backdrop: 'static',
keyboard: 'false',
remote:"{% url 'assets:asset-modal-list' %}?plain_id_lists={{ plain_id_lists }}",
});
$('#modal').on('show.bs.modal',function(){
//alert('当调用show方法时,立即触发;')
});
$('#modal').on('shown.bs.modal',function(){
//alert('当弹窗完全加载完后,再触发;')
});
$('#modal').on('hide.bs.modal',function(){
//alert('当关闭时,立即触发;')
});
$('#modal').on('hidden.bs.modal',function(){
//alert('当关完全关闭后,再触发;')
});
$('#modal').on('loaded.bs.modal',function(){
//alert('当远程数据加载完毕后,再触发;')
});
function SetSelect2(){
$('.select2').select2(); $('.select2').select2();
$("#tags").select2({ $("#id_tags").select2({
tags: true, tags: true,
maximumSelectionLength: 8, //最多能够选择的个数 maximumSelectionLength: 8, //最多能够选择的个数
closeOnSelect: false //closeOnSelect: false
}); });
}) };
function AddForm(obj,id_form) {
var oHiddenForms = document.getElementById("ridd");
var parentElem = document.getElementById("add_form");
var oH = document.getElementById(id_form);
var oNew = oH.parentNode.parentNode
var aDiv = parentElem.getElementsByClassName('form-group');
if(oNew.parentNode.id=='ridd') {
obj.className="tagBtn2 label label-warning";
parentElem.insertBefore(oNew,aDiv[0]);
SetSelect2();
}else{
oHiddenForms.appendChild(oNew);
obj.className="tagBtn2 label label-default";
SetSelect2();
};
};
</script> function ChangeBtnCss(class_var){
var changebtns = $("#formlists").find("a[name='changebtn']")
for (var i=0; i<changebtns.length;i++){
changebtns[i].className=class_var;
};
};
function AddAllForm(obj) {
var oHiddenForms = document.getElementById("ridd");
var parentElem = document.getElementById("add_form");
var aDiv = parentElem.getElementsByClassName('form-group');
var bFormBtn = document.getElementById("formbtn");
var oHidden_len = oHiddenForms.children.length;
var aDiv_len = aDiv.length;
if(oHidden_len == 0 || obj.innerText == "取消全选"){
for(var i=0;i<aDiv_len-1;i++){
oHiddenForms.appendChild(aDiv[0]);
};
ChangeBtnCss("tagBtn2 label label-default");
$('#changeall').text("全选");
}else{
for(var i=0;i<oHidden_len;i++){
parentElem.insertBefore(oHiddenForms.children[0],bFormBtn);
};
ChangeBtnCss("tagBtn2 label label-warning");
$('#changeall').text("取消全选");
SetSelect2();
};
};
</script>
{% endblock %} {% endblock %}
...@@ -75,12 +75,32 @@ class AssetCreateView(AdminUserRequiredMixin,CreateAssetTagsMiXin,CreateView): ...@@ -75,12 +75,32 @@ class AssetCreateView(AdminUserRequiredMixin,CreateAssetTagsMiXin,CreateView):
return super(AssetCreateView, self).get_context_data(**kwargs) return super(AssetCreateView, self).get_context_data(**kwargs)
class AssetModalCreateView(AdminUserRequiredMixin,CreateAssetTagsMiXin,CreateView): class AssetModalCreateView(AdminUserRequiredMixin,CreateAssetTagsMiXin,ListView):
model = Asset model = Asset
# tag_type = 'asset' # tag_type = 'asset'
form_class = AssetCreateForm form_class = AssetCreateForm
template_name = 'assets/asset_modal_update.html' template_name = 'assets/asset_modal_update.html'
success_url = reverse_lazy('assets:asset-list') success_url = reverse_lazy('assets:asset-list')
def get_queryset(self):
self.queryset = super(AssetModalCreateView,self).get_queryset()
self.s = self.request.GET.get('plain_id_lists')
if "," in str(self.s):
self.plain_id_lists = [int(x) for x in self.s.split(',')]
else:
self.plain_id_lists = [self.s]
return self.queryset
def get_context_data(self, **kwargs):
asset_on_list = Asset.objects.filter(id__in = self.plain_id_lists)
context = {
'app': 'Assets',
'action': 'Bulk Update asset',
'assets_on_list': asset_on_list,
'assets_count': len(asset_on_list),
'plain_id_lists':self.s,
}
kwargs.update(context)
return super(AssetModalCreateView, self).get_context_data(**kwargs)
class AssetUpdateView(AdminUserRequiredMixin,UpdateAssetTagsMiXin,UpdateView): class AssetUpdateView(AdminUserRequiredMixin,UpdateAssetTagsMiXin,UpdateView):
model = Asset model = Asset
...@@ -134,6 +154,17 @@ class AssetModalListView(AdminUserRequiredMixin, ListView): ...@@ -134,6 +154,17 @@ class AssetModalListView(AdminUserRequiredMixin, ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
group_id = self.request.GET.get('group_id') group_id = self.request.GET.get('group_id')
tag_id = self.request.GET.get('tag_id') tag_id = self.request.GET.get('tag_id')
plain_id_lists = self.request.GET.get('plain_id_lists')
self.s = self.request.GET.get('plain_id_lists')
if "," in str(self.s):
self.plain_id_lists = [int(x) for x in self.s.split(',')]
else:
self.plain_id_lists = [self.s]
print plain_id_lists
if plain_id_lists:
context = {
'all_assets':plain_id_lists
}
if group_id: if group_id:
group = AssetGroup.objects.get(id=group_id) group = AssetGroup.objects.get(id=group_id)
context = { context = {
......
...@@ -206,6 +206,7 @@ table.dataTable tbody td.selected td i.text-navy ...@@ -206,6 +206,7 @@ table.dataTable tbody td.selected td i.text-navy
display: block; display: block;
background: #f4f4f4; background: #f4f4f4;
padding-left: 10px; padding-left: 10px;
padding-bottom: 15px;
} }
.mar { .mar {
margin-left: 2px; margin-left: 2px;
...@@ -216,6 +217,10 @@ table.dataTable tbody td.selected td i.text-navy ...@@ -216,6 +217,10 @@ table.dataTable tbody td.selected td i.text-navy
margin-right: 3px; margin-right: 3px;
} }
.form-asset-on p{
margin-bottom:0px;
}
.form-asset-on button{ .form-asset-on button{
background: #f1f1f1; background: #f1f1f1;
margin-right: 2px; margin-right: 2px;
...@@ -229,6 +234,24 @@ table.dataTable tbody td.selected td i.text-navy ...@@ -229,6 +234,24 @@ table.dataTable tbody td.selected td i.text-navy
min-height:34px; min-height:34px;
height: 100%; height: 100%;
} }
.form-asset-on p{
margin-bottom:0px; .mgl-5 {
margin-left: 5px;
font-size: 12px;
}
.c02 {
color: #999;
}
.tagBtnList {
font-size: 12px;
line-height: 32px;
margin: -5px 0 0 0;
padding-left: 0px;
}
.tagBtn2 {
margin: 0 5px 5px 0;
font-size: 12px;
vertical-align: middle;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment