From 43c88980f3e66f760dad98e237c9d35eb8d9f439 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Sat, 10 Jun 2017 01:35:34 +0200 Subject: [PATCH] Added delete entry function --- server.py | 6 ++++++ static/script.js | 22 ++++++++++++++++++++++ static/style.css | 13 +++++++++++++ templates/partsearch.html | 1 + 4 files changed, 42 insertions(+) diff --git a/server.py b/server.py index c18cd6d..c649d36 100644 --- a/server.py +++ b/server.py @@ -117,6 +117,12 @@ def alter(partID): return '{"status":"ok"}' +@app.route('/parts/delete/') +def delete(partID): + s = text('delete from parts where id=:id;') + r = db_engine.execute(s, id=partID) + return '{"status":"ok"}' + def connect(user, password, db, host='localhost', port=5432): '''Returns a connection and a metadata object''' # We connect with the help of the PostgreSQL URL diff --git a/static/script.js b/static/script.js index 7aefe19..285e25c 100644 --- a/static/script.js +++ b/static/script.js @@ -173,6 +173,25 @@ function text_filter(string) { return ''; } +function delete_entry(partID) { + if (!confirm('Delete the selected entry?')) + return; + $.ajax({ + url: 'https://www.elab.kth.se/parts/delete/' + partID, + type: 'GET', + cache: false, + contentType: false, + processData: false, + success: function() { + overlay_out(); + perform_query(); + }, + fail: function() { + console.log('An error occurred while deleting the entry'); + }, + }); +} + function show_part_info(partID) { $.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) { $('#block-info').text(text_filter(data.block)); @@ -188,6 +207,9 @@ function show_part_info(partID) { $('#edit-button').click(function() { init_edit(partID); }); + $('#edit-button').click(function() { + delete_entry(partID); + }); overlay_in(); }).fail(function() { console.log( "Fetching part info failed" ); diff --git a/static/style.css b/static/style.css index 9725568..7b22024 100644 --- a/static/style.css +++ b/static/style.css @@ -273,6 +273,19 @@ div label input { box-shadow: 2pt 1pt 8pt black; } +.round-button-left { + position: absolute; + bottom: 15pt; + left: 15pt; + width: 40pt; + height: 32pt; + border-radius: 20pt; + background-color: #5E9292; + font-size: 20pt; + padding-top: 8pt; + box-shadow: 2pt 1pt 8pt black; +} + .round-button a{ color: #D7E2E2; } diff --git a/templates/partsearch.html b/templates/partsearch.html index 6bb2e84..cb9ab19 100644 --- a/templates/partsearch.html +++ b/templates/partsearch.html @@ -77,6 +77,7 @@
+