Mercurial > hg > orthanc
annotate OrthancExplorer/explorer.js @ 201:bee20e978835
refactoring of delete
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 27 Nov 2012 17:36:19 +0100 |
parents | f2ae23682353 |
children | f23318b11b39 |
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) { |
165 | 328 if (s.Name != "") { |
329 $('.orthanc-name').html('<a class="ui-link" href="explorer.html">' + s.Name + '</a> » '); | |
330 } | |
152
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 }); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
333 }); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
334 |
0 | 335 |
336 | |
337 $('#find-patients').live('pagebeforeshow', function() { | |
338 GetMultipleResources('patients', null, function(patients) { | |
339 var target = $('#all-patients'); | |
340 $('li', target).remove(); | |
341 | |
342 SortOnDicomTag(patients, 'PatientName', false, false); | |
343 | |
344 for (var i = 0; i < patients.length; i++) { | |
345 var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID); | |
346 target.append(p); | |
347 } | |
348 | |
349 target.listview('refresh'); | |
350 }); | |
351 }); | |
352 | |
353 | |
354 | |
355 $('#patient').live('pagebeforeshow', function() { | |
356 if ($.mobile.pageData) { | |
357 GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) { | |
358 GetMultipleResources('studies', patient.Studies, function(studies) { | |
359 SortOnDicomTag(studies, 'StudyDate', false, true); | |
360 | |
361 $('#patient-info li').remove(); | |
362 $('#patient-info') | |
363 .append('<li data-role="list-divider">Patient</li>') | |
364 .append(FormatPatient(patient)) | |
365 .listview('refresh'); | |
366 | |
367 var target = $('#list-studies'); | |
368 $('li', target).remove(); | |
369 | |
370 for (var i = 0; i < studies.length; i++) { | |
371 if (i == 0 || studies[i].MainDicomTags.StudyDate != studies[i - 1].MainDicomTags.StudyDate) | |
372 { | |
373 target.append('<li data-role="list-divider">{0}</li>'.format | |
374 (FormatDicomDate(studies[i].MainDicomTags.StudyDate))); | |
375 } | |
376 | |
377 target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID)); | |
378 } | |
379 | |
380 target.listview('refresh'); | |
381 }); | |
382 }); | |
383 } | |
384 }); | |
385 | |
386 | |
387 $('#study').live('pagebeforeshow', function() { | |
388 if ($.mobile.pageData) { | |
389 GetSingleResource('studies', $.mobile.pageData.uuid, function(study) { | |
390 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
391 GetMultipleResources('series', study.Series, function(series) { | |
392 SortOnDicomTag(series, 'SeriesDate', false, true); | |
393 | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
394 $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID); |
0 | 395 $('#study-info li').remove(); |
396 $('#study-info') | |
397 .append('<li data-role="list-divider">Patient</li>') | |
398 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
399 .append('<li data-role="list-divider">Study</li>') | |
400 .append(FormatStudy(study)) | |
401 .listview('refresh'); | |
402 | |
403 var target = $('#list-series'); | |
404 $('li', target).remove(); | |
405 for (var i = 0; i < series.length; i++) { | |
406 if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate) | |
407 { | |
408 target.append('<li data-role="list-divider">{0}</li>'.format | |
409 (FormatDicomDate(series[i].MainDicomTags.SeriesDate))); | |
410 } | |
411 target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID)); | |
412 } | |
413 target.listview('refresh'); | |
414 }); | |
415 }); | |
416 }); | |
417 } | |
418 }); | |
419 | |
420 | |
421 $('#series').live('pagebeforeshow', function() { | |
422 if ($.mobile.pageData) { | |
423 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { | |
424 GetSingleResource('studies', series.ParentStudy, function(study) { | |
425 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
426 GetMultipleResources('instances', series.Instances, function(instances) { | |
80 | 427 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); |
0 | 428 |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
429 $('#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
|
430 $('#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
|
431 |
0 | 432 $('#series-info li').remove(); |
433 $('#series-info') | |
434 .append('<li data-role="list-divider">Patient</li>') | |
435 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
436 .append('<li data-role="list-divider">Study</li>') | |
437 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) | |
438 .append('<li data-role="list-divider">Series</li>') | |
439 .append(FormatSeries(series)) | |
440 .listview('refresh'); | |
441 | |
442 var target = $('#list-instances'); | |
443 $('li', target).remove(); | |
444 for (var i = 0; i < instances.length; i++) { | |
445 target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID)); | |
446 } | |
447 target.listview('refresh'); | |
448 }); | |
449 }); | |
450 }); | |
451 }); | |
452 } | |
453 }); | |
454 | |
455 | |
456 | |
457 function ConvertForTree(dicom) | |
458 { | |
459 var result = []; | |
460 | |
461 for (var i in dicom) { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
462 if (dicom[i] != null) { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
463 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
|
464 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
465 if (dicom[i]["Type"] == 'String') |
0 | 466 { |
467 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
468 label: label + '<strong>' + dicom[i]["Value"] + '</strong>', |
0 | 469 children: [] |
470 }); | |
471 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
472 else if (dicom[i]["Type"] == 'TooLong') |
0 | 473 { |
474 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
475 label: label + '<i>Too long</i>', |
0 | 476 children: [] |
477 }); | |
478 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
479 else if (dicom[i]["Type"] == 'Null') |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
480 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
481 result.push({ |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
482 label: label + '<i>Null</i>', |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
483 children: [] |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
484 }); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
485 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
486 else if (dicom[i]["Type"] == 'Sequence') |
0 | 487 { |
488 var c = []; | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
489 for (var j = 0; j < dicom[i]["Value"].length; j++) { |
0 | 490 c.push({ |
491 label: 'Item ' + j, | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
492 children: ConvertForTree(dicom[i]["Value"][j]) |
0 | 493 }); |
494 } | |
495 | |
496 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
497 label: label + '[]', |
0 | 498 children: c |
499 }); | |
500 } | |
501 } | |
502 } | |
503 | |
504 return result; | |
505 } | |
506 | |
507 | |
508 $('#instance').live('pagebeforeshow', function() { | |
509 if ($.mobile.pageData) { | |
510 GetSingleResource('instances', $.mobile.pageData.uuid, function(instance) { | |
511 GetSingleResource('series', instance.ParentSeries, function(series) { | |
512 GetSingleResource('studies', series.ParentStudy, function(study) { | |
513 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
514 |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
515 $('#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
|
516 $('#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
|
517 $('#instance .series-link').attr('href', '#series?uuid=' + series.ID); |
0 | 518 |
519 $('#instance-info li').remove(); | |
520 $('#instance-info') | |
521 .append('<li data-role="list-divider">Patient</li>') | |
522 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
523 .append('<li data-role="list-divider">Study</li>') | |
524 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) | |
525 .append('<li data-role="list-divider">Series</li>') | |
526 .append(FormatSeries(series, '#series?uuid=' + series.ID, true)) | |
527 .append('<li data-role="list-divider">Instance</li>') | |
528 .append(FormatInstance(instance)) | |
529 .listview('refresh'); | |
530 | |
531 $.ajax({ | |
83 | 532 url: '../instances/' + instance.ID + '/tags', |
0 | 533 dataType: 'json', |
534 success: function(s) { | |
535 $('#dicom-tree').tree('loadData', ConvertForTree(s)); | |
536 } | |
537 }); | |
538 | |
539 }); | |
540 }); | |
541 }); | |
542 }); | |
543 } | |
544 }); | |
545 | |
546 | |
547 | |
548 function DeleteResource(path) | |
549 { | |
550 $.ajax({ | |
551 url: path, | |
552 type: 'DELETE', | |
553 dataType: 'json', | |
554 async: false, | |
555 success: function(s) { | |
556 var ancestor = s.RemainingAncestor; | |
557 if (ancestor == null) | |
558 $.mobile.changePage('#find-patients'); | |
559 else | |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
165
diff
changeset
|
560 $.mobile.changePage('#' + ancestor.Type.toLowerCase() + '?uuid=' + ancestor.ID); |
0 | 561 } |
562 }); | |
563 } | |
564 | |
565 | |
566 | |
567 function OpenDeleteResourceDialog(path, title) | |
568 { | |
569 $(document).simpledialog2({ | |
570 // http://dev.jtsage.com/jQM-SimpleDialog/demos2/ | |
571 // http://dev.jtsage.com/jQM-SimpleDialog/demos2/options.html | |
572 mode: 'button', | |
573 animate: false, | |
574 headerText: title, | |
575 headerClose: true, | |
576 width: '500px', | |
577 buttons : { | |
578 'OK': { | |
579 click: function () { | |
580 DeleteResource(path); | |
581 }, | |
582 icon: "delete", | |
583 theme: "c" | |
584 }, | |
585 'Cancel': { | |
586 click: function () { | |
587 } | |
588 } | |
589 } | |
590 }); | |
591 } | |
592 | |
593 | |
594 | |
595 $('#instance-delete').live('click', function() { | |
83 | 596 OpenDeleteResourceDialog('../instances/' + $.mobile.pageData.uuid, |
0 | 597 'Delete this instance?'); |
598 }); | |
599 | |
600 $('#study-delete').live('click', function() { | |
83 | 601 OpenDeleteResourceDialog('../studies/' + $.mobile.pageData.uuid, |
0 | 602 'Delete this study?'); |
603 }); | |
604 | |
605 $('#series-delete').live('click', function() { | |
83 | 606 OpenDeleteResourceDialog('../series/' + $.mobile.pageData.uuid, |
0 | 607 'Delete this series?'); |
608 }); | |
609 | |
610 $('#patient-delete').live('click', function() { | |
83 | 611 OpenDeleteResourceDialog('../patients/' + $.mobile.pageData.uuid, |
0 | 612 'Delete this patient?'); |
613 }); | |
614 | |
615 | |
616 $('#instance-download-dicom').live('click', function(e) { | |
617 // http://stackoverflow.com/a/1296101 | |
618 e.preventDefault(); //stop the browser from following | |
83 | 619 window.location.href = '../instances/' + $.mobile.pageData.uuid + '/file'; |
0 | 620 }); |
621 | |
622 $('#instance-download-json').live('click', function(e) { | |
623 // http://stackoverflow.com/a/1296101 | |
624 e.preventDefault(); //stop the browser from following | |
83 | 625 window.location.href = '../instances/' + $.mobile.pageData.uuid + '/tags'; |
0 | 626 }); |
627 | |
628 | |
629 $('#instance-preview').live('click', function(e) { | |
54
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
630 if ($.mobile.pageData) { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
631 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
|
632 if (frames.length == 1) |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
633 { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
634 // Viewing a single-frame image |
83 | 635 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
|
636 overlayFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
637 resizeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
638 imageFadeDuration : 1 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
639 }); |
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 else |
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 // Viewing a multi-frame image |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
644 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
645 var images = []; |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
646 for (var i = 0; i < frames.length; i++) { |
83 | 647 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
|
648 } |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
649 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
650 jQuery.slimbox(images, 0, { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
651 overlayFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
652 resizeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
653 imageFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
654 loop : true |
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 }); |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
658 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
659 } |
0 | 660 }); |
661 | |
662 $('#series-preview').live('click', function(e) { | |
663 if ($.mobile.pageData) { | |
664 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { | |
665 GetMultipleResources('instances', series.Instances, function(instances) { | |
80 | 666 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); |
0 | 667 |
668 var images = []; | |
669 for (var i = 0; i < instances.length; i++) { | |
83 | 670 images.push([ '../instances/' + instances[i].ID + '/preview', |
0 | 671 '{0}/{1}'.format(i + 1, instances.length) ]) |
672 } | |
673 | |
674 jQuery.slimbox(images, 0, { | |
675 overlayFadeDuration : 1, | |
676 resizeDuration : 1, | |
677 imageFadeDuration : 1, | |
678 loop : true | |
679 }); | |
680 }) | |
681 }); | |
682 } | |
683 }); | |
684 | |
685 | |
686 | |
687 | |
688 | |
689 | |
690 function ChooseDicomModality(callback) | |
691 { | |
692 $.ajax({ | |
83 | 693 url: '../modalities', |
0 | 694 type: 'GET', |
695 dataType: 'json', | |
696 async: false, | |
697 success: function(modalities) { | |
698 var clickedModality = ''; | |
699 var items = $('<ul>') | |
700 .attr('data-role', 'listview'); | |
701 | |
702 for (var i = 0; i < modalities.length; i++) { | |
703 var modality = modalities[i]; | |
704 var item = $('<li>') | |
705 .html('<a href="#" rel="close">' + modality + '</a>') | |
706 .attr('modality', modality) | |
707 .click(function() { | |
708 clickedModality = $(this).attr('modality'); | |
709 }); | |
710 items.append(item); | |
711 } | |
712 | |
713 $('#dialog').simpledialog2({ | |
714 mode: 'blank', | |
715 animate: false, | |
716 headerText: 'DICOM modality', | |
717 headerClose: true, | |
718 width: '100%', | |
719 blankContent: items, | |
720 callbackClose: function() { | |
721 var timer; | |
722 function WaitForDialogToClose() { | |
723 if (!$('#dialog').is(':visible')) { | |
724 clearInterval(timer); | |
725 callback(clickedModality); | |
726 } | |
727 } | |
728 timer = setInterval(WaitForDialogToClose, 100); | |
729 } | |
730 }); | |
731 } | |
732 }); | |
733 } | |
734 | |
735 | |
736 $('#instance-store,#series-store').live('click', function(e) { | |
737 ChooseDicomModality(function(modality) { | |
738 if (modality != '') { | |
739 $.ajax({ | |
83 | 740 url: '../modalities/' + modality + '/store', |
0 | 741 type: 'POST', |
742 dataType: 'text', | |
743 data: $.mobile.pageData.uuid, | |
744 async: true, // Necessary to block UI | |
745 beforeSend: function() { | |
746 $.blockUI({ message: $('#loading') }); | |
747 }, | |
748 complete: function(s) { | |
749 $.unblockUI(); | |
750 }, | |
751 success: function(s) { | |
752 console.log('done !'); | |
753 }, | |
754 error: function() { | |
755 alert('Error during C-Store'); | |
756 } | |
757 }); | |
758 | |
759 } | |
760 }); | |
761 }); | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
762 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
763 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
764 $('#show-tag-name').live('change', function(e) { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
765 var checked = e.currentTarget.checked; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
766 if (checked) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
767 $('.tag-name').show(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
768 else |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
769 $('.tag-name').hide(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
770 }); |