function new_location_entry() { } function init_Location_edit(locationID, name, containerID) { $('#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(); } function update_map() { var selected_map_file = $('#container-input').val(); $('#map').attr('src', 'map/' + selected_map_file); } function saveLocation(locationID) { var container_v = $('#container-input').val(); var name_v = $('#location-name-input').val(); if(name_v.length > 100) { alert('Name too long (max 100 characters).') return; } var data = new FormData(); data.append('container', container_v); data.append('name', name_v) $.ajax({ url: rootURL + 'alterLocation/' + locationID, type: 'POST', data: data, cache: false, contentType: false, processData: false, success: function(data) { alert("k."); }, error: function() { alert("Couldn't update the part information. Please retry."); } }); end_edit(); $('#edit-button').click(function() { init_edit(partID); }); } 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 } function show_location_info(locationID) { $.getJSON(rootURL + 'getpartinfo/' + partID, function(data) { $('table#details tr#location td p').text(text_filter(data.location_descriptor)); // name is the location friendly name $('#location-dropdown').val(data.location_id); $('#container-dropdown').val(data.container_id); $('table#details tr#partno td p').text(text_filter(data.partno)); $('table#details tr#partno td input').val(text_filter(data.partno)); $('table#details tr#description td p').text(text_filter(data.description)); $('table#details tr#description td input').val(text_filter(data.description)); container_onchange(); if (data.datasheet != null) { $('tr#datasheet-head').html($('