comparison Sources/OrthancExplorer.js @ 56:9ed0cb5d6082 nexus

added button to import nexus files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 May 2024 15:27:40 +0200
parents 83b1abee3ece
children c322c949bd8e
comparison
equal deleted inserted replaced
55:41e3b79e7f4b 56:9ed0cb5d6082
338 338
339 var fileInput = document.getElementById('stl-attach-instance-upload'); 339 var fileInput = document.getElementById('stl-attach-instance-upload');
340 var description = $('#stl-attach-instance-description').val(); 340 var description = $('#stl-attach-instance-description').val();
341 341
342 if (fileInput.files.length == 0) { 342 if (fileInput.files.length == 0) {
343 alert('No Instance file was selected'); 343 alert('No STL file was selected');
344 return; 344 return;
345 } 345 }
346 346
347 reader = new FileReader(); 347 reader = new FileReader();
348 reader.onload = function() { 348 reader.onload = function() {
390 }); 390 });
391 } 391 }
392 } 392 }
393 393
394 394
395 function AddImportNexusButton(studyId) {
396 if (${IS_NEXUS_ENABLED}) {
397 $('#stl-attach-nexus').remove();
398
399 var instance = $('<a>')
400 .attr('id', 'stl-attach-nexus')
401 .attr('data-role', 'button')
402 .attr('href', '#')
403 .attr('data-icon', 'search')
404 .attr('data-theme', 'e')
405 .text('Attach Nexus model')
406 .button();
407
408 instance.insertAfter($('#study-info'));
409 instance.click(function() {
410
411 var options = $('<ul>')
412 .attr('data-divider-theme', 'd')
413 .attr('data-role', 'listview');
414
415 var upload = $('<input>')
416 .attr('type', 'file')
417 .attr('id', 'stl-attach-nexus-upload')
418 .attr('data-theme', 'a');
419
420 options.append($('<li>').text('Choose the Nexus file:'));
421 options.append($('<li>').append(upload));
422
423 options.append($('<li>').text('Series description:'));
424 options.append($('<li>').append($('<input>')
425 .attr('type', 'text')
426 .attr('id', 'stl-attach-nexus-description')
427 .attr('data-theme', 'b')
428 .val('Imported Nexus')));
429
430 options.append($('<li>').append(
431 $('<a>')
432 .attr('href', '#')
433 .attr('rel', 'close').attr('data-theme', 'b')
434 .text('Import')
435 .click(function(e) {
436 e.preventDefault();
437
438 var fileInput = document.getElementById('stl-attach-nexus-upload');
439 var description = $('#stl-attach-nexus-description').val();
440
441 if (fileInput.files.length == 0) {
442 alert('No Nexus file was selected');
443 return;
444 }
445
446 reader = new FileReader();
447 reader.onload = function() {
448
449 // https://github.com/axios/axios/issues/513
450 var nexus = reader.result;
451 var nexusBase64 = btoa(new Uint8Array(nexus).reduce((data, byte) => data + String.fromCharCode(byte), ''));
452
453 $.ajax({
454 url: '../stl/create-nexus',
455 type: 'POST',
456 data: JSON.stringify({
457 'Content' : nexusBase64,
458 'Parent' : studyId,
459 'Tags' : {
460 'SeriesDescription' : description
461 }
462 }),
463 dataType: 'json',
464 success: function(s) {
465 $.mobile.changePage('#series?uuid=' + s.ParentSeries, {
466 allowSamePageTransition: true
467 });
468 },
469 error: function() {
470 alert('Error while generating the 3D model');
471 }
472 });
473
474 };
475
476 reader.readAsArrayBuffer(fileInput.files[0]);
477 })));
478
479 // Launch the dialog
480 $('#dialog').simpledialog2({
481 mode: 'blank',
482 animate: false,
483 headerText: 'Attach Nexus',
484 headerClose: true,
485 forceInput: false,
486 width: '100%',
487 blankContent: options
488 });
489 });
490 }
491 }
492
493
395 function AddOpenStlNexusButton(instanceId, id, parent) { 494 function AddOpenStlNexusButton(instanceId, id, parent) {
396 if (${IS_NEXUS_ENABLED}) { 495 if (${IS_NEXUS_ENABLED}) {
397 $.ajax({ 496 $.ajax({
398 url: '/instances/' + instanceId + '/content/0008,9123', 497 url: '/instances/' + instanceId + '/content/0008,9123',
399 success: function(creatorVersionUid) { 498 success: function(creatorVersionUid) {
480 579
481 580
482 $('#study').live('pagebeforeshow', function() { 581 $('#study').live('pagebeforeshow', function() {
483 var studyId = $.mobile.pageData.uuid; 582 var studyId = $.mobile.pageData.uuid;
484 AddImportSTLButton(studyId); 583 AddImportSTLButton(studyId);
584 AddImportNexusButton(studyId);
485 AddGenerateFromNIfTIButton(studyId); 585 AddGenerateFromNIfTIButton(studyId);
486 }); 586 });