Mercurial > hg > orthanc
annotate OrthancExplorer/explorer.js @ 164:dcf6475e2b40 Orthanc-0.2.3
teamcity test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Oct 2012 15:05:26 +0200 |
parents | 5b6b5c9f280f |
children | f2ae23682353 |
rev | line source |
---|---|
0 | 1 // http://stackoverflow.com/questions/1663741/is-there-a-good-jquery-drag-and-drop-file-upload-plugin |
2 | |
3 | |
4 // Forbid the access to IE | |
5 if ($.browser.msie) | |
6 { | |
7 alert("Please use Mozilla Firefox or Google Chrome. Microsoft Internet Explorer is not supported."); | |
8 } | |
9 | |
10 // http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html | |
11 //$.mobile.ajaxEnabled = false; | |
12 //$.mobile.page.prototype.options.addBackBtn = true; | |
13 //$.mobile.defaultPageTransition = 'slide'; | |
14 | |
15 // http://stackoverflow.com/a/4673436 | |
16 String.prototype.format = function() { | |
17 var args = arguments; | |
18 return this.replace(/{(\d+)}/g, function(match, number) { | |
19 /*return typeof args[number] != 'undefined' | |
20 ? args[number] | |
21 : match;*/ | |
22 | |
23 return args[number]; | |
24 }); | |
25 }; | |
26 | |
27 | |
28 $(document).ready(function() { | |
29 var $tree = $('#dicom-tree'); | |
30 $tree.tree({ | |
31 autoEscape: false | |
32 }); | |
33 | |
34 $('#dicom-tree').bind( | |
35 'tree.click', | |
36 function(event) { | |
37 if (event.node.is_open) | |
38 $tree.tree('closeNode', event.node, true); | |
39 else | |
40 $tree.tree('openNode', event.node, true); | |
41 } | |
42 ); | |
43 }); | |
44 | |
45 | |
46 function SplitLongUid(s) | |
47 { | |
48 return '<span>' + s.substr(0, s.length / 2) + '</span> <span>' + s.substr(s.length / 2, s.length - s.length / 2) + '</span>'; | |
49 } | |
50 | |
51 | |
52 function ParseDicomDate(s) | |
53 { | |
54 y = parseInt(s.substr(0, 4), 10); | |
55 m = parseInt(s.substr(4, 2), 10) - 1; | |
56 d = parseInt(s.substr(6, 2), 10); | |
57 | |
58 if (y == null || m == null || d == null || | |
59 !isFinite(y) || !isFinite(m) || !isFinite(d)) | |
60 { | |
61 return null; | |
62 } | |
63 | |
64 if (y < 1900 || y > 2100 || | |
65 m < 0 || m >= 12 || | |
66 d <= 0 || d >= 32) | |
67 { | |
68 return null; | |
69 } | |
70 | |
71 return new Date(y, m, d); | |
72 } | |
73 | |
74 | |
75 function FormatDicomDate(s) | |
76 { | |
77 if (s == undefined) | |
78 return "No date"; | |
79 | |
80 var d = ParseDicomDate(s); | |
81 if (d == null) | |
82 return '?'; | |
83 else | |
84 return d.toString('dddd, MMMM d, yyyy'); | |
85 } | |
86 | |
87 | |
80 | 88 function Sort(arr, fieldExtractor, isInteger, reverse) |
0 | 89 { |
33 | 90 var defaultValue; |
91 if (isInteger) | |
92 defaultValue = 0; | |
93 else | |
94 defaultValue = ''; | |
95 | |
0 | 96 arr.sort(function(a, b) { |
80 | 97 var ta = fieldExtractor(a); |
98 var tb = fieldExtractor(b); | |
0 | 99 var order; |
100 | |
33 | 101 if (ta == undefined) |
102 ta = defaultValue; | |
103 | |
104 if (tb == undefined) | |
105 tb = defaultValue; | |
106 | |
0 | 107 if (isInteger) |
108 { | |
109 ta = parseInt(ta, 10); | |
110 tb = parseInt(tb, 10); | |
111 order = ta - tb; | |
112 } | |
113 else | |
114 { | |
115 if (ta < tb) | |
116 order = -1; | |
117 else if (ta > tb) | |
118 order = 1; | |
119 else | |
120 order = 0; | |
121 } | |
122 | |
123 if (reverse) | |
124 return -order; | |
125 else | |
126 return order; | |
127 }); | |
128 } | |
129 | |
130 | |
80 | 131 function SortOnDicomTag(arr, tag, isInteger, reverse) |
132 { | |
133 return Sort(arr, function(a) { | |
134 return a.MainDicomTags[tag]; | |
135 }, isInteger, reverse); | |
136 } | |
137 | |
138 | |
0 | 139 |
140 function GetSingleResource(type, uuid, callback) | |
141 { | |
142 var resource = null; | |
143 $.ajax({ | |
83 | 144 url: '../' + type + '/' + uuid, |
0 | 145 dataType: 'json', |
146 async: false, | |
147 success: function(s) { | |
148 callback(s); | |
149 } | |
150 }); | |
151 } | |
152 | |
153 | |
154 function GetMultipleResources(type, uuids, callback) | |
155 { | |
156 if (uuids == null) | |
157 { | |
158 $.ajax({ | |
83 | 159 url: '../' + type, |
0 | 160 dataType: 'json', |
161 async: false, | |
162 success: function(s) { | |
163 uuids = s; | |
164 } | |
165 }); | |
166 } | |
167 | |
168 var resources = []; | |
169 var ajaxRequests = uuids.map(function(uuid) { | |
170 return $.ajax({ | |
83 | 171 url: '../' + type + '/' + uuid, |
0 | 172 dataType: 'json', |
173 async: true, | |
174 success: function(s) { | |
175 resources.push(s); | |
176 } | |
177 }); | |
178 }); | |
179 | |
180 // Wait for all the AJAX requests to end | |
181 $.when.apply($, ajaxRequests).then(function() { | |
182 callback(resources); | |
183 }); | |
184 } | |
185 | |
186 | |
187 | |
188 function CompleteFormatting(s, link, isReverse) | |
189 { | |
190 if (link != null) | |
191 { | |
192 s = 'href="' + link + '">' + s + '</a>'; | |
193 | |
194 if (isReverse) | |
195 s = 'data-direction="reverse" '+ s; | |
196 | |
197 s = '<a ' + s; | |
198 } | |
199 | |
200 if (isReverse) | |
201 return '<li data-icon="back">' + s + '</li>'; | |
202 else | |
203 return '<li>' + s + '</li>'; | |
204 } | |
205 | |
206 | |
38 | 207 function FormatMainDicomTags(tags, tagsToIgnore) |
208 { | |
209 var s = ''; | |
210 | |
211 for (var i in tags) | |
212 { | |
213 if (tagsToIgnore.indexOf(i) == -1) | |
214 { | |
215 var v = tags[i]; | |
216 | |
40 | 217 if (i == "PatientBirthDate" || |
218 i == "StudyDate" || | |
219 i == "SeriesDate") | |
38 | 220 { |
221 v = FormatDicomDate(v); | |
222 } | |
40 | 223 else if (i == "DicomStudyInstanceUID" || |
224 i == "DicomSeriesInstanceUID") | |
38 | 225 { |
226 v = SplitLongUid(v); | |
227 } | |
228 | |
229 | |
230 s += ('<p>{0}: <strong>{1}</strong></p>').format(i, v); | |
231 } | |
232 } | |
233 | |
234 return s; | |
235 } | |
236 | |
0 | 237 |
238 function FormatPatient(patient, link, isReverse) | |
239 { | |
40 | 240 var s = ('<h3>{0}</h3>{1}' + |
241 '<span class="ui-li-count">{2}</span>' | |
0 | 242 ).format |
38 | 243 (patient.MainDicomTags.PatientName, |
40 | 244 FormatMainDicomTags(patient.MainDicomTags, [ |
245 "PatientName", | |
246 "OtherPatientIDs" | |
247 ]), | |
0 | 248 patient.Studies.length |
249 ); | |
250 | |
251 return CompleteFormatting(s, link, isReverse); | |
252 } | |
253 | |
254 | |
255 | |
256 function FormatStudy(study, link, isReverse) | |
257 { | |
40 | 258 var s = ('<h3>{0}</h3>{1}' + |
0 | 259 '<span class="ui-li-count">{2}</span>' |
260 ).format | |
261 (study.MainDicomTags.StudyDescription, | |
40 | 262 FormatMainDicomTags(study.MainDicomTags, [ |
263 "StudyDescription", | |
264 "StudyTime" | |
265 ]), | |
0 | 266 study.Series.length |
267 ); | |
268 | |
269 return CompleteFormatting(s, link, isReverse); | |
270 } | |
271 | |
272 | |
273 | |
274 function FormatSeries(series, link, isReverse) | |
275 { | |
80 | 276 var c; |
82 | 277 if (series.ExpectedNumberOfInstances == null || |
278 series.Instances.length == series.ExpectedNumberOfInstances) | |
80 | 279 { |
82 | 280 c = series.Instances.length; |
80 | 281 } |
282 else | |
283 { | |
284 c = series.Instances.length + '/' + series.ExpectedNumberOfInstances; | |
285 } | |
286 | |
287 var s = ('<h3>{0}</h3>' + | |
288 '<p><em>Status: <strong>{1}</strong></em></p>{2}' + | |
289 '<span class="ui-li-count">{3}</span>').format | |
0 | 290 (series.MainDicomTags.SeriesDescription, |
80 | 291 series.Status, |
40 | 292 FormatMainDicomTags(series.MainDicomTags, [ |
293 "SeriesDescription", | |
294 "SeriesTime", | |
41
c1097a676eca
better naming for preview images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
295 "Manufacturer", |
c1097a676eca
better naming for preview images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
296 "ImagesInAcquisition", |
40 | 297 "SeriesDate" |
298 ]), | |
80 | 299 c |
0 | 300 ); |
301 | |
302 return CompleteFormatting(s, link, isReverse); | |
303 } | |
304 | |
305 | |
306 function FormatInstance(instance, link, isReverse) | |
307 { | |
40 | 308 var s = ('<h3>Instance {0}</h3>{1}').format |
80 | 309 (instance.IndexInSeries, |
40 | 310 FormatMainDicomTags(instance.MainDicomTags, [ |
311 "AcquisitionNumber", | |
312 "InstanceNumber", | |
313 "InstanceCreationDate", | |
314 "InstanceCreationTime" | |
315 ]) | |
0 | 316 ); |
317 | |
318 return CompleteFormatting(s, link, isReverse); | |
319 } | |
320 | |
321 | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
322 $('[data-role="page"]').live('pagebeforeshow', function() { |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
323 $.ajax({ |
153 | 324 url: '../system', |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
325 dataType: 'json', |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
326 async: false, |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
327 success: function(s) { |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
328 $('.orthanc-name').html('<a class="ui-link" href="explorer.html">' + s.Name + '</a> » '); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
329 } |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
330 }); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
331 }); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
332 |
0 | 333 |
334 | |
335 $('#find-patients').live('pagebeforeshow', function() { | |
336 GetMultipleResources('patients', null, function(patients) { | |
337 var target = $('#all-patients'); | |
338 $('li', target).remove(); | |
339 | |
340 SortOnDicomTag(patients, 'PatientName', false, false); | |
341 | |
342 for (var i = 0; i < patients.length; i++) { | |
343 var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID); | |
344 target.append(p); | |
345 } | |
346 | |
347 target.listview('refresh'); | |
348 }); | |
349 }); | |
350 | |
351 | |
352 | |
353 $('#patient').live('pagebeforeshow', function() { | |
354 if ($.mobile.pageData) { | |
355 GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) { | |
356 GetMultipleResources('studies', patient.Studies, function(studies) { | |
357 SortOnDicomTag(studies, 'StudyDate', false, true); | |
358 | |
359 $('#patient-info li').remove(); | |
360 $('#patient-info') | |
361 .append('<li data-role="list-divider">Patient</li>') | |
362 .append(FormatPatient(patient)) | |
363 .listview('refresh'); | |
364 | |
365 var target = $('#list-studies'); | |
366 $('li', target).remove(); | |
367 | |
368 for (var i = 0; i < studies.length; i++) { | |
369 if (i == 0 || studies[i].MainDicomTags.StudyDate != studies[i - 1].MainDicomTags.StudyDate) | |
370 { | |
371 target.append('<li data-role="list-divider">{0}</li>'.format | |
372 (FormatDicomDate(studies[i].MainDicomTags.StudyDate))); | |
373 } | |
374 | |
375 target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID)); | |
376 } | |
377 | |
378 target.listview('refresh'); | |
379 }); | |
380 }); | |
381 } | |
382 }); | |
383 | |
384 | |
385 $('#study').live('pagebeforeshow', function() { | |
386 if ($.mobile.pageData) { | |
387 GetSingleResource('studies', $.mobile.pageData.uuid, function(study) { | |
388 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
389 GetMultipleResources('series', study.Series, function(series) { | |
390 SortOnDicomTag(series, 'SeriesDate', false, true); | |
391 | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
392 $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID); |
0 | 393 $('#study-info li').remove(); |
394 $('#study-info') | |
395 .append('<li data-role="list-divider">Patient</li>') | |
396 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
397 .append('<li data-role="list-divider">Study</li>') | |
398 .append(FormatStudy(study)) | |
399 .listview('refresh'); | |
400 | |
401 var target = $('#list-series'); | |
402 $('li', target).remove(); | |
403 for (var i = 0; i < series.length; i++) { | |
404 if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate) | |
405 { | |
406 target.append('<li data-role="list-divider">{0}</li>'.format | |
407 (FormatDicomDate(series[i].MainDicomTags.SeriesDate))); | |
408 } | |
409 target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID)); | |
410 } | |
411 target.listview('refresh'); | |
412 }); | |
413 }); | |
414 }); | |
415 } | |
416 }); | |
417 | |
418 | |
419 $('#series').live('pagebeforeshow', function() { | |
420 if ($.mobile.pageData) { | |
421 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { | |
422 GetSingleResource('studies', series.ParentStudy, function(study) { | |
423 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
424 GetMultipleResources('instances', series.Instances, function(instances) { | |
80 | 425 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); |
0 | 426 |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
427 $('#series .patient-link').attr('href', '#patient?uuid=' + patient.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
428 $('#series .study-link').attr('href', '#study?uuid=' + study.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
429 |
0 | 430 $('#series-info li').remove(); |
431 $('#series-info') | |
432 .append('<li data-role="list-divider">Patient</li>') | |
433 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
434 .append('<li data-role="list-divider">Study</li>') | |
435 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) | |
436 .append('<li data-role="list-divider">Series</li>') | |
437 .append(FormatSeries(series)) | |
438 .listview('refresh'); | |
439 | |
440 var target = $('#list-instances'); | |
441 $('li', target).remove(); | |
442 for (var i = 0; i < instances.length; i++) { | |
443 target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID)); | |
444 } | |
445 target.listview('refresh'); | |
446 }); | |
447 }); | |
448 }); | |
449 }); | |
450 } | |
451 }); | |
452 | |
453 | |
454 | |
455 function ConvertForTree(dicom) | |
456 { | |
457 var result = []; | |
458 | |
459 for (var i in dicom) { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
460 if (dicom[i] != null) { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
461 var label = i + '<span class="tag-name"> (<i>' + dicom[i]["Name"] + '</i>)</span>: '; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
462 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
463 if (dicom[i]["Type"] == 'String') |
0 | 464 { |
465 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
466 label: label + '<strong>' + dicom[i]["Value"] + '</strong>', |
0 | 467 children: [] |
468 }); | |
469 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
470 else if (dicom[i]["Type"] == 'TooLong') |
0 | 471 { |
472 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
473 label: label + '<i>Too long</i>', |
0 | 474 children: [] |
475 }); | |
476 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
477 else if (dicom[i]["Type"] == 'Null') |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
478 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
479 result.push({ |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
480 label: label + '<i>Null</i>', |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
481 children: [] |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
482 }); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
483 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
484 else if (dicom[i]["Type"] == 'Sequence') |
0 | 485 { |
486 var c = []; | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
487 for (var j = 0; j < dicom[i]["Value"].length; j++) { |
0 | 488 c.push({ |
489 label: 'Item ' + j, | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
490 children: ConvertForTree(dicom[i]["Value"][j]) |
0 | 491 }); |
492 } | |
493 | |
494 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
495 label: label + '[]', |
0 | 496 children: c |
497 }); | |
498 } | |
499 } | |
500 } | |
501 | |
502 return result; | |
503 } | |
504 | |
505 | |
506 $('#instance').live('pagebeforeshow', function() { | |
507 if ($.mobile.pageData) { | |
508 GetSingleResource('instances', $.mobile.pageData.uuid, function(instance) { | |
509 GetSingleResource('series', instance.ParentSeries, function(series) { | |
510 GetSingleResource('studies', series.ParentStudy, function(study) { | |
511 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
512 |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
513 $('#instance .patient-link').attr('href', '#patient?uuid=' + patient.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
514 $('#instance .study-link').attr('href', '#study?uuid=' + study.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
515 $('#instance .series-link').attr('href', '#series?uuid=' + series.ID); |
0 | 516 |
517 $('#instance-info li').remove(); | |
518 $('#instance-info') | |
519 .append('<li data-role="list-divider">Patient</li>') | |
520 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
521 .append('<li data-role="list-divider">Study</li>') | |
522 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) | |
523 .append('<li data-role="list-divider">Series</li>') | |
524 .append(FormatSeries(series, '#series?uuid=' + series.ID, true)) | |
525 .append('<li data-role="list-divider">Instance</li>') | |
526 .append(FormatInstance(instance)) | |
527 .listview('refresh'); | |
528 | |
529 $.ajax({ | |
83 | 530 url: '../instances/' + instance.ID + '/tags', |
0 | 531 dataType: 'json', |
532 success: function(s) { | |
533 $('#dicom-tree').tree('loadData', ConvertForTree(s)); | |
534 } | |
535 }); | |
536 | |
537 }); | |
538 }); | |
539 }); | |
540 }); | |
541 } | |
542 }); | |
543 | |
544 | |
545 | |
546 function DeleteResource(path) | |
547 { | |
548 $.ajax({ | |
549 url: path, | |
550 type: 'DELETE', | |
551 dataType: 'json', | |
552 async: false, | |
553 success: function(s) { | |
554 var ancestor = s.RemainingAncestor; | |
555 if (ancestor == null) | |
556 $.mobile.changePage('#find-patients'); | |
557 else | |
558 $.mobile.changePage('#' + ancestor.Type + '?uuid=' + ancestor.ID); | |
559 } | |
560 }); | |
561 } | |
562 | |
563 | |
564 | |
565 function OpenDeleteResourceDialog(path, title) | |
566 { | |
567 $(document).simpledialog2({ | |
568 // http://dev.jtsage.com/jQM-SimpleDialog/demos2/ | |
569 // http://dev.jtsage.com/jQM-SimpleDialog/demos2/options.html | |
570 mode: 'button', | |
571 animate: false, | |
572 headerText: title, | |
573 headerClose: true, | |
574 width: '500px', | |
575 buttons : { | |
576 'OK': { | |
577 click: function () { | |
578 DeleteResource(path); | |
579 }, | |
580 icon: "delete", | |
581 theme: "c" | |
582 }, | |
583 'Cancel': { | |
584 click: function () { | |
585 } | |
586 } | |
587 } | |
588 }); | |
589 } | |
590 | |
591 | |
592 | |
593 $('#instance-delete').live('click', function() { | |
83 | 594 OpenDeleteResourceDialog('../instances/' + $.mobile.pageData.uuid, |
0 | 595 'Delete this instance?'); |
596 }); | |
597 | |
598 $('#study-delete').live('click', function() { | |
83 | 599 OpenDeleteResourceDialog('../studies/' + $.mobile.pageData.uuid, |
0 | 600 'Delete this study?'); |
601 }); | |
602 | |
603 $('#series-delete').live('click', function() { | |
83 | 604 OpenDeleteResourceDialog('../series/' + $.mobile.pageData.uuid, |
0 | 605 'Delete this series?'); |
606 }); | |
607 | |
608 $('#patient-delete').live('click', function() { | |
83 | 609 OpenDeleteResourceDialog('../patients/' + $.mobile.pageData.uuid, |
0 | 610 'Delete this patient?'); |
611 }); | |
612 | |
613 | |
614 $('#instance-download-dicom').live('click', function(e) { | |
615 // http://stackoverflow.com/a/1296101 | |
616 e.preventDefault(); //stop the browser from following | |
83 | 617 window.location.href = '../instances/' + $.mobile.pageData.uuid + '/file'; |
0 | 618 }); |
619 | |
620 $('#instance-download-json').live('click', function(e) { | |
621 // http://stackoverflow.com/a/1296101 | |
622 e.preventDefault(); //stop the browser from following | |
83 | 623 window.location.href = '../instances/' + $.mobile.pageData.uuid + '/tags'; |
0 | 624 }); |
625 | |
626 | |
627 $('#instance-preview').live('click', function(e) { | |
54
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
628 if ($.mobile.pageData) { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
629 GetSingleResource('instances', $.mobile.pageData.uuid + '/frames', function(frames) { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
630 if (frames.length == 1) |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
631 { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
632 // Viewing a single-frame image |
83 | 633 jQuery.slimbox('../instances/' + $.mobile.pageData.uuid + '/preview', '', { |
54
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
634 overlayFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
635 resizeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
636 imageFadeDuration : 1 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
637 }); |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
638 } |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
639 else |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
640 { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
641 // Viewing a multi-frame image |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
642 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
643 var images = []; |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
644 for (var i = 0; i < frames.length; i++) { |
83 | 645 images.push([ '../instances/' + $.mobile.pageData.uuid + '/frames/' + i + '/preview' ]); |
54
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
646 } |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
647 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
648 jQuery.slimbox(images, 0, { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
649 overlayFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
650 resizeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
651 imageFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
652 loop : true |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
653 }); |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
654 } |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
655 }); |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
656 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
657 } |
0 | 658 }); |
659 | |
660 $('#series-preview').live('click', function(e) { | |
661 if ($.mobile.pageData) { | |
662 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { | |
663 GetMultipleResources('instances', series.Instances, function(instances) { | |
80 | 664 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); |
0 | 665 |
666 var images = []; | |
667 for (var i = 0; i < instances.length; i++) { | |
83 | 668 images.push([ '../instances/' + instances[i].ID + '/preview', |
0 | 669 '{0}/{1}'.format(i + 1, instances.length) ]) |
670 } | |
671 | |
672 jQuery.slimbox(images, 0, { | |
673 overlayFadeDuration : 1, | |
674 resizeDuration : 1, | |
675 imageFadeDuration : 1, | |
676 loop : true | |
677 }); | |
678 }) | |
679 }); | |
680 } | |
681 }); | |
682 | |
683 | |
684 | |
685 | |
686 | |
687 | |
688 function ChooseDicomModality(callback) | |
689 { | |
690 $.ajax({ | |
83 | 691 url: '../modalities', |
0 | 692 type: 'GET', |
693 dataType: 'json', | |
694 async: false, | |
695 success: function(modalities) { | |
696 var clickedModality = ''; | |
697 var items = $('<ul>') | |
698 .attr('data-role', 'listview'); | |
699 | |
700 for (var i = 0; i < modalities.length; i++) { | |
701 var modality = modalities[i]; | |
702 var item = $('<li>') | |
703 .html('<a href="#" rel="close">' + modality + '</a>') | |
704 .attr('modality', modality) | |
705 .click(function() { | |
706 clickedModality = $(this).attr('modality'); | |
707 }); | |
708 items.append(item); | |
709 } | |
710 | |
711 $('#dialog').simpledialog2({ | |
712 mode: 'blank', | |
713 animate: false, | |
714 headerText: 'DICOM modality', | |
715 headerClose: true, | |
716 width: '100%', | |
717 blankContent: items, | |
718 callbackClose: function() { | |
719 var timer; | |
720 function WaitForDialogToClose() { | |
721 if (!$('#dialog').is(':visible')) { | |
722 clearInterval(timer); | |
723 callback(clickedModality); | |
724 } | |
725 } | |
726 timer = setInterval(WaitForDialogToClose, 100); | |
727 } | |
728 }); | |
729 } | |
730 }); | |
731 } | |
732 | |
733 | |
734 $('#instance-store,#series-store').live('click', function(e) { | |
735 ChooseDicomModality(function(modality) { | |
736 if (modality != '') { | |
737 $.ajax({ | |
83 | 738 url: '../modalities/' + modality + '/store', |
0 | 739 type: 'POST', |
740 dataType: 'text', | |
741 data: $.mobile.pageData.uuid, | |
742 async: true, // Necessary to block UI | |
743 beforeSend: function() { | |
744 $.blockUI({ message: $('#loading') }); | |
745 }, | |
746 complete: function(s) { | |
747 $.unblockUI(); | |
748 }, | |
749 success: function(s) { | |
750 console.log('done !'); | |
751 }, | |
752 error: function() { | |
753 alert('Error during C-Store'); | |
754 } | |
755 }); | |
756 | |
757 } | |
758 }); | |
759 }); | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
760 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
761 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
762 $('#show-tag-name').live('change', function(e) { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
763 var checked = e.currentTarget.checked; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
764 if (checked) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
765 $('.tag-name').show(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
766 else |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
767 $('.tag-name').hide(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
768 }); |