Skip to content

Commit

Permalink
fileupload successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
ManivannanMurugavel committed Apr 8, 2019
1 parent 71b6767 commit b042d3c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 30 deletions.
77 changes: 47 additions & 30 deletions assets/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $(document).ready(function(){
l('ok');
$("#edit").hide();
$('textarea').attr('readonly',false);

$("#fileUpload").click()

var cx = '011558942542564350974:nldba-ydc7g'; // Insert your own Custom Search engine ID here
var gcse = document.createElement('script');
Expand All @@ -66,35 +66,35 @@ $(document).ready(function(){
s.parentNode.insertBefore(gcse, s);


var inputText = prompt('Please enter the training dataset(filename.txt)');
l("MANI"+inputText+"vannan");
if((inputText != null) && (inputText.length > 0)){
l(inputText);
var rawFile = new XMLHttpRequest();
rawFile.open("GET", inputText, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
text_file_all_text = rawFile.responseText.split('\n');
l('success');
l(text_file_all_text);
$('#editor').text(text_file_all_text[page_num]);
setTimeout(function(){
$("#gsc-i-id1.gsc-input").val(text_file_all_text[page_num]);
$(".gsc-search-button").click();
}, 500);
// $("#gsc-i-id1.gsc-input").val(text_file_all_text[page_num]);
}
else{
alert(inputText+" doest not exist");
}
}
}
rawFile.send(null);
}
// var inputText = prompt('Please enter the training dataset(filename.txt)');
// l("MANI"+inputText+"vannan");
// if((inputText != null) && (inputText.length > 0)){
// l(inputText);
// var rawFile = new XMLHttpRequest();
// rawFile.open("GET", inputText, false);
// rawFile.onreadystatechange = function ()
// {
// if(rawFile.readyState === 4)
// {
// if(rawFile.status === 200 || rawFile.status == 0)
// {
// text_file_all_text = rawFile.responseText.split('\n');
// l('success');
// l(text_file_all_text);
// $('#editor').text(text_file_all_text[page_num]);
// setTimeout(function(){
// $("#gsc-i-id1.gsc-input").val(text_file_all_text[page_num]);
// $(".gsc-search-button").click();
// }, 500);
// // $("#gsc-i-id1.gsc-input").val(text_file_all_text[page_num]);
// }
// else{
// alert(inputText+" doest not exist");
// }
// }
// }
// rawFile.send(null);
// }
});
$("#save").click(function(){
full_text = $("#editor").text();
Expand Down Expand Up @@ -259,4 +259,21 @@ $( ".classes" ).on("click",".delete_btn",function(){
class_names.splice(class_names.indexOf(tt),1);
$(this).parent().parent().remove();
}
});
$("#upload").click(function(){
l('upload clicked');
var fileInput = $('#validatedCustomFile');
var input = fileInput.get(0);
if(input.files.length > 0){
var textFile = input.files[0];
var reader = new FileReader();
reader.onload = function(e) {
// The file's text will be printed here
text_file_all_text = e.target.result.split('\n');
$('#editor').text(text_file_all_text[page_num]);
$("#gsc-i-id1.gsc-input").val(text_file_all_text[page_num]);
$(".gsc-search-button").click();
};
reader.readAsText(textFile);
}
});
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
color: pink;
}
}
#fileUpload{
display: none;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -220,6 +223,36 @@ <h4>Class Names</h4>
<gcse:search></gcse:search>
</div>
</div>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">File Upload</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form class="was-validated">
<div class="custom-file">
<input type="file" class="custom-file-input" id="validatedCustomFile" accept=".txt" required>
<label class="custom-file-label" for="validatedCustomFile">Choose file...</label>
<div class="invalid-feedback">Please upload your training dataset(filename.txt)</div>
</div>
</form>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> -->
<button type="button" class="btn btn-primary" data-dismiss="modal" id="upload">Upload</button>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-primary" id="fileUpload" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>

<script src="assets/js/project.js"></script>
</body>
</html>

0 comments on commit b042d3c

Please sign in to comment.