Skip to content

Commit

Permalink
unify the function
Browse files Browse the repository at this point in the history
  • Loading branch information
rizalfr committed Jun 6, 2018
1 parent 0049c7b commit 975746c
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions locust/static/locust.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,41 +174,23 @@ $("#directories .select2").select2({
placeholder: "Select a state"
});

let whichform = $('.upload_file_form_test_file')[0];

$('#upload_py_submit').click(function(event){
event.preventDefault();
whichform = $('.upload_file_form_test_file')[0];
$('.upload_file_form_test_file').submit();
});

$('#upload_json_submit').click(function(event){
event.preventDefault();
$('.upload_file_form_json').submit();
});

$('.upload_file_form_test_file').submit(function(event) {
event.preventDefault();
var form_data = new FormData($('.upload_file_form_test_file')[0]);
$.ajax({
type: 'POST',
url: "/upload_file",
enctype: "multipart/form-data",
contentType: false,
data: form_data,
cache: false,
processData: false,
success: function (response) {
if (response.success) {
location.reload(true);
} else {
alert(response.message);
}
}
})
whichform = $('.upload_file_form_json')[0];
$('.upload_file_form_test_file').submit();
});

$('.upload_file_form_json').submit(function(event) {
$('.upload_file_form_test_file, .upload_file_form_json').submit(function(event) {
event.preventDefault();
var form_data = new FormData($('.upload_file_form_json')[0]);
var form_data = new FormData(whichform);
$.ajax({
type: 'POST',
url: "/upload_file",
Expand All @@ -227,7 +209,6 @@ $('.upload_file_form_json').submit(function(event) {
})
});


$('#submit_json_btn').click(function(){
event.preventDefault();
$('#hidden_config_json').val(JSON.stringify(json_editor.get(), null , 4));
Expand Down

0 comments on commit 975746c

Please sign in to comment.