Mercurial > hg > orthanc
comparison OrthancExplorer/explorer.js @ 762:45b16f67259c lua-scripting
integration mainline -> lua-scripting
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Apr 2014 16:47:21 +0200 |
parents | a8be42bcf2bb |
children | 2e11c3353356 |
comparison
equal
deleted
inserted
replaced
409:63f707278fc8 | 762:45b16f67259c |
---|---|
9 | 9 |
10 // http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html | 10 // http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html |
11 //$.mobile.ajaxEnabled = false; | 11 //$.mobile.ajaxEnabled = false; |
12 //$.mobile.page.prototype.options.addBackBtn = true; | 12 //$.mobile.page.prototype.options.addBackBtn = true; |
13 //$.mobile.defaultPageTransition = 'slide'; | 13 //$.mobile.defaultPageTransition = 'slide'; |
14 | |
15 | |
16 var currentPage = ''; | |
17 var currentUuid = ''; | |
18 | |
14 | 19 |
15 // http://stackoverflow.com/a/4673436 | 20 // http://stackoverflow.com/a/4673436 |
16 String.prototype.format = function() { | 21 String.prototype.format = function() { |
17 var args = arguments; | 22 var args = arguments; |
18 return this.replace(/{(\d+)}/g, function(match, number) { | 23 return this.replace(/{(\d+)}/g, function(match, number) { |
354 }); | 359 }); |
355 }); | 360 }); |
356 | 361 |
357 | 362 |
358 | 363 |
359 $('#patient').live('pagebeforeshow', function() { | 364 function SetupAnonymizedOrModifiedFrom(buttonSelector, resource, resourceType, field) |
365 { | |
366 if (field in resource) | |
367 { | |
368 $(buttonSelector).closest('li').show(); | |
369 $(buttonSelector).click(function(e) { | |
370 window.location.assign('explorer.html#' + resourceType + '?uuid=' + resource[field]); | |
371 }); | |
372 } | |
373 else | |
374 { | |
375 $(buttonSelector).closest('li').hide(); | |
376 } | |
377 } | |
378 | |
379 | |
380 | |
381 function RefreshPatient() | |
382 { | |
360 if ($.mobile.pageData) { | 383 if ($.mobile.pageData) { |
361 GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) { | 384 GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) { |
362 GetMultipleResources('studies', patient.Studies, function(studies) { | 385 GetMultipleResources('studies', patient.Studies, function(studies) { |
363 SortOnDicomTag(studies, 'StudyDate', false, true); | 386 SortOnDicomTag(studies, 'StudyDate', false, true); |
364 | 387 |
378 (FormatDicomDate(studies[i].MainDicomTags.StudyDate))); | 401 (FormatDicomDate(studies[i].MainDicomTags.StudyDate))); |
379 } | 402 } |
380 | 403 |
381 target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID)); | 404 target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID)); |
382 } | 405 } |
406 | |
407 SetupAnonymizedOrModifiedFrom('#patient-anonymized-from', patient, 'patient', 'AnonymizedFrom'); | |
408 SetupAnonymizedOrModifiedFrom('#patient-modified-from', patient, 'patient', 'ModifiedFrom'); | |
383 | 409 |
384 target.listview('refresh'); | 410 target.listview('refresh'); |
385 | 411 |
386 // Check whether this patient is protected | 412 // Check whether this patient is protected |
387 $.ajax({ | 413 $.ajax({ |
393 success: function (s) { | 419 success: function (s) { |
394 var v = (s == '1') ? 'on' : 'off'; | 420 var v = (s == '1') ? 'on' : 'off'; |
395 $('#protection').val(v).slider('refresh'); | 421 $('#protection').val(v).slider('refresh'); |
396 } | 422 } |
397 }); | 423 }); |
424 | |
425 currentPage = 'patient'; | |
426 currentUuid = $.mobile.pageData.uuid; | |
398 }); | 427 }); |
399 }); | 428 }); |
400 } | 429 } |
401 }); | 430 } |
402 | 431 |
403 | 432 |
404 $('#study').live('pagebeforeshow', function() { | 433 function RefreshStudy() |
434 { | |
405 if ($.mobile.pageData) { | 435 if ($.mobile.pageData) { |
406 GetSingleResource('studies', $.mobile.pageData.uuid, function(study) { | 436 GetSingleResource('studies', $.mobile.pageData.uuid, function(study) { |
407 GetSingleResource('patients', study.ParentPatient, function(patient) { | 437 GetSingleResource('patients', study.ParentPatient, function(patient) { |
408 GetMultipleResources('series', study.Series, function(series) { | 438 GetMultipleResources('series', study.Series, function(series) { |
409 SortOnDicomTag(series, 'SeriesDate', false, true); | 439 SortOnDicomTag(series, 'SeriesDate', false, true); |
414 .append('<li data-role="list-divider">Patient</li>') | 444 .append('<li data-role="list-divider">Patient</li>') |
415 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | 445 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) |
416 .append('<li data-role="list-divider">Study</li>') | 446 .append('<li data-role="list-divider">Study</li>') |
417 .append(FormatStudy(study)) | 447 .append(FormatStudy(study)) |
418 .listview('refresh'); | 448 .listview('refresh'); |
449 | |
450 SetupAnonymizedOrModifiedFrom('#study-anonymized-from', study, 'study', 'AnonymizedFrom'); | |
451 SetupAnonymizedOrModifiedFrom('#study-modified-from', study, 'study', 'ModifiedFrom'); | |
419 | 452 |
420 var target = $('#list-series'); | 453 var target = $('#list-series'); |
421 $('li', target).remove(); | 454 $('li', target).remove(); |
422 for (var i = 0; i < series.length; i++) { | 455 for (var i = 0; i < series.length; i++) { |
423 if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate) | 456 if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate) |
426 (FormatDicomDate(series[i].MainDicomTags.SeriesDate))); | 459 (FormatDicomDate(series[i].MainDicomTags.SeriesDate))); |
427 } | 460 } |
428 target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID)); | 461 target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID)); |
429 } | 462 } |
430 target.listview('refresh'); | 463 target.listview('refresh'); |
464 | |
465 currentPage = 'study'; | |
466 currentUuid = $.mobile.pageData.uuid; | |
431 }); | 467 }); |
432 }); | 468 }); |
433 }); | 469 }); |
434 } | 470 } |
435 }); | 471 } |
436 | 472 |
437 | 473 |
438 $('#series').live('pagebeforeshow', function() { | 474 function RefreshSeries() |
475 { | |
439 if ($.mobile.pageData) { | 476 if ($.mobile.pageData) { |
440 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { | 477 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { |
441 GetSingleResource('studies', series.ParentStudy, function(study) { | 478 GetSingleResource('studies', series.ParentStudy, function(study) { |
442 GetSingleResource('patients', study.ParentPatient, function(patient) { | 479 GetSingleResource('patients', study.ParentPatient, function(patient) { |
443 GetMultipleResources('instances', series.Instances, function(instances) { | 480 GetMultipleResources('instances', series.Instances, function(instances) { |
454 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) | 491 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) |
455 .append('<li data-role="list-divider">Series</li>') | 492 .append('<li data-role="list-divider">Series</li>') |
456 .append(FormatSeries(series)) | 493 .append(FormatSeries(series)) |
457 .listview('refresh'); | 494 .listview('refresh'); |
458 | 495 |
496 SetupAnonymizedOrModifiedFrom('#series-anonymized-from', series, 'series', 'AnonymizedFrom'); | |
497 SetupAnonymizedOrModifiedFrom('#series-modified-from', series, 'series', 'ModifiedFrom'); | |
498 | |
459 var target = $('#list-instances'); | 499 var target = $('#list-instances'); |
460 $('li', target).remove(); | 500 $('li', target).remove(); |
461 for (var i = 0; i < instances.length; i++) { | 501 for (var i = 0; i < instances.length; i++) { |
462 target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID)); | 502 target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID)); |
463 } | 503 } |
464 target.listview('refresh'); | 504 target.listview('refresh'); |
505 | |
506 currentPage = 'series'; | |
507 currentUuid = $.mobile.pageData.uuid; | |
465 }); | 508 }); |
466 }); | 509 }); |
467 }); | 510 }); |
468 }); | 511 }); |
469 } | 512 } |
470 }); | 513 } |
471 | 514 |
472 | 515 |
473 | 516 |
474 function ConvertForTree(dicom) | 517 function ConvertForTree(dicom) |
475 { | 518 { |
520 | 563 |
521 return result; | 564 return result; |
522 } | 565 } |
523 | 566 |
524 | 567 |
525 $('#instance').live('pagebeforeshow', function() { | 568 function RefreshInstance() |
569 { | |
526 if ($.mobile.pageData) { | 570 if ($.mobile.pageData) { |
527 GetSingleResource('instances', $.mobile.pageData.uuid, function(instance) { | 571 GetSingleResource('instances', $.mobile.pageData.uuid, function(instance) { |
528 GetSingleResource('series', instance.ParentSeries, function(series) { | 572 GetSingleResource('series', instance.ParentSeries, function(series) { |
529 GetSingleResource('studies', series.ParentStudy, function(study) { | 573 GetSingleResource('studies', series.ParentStudy, function(study) { |
530 GetSingleResource('patients', study.ParentPatient, function(patient) { | 574 GetSingleResource('patients', study.ParentPatient, function(patient) { |
552 success: function(s) { | 596 success: function(s) { |
553 $('#dicom-tree').tree('loadData', ConvertForTree(s)); | 597 $('#dicom-tree').tree('loadData', ConvertForTree(s)); |
554 } | 598 } |
555 }); | 599 }); |
556 | 600 |
601 SetupAnonymizedOrModifiedFrom('#instance-anonymized-from', instance, 'instance', 'AnonymizedFrom'); | |
602 SetupAnonymizedOrModifiedFrom('#instance-modified-from', instance, 'instance', 'ModifiedFrom'); | |
603 | |
604 currentPage = 'instance'; | |
605 currentUuid = $.mobile.pageData.uuid; | |
557 }); | 606 }); |
558 }); | 607 }); |
559 }); | 608 }); |
560 }); | 609 }); |
561 } | 610 } |
562 }); | 611 } |
612 | |
613 $(document).live('pagebeforehide', function() { | |
614 currentPage = ''; | |
615 currentUuid = ''; | |
616 }); | |
617 | |
618 | |
619 | |
620 $('#patient').live('pagebeforeshow', RefreshPatient); | |
621 $('#study').live('pagebeforeshow', RefreshStudy); | |
622 $('#series').live('pagebeforeshow', RefreshSeries); | |
623 $('#instance').live('pagebeforeshow', RefreshInstance); | |
624 | |
625 $(function() { | |
626 $(window).hashchange(function(e, data) { | |
627 // This fixes the navigation with the back button and with the anonymization | |
628 if ('uuid' in $.mobile.pageData && | |
629 currentPage == $.mobile.pageData.active && | |
630 currentUuid != $.mobile.pageData.uuid) { | |
631 if (currentPage == 'patient') | |
632 RefreshPatient(); | |
633 else if (currentPage == 'study') | |
634 RefreshStudy(); | |
635 else if (currentPage == 'series') | |
636 RefreshSeries(); | |
637 else if (currentPage == 'instance') | |
638 RefreshInstance(); | |
639 } | |
640 }); | |
641 }); | |
642 | |
643 | |
563 | 644 |
564 | 645 |
565 | 646 |
566 function DeleteResource(path) | 647 function DeleteResource(path) |
567 { | 648 { |
706 | 787 |
707 | 788 |
708 | 789 |
709 function ChooseDicomModality(callback) | 790 function ChooseDicomModality(callback) |
710 { | 791 { |
792 var clickedModality = ''; | |
793 var clickedPeer = ''; | |
794 var items = $('<ul>') | |
795 .attr('data-divider-theme', 'd') | |
796 .attr('data-role', 'listview'); | |
797 | |
798 // Retrieve the list of the known DICOM modalities | |
711 $.ajax({ | 799 $.ajax({ |
712 url: '../modalities', | 800 url: '../modalities', |
713 type: 'GET', | 801 type: 'GET', |
714 dataType: 'json', | 802 dataType: 'json', |
715 async: false, | 803 async: false, |
716 cache: false, | 804 cache: false, |
717 success: function(modalities) { | 805 success: function(modalities) { |
718 var clickedModality = ''; | 806 if (modalities.length > 0) |
719 var items = $('<ul>') | 807 { |
720 .attr('data-role', 'listview'); | 808 items.append('<li data-role="list-divider">DICOM modalities</li>'); |
721 | 809 |
722 for (var i = 0; i < modalities.length; i++) { | 810 for (var i = 0; i < modalities.length; i++) { |
723 var modality = modalities[i]; | 811 var name = modalities[i]; |
724 var item = $('<li>') | 812 var item = $('<li>') |
725 .html('<a href="#" rel="close">' + modality + '</a>') | 813 .html('<a href="#" rel="close">' + name + '</a>') |
726 .attr('modality', modality) | 814 .attr('name', name) |
727 .click(function() { | 815 .click(function() { |
728 clickedModality = $(this).attr('modality'); | 816 clickedModality = $(this).attr('name'); |
729 }); | 817 }); |
730 items.append(item); | 818 items.append(item); |
731 } | 819 } |
732 | 820 } |
733 $('#dialog').simpledialog2({ | 821 |
734 mode: 'blank', | 822 // Retrieve the list of the known Orthanc peers |
735 animate: false, | 823 $.ajax({ |
736 headerText: 'DICOM modality', | 824 url: '../peers', |
737 headerClose: true, | 825 type: 'GET', |
738 width: '100%', | 826 dataType: 'json', |
739 blankContent: items, | 827 async: false, |
740 callbackClose: function() { | 828 cache: false, |
741 var timer; | 829 success: function(peers) { |
742 function WaitForDialogToClose() { | 830 if (peers.length > 0) |
743 if (!$('#dialog').is(':visible')) { | 831 { |
744 clearInterval(timer); | 832 items.append('<li data-role="list-divider">Orthanc peers</li>'); |
745 callback(clickedModality); | 833 |
834 for (var i = 0; i < peers.length; i++) { | |
835 var name = peers[i]; | |
836 var item = $('<li>') | |
837 .html('<a href="#" rel="close">' + name + '</a>') | |
838 .attr('name', name) | |
839 .click(function() { | |
840 clickedPeer = $(this).attr('name'); | |
841 }); | |
842 items.append(item); | |
746 } | 843 } |
747 } | 844 } |
748 timer = setInterval(WaitForDialogToClose, 100); | 845 |
846 // Launch the dialog | |
847 $('#dialog').simpledialog2({ | |
848 mode: 'blank', | |
849 animate: false, | |
850 headerText: 'Choose target', | |
851 headerClose: true, | |
852 forceInput: false, | |
853 width: '100%', | |
854 blankContent: items, | |
855 callbackClose: function() { | |
856 var timer; | |
857 function WaitForDialogToClose() { | |
858 if (!$('#dialog').is(':visible')) { | |
859 clearInterval(timer); | |
860 callback(clickedModality, clickedPeer); | |
861 } | |
862 } | |
863 timer = setInterval(WaitForDialogToClose, 100); | |
864 } | |
865 }); | |
749 } | 866 } |
750 }); | 867 }); |
751 } | 868 } |
752 }); | 869 }); |
753 } | 870 } |
754 | 871 |
755 | 872 |
756 $('#instance-store,#series-store,#study-store,#patient-store').live('click', function(e) { | 873 $('#instance-store,#series-store,#study-store,#patient-store').live('click', function(e) { |
757 ChooseDicomModality(function(modality) { | 874 ChooseDicomModality(function(modality, peer) { |
758 if (modality != '') { | 875 var url; |
876 var loading; | |
877 | |
878 if (modality != '') | |
879 { | |
880 url = '../modalities/' + modality + '/store'; | |
881 loading = '#dicom-store'; | |
882 } | |
883 | |
884 if (peer != '') | |
885 { | |
886 url = '../peers/' + peer + '/store'; | |
887 loading = '#peer-store'; | |
888 } | |
889 | |
890 if (url != '') { | |
759 $.ajax({ | 891 $.ajax({ |
760 url: '../modalities/' + modality + '/store', | 892 url: url, |
761 type: 'POST', | 893 type: 'POST', |
762 dataType: 'text', | 894 dataType: 'text', |
763 data: $.mobile.pageData.uuid, | 895 data: $.mobile.pageData.uuid, |
764 async: true, // Necessary to block UI | 896 async: true, // Necessary to block UI |
765 beforeSend: function() { | 897 beforeSend: function() { |
766 $.blockUI({ message: $('#loading') }); | 898 $.blockUI({ message: $(loading) }); |
767 }, | 899 }, |
768 complete: function(s) { | 900 complete: function(s) { |
769 $.unblockUI(); | 901 $.unblockUI(); |
770 }, | 902 }, |
771 success: function(s) { | 903 success: function(s) { |
772 }, | 904 }, |
773 error: function() { | 905 error: function() { |
774 alert('Error during C-Store'); | 906 alert('Error during store'); |
775 } | 907 } |
776 }); | 908 }); |
777 | |
778 } | 909 } |
779 }); | 910 }); |
780 }); | 911 }); |
781 | 912 |
782 | 913 |
838 success: function(s) { | 969 success: function(s) { |
839 // The following line does not work... | 970 // The following line does not work... |
840 //$.mobile.changePage('explorer.html#patient?uuid=' + s.PatientID); | 971 //$.mobile.changePage('explorer.html#patient?uuid=' + s.PatientID); |
841 | 972 |
842 window.location.assign('explorer.html#patient?uuid=' + s.PatientID); | 973 window.location.assign('explorer.html#patient?uuid=' + s.PatientID); |
843 window.location.reload(); | 974 //window.location.reload(); |
844 } | 975 } |
845 }); | 976 }); |
846 }, | 977 }, |
847 icon: "delete", | 978 icon: "delete", |
848 theme: "c" | 979 theme: "c" |