Mercurial > hg > orthanc-transfers
annotate Resources/OrthancExplorer.js @ 5:5e6de82bb10f
use of user properties instead of BidirectionalPeers option
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Sep 2018 15:39:02 +0200 |
parents | 1ed03945c057 |
children | 6f504d862494 |
rev | line source |
---|---|
0 | 1 function TransferAcceleratorSelectPeer(callback) |
2 { | |
3 var items = $('<ul>') | |
4 .attr('data-divider-theme', 'd') | |
5 .attr('data-role', 'listview'); | |
6 | |
7 $.ajax({ | |
8 url: '../transfers/peers', | |
9 type: 'GET', | |
10 dataType: 'json', | |
11 async: false, | |
12 cache: false, | |
13 success: function(peers) { | |
4
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
14 console.log(peers); |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
15 var clickedPeer = null; |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
16 |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
17 for (var name in peers) { |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
18 if (peers.hasOwnProperty(name)) { |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
19 var item = $('<li>') |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
20 .html('<a href="#" rel="close">' + name + '</a>') |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
21 .attr('name', name) |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
22 .click(function() { |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
23 clickedPeer = $(this).attr('name'); |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
24 }); |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
25 |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
26 if (peers[name] != 'installed' && |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
27 peers[name] != 'bidirectional') { |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
28 item.addClass('ui-disabled'); |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
29 } |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
30 |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
31 items.append(item); |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
32 } |
0 | 33 } |
34 | |
35 // Launch the dialog | |
36 $('#dialog').simpledialog2({ | |
37 mode: 'blank', | |
38 animate: false, | |
4
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
39 headerText: 'Choose Orthanc peer', |
0 | 40 headerClose: true, |
41 forceInput: false, | |
42 width: '100%', | |
43 blankContent: items, | |
44 callbackClose: function() { | |
45 var timer; | |
46 function WaitForDialogToClose() { | |
47 if (!$('#dialog').is(':visible')) { | |
48 clearInterval(timer); | |
4
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
49 if (clickedPeer !== null) { |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
50 callback(clickedPeer); |
1ed03945c057
showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
51 } |
0 | 52 } |
53 } | |
54 timer = setInterval(WaitForDialogToClose, 100); | |
55 } | |
56 }); | |
57 } | |
58 }); | |
59 } | |
60 | |
61 | |
62 function TransferAcceleratorAddSendButton(level, siblingButton) | |
63 { | |
64 var b = $('<a>') | |
65 .attr('data-role', 'button') | |
66 .attr('href', '#') | |
67 .attr('data-icon', 'search') | |
68 .attr('data-theme', 'e') | |
69 .text('Transfer accelerator'); | |
70 | |
71 b.insertBefore($(siblingButton).parent().parent()); | |
72 | |
73 b.click(function() { | |
74 if ($.mobile.pageData) { | |
75 var uuid = $.mobile.pageData.uuid; | |
76 TransferAcceleratorSelectPeer(function(peer) { | |
77 console.log('Sending ' + level + ' ' + uuid + ' to peer ' + peer); | |
78 | |
79 var query = { | |
80 'Resources' : [ | |
81 { | |
82 'Level' : level, | |
83 'ID' : uuid | |
84 } | |
85 ], | |
86 'Compression' : 'gzip', | |
87 'Peer' : peer | |
88 }; | |
89 | |
90 $.ajax({ | |
91 url: '../transfers/send', | |
92 type: 'POST', | |
93 dataType: 'json', | |
94 data: JSON.stringify(query), | |
95 success: function(job) { | |
96 if (!(typeof job.ID === 'undefined')) { | |
97 $.mobile.changePage('#job?uuid=' + job.ID); | |
98 } | |
99 }, | |
100 error: function() { | |
101 alert('Error while creating the transfer job'); | |
102 } | |
103 }); | |
104 }); | |
105 } | |
106 }); | |
107 } | |
108 | |
109 | |
110 | |
111 $('#patient').live('pagebeforecreate', function() { | |
112 TransferAcceleratorAddSendButton('Patient', '#patient-delete'); | |
113 }); | |
114 | |
115 $('#study').live('pagebeforecreate', function() { | |
116 TransferAcceleratorAddSendButton('Study', '#study-delete'); | |
117 }); | |
118 | |
119 $('#series').live('pagebeforecreate', function() { | |
120 TransferAcceleratorAddSendButton('Series', '#series-delete'); | |
121 }); |