mirror of https://github.com/jumpserver/jumpserver
update toastr js and close #8
parent
7fd224e690
commit
8cdc4674d7
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -211,124 +211,147 @@
|
||||||
{% block custom_foot_js %}
|
{% block custom_foot_js %}
|
||||||
<script>
|
<script>
|
||||||
jumpserver.selected_groups = {};
|
jumpserver.selected_groups = {};
|
||||||
function updateUserGroups(user_groups) {
|
|
||||||
var the_url = "{% url 'users:user-group-edit-api' pk=user_object.id%}";
|
|
||||||
var body = {
|
|
||||||
id: {{ user_object.id }},
|
|
||||||
groups: Object.assign([], user_groups)
|
|
||||||
};
|
|
||||||
var success = function(data) {
|
|
||||||
// remove all the selected groups from select > option and rendered ul element;
|
|
||||||
$('.select2-selection__rendered').empty();
|
|
||||||
$('#slct_groups').val('');
|
|
||||||
$.map(jumpserver.selected_groups, function(group_name, index){
|
|
||||||
$('#opt_' + index).remove();
|
|
||||||
// change tr html of user groups.
|
|
||||||
$('.group_edit tbody').append(
|
|
||||||
'<tr>' +
|
|
||||||
'<td><b class="bdg_user_group" data-gid="' + index + '">' + group_name + '</b></td>' +
|
|
||||||
'<td><button class="btn btn-danger btn-sm pull-right btn_delete_user_group" type="button"><i class="fa fa-minus"></i></button></td>' +
|
|
||||||
'</tr>'
|
|
||||||
)
|
|
||||||
});
|
|
||||||
// clear jumpserver.selected_groups
|
|
||||||
jumpserver.selected_groups = {};
|
|
||||||
toastr.success('{% trans "UserGroup Update Success!" %}')
|
|
||||||
};
|
|
||||||
APIUpdateAttr({ url: the_url, body: JSON.stringify(body), success: success, method: 'PUT'});
|
|
||||||
|
|
||||||
|
function updateUserGroups(user_groups) {
|
||||||
|
var the_url = "{% url 'users:user-group-edit-api' pk=user_object.id %}";
|
||||||
|
var body = {
|
||||||
|
id: {{ user_object.id }},
|
||||||
|
groups: Object.assign([], user_groups)
|
||||||
|
};
|
||||||
|
var success = function(data) {
|
||||||
|
// remove all the selected groups from select > option and rendered ul element;
|
||||||
|
$('.select2-selection__rendered').empty();
|
||||||
|
$('#slct_groups').val('');
|
||||||
|
$.map(jumpserver.selected_groups, function(group_name, index) {
|
||||||
|
$('#opt_' + index).remove();
|
||||||
|
// change tr html of user groups.
|
||||||
|
$('.group_edit tbody').append(
|
||||||
|
'<tr>' +
|
||||||
|
'<td><b class="bdg_user_group" data-gid="' + index + '">' + group_name + '</b></td>' +
|
||||||
|
'<td><button class="btn btn-danger btn-sm pull-right btn_delete_user_group" type="button"><i class="fa fa-minus"></i></button></td>' +
|
||||||
|
'</tr>'
|
||||||
|
)
|
||||||
|
});
|
||||||
|
// clear jumpserver.selected_groups
|
||||||
|
jumpserver.selected_groups = {};
|
||||||
|
toastr.success('{% trans "UserGroup Update Success!" %}')
|
||||||
|
};
|
||||||
|
APIUpdateAttr({
|
||||||
|
url: the_url,
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
success: success,
|
||||||
|
method: 'PUT'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
$(document).ready(function () {
|
$(document).ready(function() {
|
||||||
$('.select2').select2()
|
$('.select2').select2()
|
||||||
.on('select2:select', function(evt) {
|
.on('select2:select', function(evt) {
|
||||||
var data = evt.params.data;
|
var data = evt.params.data;
|
||||||
jumpserver.selected_groups[data.id] = data.text;
|
jumpserver.selected_groups[data.id] = data.text;
|
||||||
}).on('select2:unselect', function(evt) {
|
}).on('select2:unselect', function(evt) {
|
||||||
var data = evt.params.data;
|
var data = evt.params.data;
|
||||||
delete jumpserver.selected_groups[data.id]
|
delete jumpserver.selected_groups[data.id]
|
||||||
})
|
})
|
||||||
}).on('click', '#is_active', function(){
|
}).on('click', '#is_active', function() {
|
||||||
var the_url = "{% url 'users:user-patch-api' pk=user_object.id %}";
|
var the_url = "{% url 'users:user-patch-api' pk=user_object.id %}";
|
||||||
var checked = !$(this).prop('checked');
|
var checked = !$(this).prop('checked');
|
||||||
var body = {'is_active': checked };
|
var body = {
|
||||||
var success = '{% trans "Update Successfully!" %}';
|
'is_active': checked
|
||||||
APIUpdateAttr({ url: the_url, body: JSON.stringify(body), success_message: success});
|
};
|
||||||
}).on('click', '#enable_otp', function(){
|
var success = '{% trans "Update Successfully!" %}';
|
||||||
var the_url = "{% url 'users:user-patch-api' pk=user_object.id %}";
|
APIUpdateAttr({
|
||||||
var checked = !$(this).prop('checked');
|
url: the_url,
|
||||||
var body = {'enable_otp': checked };
|
body: JSON.stringify(body),
|
||||||
var success = '{% trans "Update Successfully!" %}';
|
success_message: success
|
||||||
APIUpdateAttr({ url: the_url, body: JSON.stringify(body), success_message: success});
|
});
|
||||||
}).on('click', '#btn_add_user_group', function(){
|
}).on('click', '#enable_otp', function() {
|
||||||
if (Object.keys(jumpserver.selected_groups).length === 0) {
|
var the_url = "{% url 'users:user-patch-api' pk=user_object.id %}";
|
||||||
return false;
|
var checked = !$(this).prop('checked');
|
||||||
}
|
var body = {
|
||||||
var user_groups = $('.bdg_user_group').map(function(){
|
'enable_otp': checked
|
||||||
return $(this).data('gid');
|
};
|
||||||
}).get();
|
var success = '{% trans "Update Successfully!" %}';
|
||||||
$.map(jumpserver.selected_groups, function(value, index){
|
APIUpdateAttr({
|
||||||
user_groups.push(parseInt(index));
|
url: the_url,
|
||||||
$('#opt_' + index).remove();
|
body: JSON.stringify(body),
|
||||||
});
|
success_message: success
|
||||||
updateUserGroups(user_groups)
|
});
|
||||||
}).on('click', '.btn_delete_user_group', function(){
|
}).on('click', '#btn_add_user_group', function() {
|
||||||
var $this = $(this);
|
if (Object.keys(jumpserver.selected_groups).length === 0) {
|
||||||
var $tr = $this.closest('tr');
|
return false;
|
||||||
var $badge = $tr.find('.bdg_user_group');
|
|
||||||
var gid = $badge.data('gid');
|
|
||||||
var group_name = $badge.html() || $badge.text();
|
|
||||||
$('#slct_groups').append(
|
|
||||||
'<option value="' + gid + '" id="opt_' + gid + '">' + group_name + '</option>'
|
|
||||||
);
|
|
||||||
$tr.remove();
|
|
||||||
var user_groups = $('.bdg_user_group').map(function(){
|
|
||||||
return $(this).data('gid');
|
|
||||||
}).get();
|
|
||||||
updateUserGroups(user_groups)
|
|
||||||
}).on('click', '#btn_reset_password', function(){
|
|
||||||
function doReset() {
|
|
||||||
var the_url = '{% url "users:user-reset-password-api" pk=user_object.id %}';
|
|
||||||
var body = {};
|
|
||||||
var success = function() {
|
|
||||||
var msg = "{% trans 'E-mail sent successfully. An e-mail has been sent to the user\'s mailbox.' %}";
|
|
||||||
swal("{% trans 'Password-Reset' %}", msg, "success");
|
|
||||||
}
|
}
|
||||||
APIUpdateAttr({ url: the_url, body: JSON.stringify(body), success: success});
|
var user_groups = $('.bdg_user_group').map(function() {
|
||||||
}
|
return $(this).data('gid');
|
||||||
swal({
|
}).get();
|
||||||
title: "{% trans 'Are you sure?' %}",
|
$.map(jumpserver.selected_groups, function(value, index) {
|
||||||
text: "{% trans 'This will reset the user\'s password.' %}",
|
user_groups.push(parseInt(index));
|
||||||
type: "warning",
|
$('#opt_' + index).remove();
|
||||||
showCancelButton: true,
|
});
|
||||||
confirmButtonColor: "#DD6B55",
|
updateUserGroups(user_groups)
|
||||||
confirmButtonText: "{% trans 'Confirm' %}",
|
}).on('click', '.btn_delete_user_group', function() {
|
||||||
closeOnConfirm: false
|
var $this = $(this);
|
||||||
}, function () {
|
var $tr = $this.closest('tr');
|
||||||
doReset();
|
var $badge = $tr.find('.bdg_user_group');
|
||||||
|
var gid = $badge.data('gid');
|
||||||
|
var group_name = $badge.html() || $badge.text();
|
||||||
|
$('#slct_groups').append(
|
||||||
|
'<option value="' + gid + '" id="opt_' + gid + '">' + group_name + '</option>'
|
||||||
|
);
|
||||||
|
$tr.remove();
|
||||||
|
var user_groups = $('.bdg_user_group').map(function() {
|
||||||
|
return $(this).data('gid');
|
||||||
|
}).get();
|
||||||
|
updateUserGroups(user_groups)
|
||||||
|
}).on('click', '#btn_reset_password', function() {
|
||||||
|
function doReset() {
|
||||||
|
var the_url = '{% url "users:user-reset-password-api" pk=user_object.id %}';
|
||||||
|
var body = {};
|
||||||
|
var success = function() {
|
||||||
|
var msg = "{% trans 'E-mail sent successfully. An e-mail has been sent to the user\'s mailbox.' %}";
|
||||||
|
swal("{% trans 'Password-Reset' %}", msg, "success");
|
||||||
|
};
|
||||||
|
APIUpdateAttr({
|
||||||
|
url: the_url,
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
success: success
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
swal({
|
||||||
}).on('click', '#btn_reset_pk', function(){
|
title: "{% trans 'Are you sure?' %}",
|
||||||
function doReset() {
|
text: "{% trans 'This will reset the user\'s password.' %}",
|
||||||
var the_url = '{% url "users:user-reset-pk-api" pk=user_object.id %}';
|
type: "warning",
|
||||||
var body = {};
|
showCancelButton: true,
|
||||||
var success = function() {
|
confirmButtonColor: "#DD6B55",
|
||||||
var msg = "{% trans 'The reset-ssh-public-key E-mail has been sent successfully. Please inform the user to update his new ssh public key.' %}";
|
confirmButtonText: "{% trans 'Confirm' %}",
|
||||||
swal("{% trans 'SSH-Public-Key Reset' %}", msg, "success");
|
closeOnConfirm: false
|
||||||
|
}, function() {
|
||||||
|
doReset();
|
||||||
|
});
|
||||||
|
}).on('click', '#btn_reset_pk', function() {
|
||||||
|
function doReset() {
|
||||||
|
var the_url = '{% url "users:user-reset-pk-api" pk=user_object.id %}';
|
||||||
|
var body = {};
|
||||||
|
var success = function() {
|
||||||
|
var msg = "{% trans 'The reset-ssh-public-key E-mail has been sent successfully. Please inform the user to update his new ssh public key.' %}";
|
||||||
|
swal("{% trans 'SSH-Public-Key Reset' %}", msg, "success");
|
||||||
|
};
|
||||||
|
APIUpdateAttr({
|
||||||
|
url: the_url,
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
success: success
|
||||||
|
});
|
||||||
}
|
}
|
||||||
APIUpdateAttr({ url: the_url, body: JSON.stringify(body), success: success});
|
swal({
|
||||||
}
|
title: "{% trans 'Are you sure?' %}",
|
||||||
swal({
|
text: "{% trans 'This will reset the user\'s public key.' %}",
|
||||||
title: "{% trans 'Are you sure?' %}",
|
type: "warning",
|
||||||
text: "{% trans 'This will reset the user\'s public key.' %}",
|
showCancelButton: true,
|
||||||
type: "warning",
|
confirmButtonColor: "#DD6B55",
|
||||||
showCancelButton: true,
|
confirmButtonText: "{% trans 'Confirm' %}",
|
||||||
confirmButtonColor: "#DD6B55",
|
closeOnConfirm: false
|
||||||
confirmButtonText: "{% trans 'Confirm' %}",
|
}, function() {
|
||||||
closeOnConfirm: false
|
doReset();
|
||||||
}, function () {
|
});
|
||||||
doReset();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue