diff --git a/static/script.js b/static/script.js
index 7e721a0..bd80d9a 100644
--- a/static/script.js
+++ b/static/script.js
@@ -188,77 +188,103 @@ function show_part_info(partID) {
});
}
+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 = $('
');
+ for(var i = 0; i < data.length; i++) { // Create new view for results
+ var newRow = $('');
+ var newClicker = $('');
+
+ newClicker.append($('').text(text_filter(data[i].block)));
+ newClicker.append($('').text(text_filter(data[i].type)));
+ newClicker.append($('').text(text_filter(data[i].partno)));
+ newClicker.append($('').text(text_filter(data[i].description)));
+ var notes = $('');
+ if (data[i].notes != null && data[i].notes.length > 0) {
+ var icon = $('');
+ var tooltipText = $('');
+ tooltip.append(icon, tooltipText);
+ notes.append(tooltip);
+ }
+ newClicker.append(notes);
+ newClicker.append($('')
+ .html(''));
+
+ newRow.append(newClicker);
+ newResults.append(newRow);
+ /*newResults += '';
+ if (data[i].datasheet != null)
+ newResults += '
';
+ newResults += '
';*/
+
+
+ //newResults += '';
+ }
+ //newResults += '';
+ if(data.length == 0) {
+ newResults = '';
+ newResults += '
No results.
';
+ newResults += '';
+ }
+ $('.results').replaceWith(newResults);
+ }).fail(function() {
+ var newResults = '';
+ newResults += '
No results.
';
+ newResults += '';
+ $('.results').replaceWith(newResults);
+ console.log( "Query failed" );
+ });
+}
+
$(document).ready(function() {
$.ajaxSetup({ cache: false });
$('.search-bar').on('keyup', function() {
- 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 = '';
- for(var i = 0; i < data.length; i++) { // Create new view for results
- newResults += '
';
- }
- newResults += '
';
- if(data.length == 0) {
- newResults = '';
- newResults += '
No results.
';
- newResults += '';
- }
- $('.results').replaceWith(newResults);
- }).fail(function() {
- var newResults = '';
- newResults += '
No results.
';
- newResults += '';
- $('.results').replaceWith(newResults);
- console.log( "Query failed" );
- });
+ perform_query();
});
-
$('.toggle-btn').on('change', function() {
- // Re-perform query
+ perform_query();
});
-
- //$('.results-row').on('click', );
});