From 9fd6491c96a13a28aa0d55ad6702ad2f4e3b000e Mon Sep 17 00:00:00 2001 From: assar Date: Tue, 6 Jun 2017 16:24:29 +0000 Subject: [PATCH] Added save function --- static/script.js | 58 +++++++++++++++++++++++++++++++++++++++++++++--- static/style.css | 4 ++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/static/script.js b/static/script.js index aaebfda..9d8292f 100644 --- a/static/script.js +++ b/static/script.js @@ -12,6 +12,7 @@ function overlay_out() { $('.overlay').animate({'top' : '-70%'}, function () { $('.shadow').css({'display' : 'none'}); }); + end_edit(); } function init_edit() { @@ -58,15 +59,66 @@ function end_edit() { var notes_par = '

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

'; $('#notes-input').replaceWith(notes_par); - var datasheet_par = '

Please reload part info.

'; + var datasheet_par = '

'; $('#datasheet-input').replaceWith(datasheet_par); var newButton = '
'; $('.round-button').replaceWith(newButton); } -function save() { - console.log('pls add init edit code'); +function save(partID) { + 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: '); + 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 = '

'; + $('#datasheet-info').replaceWith(datasheet_par); + } ; + return xhr; + }, + }); + } + end_edit(); } diff --git a/static/style.css b/static/style.css index 2939b0e..ab9b799 100644 --- a/static/style.css +++ b/static/style.css @@ -299,3 +299,7 @@ div label input { .round-floating-button a{ color: #D7E2E2; } + +#datasheet-info p { + font-size: 12pt; +}