1jQuery(document).ready(function($) { 2 var ctx = document.getElementById("form-halotype-report-result"); 3 // declare var for icon 4 5 if (typeof ctx !== 'undefined' && ctx !== null) { 6 callBackSavedToken(showHaplotypeDataTable, $); 7 } 8 9 jQuery('.more-columns-button').click(function(event) { 10 jQuery('#form-halotype-report-result .dt-button.buttons-columnVisibility').click(function() { 11 let haplotypeColumns = { 12 checked_arr : [], 13 unchecked_arr : [] 14 } 15 $.each($('#form-halotype-report-result .dt-button.buttons-columnVisibility'), function (key, value) { 16 if(value.className.includes('active')) { 17 haplotypeColumns.checked_arr.push(key); 18 } 19 else 20 { 21 haplotypeColumns.unchecked_arr.push(key); 22 } 23 }); 24 setHalotypeColumns(haplotypeColumns); 25 }); 26 }); 27}); 28 29function showHaplotypeDataTable($) { 30 var iconHalotypeCheckbull = '<div class="div-tooltip">' + '<img class="style-guide-img" src="./../themes/datagene/images/checkbull.png">' + 31 '<span class="cd-tooltiptext cd-top-tooltip" style="left:-40px; min-width:110px;">Tested Free</span>' + 32 "</div>"; 33 var iconHalotypeCarrier = '<div class="div-tooltip">' + '<img class="style-guide-img" src="./../themes/datagene/images/carrier.png">' + 34 '<span class="cd-tooltiptext cd-top-tooltip" style="left:-20px">Carrier</span>' + 35 "</div>"; 36 37 // Variable handle firstload 38 GlobalVariable.firstLoadHaplotype = true; 39 var apiUrl = $('#api_url').val(); 40 41 // Disable show alert when error 42 $.fn.dataTable.ext.errMode = 'none'; 43 44 var tableHalotypeResult = $('#halotype-table') 45 46 // Handle draw again datatables 47 .on('draw.dt', function(e, settings, json, xhr) { 48 if (GlobalVariable.firstLoadHaplotype) { 49 GlobalVariable.firstLoadHaplotype = false;
50 } 51 // disable icon sort fisrt column 52 $("#th-select-all").removeClass("sorting_asc"); 53 54 // Show item selected 55 $("#halotype-table_info").append($("<span class='item-selected' id='item-selected'>")); 56 57 // Render items selected 58 renderItemSelected(GlobalVariable.selectedHaplotype); 59 60 hideLoading(); 61 }) 62 // Handle switch paging 63 .on('page.dt', function(e, settings, json, xhr) { 64 // Switch page 65 $('#cb-select-all').prop('checked', false); 66 }) 67 // Handle loading after call ajax success 68 .on('xhr.dt', function(e, settings, json, xhr) { 69 if (json) { 70 // var carrierStatus = ["HH1", "HH2", "HH3", "HH4", "HH5", "JH1", "JNS", "AH1", "BH1", "BH2"]; 71 // var carrierStatus = ["HH1", "HH2", "HH3", "HH4", "JH1", "AH1"]; 72 // var carrierStatus = ["HH1", "HH2", "HH3", "HH4", "JH1"]; 73 // Show all column hidden 74 // carrierStatus.forEach(function(element) { 75 // GlobalVariable.tableHalotype.column('#' + element).visible(true); 76 // }); 77 78 GlobalVariable.totalItem = json.total; 79 80 // Hide column not available 81 // var row = json.data[0]; 82 // jQuery.map(row, function(value, index) { 83 // if (jQuery.inArray(index.toUpperCase(), carrierStatus) !== -1) { 84 // var idx = carrierStatus.indexOf(index.toUpperCase()); 85 // carrierStatus.splice(idx, 1); 86 // } 87 // }); 88 // carrierStatus.forEach(function(element) { 89 // GlobalVariable.tableHalotype.column('#' + element).visible(false); 90 // }); 91 92 } 93 GlobalVariable.firstLoadHaplotype && !pressSearchHaplotype ? GlobalVariable.breedHaplotypeLatest = "All breeds" : null; 94 95 if (GlobalVariable.firstLoadHaplotype || pressSearchHaplotype) { 96 // Get index of BPI 97 var idx = settings.aoColumns.filter(function(x) { 98 return x.data === 'birtH_DATE'; 99 }).map(function(x) { 100 return x.idx 101 })[0]; 102 // Set sort desc for column BPI 103 // index column 104 settings.aaSorting[0][0] = idx; 105 settings.aaSorting[0][1] = "desc"; 106 settings.aaSorting[0]['_idx'] = idx; 107 108 // Unset press search 109 pressSearchHaplotype = false;
110 111 } 112 hideLoading(); 113 }) 114 // Handle error here 115 .on('error.dt', function(e, settings, techNote, message) { 116 console.log('An error has been reported by DataTables: ', message); 117 hideLoading(); 118 }) 119 .DataTable({ 120 // allow sort column 121 "ordering": true, 122 // p:paging B:button... 123 dom: '<"#top-table.clearfix"<"#left-top"i><"#right-top"lB>><"#content-table"t<"#bottom-table.clearfix"p>>', 124 buttons: [], 125 // call ajax get api 126 "processing": false, 127 "serverSide": true, 128 // Change title when the table is empty of data 129 "language": { 130 "emptyTable": "No result found", 131 "info": "_TOTAL_ results returned", 132 "infoEmpty": "0 result returned", 133 "lengthMenu": "_MENU_", 134 oPaginate: { 135 sNext: '<svg class="svg-inline--fa fa-angle-right fa-w-8" aria-hidden="true" data-prefix="fa" data-icon="angle-right" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512" data-fa-i2svg=""><path fill="currentColor" d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"></path></svg>', 136 sPrevious: '<svg class="svg-inline--fa fa-angle-left fa-w-8" aria-hidden="true" data-prefix="fa" data-icon="angle-left" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512" data-fa-i2svg=""><path fill="currentColor" d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"></path></svg>' 137 } 138 139 }, 140 // "pagingType": 'simple_numbers', 141 pagingType: 'simple_numbers', 142 ajax: { 143 "url": apiUrl + "/api/haplotype/search-results", 144 "type": "POST", 145 "dataType": "json", 146 "contentType": "application/json", 147 beforeSend: async function(jqXHR, settings) { 148 showLoading(); 149 var authorization = getAuthorization(); 150 jqXHR.setRequestHeader('Authorization', authorization); 151 152 if(!GlobalVariable.firstLoadHaplotype){ 153 await checkpointReloadPage('haplotype'); 154 } 155 }, 156 statusCode: { 157 400: function() { 158 console.log('Bad Request 400'); 159 $('#halotype-table tbody') 160 .empty() 161 .append('<tr><td colspan="6" class="dataTables_empty">Bad request</td></tr>') 162 }, 163 401: function() { 164 console.log('Access Denied 401'); 165 $('#halotype-table tbody') 166 .empty() 167 .append('<tr><td colspan="12" class="dataTables_empty">Authorization has been denied for this request.</td></tr>'); 168 processExpireToken(); 169 170 }, 171 500: function() { 172 console.log('Internal server error 500'); 173 $('#halotype-table tbody') 174 .empty() 175 .append('<tr><td colspan="6" class="dataTables_empty">Internal server error</td></tr>') 176 } 177 }, 178 "data": function(data) { 179 180 var pBreedSelect = jQuery('[attr-select-box="h_breed"]'); 181 // Show loading spinner 182 showLoading(); 183 184 // Save breedRunName to local storage 185 localStorage.setItem('breedRunNameHaplotype', $("#edit-breed option:selected").text()); 186 // Save the search criteria to local storage 187 localStorage.setItem('searchCriteriaHaplotype', $("#edit-search-text").val()); 188 // Hard code API release 189 // var releaseId = "DB591E6B-97C4-43B3-A667-E265769A845D"; 190 // Prepare parameters to call API 191 var pageCount = data.length; 192 var pageNumber = (data.start / data.length) + 1; 193 var sortedBy = data.order[0].column != 0 ? data.columns[data.order[0].column].data.toUpperCase() : 'BITH_DATE'; 194 var isDescSorting = data.order[0].dir == 'asc' ? false : true; 195 var criterias = { 196 // "RELEASE_ID": releaseId, 197 // "ygeN_BREED": document.forms["halotype-form"].elements['edit-breed'].value.trim(), 198 199 "ygeN_BREED": pBreedSelect.find('[attr-hiden-value="true"]').val().trim().charAt(0), 200 "SEARCH_HAPLOTYPE": document.forms["halotype-form"].elements['edit-search-text'].value.trim(), 201 "NASIS_ACTIVE": getObjectSelectBoxForHaplotype(jQuery('[attr-select-box="active-status-haplotype"]')), 202 }; 203 if (criterias["NASIS_ACTIVE"].length === 3) {
204 criterias["NASIS_ACTIVE"] = []; 205 } 206 207 criterias = formatCriteriasNotObjectInside(criterias); 208 209 GlobalVariable.printAll = { 210 pageCount: pageCount, 211 pageNumber: pageNumber, 212 sortedBy: sortedBy, 213 isDescSorting: isDescSorting, 214 criterias: criterias 215 }; 216 217 // Handle firstload page, default sort 218 if (GlobalVariable.firstLoadHaplotype) { 219 sortedBy = 'birtH_DATE'; 220 isDescSorting = true; 221 222 } else if (pressSearchHaplotype) { 223 sortedBy = 'birtH_DATE'; 224 isDescSorting = true; 225 226 } 227 228 // Support for print haplotype 229 GlobalVariable.printHaplotypeCriterias = { 230 sortedBy: sortedBy, 231 isDescSorting: isDescSorting, 232 } 233 234 return JSON.stringify({ 235 'criterias': cleanCriterias(criterias), 236 'sortedBy': sortedBy, 237 'isDescSorting': isDescSorting, 238 'pageNumber': pageNumber, 239 'pageCount': pageCount 240 }); 241 } 242 }, 243 // Redraw checkbox when load page again 244 rowCallback: function(row, data) { 245 if ($.inArray(data.animaL_NATIONAL_ID, GlobalVariable.selectedHaplotype) !== -1) { 246 $('input[type="checkbox"]', row).prop('checked', true); 247 } 248 }, 249 columnDefs: [{ 250 'targets': 0, 251 'searchable': false, 252 'orderable': false, 253 'className': 'dt-body-center', 254 'render': function(data, type, full, meta) { 255 return '<label class="cd-checkbox-container"><input type="checkbox" class="checkbox-in-table" value="' + full.animaL_NATIONAL_ID + '"><span class="cd-checkmark"></span></label>' 256 //return '<input type="checkbox" class="item-checkbox" value="' + full.animaL_NATIONAL_ID + '">'; 257 } 258 }], 259 // Define column by row 260 columns: [{ 261 // Checkbox selection by row 262 "data": "checkbox_id", 263 "orderable": false 264 }, 265 266 { 267 data: "animaL_NATIONAL_ID", 268 orderable: true, 269 className: "animal_national_id" 270 }, 271 { 272 data: "nasiS_BULL_ID", 273 orderable: true 274 }, 275 { 276 data: "lonG_NAME", 277 orderable: true 278 }, 279 { 280 data: "breed", 281 orderable: true 282 }, 283 { 284 data: "bulL_OWNER", 285 orderable: true 286 }, 287 { 288 data: "birtH_DATE", 289 orderable: true 290 }, 291 { 292 data: "hH1", 293 className: "column_hH1", 294 // render: function ( value ) { 295 // return value ? value : null; 296 // }, 297 // orderable: false, 298 // defaultContent: "-" 299 300 // fix feedback for searching haplotypes page from hH1 to bH2 301 render: function(value) { 302 if (value != null) { 303 if (value === ("F")) { 304 return iconHalotypeCheckbull; 305 } 306 if (value === ("C")) { 307 return iconHalotypeCarrier; 308 } 309 } else { 310 return value; 311 } 312 }, 313 orderable: false, 314 defaultContent: "" 315 }, 316 { 317 data: "hH2", 318 className: "column_hH2", 319 render: function(value) { 320 if (value != null) { 321 if (value === ("F")) { 322 return iconHalotypeCheckbull; 323 } 324 if (value === ("C")) { 325 return iconHalotypeCarrier; 326 } 327 } else { 328 return value; 329 } 330 }, 331 orderable: false, 332 defaultContent: "" 333 }, 334 { 335 data: "hH3", 336 className: "column_hH3", 337 render: function(value) { 338 if (value != null) { 339 if (value === ("F")) { 340 return iconHalotypeCheckbull; 341 } 342 if (value === ("C")) { 343 return iconHalotypeCarrier; 344 } 345 } else { 346 return value; 347 } 348 }, 349 orderable: false, 350 defaultContent: "" 351 352 }, 353 { 354 data: "hH4", 355 className: "column_hH4", 356 render: function(value) { 357 if (value != null) { 358 if (value === ("F")) { 359 return iconHalotypeCheckbull; 360 } 361 if (value === ("C")) { 362 return iconHalotypeCarrier; 363 } 364 } else { 365 return value; 366 } 367 }, 368 orderable: false, 369 defaultContent: "" 370 }, 371 { 372 data: "hH5", 373 className: "column_hH5", 374 render: function(value) { 375 if (value != null) { 376 if (value === ("F")) { 377 return iconHalotypeCheckbull; 378 } 379 if (value === ("C")) { 380 return iconHalotypeCarrier; 381 } 382 } else { 383 return value; 384 } 385 }, 386 orderable: false, 387 defaultContent: "" 388 }, 389 { 390 data: "hH6", 391 className: "column_hH6", 392 render: function(value) { 393 if (value != null) { 394 if (value === ("F")) { 395 return iconHalotypeCheckbull; 396 } 397 if (value === ("C")) { 398 return iconHalotypeCarrier; 399 } 400 } else { 401 return value; 402 } 403 }, 404 orderable: false, 405 defaultContent: "" 406 }, 407 { 408 data: "jH1", 409 className: "column_jH1", 410 render: function(value) { 411 if (value != null) { 412 if (value === ("F")) { 413 return iconHalotypeCheckbull; 414 } 415 if (value === ("C")) { 416 return iconHalotypeCarrier; 417 } 418 } else { 419 return value; 420 } 421 }, 422 orderable: false, 423 defaultContent: "", 424 //visible: false 425 }, 426 // { 427 // data: "jNS", 428 // className: "column_jNS", 429 // render: function(value) { 430 // if (value != null) { 431 // if (value === ("F")) { 432 // return iconHalotypeCheckbull; 433 // } 434 // if (value === ("C")) { 435 // return iconHalotypeCarrier; 436 // } 437 // } else { 438 // return value; 439 // } 440 // }, 441 // orderable: false, 442 // defaultContent: "", 443 // //visible: false 444 // }, 445 // { 446 // data: "jH2", 447 // className: "column_jH2", 448 // render: function(value) { 449 // if (value != null) { 450 // if (value === ("F")) { 451 // return iconHalotypeCheckbull; 452 // } 453 // if (value === ("C")) { 454 // return iconHalotypeCarrier; 455 // } 456 // } else { 457 // return value; 458 // } 459 // }, 460 // orderable: false, 461 // defaultContent: "", 462 // //visible: false 463 // }, 464 { 465 data: "aH1", 466 className: "column_aH1", 467 render: function(value) { 468 if (value != null) { 469 if (value === ("F")) { 470 return iconHalotypeCheckbull; 471 } else 472 if (value === ("C")) { 473 return iconHalotypeCarrier; 474 } 475 } else { 476 return value; 477 } 478 }, 479 orderable: false, 480 defaultContent: "", 481 //visible: false 482 }, 483 { 484 data: "aH2", 485 className: "column_aH2", 486 render: function(value) { 487 if (value != null) { 488 if (value === ("F")) { 489 return iconHalotypeCheckbull; 490 } else 491 if (value === ("C")) { 492 return iconHalotypeCarrier; 493 } 494 } else { 495 return value; 496 } 497 }, 498 orderable: false, 499 defaultContent: "", 500 //visible: false 501 }, 502 { 503 data: "bH2", 504 className: "column_bH2", 505 render: function(value) { 506 if (value != null) { 507 if (value === ("F")) { 508 return iconHalotypeCheckbull; 509 } else 510 if (value === ("C")) { 511 return iconHalotypeCarrier; 512 } 513 } else { 514 return value; 515 } 516 }, 517 orderable: false, 518 defaultContent: "", 519 //visible: false 520 }, 521 { 522 data: "bH14", 523 className: "column_bH14", 524 render: function(value) { 525 if (value != null) { 526 if (value === ("F")) { 527 return iconHalotypeCheckbull; 528 } else 529 if (value === ("C")) { 530 return iconHalotypeCarrier; 531 } 532 } else { 533 return value; 534 } 535 }, 536 orderable: false, 537 defaultContent: "", 538 //visible: false 539 } 540 ] 541 }); 542
543 // Add button into region top table 544 $(".btn-outter").prependTo("#left-top"); 545 $(".wrap-table > br").remove(); 546 547 // More columns button 548 tableHalotypeResult.button().add(0, { 549 text: 'Columns', 550 extend: 'colvis', 551 columns: ':not(.noVis)', 552 className: 'cd-button button-sub more-columns-button' 553 }); 554 555 // if(getHalotypeColumns()) 556 // { 557 // tableHalotypeResult.columns(getHalotypeColumns().checked_arr).visible(true); 558 // tableHalotypeResult.columns(getHalotypeColumns().unchecked_arr).visible(false); 559 // } 560 561 // Handle click on "Select all" control 562 $('#cb-select-all').on('click', function() { 563 if (!this.checked) { 564 GlobalVariable.selectedSearchBull = []; 565 } 566 // Get all rows with search applied 567 var rows = tableHalotypeResult.rows({ 568 'search': 'applied' 569 }).nodes(); 570 // Check/uncheck checkboxes for all rows in the table 571 $('input[type="checkbox"]', rows).prop('checked', this.checked); 572 573 importArrayItemSelected(this, rows, GlobalVariable.selectedHaplotype, 1); 574 575 // Render items selected 576 renderItemSelected(GlobalVariable.selectedHaplotype); 577 }); 578 $('#halotype-table tbody').on('click', 'input[type="checkbox"]', function() { 579 580 if (this.checked) { 581 pushItemSelected(this.value, GlobalVariable.selectedHaplotype); 582 jQuery(this).parents("tr").addClass("background-color-primary-1"); 583 //jQuery(this).parents("tr").css("background-color", "#E7EBDC"); 584 } else { 585 popItemSelected(this.value, GlobalVariable.selectedHaplotype); 586 jQuery(this).parents("tr").removeClass("background-color-primary-1"); 587 //jQuery(this).parents("tr").css("background-color", "white"); 588 589 var el = $('#cb-select-all').get(0); 590 // If "Select all" control is checked and has 'indeterminate' property 591 if (el && el.checked && ('indeterminate' in el)) { 592 // Set visual state of "Select all" control 593 // as 'indeterminate' 594 el.indeterminate = true; 595 } 596 } 597 renderItemSelected(GlobalVariable.selectedHaplotype); 598 599 }); 600 601 //Assign table halotype report into Golbal Variable 602 GlobalVariable.tableHalotype = tableHalotypeResult; 603 GlobalVariable.selectedHaplotype = []; 604 605 //for config datatables js 606 // jQuery(".more-columns-button").append('<i class="fa fa-chevron-down"></i>'); 607 // jQuery(".dataTables_info").addClass("custom-dataTables_info"); 608 // jQuery(".dt-buttons").addClass("button-column"); 609 // jQuery(".dataTables_length label").append('<i class="fa fa-chevron-down"></i>'); 610 611 //for config datatables js 612 jQuery(".more-columns-button").append('<svg class="svg-inline--fa fa-chevron-down fa-w-14" aria-hidden="true" data-prefix="fa" data-icon="chevron-down" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"></path></svg>'); 613 jQuery(".dataTables_info").addClass("custom-dataTables_info"); 614 jQuery(".dt-buttons").addClass("button-column"); 615 jQuery(".dataTables_length label").append('<svg class="svg-inline--fa fa-chevron-down fa-w-14" style="right: 30px;top: 39px;" aria-hidden="true" data-prefix="fa" data-icon="chevron-down" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"></path></svg>'); 616 617}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.