From 5f21bdec7404b96c4d4a69eb3357504acb4fedb2 Mon Sep 17 00:00:00 2001 From: Cristina Cochior Date: Sun, 11 Oct 2020 02:21:01 +0200 Subject: [PATCH] Show All button works now --- templates/layout.html | 137 ++++++++++++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 39 deletions(-) diff --git a/templates/layout.html b/templates/layout.html index ead9aeb..b954228 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -6,9 +6,6 @@ Library - - - @@ -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 = "
"; + } else { + checkboite = "
"; + } + + + if ((extension=="jpg") || (extension=="jpeg") || (extension=="png") || (extension=="gif") || (extension=="tiff")) { + $(".name-elements").append("
  • "+checkboite+"
  • "); + } + else if (extension=="pdf") { + $(".name-elements").append("
  • "+checkboite+""); + } + else if (extension=="epub") { + $(".name-elements").append("
  • "+actualdocument+"
  • "); + } + else if ((extension=="mp3") || (extension=="wav") || (extension=="m4a")) { + $(".name-elements").append("
  • "+checkboite+"
  • "); + } + else if ((extension=="mov") || (extension=="mp4")) { + $(".name-elements").append("
  • "+checkboite+"
  • "); + } + else if ((extension=="odt") || (extension=="docx")) { + // something for odt and docx + $(".name-elements").append("
  • "+actualdocument+"
  • "); + }; + }; + 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({
    -