2 <& /util/import_javascript.mas, classes => [ 'jquery', 'jquery.dataTables', 'jquery.dataTables-buttons-min', 'jszip-min', 'buttons.bootstrap-min', 'buttons.html5-min' ], &>
4 <div class="container-fluid">
6 <& /page/page_title.mas, title=>'Bulk Search' &>
8 <p>The Bulk Search will check a list of data items if they exist in the database for the specified data type.<p>
12 <!-- QUERY SECTION -->
13 <div id="bulk_search_query">
17 <select id="bulk_search_type" class="form-control" disabled>
18 <option>Loading...</option>
25 <p>Enter the names of the data items (one per line)</p>
27 <textarea id="bulk_search_items" class="form-control" rows="25"></textarea>
31 <button id="bulk_search_start" class="btn btn-primary btn-block">Search</button>
36 <!-- RESULTS SECTION -->
37 <div id="bulk_search_results" style="display: none">
39 <h3>Existing Items</h3>
41 <table id="bulk_search_existing" class="table table-striped table-hover">
49 <h3>Missing Items</h3>
51 <table id="bulk_search_missing" class="table table-striped table-hover">
59 <button id="bulk_search_back" class="btn btn-primary btn-block"><span class="glyphicon glyphicon-chevron-left"></span> Back to Search</button>
68 <script type="text/javascript">
69 jQuery(document).ready(function() {
71 // Get the supported data types
75 jQuery('#bulk_search_start').click(bulkSearch);
76 jQuery('#bulk_search_back').click(toggleSections);
79 jQuery('#bulk_search_existing').DataTable({
83 columns: [{ title: "Name" }],
87 title: 'existing_items'
91 title: 'existing_items'
95 jQuery('#bulk_search_missing').DataTable({
99 columns: [{ title: "Name" }],
102 extend: 'excelHtml5',
103 title: 'missing_items'
107 title: 'missing_items'
116 * Get the supported data types
117 * Update the select box with the data types
119 function updateDataTypes() {
120 let urlParams = new URLSearchParams(window.location.search);
121 let type_name = urlParams.get('type');
122 let type_id = urlParams.get('type_id');
125 url: '/list/alltypes',
126 success: function(data) {
127 if ( data && data.length > 0 ) {
129 data.sort((a,b) => a[1].toUpperCase().localeCompare(b[1].toUpperCase()));
130 for ( let i = 0; i < data.length; i++ ) {
132 let name = data[i][1];
133 let selected = parseInt(id) === parseInt(type_id) || name === type_name ? 'selected' : '';
134 html += "<option value='" + id + "' " + selected + ">" + name + "</option>";
136 jQuery('#bulk_search_type').html(html).attr('disabled', false);
140 alert("Could not get supported data types!");
147 * Perform the bulk search
148 * call displayResults() when complete
150 function bulkSearch() {
151 let type_id = jQuery('#bulk_search_type').val();
152 let type_name = jQuery("#bulk_search_type option:selected").text();
153 let names = jQuery('#bulk_search_items').val().split('\n');
154 names = names.filter(function(str) {
155 return /\S/.test(str);
158 jQuery('#bulk_search_start').html('Searching...').attr('disabled', true);
161 url: "/list/validate/temp",
165 "items": JSON.stringify(names),
167 success: function(data) {
168 jQuery('#bulk_search_start').html('Search').attr('disabled', false);
169 displayResults(data);
172 alert("Could not run bulk search!");
173 jQuery('#bulk_search_start').html('Search').attr('disabled', false);
180 * Display the results of the bulk search
181 * @param {Object} data JSON response from server
183 function displayResults(data) {
184 let dte = jQuery('#bulk_search_existing').DataTable();
185 let dtm = jQuery('#bulk_search_missing').DataTable();
193 else if ( data.existing && data.missing ) {
195 while(data.existing.length) e.push(data.existing.splice(0,1));
197 while(data.missing.length) m.push(data.missing.splice(0,1));
203 alert("Invalid response from the server!");
213 * Toggle the display of the query and results sections
215 function toggleSections() {
216 jQuery('#bulk_search_query').toggle();
217 jQuery('#bulk_search_results').toggle();