success: function (result) {
//$('#modal_show_vim_body').empty();
dialog.modal('hide');
- location.reload();
+ table.ajax.reload();
},
error: function (result) {
dialog.modal('hide');
<script src="/static/bower_components/select2/dist/js/select2.js"></script>
<script src="/static/src/userhandler/user_list.js"></script>
<script>
+ var table;
$(document).ready(function () {
- var table = $('#users_table').DataTable({
+ table = $('#users_table').DataTable({
responsive: true,
"ajax": {
"url": "/admin/users/list",
table.ajax.reload();
}, 10000);
+ $("#formCreateUser").submit(function (event) {
+ event.preventDefault(); //prevent default action
+ var post_url = $(this).attr("action"); //get form action url
+ var request_method = $(this).attr("method");
+ var form_data = new FormData(this); //Encode form elements for submission
+
+ $.ajax({
+ url: post_url,
+ type: request_method,
+ data: form_data,
+ headers: {
+ "Accept": 'application/json'
+ },
+ contentType: false,
+ processData: false
+ }).done(function (response, textStatus, jqXHR) {
+ $('#modal_new_user').modal('hide');
+ table.ajax.reload();
+ bootbox.alert({
+ title: "Result",
+ message: "User successfully created."
+ });
+
+ }).fail(function (result) {
+ var data = result.responseJSON;
+ var title = "Error " + (data.code ? data.code : 'unknown');
+ var message = data.detail ? data.detail : 'No detail available.';
+ bootbox.alert({
+ title: title,
+ message: message
+ });
+ });
+ });
+
$("#formEditUser").submit(function (event) {
event.preventDefault(); //prevent default action
var post_url = $(this).attr("action"); //get form action url
table.ajax.reload();
bootbox.alert({
title: "Result",
- message: "User modified successfully."
+ message: "User successfully modified."
});
}).fail(function (result) {
});
});
});
+
});
</script>
"password": request.POST['password'],
"projects": request.POST.getlist('projects')
}
-
result = client.user_create(user.get_token(), user_data)
-
- return __response_handler(request, result, 'users:list', to_redirect=True)
+ if result['error']:
+ return __response_handler(request, result['data'], url=None,
+ status=result['data']['status'] if 'status' in result['data'] else 500)
+ else:
+ return __response_handler(request, {}, url=None, status=200)
@login_required
user = osmutils.get_user(request)
try:
client = Client()
- del_res = client.user_delete(user.get_token(), user_id)
+ result = client.user_delete(user.get_token(), user_id)
except Exception as e:
log.exception(e)
- return __response_handler(request, {}, 'users:list', to_redirect=True, )
+ result = {'error': True, 'data': str(e)}
+ if result['error']:
+ return __response_handler(request, result['data'], url=None,
+ status=result['data']['status'] if 'status' in result['data'] else 500)
+ else:
+ return __response_handler(request, {}, url=None, status=200)
@login_required
def update(request, user_id=None):