|
|
@ -12,9 +12,10 @@ function overlay_out() {
|
|
|
|
$('.overlay').animate({'top' : '-70%'}, function () {
|
|
|
|
$('.overlay').animate({'top' : '-70%'}, function () {
|
|
|
|
$('.shadow').css({'display' : 'none'});
|
|
|
|
$('.shadow').css({'display' : 'none'});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
end_edit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function init_edit() {
|
|
|
|
function init_edit(partID) {
|
|
|
|
var block_input = $('<input type="text" class="part-edit-input" id="block-input" placeholder="Location">')
|
|
|
|
var block_input = $('<input type="text" class="part-edit-input" id="block-input" placeholder="Location">')
|
|
|
|
block_input.val($('#block-info').text());
|
|
|
|
block_input.val($('#block-info').text());
|
|
|
|
$('#block-info').replaceWith(block_input);
|
|
|
|
$('#block-info').replaceWith(block_input);
|
|
|
@ -38,10 +39,20 @@ function init_edit() {
|
|
|
|
var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
|
|
|
|
var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
|
|
|
|
$('#datasheet-info').replaceWith(datasheet_input);
|
|
|
|
$('#datasheet-info').replaceWith(datasheet_input);
|
|
|
|
|
|
|
|
|
|
|
|
var newButton = '<div class="round-button"><a href="#" onclick="save()"><i class="fa fa-check" aria-hidden="true"></i></a></div>';
|
|
|
|
var newButton = '<div class="round-button"><a href="#" onclick="save(' + partID + ')"><i class="fa fa-check" aria-hidden="true"></i></a></div>';
|
|
|
|
$('.round-button').replaceWith(newButton);
|
|
|
|
$('.round-button').replaceWith(newButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function new_entry() {
|
|
|
|
|
|
|
|
$('#block-info').text('');
|
|
|
|
|
|
|
|
$('#partno-info').text('');
|
|
|
|
|
|
|
|
$('#description-info').text('');
|
|
|
|
|
|
|
|
$('#quantity-info').text('');
|
|
|
|
|
|
|
|
$('#notes-info').text('');
|
|
|
|
|
|
|
|
init_edit(-1);
|
|
|
|
|
|
|
|
overlay_in();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function end_edit() {
|
|
|
|
function end_edit() {
|
|
|
|
var block_par = '<p id="block-info">' + $('#block-input').val() + '</p>';
|
|
|
|
var block_par = '<p id="block-info">' + $('#block-input').val() + '</p>';
|
|
|
|
$('#block-input').replaceWith(block_par);
|
|
|
|
$('#block-input').replaceWith(block_par);
|
|
|
@ -58,15 +69,66 @@ function end_edit() {
|
|
|
|
var notes_par = '<p id="notes-info">' + $('#notes-input').val() + '</p>';
|
|
|
|
var notes_par = '<p id="notes-info">' + $('#notes-input').val() + '</p>';
|
|
|
|
$('#notes-input').replaceWith(notes_par);
|
|
|
|
$('#notes-input').replaceWith(notes_par);
|
|
|
|
|
|
|
|
|
|
|
|
var datasheet_par = '<p id="datasheet-info">Please reload part info.</p>';
|
|
|
|
var datasheet_par = '<p id="datasheet-info"><i class="fa fa-circle-o-notch fa-spin fa-fw"></i></p>';
|
|
|
|
$('#datasheet-input').replaceWith(datasheet_par);
|
|
|
|
$('#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>';
|
|
|
|
var newButton = '<div class="round-button"><a href="#" onclick="init_edit()"><i class="fa fa-pencil" aria-hidden="true"></i></a></div>';
|
|
|
|
$('.round-button').replaceWith(newButton);
|
|
|
|
$('.round-button').replaceWith(newButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function save() {
|
|
|
|
function save(partID) {
|
|
|
|
console.log('pls add init edit code');
|
|
|
|
var block_v = $('#block-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.match(/^([a-zA-Z0-9]+\s*){1,3}$/g)) {
|
|
|
|
|
|
|
|
alert('Invalid part number format. Accepted: <Part-number-line-1> <Part-number-line-2> <Part-number-line-3>');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(! block.match(/^[0-9]+$/g)) {
|
|
|
|
|
|
|
|
alert('Invalid location field. Only numbers accepted.');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
partnos = partno_v.split(' ');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (datasheet.length == 1) {
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
|
|
|
// Your server script to process the upload
|
|
|
|
|
|
|
|
url: 'https://www.elab.kth.se/parts/alter/' + partID,
|
|
|
|
|
|
|
|
type: 'POST',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
file: datasheet[0],
|
|
|
|
|
|
|
|
block: block_v,
|
|
|
|
|
|
|
|
partno: partnos[0],
|
|
|
|
|
|
|
|
partnoalt: partnos[1],
|
|
|
|
|
|
|
|
partnoalt2: partnos[2],
|
|
|
|
|
|
|
|
description: description_v,
|
|
|
|
|
|
|
|
quantity: quantity_v,
|
|
|
|
|
|
|
|
notes: notes_v
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tell jQuery not to process data or worry about content-type
|
|
|
|
|
|
|
|
// You *must* include these options!
|
|
|
|
|
|
|
|
cache: false,
|
|
|
|
|
|
|
|
contentType: false,
|
|
|
|
|
|
|
|
processData: false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Custom XMLHttpRequest
|
|
|
|
|
|
|
|
xhr: function() {
|
|
|
|
|
|
|
|
var xhr = $.ajaxSettings.xhr();
|
|
|
|
|
|
|
|
xhr.upload.onload = function(){
|
|
|
|
|
|
|
|
var datasheet_par = '<p id="datasheet-info"><i class="fa fa-check"></i></p>';
|
|
|
|
|
|
|
|
$('#datasheet-info').replaceWith(datasheet_par);
|
|
|
|
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return xhr;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
end_edit();
|
|
|
|
end_edit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|