function overlay_in() { $('.shadow').css({'display' : 'block'}); $('.overlay').css({'display' : 'block'}); $('.shadow').animate({'opacity' : 0.7}); $('.overlay').animate({'opacity' : 1.0, 'top' : '10%'}); } function overlay_out() { $('.shadow').animate({'opacity' : 0.0}, function () { $('.overlay').css({'display' : 'none'}); }); $('.overlay').animate({'opacity' : 0.0, 'top' : '5%'}, function () { $('.shadow').css({'display' : 'none'}); }); end_edit(); } function init_edit(partID) { var block_input = $('') block_input.val($('#block-info').text()); $('#block-info').replaceWith(block_input); var type_input = $('') type_input.val($('#type-info').text()); $('#type-info').replaceWith(type_input); var partno_input = $('') partno_input.val($('#partno-info').text()); $('#partno-info').replaceWith(partno_input); var description_input = $('') description_input.val($('#description-info').text()); $('#description-info').replaceWith(description_input); var quantity_input = $('') quantity_input.val($('#quantity-info').text()); $('#quantity-info').replaceWith(quantity_input); var notes_input = $('') notes_input.val($('#notes-info').text()); $('#notes-info').replaceWith(notes_input); var datasheet_input = $('') $('#datasheet-info').replaceWith(datasheet_input); var newButton = '
'; $('.round-button').replaceWith(newButton); } function new_entry() { $('#block-info').text(''); $('#type-info').text(''); $('#partno-info').text(''); $('#description-info').text(''); $('#quantity-info').text(''); $('#notes-info').text(''); init_edit(-1); overlay_in(); } function end_edit() { var block_par = '' + $('#block-input').val() + '
'; $('#block-input').replaceWith(block_par); var type_par = '' + $('#type-input').val() + '
'; $('#type-input').replaceWith(type_par); var partno_par = '' + $('#partno-input').val() + '
'; $('#partno-input').replaceWith(partno_par); var description_par = '' + $('#description-input').val() + '
'; $('#description-input').replaceWith(description_par); var quantity_par = '' + $('#quantity-input').val() + '
'; $('#quantity-input').replaceWith(quantity_par); var notes_par = '' + $('#notes-input').val() + '
'; $('#notes-input').replaceWith(notes_par); var datasheet_par = ''; $('#datasheet-input').replaceWith(datasheet_par); var newButton = ' '; $('.round-button').replaceWith(newButton); } function save(partID) { var block_v = $('#block-input').val(); var type_v = $('#type-input').val(); var partno_v = $('#partno-input').val(); var description_v = $('#description-input').val(); var quantity_v = $('#quantity-input').val(); var notes_v = $('#notes-input').val(); var datasheet = $('#datasheet-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); }, error: function() { alert("Couldn't update the part information. Please retry."); } }); end_edit(); $('#edit-button').click(function() { init_edit(partID); }); } 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: '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)); $('#type-info').text(text_filter(data.type)); $('#partno-info').text(text_filter(data.partno) + ' ' + text_filter(data.partnoalt) + ' ' + text_filter(data.partnoalt2)); $('#description-info').text(text_filter(data.description)); $('#quantity-info').text(text_filter(data.quantity)); $('#notes-info').text(text_filter(data.notes)); if (data.datasheet != null) $('#datasheet-info').append($('')); else $('#datasheet-info').text(' '); $('#edit-button').click(function() { init_edit(partID); }); $('#delete-button').click(function() { delete_entry(partID); }); overlay_in(); }).fail(function() { console.log( "Fetching part info failed" ); }); } function perform_query() { var query = $('.search-bar').val(); var filter = 0; if($('#type').is(':checked')) filter += 1; if($('#partno').is(':checked')) filter += 2 + 4 + 8; if($('#description').is(':checked')) filter += 16; if($('#notes').is(':checked')) filter += 32; $.getJSON('https://www.elab.kth.se/parts/query/' + filter + '/' + query, function(data) { var newResults = $(''); for(var i = 0; i < data.length; i++) { // Create new view for results var newRow = $(''); var newClicker = $(''); newClicker.append($('').text(text_filter(data[i].block))); newClicker.append($('').text(text_filter(data[i].type))); newClicker.append($('').text(text_filter(data[i].partno))); newClicker.append($('').text(text_filter(data[i].description))); var notes = $(''); if (data[i].notes != null && data[i].notes.length > 0) { var icon = $(''); var tooltipText = $('').text(data[i].notes); var tooltip = $(''); tooltip.append(icon, tooltipText); notes.append(tooltip); } newClicker.append(notes); var datasheet = $(''); if (data[i].datasheet != null) datasheet.html(''); newClicker.append(datasheet); newRow.append(newClicker); newResults.append(newRow); } if(data.length == 0) { newResults = '