Fixed part info view

pull/3/head
Davide Bongiovanni 8 years ago
parent 40a267f4d1
commit 4a33831554

@ -35,7 +35,7 @@ function init_edit() {
notes_input.val($('#notes-info').text());
$('#notes-info').replaceWith(notes_input);
var datasheet_input = $('<input type="text" class="part-edit-input" id="datasheet-input" placeholder="Datasheet">')
var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
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 = '<p id="block-info">' + $('#block-input').val() + '</p>';
$('#block-input').replaceWith(block_par);
var partno_par = '<p id="partno-info">' + $('#partno-input').val() + '</p>';
$('#partno-input').replaceWith(partno_par);
var description_par = '<p id="description-info">' + $('#description-input').val() + '</p>';
$('#description-input').replaceWith(description_par);
var quantity_par = '<p id="quantity-info">' + $('#quantity-input').val() + '</p>';
$('#quantity-input').replaceWith(quantity_par);
var notes_par = '<p id="notes-info">' + $('#notes-input').val() + '</p>';
$('#notes-input').replaceWith(notes_par);
var datasheet_par = '<p id="datasheet-info">Please reload part info.</p>';
$('#datasheet-input').replaceWith(datasheet_par);
var newButton = '<div class="round-button"><a href="#" onclick="init_edit()"><i class="fa fa-pencil" aria-hidden="true"></i></a></div>';
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('<a href="https://www.elab.kth.se/parts/getfile/' + data.datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>');
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 = '<div class="results">';
for(var i = 0; i < data.length; i++) { // Create new view for results
newResults += '<div class="results-row" part-id="' + data[i].id + '">';
newResults += '<a href=#>'
newResults += '<div class="results-row">';
newResults += '<a href=# onclick="show_part_info(' + data[i].id + ')">'
newResults += '<div class="results-block">';
if (data[i].block != null)
@ -107,12 +154,5 @@ $(document).ready(function() {
});
});
$('.results-row').on('click', function() {
var partID = $(this).attr('part-id');
$.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) {
// TODO: Fill stuff with the fetched info
}).fail(function() {
console.log( "Fetching part info failed" );
});
});
//$('.results-row').on('click', );
});

@ -39,8 +39,8 @@
<h2>Part Details</h2>
<div class="details-row">
<div class="details-item">Location</div>
<div class="details-content"><p id="block-info">Block 1</p></div>
<div class="details-item">Location: block</div>
<div class="details-content"><p id="block-info">1</p></div>
</div>
<div class="details-row">

Loading…
Cancel
Save