Skip to content

Commit

Permalink
přidáno zvýraznování dárců (donors_override)
Browse files Browse the repository at this point in the history
Přidáno zvýraznování dárců se záznamem v donors_override.
  • Loading branch information
j-jzk committed May 26, 2021
1 parent 72860ef commit df40516
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 18 deletions.
11 changes: 11 additions & 0 deletions registry/donor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,14 @@ class DonorsOverride(db.Model):
city = db.Column(db.String)
postal_code = db.Column(db.String(5))
kod_pojistovny = db.Column(db.String(3))

def to_dict(self):
result = {}
for field in ["rodne_cislo", "first_name", "last_name", "address", "city",
"postal_code", "kod_pojistovny"]:
if getattr(self, field) != None:
result[field] = str(getattr(self, field))
else:
result[field] = None

return result
13 changes: 12 additions & 1 deletion registry/donor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def save_note():
return redirect(url_for("donor.detail", rc=note_form.rodne_cislo.data))


@blueprint.post("/override")
@blueprint.post("/override/")
@login_required
def save_override():
override_form = DonorsOverrideForm()
Expand Down Expand Up @@ -211,3 +211,14 @@ def save_override():
flash_errors(override_form)

return redirect(url_for("donor.detail", rc=override_form.rodne_cislo.data))


@blueprint.get("/override/all")
@login_required
def get_overrides():
overrides_dict = {}

for override in DonorsOverride.query.all():
overrides_dict[str(override.rodne_cislo)] = override.to_dict()

return jsonify(overrides_dict)
72 changes: 55 additions & 17 deletions registry/templates/donor/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,60 @@ <h1>Přehled dárců</h1>
}

$(document).ready( function () {
$('#overview').DataTable({
const columnDefs = [{
"targets": "rodne_cislo",
"render": function (data, type, row, meta) {
if (type == "display")
return "<a href='"+"{{ url_for('donor.detail', rc='REPLACE_ME') }}".replace("REPLACE_ME", row.rodne_cislo) + "'>" + row.rodne_cislo + "</a>"
else
return data;
}
}, {
"targets": "donations",
"render": function (data, type, row, meta) {
return row.donation_count_total + create_tooltip_for_donations(row);
}
}, {
"targets": "awards",
"render": function (data, type, row, meta) {
return last_award_name(row);
}
}, {
"targets": ["donation_count_fm", "donation_count_fm_bubenik", "donation_count_trinec", "donation_count_mp", "donation_count_manual", "donation_count_total", "awarded_medal_br", "awarded_medal_st", "awarded_medal_zl", "awarded_medal_kr3", "awarded_medal_kr2", "awarded_medal_kr1", "awarded_medal_plk"],
"visible": false
}];

// Highlight fields that have a corresponding record in donors_override
let overrides = {}; // Will be set by an AJAX request

for (const column of ["first_name", "last_name", "address", "city", "postal_code", "kod_pojistovny"]) {
columnDefs.push({
"targets": column,
"render": function (data, type, row, meta) {
// We only want to highlight the value that is displayed
// to the user, not the ones used for searching and sorting
if (type != "display") return data;

if (overrides.hasOwnProperty(row.rodne_cislo) && overrides[row.rodne_cislo][column]) {
return `<mark title="Tato hodnota byla ručně nastavena">${data}</mark>`;
} else {
return data;
}
}
});
}

// Forward declaration of the DataTable
let dataTable = null;

// Request the list of overrides
$.getJSON("{{ url_for('donor.get_overrides') }}", function (data) {
overrides = data;
if (dataTable !== null)
dataTable.draw();
});

dataTable = $('#overview').DataTable({
language: {
url: '//cdn.datatables.net/plug-ins/1.10.21/i18n/Czech.json'
},
Expand All @@ -58,22 +111,7 @@ <h1>Přehled dárců</h1>
null, // calculated column donations
null, // calculated column awards
],
"columnDefs": [{
"targets": "rodne_cislo",
"render": function ( data, type, row, meta ) {
return "<a href='"+"{{ url_for('donor.detail', rc='REPLACE_ME') }}".replace("REPLACE_ME", row.rodne_cislo) + "'>" + row.rodne_cislo + "</a>";}
},{
"targets": "donations",
"render": function ( data, type, row, meta ) {
return row.donation_count_total + create_tooltip_for_donations(row);}
},{
"targets": "awards",
"render": function ( data, type, row, meta ) {
return last_award_name(row);}
},{
"targets": ["donation_count_fm", "donation_count_fm_bubenik", "donation_count_trinec", "donation_count_mp", "donation_count_manual", "donation_count_total", "awarded_medal_br", "awarded_medal_st", "awarded_medal_zl", "awarded_medal_kr3", "awarded_medal_kr2", "awarded_medal_kr1", "awarded_medal_plk"],
"visible": false
}]
"columnDefs": columnDefs
});
} );
</script>
Expand Down

0 comments on commit df40516

Please sign in to comment.