comparison PalantirExplorer/explorer.js @ 35:f6d12037f886

full json vs. simplified json
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Aug 2012 12:24:31 +0200
parents 3959d33612cc
children dfb159a079ea
comparison
equal deleted inserted replaced
34:96e57b863dd9 35:f6d12037f886
379 function ConvertForTree(dicom) 379 function ConvertForTree(dicom)
380 { 380 {
381 var result = []; 381 var result = [];
382 382
383 for (var i in dicom) { 383 for (var i in dicom) {
384 if (dicom [i] != null) { 384 if (dicom[i] != null) {
385 if (typeof dicom[i] == 'string') 385 var label = i + '<span class="tag-name"> (<i>' + dicom[i]["Name"] + '</i>)</span>: ';
386
387 if (dicom[i]["Type"] == 'String')
386 { 388 {
387 result.push({ 389 result.push({
388 label: i + ': <strong>' + dicom[i] + '</strong>', 390 label: label + '<strong>' + dicom[i]["Value"] + '</strong>',
389 children: [] 391 children: []
390 }); 392 });
391 } 393 }
392 else if (typeof dicom[i] == 'number') 394 else if (dicom[i]["Type"] == 'TooLong')
393 { 395 {
394 result.push({ 396 result.push({
395 label: i + ': <i>Too long</i>', 397 label: label + '<i>Too long</i>',
396 children: [] 398 children: []
397 }); 399 });
398 } 400 }
399 else 401 else if (dicom[i]["Type"] == 'Null')
402 {
403 result.push({
404 label: label + '<i>Null</i>',
405 children: []
406 });
407 }
408 else if (dicom[i]["Type"] == 'Sequence')
400 { 409 {
401 var c = []; 410 var c = [];
402 for (var j = 0; j < dicom[i].length; j++) { 411 for (var j = 0; j < dicom[i]["Value"].length; j++) {
403 c.push({ 412 c.push({
404 label: 'Item ' + j, 413 label: 'Item ' + j,
405 children: ConvertForTree(dicom[i][j]) 414 children: ConvertForTree(dicom[i]["Value"][j])
406 }); 415 });
407 } 416 }
408 417
409 result.push({ 418 result.push({
410 label: i + '[]', 419 label: label + '[]',
411 children: c 420 children: c
412 }); 421 });
413 } 422 }
414 } 423 }
415 } 424 }
436 .append('<li data-role="list-divider">Instance</li>') 445 .append('<li data-role="list-divider">Instance</li>')
437 .append(FormatInstance(instance)) 446 .append(FormatInstance(instance))
438 .listview('refresh'); 447 .listview('refresh');
439 448
440 $.ajax({ 449 $.ajax({
441 url: '/instances/' + instance.ID + '/all-tags', 450 url: '/instances/' + instance.ID + '/tags',
442 dataType: 'json', 451 dataType: 'json',
443 success: function(s) { 452 success: function(s) {
444 $('#dicom-tree').tree('loadData', ConvertForTree(s)); 453 $('#dicom-tree').tree('loadData', ConvertForTree(s));
445 } 454 }
446 }); 455 });
529 }); 538 });
530 539
531 $('#instance-download-json').live('click', function(e) { 540 $('#instance-download-json').live('click', function(e) {
532 // http://stackoverflow.com/a/1296101 541 // http://stackoverflow.com/a/1296101
533 e.preventDefault(); //stop the browser from following 542 e.preventDefault(); //stop the browser from following
534 window.location.href = '/instances/' + $.mobile.pageData.uuid + '/all-tags'; 543 window.location.href = '/instances/' + $.mobile.pageData.uuid + '/tags';
535 }); 544 });
536 545
537 546
538 $('#instance-preview').live('click', function(e) { 547 $('#instance-preview').live('click', function(e) {
539 jQuery.slimbox('/instances/' + $.mobile.pageData.uuid + '/normalized-image', '', { 548 jQuery.slimbox('/instances/' + $.mobile.pageData.uuid + '/normalized-image', '', {
641 }); 650 });
642 651
643 } 652 }
644 }); 653 });
645 }); 654 });
655
656
657 $('#show-tag-name').live('change', function(e) {
658 var checked = e.currentTarget.checked;
659 if (checked)
660 $('.tag-name').show();
661 else
662 $('.tag-name').hide();
663 });