function init_edit(partID) { $('table#details tr#location td p').hide(); $('table#details tr#location td select').show(); $('table#details tr#partno td p').hide(); $('table#details tr#partno td input').show(); $('table#details tr#description td p').hide(); $('table#details tr#description td input').show(); $('table#details tr#datasheet td input').show(); var datasheet_input = $('') $('#datasheet-info').replaceWith(datasheet_input); var newButton = '
'; $('.round-button-left').replaceWith(newButton); } function new_entry() { $('table#details tr#location td p').text(''); $('table#details tr#partno td p').text(''); $('table#details tr#description td p').text(''); // $('table#details tr#location select').text(''); $('table#details tr#partno td input').text(''); $('table#details tr#description td input').text(''); init_edit(-1); overlay_in(); } function end_edit() { $('table#details tr#location td p').text($('table#details tr#location td select option:checked').text()); $('table#details tr#location td p').show(); $('table#details tr#location td select').hide(); $('table#details tr#partno td p').text($('table#details tr#partno td input').val()); $('table#details tr#partno td p').show(); $('table#details tr#partno td input').hide(); $('table#details tr#description td p').text($('table#details tr#description td input').val()); $('table#details tr#description td p').show(); $('table#details tr#description td input').hide(); $('table#details tr#datasheet td input').hide(); var newButton = ' '; $('.round-button-left').replaceWith(newButton); } function save(partID) { // var block_v = $('#block-input').val(); // var type_v = $('#type-input').val(); var location_id_v = $('table#details tr#location td select').val(); var partno_v = $('table#details tr#partno td input').val(); var description_v = $('table#details tr#description td input').val(); // var quantity_v = $('#quantity-input').val(); // var notes_v = $('#notes-input').val(); var datasheet = $('table#details tr#datasheet td input')[0].files; // if(! partno_v.match(/^([a-zA-Z0-9]{1,20}\s*){1,3}$/g)) { // alert('Invalid part number format. Accepted:'; $('#datasheet-info').replaceWith(datasheet_par); // Fix addressing $('#edit-button').click(function() { init_edit(JSON.parse(data).part_id); }); }, error: function() { alert("Couldn't update the part information. Please retry."); } }); end_edit(); } function text_filter(string) { if (string != null) return string; else return ''; } function delete_entry(partID) { if (partID < 0) return; if (!confirm('Delete the selected entry?')) return; $.ajax({ url: rootURL + '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(rootURL + 'getpartinfo/' + partID, function(data) { $('table#details tr#location td p').text(text_filter(data.name)); // name is the location friendly name $('table#details tr#location td select').val(data.location_id); // name is the location friendly name $('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)); $('img#map').attr('src', 'parts/map/' + data.map); if (data.datasheet != null) $('tr#datasheet-head').html($('