Modified save command. Added onchange for dropdown list

master
Davide Bongiovanni 6 years ago
parent bd3715888a
commit cf97254ff0

@ -35,12 +35,12 @@ function init_edit(partID) {
}
function new_entry() {
$('table#details tr#location td').text('');
$('table#details tr#partno td').text('');
$('table#details tr#description td').text('');
$('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 input').text('');
$('table#details tr#description input').text('');
$('table#details tr#partno td input').text('');
$('table#details tr#description td input').text('');
init_edit(-1);
overlay_in();
}
@ -62,39 +62,40 @@ function end_edit() {
}
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: <Part-number-line-1(max 20 chars)> <Part-number-line-2(max 20 chars)> <Part-number-line-3(max 20 chars)>');
return;
}
if(! block_v.match(/^[0-9]+$/g)) {
alert('Invalid location field. Only numbers accepted.');
return;
}
if(type_v.length > 25) {
alert('Manufacturer name too long (max 25 characters).')
return;
}
// 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: <Part-number-line-1(max 20 chars)> <Part-number-line-2(max 20 chars)> <Part-number-line-3(max 20 chars)>');
// return;
// }
// if(! block_v.match(/^[0-9]+$/g)) {
// alert('Invalid location field. Only numbers accepted.');
// return;
// }
// if(type_v.length > 25) {
// alert('Manufacturer name too long (max 25 characters).')
// return;
// }
if(description_v.length > 200) {
alert('Description too long (max 200 characters).')
return;
}
if(quantity_v.length > 10) {
alert('Quantity info too long (max 10 characters).')
return;
}
if(notes_v.length > 200) {
alert('Notes too long (max 200 characters).')
return;
}
// if(quantity_v.length > 10) {
// alert('Quantity info too long (max 10 characters).')
// return;
// }
// if(notes_v.length > 200) {
// alert('Notes too long (max 200 characters).')
// return;
// }
var partnos = partno_v.split(' ');
// var partnos = partno_v.split(' ');
var data = new FormData();
@ -104,20 +105,21 @@ function save(partID) {
return;
}
data.append('datasheet-file', datasheet[0]);
data.append('block', block_v);
data.append('type', type_v);
data.append('partno', partnos[0]);
if (partnos.length > 1)
data.append('partnoalt', partnos[1]);
else
data.append('partnoalt', '');
if(partnos.length > 2)
data.append('partnoalt2', partnos[2]);
else
data.append('partnoalt2', '');
// data.append('block', block_v);
// data.append('type', type_v);
data.append('partno', partno_v);
data.append('location_id', location_id_v)
// if (partnos.length > 1)
// data.append('partnoalt', partnos[1]);
// else
// data.append('partnoalt', '');
// if(partnos.length > 2)
// data.append('partnoalt2', partnos[2]);
// else
// data.append('partnoalt2', '');
data.append('description', description_v);
data.append('quantity', quantity_v);
data.append('notes', notes_v);
// data.append('quantity', quantity_v);
// data.append('notes', notes_v);
$.ajax({
// Your server script to process the upload
@ -232,8 +234,15 @@ function perform_query() {
});
}
function update_map() {
var selected_id = $('table#details tr#location td select').val();
$.ajax('parts/getlocationURL/' + selected_id).done( function(data) {
$('img#map').attr('src', 'parts/map/' + data);
});
}
$(document).ready(function() {
$.getJSON('http://127.0.0.1:5000/parts/getlocations', function(data){
$.getJSON('parts/getlocations', function(data){
$.each(data, function(i, val) {
$('table#details tr#location td select').append('<option value="' + i + '">' + val + '</option>');
});

Loading…
Cancel
Save