|
50 | 50 | itemsSelection.each(updateItem) |
51 | 51 | } |
52 | 52 |
|
| 53 | + function checkRunningState(data){ |
| 54 | + switch(data.state){ |
| 55 | + case 'running': |
| 56 | + case 'ending': |
| 57 | + return true |
| 58 | + default: |
| 59 | + return false |
| 60 | + } |
| 61 | + } |
| 62 | + |
53 | 63 | // Set up the export and delete links for the data/item. |
54 | 64 | // This assumes that the hrefs won't change |
55 | 65 | function setupNewItem(data){ |
|
62 | 72 | .attr('data-downloader', data.exportHref) |
63 | 73 | .attr('data-filename', data.name + '.pulse') |
64 | 74 | .traceDownloader('create') |
65 | | - |
66 | | - // set up the delete link |
67 | | - $deleteLink.click(function(){ |
68 | | - $.ajax(data.deleteHref, { |
69 | | - type: 'DELETE', |
70 | | - error: function(xhr, status){ |
71 | | - alert('Deleting failed.') |
72 | | - } |
73 | | - }) |
74 | | - }) |
75 | 75 | } |
76 | 76 |
|
77 | 77 | // Update the name and dates for the data/item |
|
81 | 81 | $nameDiv = $item.find('.traceName'), |
82 | 82 | $created = $item.find('.date-created span[name=date]'), |
83 | 83 | $importedDiv = $item.find('.date-imported'), |
84 | | - $imported = $importedDiv.find('span[name=date]') |
| 84 | + $imported = $importedDiv.find('span[name=date]'), |
| 85 | + isTraceRunning = checkRunningState(data) |
85 | 86 |
|
86 | 87 | $link |
87 | 88 | .attr('href', data.href) |
|
93 | 94 | $imported.text(imported) |
94 | 95 | $importedDiv.css('display', imported ? null : 'none') |
95 | 96 |
|
96 | | - switch(data.state){ |
97 | | - case 'idle': |
98 | | - case 'connecting': |
99 | | - $item.removeClass('stripedBackground animated') |
100 | | - break; |
101 | | - case 'running': |
102 | | - case 'ending': |
103 | | - $item.addClass('stripedBackground animated') |
104 | | - break; |
| 97 | + $item.toggleClass('stripedBackground animated', isTraceRunning) |
| 98 | + |
| 99 | + function handleDeleteClick(){ |
| 100 | + if(isTraceRunning){ |
| 101 | + var msg = "You can't delete this trace because it is currently running." |
| 102 | + alert(msg) |
| 103 | + } else $.ajax(data.deleteHref, { |
| 104 | + type: 'DELETE', |
| 105 | + error: function(xhr, status){ |
| 106 | + alert('Deleting failed.') |
| 107 | + } |
| 108 | + }) |
105 | 109 | } |
| 110 | + |
| 111 | + // update the delete link: if the trace is running, you can't click it |
| 112 | + d3.select($item.find('a[name=delete]')[0]) |
| 113 | + .on('click', handleDeleteClick) |
| 114 | + .attr('disabled', isTraceRunning ? 'disabled' : null) |
106 | 115 | } |
107 | 116 |
|
108 | 117 | // Initiate an AJAX request to load the trace data list |
|
0 commit comments