removing from saved

This commit is contained in:
Sriram Hariharan
2018-07-13 16:35:52 -05:00
parent ffd84bbb69
commit 05c9aa9005
6 changed files with 74 additions and 28 deletions

View File

@@ -36,7 +36,7 @@ chrome.storage.sync.get('savedCourses', function(data) {
var department = courses[i].coursename.substring(0,courses[i].coursename.search(/\d/)-2);
var course_nbr = courses[i].coursename.substring(courses[i].coursename.search(/\d/),courses[i].coursename.indexOf(" ",courses[i].coursename.search(/\d/)));
var profname = courses[i].profname.substring(0,1)+courses[i].profname.substring(1).toLowerCase();
var listhtml = "<li id='"+i+"'style='padding: 0px 5px 5px 5px; overflow-y: auto;max-height:400px;'><div class='card'><div class='container' style='background:"+color+"''><h4 style='color:white; margin:5px; font-size:large;'><b>"+department + " "+course_nbr+"<span style='font-size:medium'>"+" with </span><span style='font-size:medium'>"+profname+" ("+courses[i].unique+")"+"</span></b></h4></div></div><p style='display: none;font-weight:bold;padding:10px;font-size:small;background-color:#FFCDD2;'>"+makeLine(i)+"</p></li>";
var listhtml = "<li id='"+i+"'style='padding: 0px 5px 5px 5px; overflow-y: auto;max-height:400px;'><div class='card'><div class='container' style='background:"+color+"''><h4 class='truncate' style='color:white;margin:5px; font-size:large;'><b>"+department + " "+course_nbr+"<span style='font-size:medium'>"+" with </span><span style='font-size:medium'>"+profname+" ("+courses[i].unique+")"+"</span></b></h4></div></div><div id='moreInfo' style='display: none;'><p style='font-weight:bold;padding:10px;margin:0px;font-size:small;background-color:#FFCDD2;'>"+makeLine(i)+"</p><div id='infoButtons' style='border-radius:0px;'><button class='matbut' id='listRemove'style='float:right;background:#F44336; margin:5px;'>Remove</button><button class='matbut' id='listMoreInfo' style='float:right;background:#2196F3; margin:5px;'>More Info</button></div></div></li>";
$("#courseList").append(listhtml);
}
});
@@ -47,20 +47,53 @@ function getSimpleName(coursename, unique){
return department+" "+course_nbr+" ("+unique+")";
}
function updateConflicts(){
chrome.runtime.sendMessage({command: "checkConflicts"}, function(response) {
var isConflicted = [];
if(response.isConflict){
var between = response.between;
var text = "";
for(var i = 0; i<between.length;i++){
text+="Conflict between: "+ getSimpleName(between[i][0].coursename,between[i][0].unique) + " and "+getSimpleName(between[i][1].coursename,between[i][1].unique);
isConflicted.push(between[i][0].unique);
isConflicted.push(between[i][1].unique);
if(i != between.length-1){
text+= "<br>";
}
}
$("#courseList").prepend("<p style='font-size:small; font-weight:bold; color:red; margin:5px;'>"+text+"</>");
}
});
}
$(document).ready(function() {
$("#clear").click(function(){
clear();
});
$("#courseList li").click(function(){
//makeLine($(this).attr("id"));
if($(this).find("p").is(":hidden")){
$(this).find("p").fadeIn(200);
//GACKY FIX
$(this).find("#listMoreInfo").click(function(){
window.open(courses[$(this).closest("li").attr("id")].link);
});
$(this).find("#listRemove").click(function(){
var thisForm = this;
chrome.runtime.sendMessage({command: "courseStorage",course: courses[$(thisForm).closest("li").attr("id")], action:"remove"}, function(response) {
$(thisForm).closest("li").fadeOut(200);
console.log($(thisForm).closest("ul").children(":visible").length);
$(thisForm).closest("ul").find("> p").remove();
if($(thisForm).closest("ul").children(':visible').length===1){
$("#empty").fadeIn(200);
}
updateConflicts();
});
});
if($(this).find("#moreInfo").is(":hidden")){
$(this).find("#moreInfo").fadeIn(200);
//alert("hello");
}
else{
$(this).find("p").fadeOut(200);
$(this).find("#moreInfo").fadeOut(200);
}
// window.open(courses[$(this).attr("id")].link);
});
});
@@ -100,10 +133,7 @@ function clear(){
chrome.storage.sync.set({savedCourses: []});
console.log("cleared");
$("#courseList").fadeOut(300,function(){
$("#empty").show();
$("#empty").fadeIn(200);
});
}
function update(){
}