diff --git a/parts/server.py b/parts/server.py index be123c5..068803f 100644 --- a/parts/server.py +++ b/parts/server.py @@ -263,6 +263,15 @@ def delete(partID): r = db_engine.execute(s, id=partID) return '{"status":"ok"}' +@app.route('/parts/deleteLocation/') +# @requires_auth +def deleteLocation(locationID): + if int(locationID) < 0: + abort(400) + s = text('delete from locations where id=:id;') + r = db_engine.execute(s, id=locationID) + 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/parts/static/locationEditorScript.js b/parts/static/locationEditorScript.js index 4c4bd4e..c8c5c0b 100644 --- a/parts/static/locationEditorScript.js +++ b/parts/static/locationEditorScript.js @@ -3,11 +3,12 @@ function new_location_entry() { } function init_Location_edit(locationID, name, containerID) { - var newButton = '
'; $('#save-button').attr("onclick", "saveLocation(" + locationID + ")"); + $('#delete-button').attr("onclick", "deleteLocation(" + locationID + ")"); $('#location-name-input').val(name); if(containerID > 0){ $("#container-input").val(containerID); + update_map(); } overlay_in(); } @@ -52,6 +53,30 @@ function saveLocation(locationID) { }); } + +function deleteLocation(locationID) { + if (locationID < 0) + alert('Congratulations! You found the secret UI bug easter egg! This button should not be here, yet I left it specifically because I wanted an easter egg and not because of any other reasons! Good for you!') + return; + if (!confirm('Delete the selected location? If there are parts there, this will leave a mess in the database and Marek will be very sad.')) + return; + $.ajax({ + url: rootURL + 'deleteLocation/' + locationID, + type: 'GET', + cache: false, + contentType: false, + processData: false, + success: function() { + alert("location removed."); + overlay_out(); + location.reload(); + }, + fail: function() { + console.log('An error occurred while deleting the entry'); + }, + }); +} + function end_edit(){ //intentionally left blank }