Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#306 Fixed Options Buttons Don't Work On 2+ Pages Of Table. #307

Merged
merged 1 commit into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 138 additions & 119 deletions src/main/resources/public/js/getAndAddContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
);
});
}
});
}
Expand All @@ -146,7 +158,9 @@ var projectContractsCount = -1;
if (invoice.paymentTime == "null" && invoice.transactionId == "null") {
status = "Active";
if (parseFloat(invoice.totalAmount) > 0.0) {
payIcon = "<a href='#' title='Pay Invoice' class='payInvoice'>"
payIcon = "<a href='#' title='Pay Invoice' class='payInvoice' "
+ "data-contributor='" + contract.id.contributorUsername + "' "
+ "data-role='" + contract.id.role + "' data-repo='" + contract.id.repoFullName + "'>"
+ "<i class='fa fa-credit-card fa-lg'></i>"
+ "</a>";
}
Expand Down Expand Up @@ -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));
}
)
}
)
}
});
}
Expand Down
Loading