[Update] 修改前端rdp相关配置的选择逻辑

pull/1333/head
BaiJiangJie 7 years ago
parent 599431f402
commit ac67c231fc

@ -79,59 +79,50 @@
</div> </div>
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <script>
var auto_generate_key = '#'+'{{ form.auto_generate_key.id_for_label }}'; var auto_generate_key = '#'+'{{ form.auto_generate_key.id_for_label }}';
var protocol_id = '#' + '{{ form.protocol.id_for_label }}'; var protocol_id = '#' + '{{ form.protocol.id_for_label }}';
var private_key_id = '#' + '{{ form.private_key_file.id_for_label }}'; var private_key_id = '#' + '{{ form.private_key_file.id_for_label }}';
var auto_push_id = '#' + '{{ form.auto_push.id_for_label }}'; var auto_push_id = '#' + '{{ form.auto_push.id_for_label }}';
var sudo_id = '#' + '{{ form.sudo.id_for_label }}'; var sudo_id = '#' + '{{ form.sudo.id_for_label }}';
var shell_id = '#' + '{{ form.shell.id_for_label }}'; var shell_id = '#' + '{{ form.shell.id_for_label }}';
var need_change_field = [
auto_generate_key, private_key_id, auto_push_id, sudo_id, shell_id
];
var div_auto_generate_key = $(auto_generate_key).parent().parent(); function protocolChange() {
var div_ssh_private_key = $(private_key_id).parent().parent().parent().parent(); if ($(protocol_id + " option:selected").text() === 'rdp') {
var div_auto_push = $(auto_push_id).parent().parent(); $('.auth-fields').removeClass('hidden');
var div_sudo = $(sudo_id).parent().parent(); $.each(need_change_field, function (index, value) {
var div_shell = $(shell_id).parent().parent(); $(value).closest('.form-group').addClass('hidden')
var need_change_div = [ });
div_auto_generate_key, div_ssh_private_key, } else {
div_auto_push, div_sudo, div_shell authFieldsDisplay();
]; $.each(need_change_field, function (index, value) {
$(value).closest('.form-group').removeClass('hidden')
function authFieldsDisplay() { });
if ($(auto_generate_key).prop('checked')) { }
$('.auth-fields').addClass('hidden'); }
} else {
$('.auth-fields').removeClass('hidden');
}
}
function protocolChange() { function authFieldsDisplay() {
if ($(protocol_id + " option:selected").text() === 'rdp') { if ($(auto_generate_key).prop('checked')) {
$('.auth-fields').removeClass('hidden'); $('.auth-fields').addClass('hidden');
$.each(need_change_div, function (index, value) { } else {
$(value).addClass('hidden') $('.auth-fields').removeClass('hidden');
}); }
} else { }
authFieldsDisplay();
$.each(need_change_div, function (index, value) {
$(value).removeClass('hidden')
});
}
}
{% block document_ready %} $(document).ready(function () {
$(document).ready(function () { $('.select2').select2();
$('.select2').select2(); authFieldsDisplay();
authFieldsDisplay(); protocolChange();
protocolChange(); })
}); .on('change', protocol_id, function(){
{% endblock %} protocolChange();
})
.on('change', auto_generate_key, function(){
authFieldsDisplay();
});
$(protocol_id).change(function (){ </script>
protocolChange();
});
$(auto_generate_key).change(function () {
authFieldsDisplay();
});
</script>
{% endblock %} {% endblock %}

@ -68,27 +68,26 @@
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <script>
var protocol_id = '#' + '{{ form.protocol.id_for_label }}'; var protocol_id = '#' + '{{ form.protocol.id_for_label }}';
var private_key_id = '#' + '{{ form.private_key_file.id_for_label }}'; var private_key_id = '#' + '{{ form.private_key_file.id_for_label }}';
var port = '#' + '{{ form.port.id_for_label }}'; var port = '#' + '{{ form.port.id_for_label }}';
var div_ssh_private_key = $(private_key_id).parent().parent().parent().parent();
function protocolChange() { function protocolChange() {
if ($(protocol_id + " option:selected").text() === 'rdp') { if ($(protocol_id + " option:selected").text() === 'rdp') {
$(port).val(3389); $(port).val(3389);
$(div_ssh_private_key).addClass('hidden') $(private_key_id).closest('.form-group').addClass('hidden')
} else { } else {
$(port).val(22); $(port).val(22);
$(div_ssh_private_key).removeClass('hidden') $(private_key_id).closest('.form-group').removeClass('hidden')
}
} }
}
$(document).ready(function(){ $(document).ready(function(){
protocolChange(); protocolChange();
}); })
$(protocol_id).change(function (){ .on('change', protocol_id, function(){
protocolChange(); protocolChange();
}); });
</script> </script>
{% endblock %} {% endblock %}

@ -66,12 +66,12 @@
<td>{% trans 'Protocol' %}:</td> <td>{% trans 'Protocol' %}:</td>
<td><b id="id_protocol_type">{{ system_user.protocol }}</b></td> <td><b id="id_protocol_type">{{ system_user.protocol }}</b></td>
</tr> </tr>
<tr id="id_sudo"> <tr class="only-ssh">
<td>{% trans 'Sudo' %}:</td> <td>{% trans 'Sudo' %}:</td>
<td><b>{{ system_user.sudo }}</b></td> <td><b>{{ system_user.sudo }}</b></td>
</tr> </tr>
{% if system_user.shell %} {% if system_user.shell %}
<tr id="id_shell"> <tr class="only-ssh">
<td>{% trans 'Shell' %}:</td> <td>{% trans 'Shell' %}:</td>
<td><b>{{ system_user.shell }}</b></td> <td><b>{{ system_user.shell }}</b></td>
</tr> </tr>
@ -107,7 +107,7 @@
</div> </div>
<div class="col-sm-4" style="padding-left: 0;padding-right: 0"> <div class="col-sm-4" style="padding-left: 0;padding-right: 0">
<div class="panel panel-primary" id="id_quick_update"> <div class="panel panel-primary only-ssh">
<div class="panel-heading"> <div class="panel-heading">
<i class="fa fa-info-circle"></i> {% trans 'Quick update' %} <i class="fa fa-info-circle"></i> {% trans 'Quick update' %}
</div> </div>
@ -237,11 +237,8 @@ function updateSystemUserNode(nodes) {
jumpserver.nodes_selected = {}; jumpserver.nodes_selected = {};
$(document).ready(function () { $(document).ready(function () {
if($('#id_protocol_type').text() === 'rdp'){ if($('#id_protocol_type').text() === 'rdp'){
$('#id_quick_update').addClass('hidden'); $('.only-ssh').addClass('hidden')
$('#id_sudo').addClass('hidden');
$('#id_shell').addClass('hidden');
} }
$('.select2').select2() $('.select2').select2()
.on('select2:select', function(evt) { .on('select2:select', function(evt) {
var data = evt.params.data; var data = evt.params.data;

@ -15,9 +15,3 @@
</div> </div>
{% endblock %} {% endblock %}
{% block document_ready %}
$(document).ready(function () {
$('.select2').select2();
protocolChange();
});
{% endblock %}

Loading…
Cancel
Save