Browse Source

Show All button works now

master
Cristina Cochior 4 years ago
parent
commit
5f21bdec74
  1. 137
      templates/layout.html

137
templates/layout.html

@ -6,9 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Library</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
<!--TEST-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="{{ url_for('static', filename='js/highlight.js') }}"></script>
@ -74,7 +71,9 @@
location.href = address;
};
});
/////DISPLAY FILES/////////////
/////DISPLAY FILENAMES/////////////
$(".file-names").click(function(event){
// alert(listofselecteddocs);
@ -86,14 +85,11 @@
// iterate in test[i].librarian to find where the name is present
//to get the test[i].debris that goes with it
var allpeeps = [];
var category = null;
for (var i = 0; i < test.length; ++i) {
var item = test[i];
if(item.debrisname.includes(thefile)){
ledocument = item.debrispath;
// allpeeps.push(ledocument);
var extension = ledocument.replace(/^.*\./, '');
// var classname = ledocument.substring(ledocument.lastIndexOf('/')+1);
// classname = classname.substr(0, classname.lastIndexOf('.')) || classname;
@ -101,6 +97,7 @@
console.log(ledocument);
// check or unchecked checkbox if classname in array
var checkboite;
if(jQuery.inArray(classname, listofselecteddocs) != -1) {
console.log("is in array");
@ -136,44 +133,107 @@
});
});
///////////CHECKBOXES////////////////
////DISPLAY FILES/////////////
var flag = true;
$("#showall").click(function(event){
if (flag === true) {
$('.file-names-container span').each(function () {
var current = $(this).attr('id');
$.getJSON('{{ url_for('static', filename='js/mergedjson.json') }}', function(test) {
var category = null;
for (var i = 0; i < test.length; ++i) {
var item = test[i];
if(item.debrisname.includes(current)){
actualdocument = item.debrispath;
var extension = actualdocument.replace(/^.*\./, '');
var classname = actualdocument;
// check or unchecked checkbox if classname in array
var checkboite;
if(jQuery.inArray(classname, listofselecteddocs) != -1) {
console.log("is in array");
checkboite = "<br /><input type='checkbox' class='addtoprint' id='"+classname+"' name='"+classname+"' value='print' checked><label for='"+classname+"'> Add to print</label>";
} else {
checkboite = "<br /><input type='checkbox' class='addtoprint' id='"+classname+"' name='"+classname+"' value='print'><label for='"+classname+"'> Add to print</label>";
}
if ((extension=="jpg") || (extension=="jpeg") || (extension=="png") || (extension=="gif") || (extension=="tiff")) {
$(".name-elements").append("<li><img class='listed-images' src='/files/"+actualdocument+"'>"+checkboite+"</li>");
}
else if (extension=="pdf") {
$(".name-elements").append("<li><object class='listed-pdf' data='files/"+actualdocument+"'/>"+checkboite+"</li>");
}
else if (extension=="epub") {
$(".name-elements").append("<li>"+actualdocument+"</li>");
}
else if ((extension=="mp3") || (extension=="wav") || (extension=="m4a")) {
$(".name-elements").append("<li><audio class='listed-audio' controls><source src='files/"+actualdocument+"'></audio>"+checkboite+"</li>");
}
else if ((extension=="mov") || (extension=="mp4")) {
$(".name-elements").append("<li><video class='listed-videos' controls><source src='files/"+actualdocument+"'></video>"+checkboite+"</li>");
}
else if ((extension=="odt") || (extension=="docx")) {
// something for odt and docx
$(".name-elements").append("<li>"+actualdocument+"</li>");
};
};
category = item.method;
};
var listofselecteddocs = [];
$(document.body).on("click", "input[type='checkbox']", function() {
var self=$(this);
if(self.is(":checked")){
theid = self.attr("id");
alert("checkbox id ="+theid +"is checked ");
listofselecteddocs.push(theid);
alert(listofselecteddocs.length);
}else {
theid = self.attr("id");
alert("id = "+theid +"is Unchecked ");
listofselecteddocs = $.grep(listofselecteddocs, function(value) {
return value != theid;
});
alert(listofselecteddocs.length);
});
});
flag = false;
} else {
$(".name-elements").empty();
flag = true;
};
}
});
///////////CHECKBOXES////////////////
var listofselecteddocs = [];
$(document.body).on("click", "input[type='checkbox']", function() {
var self=$(this);
if(self.is(":checked")){
theid = self.attr("id");
alert("checkbox id ="+theid +"is checked ");
listofselecteddocs.push(theid);
alert(listofselecteddocs.length);
}else {
theid = self.attr("id");
alert("id = "+theid +"is Unchecked ");
listofselecteddocs = $.grep(listofselecteddocs, function(value) {
return value != theid;
});
alert(listofselecteddocs.length);
}
});
//THE SENDING OF THE LIST TO PYTHON ///////////////////
$("#listoffiles").click(function(){
console.log(listofselecteddocs)
$.ajax({
type : 'POST',
url : "{{url_for('test')}}",
data : JSON.stringify(listofselecteddocs),
success: function(response){
alert("yesss")
},
contentType: "application/json",
dataType: 'json'
});
});
$("#listoffiles").click(function(){
console.log(listofselecteddocs)
$.ajax({
type : 'POST',
url : "{{url_for('test')}}",
data : JSON.stringify(listofselecteddocs),
success: function(response){
alert("yesss")
},
contentType: "application/json",
dataType: 'json'
});
});
});
@ -239,7 +299,6 @@ $.ajax({
</div>
<div class="main-column-right">
<!--<a href="{{ url_for('static', filename='realjson.json') }}">test link</a>-->
<ul class="name-elements">
</ul>

Loading…
Cancel
Save