Locations can now be deleted. I have created you, now I can destroy you!

master
Marek Baczynski 6 years ago
parent 954b449757
commit d1bd2aa0ec

@ -263,6 +263,15 @@ def delete(partID):
r = db_engine.execute(s, id=partID) r = db_engine.execute(s, id=partID)
return '{"status":"ok"}' return '{"status":"ok"}'
@app.route('/parts/deleteLocation/<locationID>')
# @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): def connect(user, password, db, host='localhost', port=5432):
'''Returns a connection and a metadata object''' '''Returns a connection and a metadata object'''
# We connect with the help of the PostgreSQL URL # We connect with the help of the PostgreSQL URL

@ -3,11 +3,12 @@ function new_location_entry() {
} }
function init_Location_edit(locationID, name, containerID) { function init_Location_edit(locationID, name, containerID) {
var newButton = '<div class="round-button-left"><a href="#" onclick="saveLocation(' + locationID + ')"><i class="fa fa-check" aria-hidden="true"></i></a></div>';
$('#save-button').attr("onclick", "saveLocation(" + locationID + ")"); $('#save-button').attr("onclick", "saveLocation(" + locationID + ")");
$('#delete-button').attr("onclick", "deleteLocation(" + locationID + ")");
$('#location-name-input').val(name); $('#location-name-input').val(name);
if(containerID > 0){ if(containerID > 0){
$("#container-input").val(containerID); $("#container-input").val(containerID);
update_map();
} }
overlay_in(); 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(){ function end_edit(){
//intentionally left blank //intentionally left blank
} }

Loading…
Cancel
Save