|
| 1 | +$(document).ready(function() { |
| 2 | + $(".integration-settings") |
| 3 | + .materialMenu("init", { |
| 4 | + position: "overlay", |
| 5 | + animationSpeed: 1, |
| 6 | + items: [ |
| 7 | + { |
| 8 | + type: "normal", |
| 9 | + text: "Delete all pact versions...", |
| 10 | + click: function(e) { |
| 11 | + promptToDeletePactVersions($(e).data(), $(e).closest("tr")); |
| 12 | + } |
| 13 | + } |
| 14 | + ] |
| 15 | + }) |
| 16 | + .click(function() { |
| 17 | + $(this).materialMenu("open"); |
| 18 | + }); |
| 19 | +}); |
| 20 | + |
| 21 | +function promptToDeletePactVersions(rowData, row) { |
| 22 | + const agree = confirm( |
| 23 | + `This will delete all versions of the pact between ${ |
| 24 | + rowData.consumerName |
| 25 | + } and ${rowData.providerName}. It will keep ${rowData.consumerName} and ${ |
| 26 | + rowData.providerName |
| 27 | + }, and all other data related to them (webhooks, application versions, and tags). Do you wish to continue?` |
| 28 | + ); |
| 29 | + if (agree) { |
| 30 | + deletePactVersions( |
| 31 | + rowData.pactVersionsUrl, |
| 32 | + function() { |
| 33 | + handleDeletionSuccess(row); |
| 34 | + }, |
| 35 | + handleDeletionFailure |
| 36 | + ); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +function handleDeletionSuccess(row) { |
| 41 | + row |
| 42 | + .children("td, th") |
| 43 | + .animate({ padding: 0 }) |
| 44 | + .wrapInner("<div />") |
| 45 | + .children() |
| 46 | + .slideUp(function() { |
| 47 | + $(this) |
| 48 | + .closest("tr") |
| 49 | + .remove(); |
| 50 | + }); |
| 51 | +} |
| 52 | + |
| 53 | +function handleDeletionFailure(response) { |
| 54 | + let errorMessage = null; |
| 55 | + |
| 56 | + if (response.error && response.error.message && response.error.reference) { |
| 57 | + errorMessage = |
| 58 | + "Could not delete resources due to error: " + |
| 59 | + response.error.message + |
| 60 | + "\nError reference: " + |
| 61 | + response.error.reference; |
| 62 | + } else { |
| 63 | + errorMessage = |
| 64 | + "Could not delete resources due to error: " + JSON.stringify(response); |
| 65 | + } |
| 66 | + |
| 67 | + alert(errorMessage); |
| 68 | +} |
| 69 | + |
| 70 | +function deletePactVersions(url, successCallback, errorCallback) { |
| 71 | + $.ajax({ |
| 72 | + url: url, |
| 73 | + dataType: "json", |
| 74 | + type: "delete", |
| 75 | + accepts: { |
| 76 | + text: "application/hal+json" |
| 77 | + }, |
| 78 | + success: function(data, textStatus, jQxhr) { |
| 79 | + successCallback(); |
| 80 | + }, |
| 81 | + error: function(jqXhr, textStatus, errorThrown) { |
| 82 | + errorCallback(jqXhr.responseJSON); |
| 83 | + } |
| 84 | + }); |
| 85 | +} |
0 commit comments