diff --git a/src/main/resources/public/js/getAndAddContracts.js b/src/main/resources/public/js/getAndAddContracts.js index 196922b1..b3466179 100644 --- a/src/main/resources/public/js/getAndAddContracts.js +++ b/src/main/resources/public/js/getAndAddContracts.js @@ -98,30 +98,42 @@ var projectContractsCount = -1; statusCode: { 200: function (invoices) { callback({ data: invoices.map(invoiceAsTableRow(contract))}); - if(invoices.length > 0){ - var invoice = invoices[invoices.length - 1]; //active invoice - if (invoice.paymentTime == "null" && invoice.transactionId == "null" && parseFloat(invoice.totalAmount) > 0.0){ - $($(".payInvoice")[$(".payInvoice").length - 1]).on( - "click", - function (event) { - event.preventDefault(); - var message = "Are you sure you want to make this payment?" - if (activeWallet.type == 'FAKE') { - message += ' You are using a fake wallet, the payment will be fictive.' - } - confirmDialog - .create(message) - .then( - () => payInvoice(invoice, contract, $(this)) - ); - } - ); - } - } } } } ); + }, + drawCallback: function(){ + $("#invoicesTable .payInvoice").off(); + $("#invoicesTable .payInvoice").each(function () { + $(this).on( + "click", + function (event) { + event.preventDefault(); + var message = "Are you sure you want to make this payment?" + if (activeWallet.type == 'FAKE') { + message += ' You are using a fake wallet, the payment will be fictive.' + } + confirmDialog + .create(message) + .then(() => { + var table = $("#invoicesTable").DataTable(); + var row = table.row($(event.currentTarget).parents('tr')); + var contract = { + id: { + contributorUsername: $(this).attr("data-contributor"), + role: $(this).attr("data-role"), + repoFullName: $(this).attr("data-repo") + } + }; + var invoice = { + id: row.data()[0] + }; + payInvoice(invoice, contract, $(this)); + }); + } + ); + }); } }); } @@ -146,7 +158,9 @@ var projectContractsCount = -1; if (invoice.paymentTime == "null" && invoice.transactionId == "null") { status = "Active"; if (parseFloat(invoice.totalAmount) > 0.0) { - payIcon = "" + payIcon = "" + "" + ""; } @@ -244,110 +258,115 @@ var projectContractsCount = -1; .then(function (contracts) { //adding contracts to table callback({ data: contracts.map(contractAsTableRowArray) }); - $('[data-toggle="tooltip"]').tooltip(); - $("#contracts .contractAgenda").each( - function () { - $(this).on( - "click", - function (event) { - var repo = $("#owner").text() + "/" + $("#name").text(); - var contributor = $(this).parent().parent().children()[0].innerText; - var role = $(this).parent().parent().children()[1].innerText; - var hourlyRate = $(this).parent().parent().children()[2].innerText; - var provider = "github"; - var contract = { - id: { - repoFullName: repo, - contributorUsername: contributor, - role: role, - provider: provider - }, - hourlyRate: hourlyRate - } - getTasksOfContract(contract); - getInvoicesOfContract(contract); + }) + .catch(handleError); + }, + drawCallback: function(){ + $("#contracts .contractAgenda").off(); + $("#contracts .removeContract").off(); + $("#contracts .editContract").off(); + $('[data-toggle="tooltip"]').tooltip(); + $("#contracts .contractAgenda").each( + function () { + $(this).on( + "click", + function (event) { + var repo = $("#owner").text() + "/" + $("#name").text(); + var contributor = $(this).parent().parent().children()[0].innerText; + var role = $(this).parent().parent().children()[1].innerText; + var hourlyRate = $(this).parent().parent().children()[2].innerText; + var provider = "github"; + var contract = { + id: { + repoFullName: repo, + contributorUsername: contributor, + role: role, + provider: provider + }, + hourlyRate: hourlyRate } - ) - } - ); - if ($("#contracts .contractAgenda").length > 0) { - $($("#contracts .contractAgenda")[0]).trigger("click"); + getTasksOfContract(contract); + getInvoicesOfContract(contract); + } + ) } - $("#contracts .editContract").each( - function () { - $(this).on( - "click", - function (event) { - var contributor = $(this).parent().parent().children()[0].innerText; - var role = $(this).parent().parent().children()[1].innerText; - - $("#newContractCard").hide(); - - $("#updateContractUsername").val(contributor); - $("#updateContractRole").val(role); - $("#usernameDisplayed").html(contributor); - $("#roleDisplayed").html(role); - $("#updatedHourlyRate").val(""); - - $("#updateContractCard").show(); - } - ) - } - ); - $("#contracts .removeContract").each( - function () { - $(this).on( - "click", - function (event) { - event.preventDefault(); - - var repo = $("#owner").text() + "/" + $("#name").text(); - var contributor = $(this).parent().parent().children()[0].innerText; - var role = $(this).parent().parent().children()[1].innerText; - var provider = "github"; - var contract = { - id: { - repoFullName: repo, - contributorUsername: contributor, - role: role, - provider: provider - } + ); + if ($("#contracts .contractAgenda").length > 0) { + $($("#contracts .contractAgenda")[0]).trigger("click"); + } + $("#contracts .editContract").each( + function () { + $(this).on( + "click", + function (event) { + var contributor = $(this).parent().parent().children()[0].innerText; + var role = $(this).parent().parent().children()[1].innerText; + + $("#newContractCard").hide(); + + $("#updateContractUsername").val(contributor); + $("#updateContractRole").val(role); + $("#usernameDisplayed").html(contributor); + $("#roleDisplayed").html(role); + $("#updatedHourlyRate").val(""); + + $("#updateContractCard").show(); + } + ) + } + ); + $("#contracts .removeContract").each( + function () { + $(this).on( + "click", + function (event) { + event.preventDefault(); + + var repo = $("#owner").text() + "/" + $("#name").text(); + var contributor = $(this).parent().parent().children()[0].innerText; + var role = $(this).parent().parent().children()[1].innerText; + var provider = "github"; + var contract = { + id: { + repoFullName: repo, + contributorUsername: contributor, + role: role, + provider: provider } - confirmDialog - .create("Are you sure you want to remove this contract?") - .then(() => markContractForRemoval(contract)); } - ) - } - ) - $("#contracts .restoreContract").each( - function () { - $(this).on( - "click", - function (event) { - event.preventDefault(); - - var repo = $("#owner").text() + "/" + $("#name").text(); - var contributor = $(this).parent().parent().children()[0].innerText; - var role = $(this).parent().parent().children()[1].innerText; - var provider = "github"; - var contract = { - id: { - repoFullName: repo, - contributorUsername: contributor, - role: role, - provider: provider - } + confirmDialog + .create("Are you sure you want to remove this contract?") + .then(() => markContractForRemoval(contract)); + } + ) + } + ) + $("#contracts .restoreContract").each( + function () { + $(this).on( + "click", + function (event) { + event.preventDefault(); + + var repo = $("#owner").text() + "/" + $("#name").text(); + var contributor = $(this).parent().parent().children()[0].innerText; + var role = $(this).parent().parent().children()[1].innerText; + var provider = "github"; + var contract = { + id: { + repoFullName: repo, + contributorUsername: contributor, + role: role, + provider: provider } - confirmDialog - .create("Are you sure you want to restore this contract?") - .then(() => restoreContract(contract)); } - ) - } - ) - }) - .catch(handleError); + confirmDialog + .create("Are you sure you want to restore this contract?") + .then(() => restoreContract(contract)); + } + ) + } + ) } }); } diff --git a/src/main/resources/public/js/getContributor.js b/src/main/resources/public/js/getContributor.js index 5cbe782f..8fa17bc5 100644 --- a/src/main/resources/public/js/getContributor.js +++ b/src/main/resources/public/js/getContributor.js @@ -14,38 +14,6 @@ function getContributorDashboard() { $("#contributorCardFooter").show(); $("#contributorDashboard").removeClass("d-none"); $("#contributorDashboard").addClass("show"); - $("#contractsTable .contractAgenda").each(function () { - $(this).on("click", function() { - var data = $("#contractsTable").DataTable().row($(this).parents('tr')).data() - var contract = { - id: { - repoFullName: $(data[0]).text(), - role: data[1] - } - } - getTasksOfContract(contract); - getInvoicesOfContract(contract); - }); - }); - $("#contractsTable .removeContract").each(function () { - $(this).on("click", function(event){ - event.preventDefault(); - var removeButton = $(this); - var data = $("#contractsTable").DataTable().row($(this).parents('tr')).data() - var contract = { - id: { - repoFullName: $(data[0]).text(), - role: data[1] - } - } - confirmDialog - .create("Are you sure you want to remove this contract?") - .then(() => markContractForRemoval(contract, removeButton)); - }); - }); - $('[data-toggle="tooltip"]').tooltip({ - boundary: 'window' - }); if (contributor.contracts.length > 0) { $("#tasks").show(); getTasksOfContract(contributor.contracts[0]); @@ -64,6 +32,42 @@ function getContributorDashboard() { } } }); + }, + drawCallback:function(){ + $("#contractsTable .contractAgenda").off(); + $("#contractsTable .removeContract").off(); + $('[data-toggle="tooltip"]').tooltip({ + boundary: 'window' + }); + $("#contractsTable .contractAgenda").each(function () { + $(this).on("click", function() { + var data = $("#contractsTable").DataTable().row($(this).parents('tr')).data(); + var contract = { + id: { + repoFullName: $(data[0]).text(), + role: data[1] + } + } + getTasksOfContract(contract); + getInvoicesOfContract(contract); + }); + }); + $("#contractsTable .removeContract").each(function () { + $(this).on("click", function(event){ + event.preventDefault(); + var removeButton = $(this); + var data = $("#contractsTable").DataTable().row($(this).parents('tr')).data(); + var contract = { + id: { + repoFullName: $(data[0]).text(), + role: data[1] + } + }; + confirmDialog + .create("Are you sure you want to remove this contract?") + .then(() => markContractForRemoval(contract, removeButton)); + }); + }); } }); }