Moved project to subfolder because of a cheap hack
This commit is contained in:
@@ -0,0 +1,294 @@
|
||||
function overlay_in() {
|
||||
$('.shadow').css({'display' : 'block'});
|
||||
$('.overlay').css({'display' : 'block'});
|
||||
$('.shadow').animate({'opacity' : 0.7});
|
||||
$('.overlay').animate({'opacity' : 1.0, 'top' : '10%'});
|
||||
}
|
||||
|
||||
function overlay_out() {
|
||||
$('.shadow').animate({'opacity' : 0.0}, function () {
|
||||
$('.overlay').css({'display' : 'none'});
|
||||
});
|
||||
$('.overlay').animate({'opacity' : 0.0, 'top' : '5%'}, function () {
|
||||
$('.shadow').css({'display' : 'none'});
|
||||
});
|
||||
end_edit();
|
||||
}
|
||||
|
||||
function init_edit(partID) {
|
||||
var block_input = $('<input type="text" class="part-edit-input" id="block-input" placeholder="Location">')
|
||||
block_input.val($('#block-info').text());
|
||||
$('#block-info').replaceWith(block_input);
|
||||
|
||||
var type_input = $('<input type="text" class="part-edit-input" id="type-input" placeholder="Manufacturer">')
|
||||
type_input.val($('#type-info').text());
|
||||
$('#type-info').replaceWith(type_input);
|
||||
|
||||
var partno_input = $('<input type="text" class="part-edit-input" id="partno-input" placeholder="Part number">')
|
||||
partno_input.val($('#partno-info').text());
|
||||
$('#partno-info').replaceWith(partno_input);
|
||||
|
||||
var description_input = $('<input type="text" class="part-edit-input" id="description-input" placeholder="Description">')
|
||||
description_input.val($('#description-info').text());
|
||||
$('#description-info').replaceWith(description_input);
|
||||
|
||||
var quantity_input = $('<input type="text" class="part-edit-input" id="quantity-input" placeholder="Quantity">')
|
||||
quantity_input.val($('#quantity-info').text());
|
||||
$('#quantity-info').replaceWith(quantity_input);
|
||||
|
||||
var notes_input = $('<input type="text" class="part-edit-input" id="notes-input" placeholder="Notes">')
|
||||
notes_input.val($('#notes-info').text());
|
||||
$('#notes-info').replaceWith(notes_input);
|
||||
|
||||
var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
|
||||
$('#datasheet-info').replaceWith(datasheet_input);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function new_entry() {
|
||||
$('#block-info').text('');
|
||||
$('#type-info').text('');
|
||||
$('#partno-info').text('');
|
||||
$('#description-info').text('');
|
||||
$('#quantity-info').text('');
|
||||
$('#notes-info').text('');
|
||||
init_edit(-1);
|
||||
overlay_in();
|
||||
}
|
||||
|
||||
function end_edit() {
|
||||
var block_par = '<p id="block-info">' + $('#block-input').val() + '</p>';
|
||||
$('#block-input').replaceWith(block_par);
|
||||
|
||||
var type_par = '<p id="type-info">' + $('#type-input').val() + '</p>';
|
||||
$('#type-input').replaceWith(type_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"><i class="fa fa-circle-o-notch fa-spin fa-fw"></i></p>';
|
||||
$('#datasheet-input').replaceWith(datasheet_par);
|
||||
|
||||
var newButton = '<div class="round-button"><a href="#" id="edit-button"><i class="fa fa-pencil" aria-hidden="true"></i></a></div>';
|
||||
$('.round-button').replaceWith(newButton);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
var partnos = partno_v.split(' ');
|
||||
|
||||
var data = new FormData();
|
||||
|
||||
if (datasheet.length == 1)
|
||||
if(! datasheet[0]['name'].match(/^[\w\-]+\.pdf$/g)) {
|
||||
alert('Invalid filename. Please match /^[\w\-]+\.pdf$/g');
|
||||
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('description', description_v);
|
||||
data.append('quantity', quantity_v);
|
||||
data.append('notes', notes_v);
|
||||
|
||||
$.ajax({
|
||||
// Your server script to process the upload
|
||||
url: 'https://www.elab.kth.se/parts/alter/' + partID,
|
||||
type: 'POST',
|
||||
|
||||
data: data,
|
||||
|
||||
// Tell jQuery not to process data or worry about content-type
|
||||
// You *must* include these options!
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function(data) {
|
||||
var datasheet_par = '<p id="datasheet-info"><i class="fa fa-check"></i></p>';
|
||||
$('#datasheet-info').replaceWith(datasheet_par);
|
||||
},
|
||||
error: function() {
|
||||
alert("Couldn't update the part information. Please retry.");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
end_edit();
|
||||
$('#edit-button').click(function() {
|
||||
init_edit(partID);
|
||||
});
|
||||
}
|
||||
|
||||
function text_filter(string) {
|
||||
if (string != null)
|
||||
return string;
|
||||
else
|
||||
return '';
|
||||
}
|
||||
|
||||
function delete_entry(partID) {
|
||||
if (partID < 0)
|
||||
return;
|
||||
if (!confirm('Delete the selected entry?'))
|
||||
return;
|
||||
$.ajax({
|
||||
url: 'https://www.elab.kth.se/parts/delete/' + partID,
|
||||
type: 'GET',
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function() {
|
||||
overlay_out();
|
||||
perform_query();
|
||||
},
|
||||
fail: function() {
|
||||
console.log('An error occurred while deleting the entry');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function show_part_info(partID) {
|
||||
$.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) {
|
||||
$('#block-info').text(text_filter(data.block));
|
||||
$('#type-info').text(text_filter(data.type));
|
||||
$('#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').html($('<a href="https://www.elab.kth.se/parts/getfile/' + data.datasheet.substring(0, data.datasheet.length - 4) + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>'));
|
||||
else
|
||||
$('#datasheet-info').text(' ');
|
||||
$('#edit-button').click(function() {
|
||||
init_edit(partID);
|
||||
});
|
||||
$('#delete-button').click(function() {
|
||||
delete_entry(partID);
|
||||
});
|
||||
overlay_in();
|
||||
}).fail(function() {
|
||||
console.log( "Fetching part info failed" );
|
||||
});
|
||||
}
|
||||
|
||||
function perform_query() {
|
||||
var query = $('.search-bar').val();
|
||||
var filter = 0;
|
||||
if($('#type').is(':checked'))
|
||||
filter += 1;
|
||||
if($('#partno').is(':checked'))
|
||||
filter += 2 + 4 + 8;
|
||||
if($('#description').is(':checked'))
|
||||
filter += 16;
|
||||
if($('#notes').is(':checked'))
|
||||
filter += 32;
|
||||
$.getJSON('https://www.elab.kth.se/parts/query/' + filter + '/' + query, function(data) {
|
||||
var newResults = $('<div class="results"></div>');
|
||||
for(var i = 0; i < data.length; i++) { // Create new view for results
|
||||
var newRow = $('<div class="results-row"></div>');
|
||||
var newClicker = $('<a href="#" onclick="show_part_info(' + data[i].id + ')"></a>');
|
||||
|
||||
newClicker.append($('<div class="results-block"></div>').text(text_filter(data[i].block)));
|
||||
newClicker.append($('<div class="results-type"></div>').text(text_filter(data[i].type)));
|
||||
newClicker.append($('<div class="results-partno"></div>').text(text_filter(data[i].partno)));
|
||||
newClicker.append($('<div class="results-description"></div>').text(text_filter(data[i].description)));
|
||||
var notes = $('<div class="results-notes"></div>');
|
||||
if (data[i].notes != null && data[i].notes.length > 0) {
|
||||
var icon = $('<i class="fa fa-sticky-note"></i>');
|
||||
var tooltipText = $('<div class="tooltiptext"></div>').text(data[i].notes);
|
||||
var tooltip = $('<div class="tooltip"></div>');
|
||||
tooltip.append(icon, tooltipText);
|
||||
notes.append(tooltip);
|
||||
}
|
||||
newClicker.append(notes);
|
||||
var datasheet = $('<div class="results-datasheet"></div>');
|
||||
if (data[i].datasheet != null)
|
||||
datasheet.html('<a href="https://www.elab.kth.se/parts/getfile/'
|
||||
+ data[i].datasheet.substring(0, data[i].datasheet.length - 4)
|
||||
+ '"><i class="fa fa-file-text" aria-hidden="true"></i></a>');
|
||||
newClicker.append(datasheet);
|
||||
|
||||
newRow.append(newClicker);
|
||||
newResults.append(newRow);
|
||||
}
|
||||
if(data.length == 0) {
|
||||
newResults = '<div class="results">';
|
||||
newResults += '<h3>No results.</h3>';
|
||||
newResults += '</div>';
|
||||
}
|
||||
$('.results').replaceWith(newResults);
|
||||
}).fail(function() {
|
||||
var newResults = '<div class="results">';
|
||||
newResults += '<h3>No results.</h3>';
|
||||
newResults += '</div>';
|
||||
$('.results').replaceWith(newResults);
|
||||
console.log( "Query failed" );
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$.ajaxSetup({ cache: false });
|
||||
$('.search-bar').on('keyup', function() {
|
||||
perform_query();
|
||||
});
|
||||
$('.checkbox').change( function() {
|
||||
if ( !$('#type').is(':checked')
|
||||
&& !$('#partno').is(':checked')
|
||||
&& !$('#description').is(':checked')
|
||||
&& !$('#notes').is(':checked'))
|
||||
$(this).prop('checked', true);
|
||||
else
|
||||
perform_query();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,333 @@
|
||||
html {
|
||||
background-color: #D7E2E2;
|
||||
color: #000F0F;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
padding: 16pt;
|
||||
margin: 0 0 20pt 0;
|
||||
text-align: center;
|
||||
color: #D7E2E2;
|
||||
background-color: #013A3A;
|
||||
}
|
||||
|
||||
h2 {
|
||||
background-color: #013A3A;
|
||||
padding: 12pt 0 12pt 0;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: #5E9292;
|
||||
text-align: center;
|
||||
padding: 12pt;
|
||||
font-size: 20pt;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #000F0F;
|
||||
}
|
||||
|
||||
input[type=text].search-bar {
|
||||
color: #404040;
|
||||
font-size: 20pt;
|
||||
padding: 5pt 8pt 5pt 8pt;
|
||||
margin-top: 8pt;
|
||||
margin-bottom: 8pt;
|
||||
margin-left: 20pt;
|
||||
width: 70%;
|
||||
border: 2pt solid grey;
|
||||
border-radius: 5pt;
|
||||
}
|
||||
|
||||
.search-bar-container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
background-color: #226666;
|
||||
padding: 10pt 15pt 10pt 15pt;
|
||||
margin-top: 10pt;
|
||||
margin-bottom: 10pt;
|
||||
border-radius: 2pt;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.filter-container p {
|
||||
text-align: left;
|
||||
color: #D7E2E2;
|
||||
font-size: 10pt;
|
||||
margin-top: 4pt;
|
||||
margin-left: 16pt;
|
||||
margin-bottom: 4pt;
|
||||
}
|
||||
|
||||
.filter-concontainertainer {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input[type=checkbox]{
|
||||
display: none;
|
||||
}
|
||||
|
||||
input[type=checkbox] + label.toggle-btn {
|
||||
border-radius: 3pt;
|
||||
display: inline-block;
|
||||
padding: 5pt;
|
||||
color: #D7E2E2;
|
||||
margin-top: 6pt;
|
||||
margin-bottom: 6pt;
|
||||
margin-left: 3pt;
|
||||
margin-right: 3pt;
|
||||
width: 100pt;
|
||||
text-align: center;
|
||||
border: 1pt solid #D7E2E2;
|
||||
transition: 0.2s;
|
||||
-webkit-transition: 0.2s;
|
||||
}
|
||||
|
||||
input[type=checkbox]:checked + label.toggle-btn {
|
||||
background-color: #D7E2E2;
|
||||
color: #000F0F;
|
||||
}
|
||||
|
||||
.results {
|
||||
margin-top: 5pt;
|
||||
margin-left: 2pt;
|
||||
margin-right: 2pt;
|
||||
}
|
||||
|
||||
.results-row {
|
||||
padding: 5pt;
|
||||
font-size: 16pt;
|
||||
}
|
||||
|
||||
.results-row:nth-child(2n+1) {
|
||||
background-color: #5E9292;
|
||||
}
|
||||
|
||||
.results-row div {
|
||||
display: inline-block;
|
||||
width: 16.7%;
|
||||
margin-left: 6pt;
|
||||
margin-right: 6pt;
|
||||
}
|
||||
|
||||
.results-row .results-datasheet {
|
||||
width: 5%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.results-row .results-notes {
|
||||
width: 5%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.results-row .results-block {
|
||||
width: 5%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.results-row .results-description {
|
||||
width: 43.5%;
|
||||
}
|
||||
|
||||
div label input {
|
||||
margin-right:100px;
|
||||
}
|
||||
|
||||
.res-header, .res-header-3, .res-header-small {
|
||||
display: inline-block;
|
||||
margin-left: 2pt;
|
||||
background-color: #226666;
|
||||
color: #D7E2E2;
|
||||
padding: 4pt;
|
||||
border-radius: 2pt;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.res-header {
|
||||
width: 16.7%;
|
||||
}
|
||||
|
||||
.res-header-small {
|
||||
width: 5%;
|
||||
}
|
||||
|
||||
.res-header-3 {
|
||||
width: 43.5%;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.tooltip .tooltiptext {
|
||||
font-size: 10pt;
|
||||
visibility: hidden;
|
||||
width: 120px;
|
||||
background-color: black;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
border-radius: 6px;
|
||||
padding: 5px 0;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
top: -5px;
|
||||
right: 105%;
|
||||
margin-left: -60px;
|
||||
|
||||
/* Fade in tooltip - takes 1 second to go from 0% to 100% opac: */
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.tooltip:hover .tooltiptext {
|
||||
visibility: visible;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tooltip .tooltiptext::after {
|
||||
content: " ";
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 100%; /* To the right of the tooltip */
|
||||
margin-top: -5px;
|
||||
border-width: 5px;
|
||||
border-style: solid;
|
||||
border-color: transparent transparent transparent black;
|
||||
}
|
||||
|
||||
.shadow {
|
||||
background-color: black;
|
||||
display: none;
|
||||
height: 100%;
|
||||
left: 0;
|
||||
opacity: 0.0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
background-color: #226666;
|
||||
color: #D7E2E2;
|
||||
display: none;
|
||||
height: 70%;
|
||||
left: 20%;
|
||||
padding: 0;
|
||||
position: fixed;
|
||||
top:5%;
|
||||
width: 60%;
|
||||
z-index: 201;
|
||||
border-radius: 2pt;
|
||||
text-align: center;
|
||||
opacity: 0.0;
|
||||
}
|
||||
|
||||
/*.details-row {
|
||||
padding-top: 10pt;
|
||||
padding-bottom: 10pt;
|
||||
}*/
|
||||
|
||||
.details-item {
|
||||
display: inline-block;
|
||||
width: 25%;
|
||||
padding: 12pt 10pt 12pt 0;
|
||||
text-align: right;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.details-content {
|
||||
display: inline-block;
|
||||
width: 65%;
|
||||
padding-left: 20pt;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.details-content p {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.round-button {
|
||||
position: absolute;
|
||||
bottom: 15pt;
|
||||
right: 15pt;
|
||||
width: 40pt;
|
||||
height: 32pt;
|
||||
border-radius: 20pt;
|
||||
background-color: #5E9292;
|
||||
font-size: 20pt;
|
||||
padding-top: 8pt;
|
||||
box-shadow: 2pt 1pt 8pt black;
|
||||
}
|
||||
|
||||
.round-button-left {
|
||||
position: absolute;
|
||||
bottom: 15pt;
|
||||
right: 70pt;
|
||||
width: 40pt;
|
||||
height: 32pt;
|
||||
border-radius: 20pt;
|
||||
background-color: #5E9292;
|
||||
font-size: 20pt;
|
||||
padding-top: 8pt;
|
||||
box-shadow: 2pt 1pt 8pt black;
|
||||
}
|
||||
|
||||
.round-button a{
|
||||
color: #D7E2E2;
|
||||
}
|
||||
|
||||
.round-button-left a{
|
||||
color: #D7E2E2;
|
||||
}
|
||||
|
||||
.small-square-button {
|
||||
position: absolute;
|
||||
top: 5pt;
|
||||
right: 5pt;
|
||||
padding-right: 5pt;
|
||||
font-size: 16pt;
|
||||
}
|
||||
|
||||
.small-square-button a {
|
||||
color: #D7E2E2;
|
||||
}
|
||||
|
||||
.round-floating-button {
|
||||
position: fixed;
|
||||
bottom: 15pt;
|
||||
right: 15pt;
|
||||
width: 40pt;
|
||||
height: 32pt;
|
||||
border-radius: 20pt;
|
||||
background-color: #5E9292;
|
||||
font-size: 22pt;
|
||||
padding-top: 8pt;
|
||||
box-shadow: 2pt 1pt 8pt black;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.round-floating-button a{
|
||||
color: #D7E2E2;
|
||||
}
|
||||
|
||||
#datasheet-info p {
|
||||
font-size: 12pt;
|
||||
}
|
||||
|
||||
.bottom-spacer {
|
||||
height: 80pt;
|
||||
}
|
||||
Reference in New Issue
Block a user