diff --git a/deletelink.py b/deletelink.py index 2d8a04bc19cf1432c8bbec87624e7c1e16bc6289..b68b155fa737ff99dd123b03ecd1d506c028d282 100644 --- a/deletelink.py +++ b/deletelink.py @@ -14,7 +14,7 @@ def deleteLink(request, s): cursor = conn.cursor() try: cursor.execute('DELETE FROM WEB_URL WHERE SHORT_URL=? AND USERNAME=?', [linkToDelete, userID]) #Delete the entrie - return redirect('/user/links') #redirect the user back to the table. + return "OK" #response is only for ajax request except: abort(500) diff --git a/templates/editEntries.html b/templates/editEntries.html index 404ad1363b371d2e2ceb061dd46baf8139036a4d..b08740a0b5428939d7c23015cc886c20cc823ade 100644 --- a/templates/editEntries.html +++ b/templates/editEntries.html @@ -41,6 +41,20 @@ }); } + + function deleteLink(link, elementId) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + var element = document.getElementById(elementId); + element.parentNode.removeChild(element); + }else if(this.readyState == 4) { + alert("error deleting link") + } + }; + xhttp.open("GET", link, true); + xhttp.send(); + } </script> </body> </html> \ No newline at end of file diff --git a/userprofile.py b/userprofile.py index 216f0263c9d38b5e1705afc23e76c345e5501037..d4f67379a075ef40c6290c9fd83563cb224266d3 100644 --- a/userprofile.py +++ b/userprofile.py @@ -25,13 +25,15 @@ def userProfile(request, cookieNotice, s, pageNumber, url_scheme): try: entriesList = res.fetchall() lenEntries = len(entriesList) + idCounter = 0 for entries in entriesList[offset:][:25]: #for every entrie in the database add a line to the table cursor2 = conn.cursor() try: calls = str(cursor2.execute('SELECT CALLS FROM ANALYTICS WHERE SHORT_URL=?', [entries[1]]).fetchone()[0]) except: calls = "0" - response = response + "<tr>\n<td>" + entries[0] + "</td>\n<td><a href=\"" + url_scheme + "://" + entries[1] + '">' + entries[1] + '</a></td>\n<td>' + calls + '</td>\n<td><a id="red" href="/user/delete?link=' + escape(entries[1]) + '">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n' + response = response + "<tr id=tr_" + str(idCounter) + ">\n<td>" + entries[0] + "</td>\n<td><a href=\"" + url_scheme + "://" + entries[1] + '">' + entries[1] + '</a></td>\n<td>' + calls + '</td>\n<td><a id="red" href="javascript:deleteLink(\'/user/delete?link=' + escape(entries[1]) + '\',\'tr_' + str(idCounter) + '\')">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n' + idCounter=idCounter+1 response = response + "</table>" #Close the table if(len(entriesList) == 0): response = 'you have no shorten links.' #If user has no shorten links make this message