From 4a3383155498bfc45104bbf79453bf382e7b6108 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 6 Jun 2017 15:09:33 +0200 Subject: [PATCH] Fixed part info view --- static/script.js | 66 +++++++++++++++++++++++++++++++-------- templates/partsearch.html | 4 +-- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/static/script.js b/static/script.js index 9d7d965..9f5660b 100644 --- a/static/script.js +++ b/static/script.js @@ -35,7 +35,7 @@ function init_edit() { notes_input.val($('#notes-info').text()); $('#notes-info').replaceWith(notes_input); - var datasheet_input = $('') + var datasheet_input = $('') datasheet_input.val($('#datasheet-info').text()); $('#datasheet-info').replaceWith(datasheet_input); @@ -43,12 +43,59 @@ function init_edit() { $('.round-button').replaceWith(newButton); } -function save() { +function end_edit() { + var block_par = '

' + $('#block-input').val() + '

'; + $('#block-input').replaceWith(block_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 = '

Please reload part info.

'; + $('#datasheet-input').replaceWith(datasheet_par); + var newButton = '
'; - console.log('pls add init edit code') $('.round-button').replaceWith(newButton); } +function save() { + console.log('pls add init edit code'); + end_edit(); +} + +function text_filter(string) { + if (string != null) + return string; + else + return ''; +} + +function show_part_info(partID) { + //var partID = $(this).attr('part-id'); + $.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) { + $('#block-info').text(text_filter(data.block)); + $('#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').text(''); + else + $('#datasheet-info').text(' '); + overlay_in(); + }).fail(function() { + console.log( "Fetching part info failed" ); + }); +} + $(document).ready(function() { $('.search-bar').on('keyup', function() { var query = $('.search-bar').val(); @@ -64,8 +111,8 @@ $(document).ready(function() { $.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 - newResults += '