mirror of https://gitlab.crans.org/bde/nk20
Notes of users that don't have validated their email addresses are displayed with a different background
This commit is contained in:
parent
31205b9b5d
commit
658d402242
|
@ -106,6 +106,8 @@ class ConsumerSerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""
|
||||||
note = serializers.SerializerMethodField()
|
note = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
email_confirmed = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Alias
|
model = Alias
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
@ -120,6 +122,11 @@ class ConsumerSerializer(serializers.ModelSerializer):
|
||||||
return NotePolymorphicSerializer().to_representation(obj.note)
|
return NotePolymorphicSerializer().to_representation(obj.note)
|
||||||
return dict(id=obj.id)
|
return dict(id=obj.id)
|
||||||
|
|
||||||
|
def get_email_confirmed(self, obj):
|
||||||
|
if isinstance(obj.note, NoteUser):
|
||||||
|
return obj.note.user.profile.email_confirmed
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class TemplateCategorySerializer(serializers.ModelSerializer):
|
class TemplateCategorySerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -21,7 +21,7 @@ function pretty_money(value) {
|
||||||
* @param alert_type The type of the alert. Choices: info, success, warning, danger
|
* @param alert_type The type of the alert. Choices: info, success, warning, danger
|
||||||
* @param timeout The delay (in millis) after that the message is auto-closed. If negative, then it is ignored.
|
* @param timeout The delay (in millis) after that the message is auto-closed. If negative, then it is ignored.
|
||||||
*/
|
*/
|
||||||
function addMsg(msg, alert_type, timeout=-1) {
|
function addMsg(msg, alert_type, timeout = -1) {
|
||||||
let msgDiv = $("#messages");
|
let msgDiv = $("#messages");
|
||||||
let html = msgDiv.html();
|
let html = msgDiv.html();
|
||||||
let id = Math.floor(10000 * Math.random() + 1);
|
let id = Math.floor(10000 * Math.random() + 1);
|
||||||
|
@ -42,18 +42,18 @@ function addMsg(msg, alert_type, timeout=-1) {
|
||||||
* @param errs_obj [{error_code:erro_message}]
|
* @param errs_obj [{error_code:erro_message}]
|
||||||
* @param timeout The delay (in millis) after that the message is auto-closed. If negative, then it is ignored.
|
* @param timeout The delay (in millis) after that the message is auto-closed. If negative, then it is ignored.
|
||||||
*/
|
*/
|
||||||
function errMsg(errs_obj, timeout=-1) {
|
function errMsg(errs_obj, timeout = -1) {
|
||||||
for (const err_msg of Object.values(errs_obj)) {
|
for (const err_msg of Object.values(errs_obj)) {
|
||||||
addMsg(err_msg,'danger', timeout);
|
addMsg(err_msg, 'danger', timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var reloadWithTurbolinks = (function () {
|
var reloadWithTurbolinks = (function () {
|
||||||
var scrollPosition;
|
var scrollPosition;
|
||||||
|
|
||||||
function reload () {
|
function reload() {
|
||||||
scrollPosition = [window.scrollX, window.scrollY];
|
scrollPosition = [window.scrollX, window.scrollY];
|
||||||
Turbolinks.visit(window.location.toString(), { action: 'replace' })
|
Turbolinks.visit(window.location.toString(), {action: 'replace'})
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('turbolinks:load', function () {
|
document.addEventListener('turbolinks:load', function () {
|
||||||
|
@ -85,25 +85,27 @@ function getMatchedNotes(pattern, fun) {
|
||||||
/**
|
/**
|
||||||
* Generate a <li> entry with a given id and text
|
* Generate a <li> entry with a given id and text
|
||||||
*/
|
*/
|
||||||
function li(id, text,extra_css) {
|
function li(id, text, extra_css) {
|
||||||
return "<li class=\"list-group-item py-1 d-flex justify-content-between align-items-center " + extra_css + "\"" +
|
return "<li class=\"list-group-item py-1 d-flex justify-content-between align-items-center " + extra_css + "\"" +
|
||||||
" id=\"" + id + "\">" + text + "</li>\n";
|
" id=\"" + id + "\">" + text + "</li>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return style to apply according to the balance of the note
|
* Return style to apply according to the balance of the note and the validation status of the email address
|
||||||
* @param balance The balance of the note.
|
* @param note The concerned note.
|
||||||
*/
|
*/
|
||||||
function displayStyle(balance){
|
function displayStyle(note) {
|
||||||
if (balance < -5000){
|
let balance = note.balance;
|
||||||
return " text-danger bg-dark"
|
var css = "";
|
||||||
}
|
if (balance < -5000)
|
||||||
else if(balance <-1000){
|
css += " text-danger bg-dark";
|
||||||
return " text-danger"
|
else if (balance < -1000)
|
||||||
}
|
css += " text-danger";
|
||||||
else if(balance < 0){
|
else if (balance < 0)
|
||||||
return "text-warning"
|
css += " text-warning";
|
||||||
}
|
if (!note.email_confirmed)
|
||||||
return ""
|
css += " text-white bg-primary";
|
||||||
|
return css;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,30 +116,29 @@ function displayStyle(balance){
|
||||||
* @param user_note_field
|
* @param user_note_field
|
||||||
* @param profile_pic_field
|
* @param profile_pic_field
|
||||||
*/
|
*/
|
||||||
function displayNote(note, alias, user_note_field=null, profile_pic_field=null) {
|
function displayNote(note, alias, user_note_field = null, profile_pic_field = null) {
|
||||||
if (!note.display_image) {
|
if (!note.display_image) {
|
||||||
note.display_image = '/media/pic/default.png';
|
note.display_image = '/media/pic/default.png';
|
||||||
}
|
}
|
||||||
let img = note.display_image;
|
let img = note.display_image;
|
||||||
if (alias !== note.name && note.name)
|
if (alias !== note.name && note.name)
|
||||||
alias += " (aka. " + note.name + ")";
|
alias += " (aka. " + note.name + ")";
|
||||||
if (user_note_field !== null)
|
if (user_note_field !== null) {
|
||||||
|
|
||||||
$("#" + user_note_field).removeAttr('class');
|
$("#" + user_note_field).removeAttr('class');
|
||||||
$("#" + user_note_field).addClass(displayStyle(note.balance));
|
$("#" + user_note_field).addClass(displayStyle(note));
|
||||||
$("#" + user_note_field).text(alias + (note.balance == null ? "" : (":\n" + pretty_money(note.balance))));
|
$("#" + user_note_field).text(alias + (note.balance == null ? "" : (":\n" + pretty_money(note.balance))));
|
||||||
if (profile_pic_field != null){
|
if (profile_pic_field != null) {
|
||||||
$("#" + profile_pic_field).attr('src', img);
|
$("#" + profile_pic_field).attr('src', img);
|
||||||
$("#" + profile_pic_field).click(function(){
|
$("#" + profile_pic_field).click(function () {
|
||||||
console.log(note);
|
console.log(note);
|
||||||
if(note.resourcetype == "NoteUser"){
|
if (note.resourcetype === "NoteUser") {
|
||||||
document.location.href = "/accounts/user/" + note.user;
|
document.location.href = "/accounts/user/" + note.user;
|
||||||
}
|
} else if (note.resourcetype === "NoteClub") {
|
||||||
else if(note.resourcetype == "NoteClub"){
|
|
||||||
document.location.href = "/accounts/club/" + note.club;
|
document.location.href = "/accounts/club/" + note.club;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,8 +153,8 @@ function displayNote(note, alias, user_note_field=null, profile_pic_field=null)
|
||||||
* (useful in consumptions, put null if not used)
|
* (useful in consumptions, put null if not used)
|
||||||
* @returns an anonymous function to be compatible with jQuery events
|
* @returns an anonymous function to be compatible with jQuery events
|
||||||
*/
|
*/
|
||||||
function removeNote(d, note_prefix="note", notes_display, note_list_id, user_note_field=null, profile_pic_field=null) {
|
function removeNote(d, note_prefix = "note", notes_display, note_list_id, user_note_field = null, profile_pic_field = null) {
|
||||||
return (function() {
|
return (function () {
|
||||||
let new_notes_display = [];
|
let new_notes_display = [];
|
||||||
let html = "";
|
let html = "";
|
||||||
notes_display.forEach(function (disp) {
|
notes_display.forEach(function (disp) {
|
||||||
|
@ -166,7 +167,7 @@ function removeNote(d, note_prefix="note", notes_display, note_list_id, user_not
|
||||||
});
|
});
|
||||||
|
|
||||||
notes_display.length = 0;
|
notes_display.length = 0;
|
||||||
new_notes_display.forEach(function(disp) {
|
new_notes_display.forEach(function (disp) {
|
||||||
notes_display.push(disp);
|
notes_display.push(disp);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -174,7 +175,7 @@ function removeNote(d, note_prefix="note", notes_display, note_list_id, user_not
|
||||||
notes_display.forEach(function (disp) {
|
notes_display.forEach(function (disp) {
|
||||||
let obj = $("#" + note_prefix + "_" + disp.id);
|
let obj = $("#" + note_prefix + "_" + disp.id);
|
||||||
obj.click(removeNote(disp, note_prefix, notes_display, note_list_id, user_note_field, profile_pic_field));
|
obj.click(removeNote(disp, note_prefix, notes_display, note_list_id, user_note_field, profile_pic_field));
|
||||||
obj.hover(function() {
|
obj.hover(function () {
|
||||||
if (disp.note)
|
if (disp.note)
|
||||||
displayNote(disp.note, disp.name, user_note_field, profile_pic_field);
|
displayNote(disp.note, disp.name, user_note_field, profile_pic_field);
|
||||||
});
|
});
|
||||||
|
@ -199,18 +200,18 @@ function removeNote(d, note_prefix="note", notes_display, note_list_id, user_not
|
||||||
* the associated note is not displayed.
|
* the associated note is not displayed.
|
||||||
* Useful for a consumption if the item is selected before.
|
* Useful for a consumption if the item is selected before.
|
||||||
*/
|
*/
|
||||||
function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes_display, alias_prefix="alias",
|
function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes_display, alias_prefix = "alias",
|
||||||
note_prefix="note", user_note_field=null, profile_pic_field=null, alias_click=null) {
|
note_prefix = "note", user_note_field = null, profile_pic_field = null, alias_click = null) {
|
||||||
let field = $("#" + field_id);
|
let field = $("#" + field_id);
|
||||||
// When the user clicks on the search field, it is immediately cleared
|
// When the user clicks on the search field, it is immediately cleared
|
||||||
field.click(function() {
|
field.click(function () {
|
||||||
field.val("");
|
field.val("");
|
||||||
});
|
});
|
||||||
|
|
||||||
let old_pattern = null;
|
let old_pattern = null;
|
||||||
|
|
||||||
// When the user type "Enter", the first alias is clicked
|
// When the user type "Enter", the first alias is clicked
|
||||||
field.keypress(function(event) {
|
field.keypress(function (event) {
|
||||||
if (event.originalEvent.charCode === 13 && notes.length > 0) {
|
if (event.originalEvent.charCode === 13 && notes.length > 0) {
|
||||||
let li_obj = $("#" + alias_matched_id + " li").first();
|
let li_obj = $("#" + alias_matched_id + " li").first();
|
||||||
displayNote(notes[0], li_obj.text(), user_note_field, profile_pic_field);
|
displayNote(notes[0], li_obj.text(), user_note_field, profile_pic_field);
|
||||||
|
@ -219,7 +220,7 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
|
||||||
});
|
});
|
||||||
|
|
||||||
// When the user type something, the matched aliases are refreshed
|
// When the user type something, the matched aliases are refreshed
|
||||||
field.keyup(function(e) {
|
field.keyup(function (e) {
|
||||||
if (e.originalEvent.charCode === 13)
|
if (e.originalEvent.charCode === 13)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -233,7 +234,7 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
|
||||||
let aliases_matched_obj = $("#" + alias_matched_id);
|
let aliases_matched_obj = $("#" + alias_matched_id);
|
||||||
let aliases_matched_html = "";
|
let aliases_matched_html = "";
|
||||||
// get matched Alias with note associated
|
// get matched Alias with note associated
|
||||||
if(pattern == ""){
|
if (pattern === "") {
|
||||||
aliases_matched_obj = $("#" + alias_matched_id);
|
aliases_matched_obj = $("#" + alias_matched_id);
|
||||||
aliases_matched_html = "";
|
aliases_matched_html = "";
|
||||||
aliases_matched_obj.html("")
|
aliases_matched_obj.html("")
|
||||||
|
@ -244,27 +245,29 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
|
||||||
$.getJSON("/api/note/consumer/?format=json&alias="
|
$.getJSON("/api/note/consumer/?format=json&alias="
|
||||||
+ pattern
|
+ pattern
|
||||||
+ "&search=user|club&ordering=normalized_name",
|
+ "&search=user|club&ordering=normalized_name",
|
||||||
function(consumers){
|
function (consumers) {
|
||||||
// The response arrived too late, we stop the request
|
// The response arrived too late, we stop the request
|
||||||
if (pattern !== $("#" + field_id).val())
|
if (pattern !== $("#" + field_id).val())
|
||||||
return;
|
return;
|
||||||
consumers.results.forEach(function (consumer){
|
consumers.results.forEach(function (consumer) {
|
||||||
let note = consumer.note;
|
let note = consumer.note;
|
||||||
extra_css = displayStyle(note.balance);
|
note.email_confirmed = consumer.email_confirmed;
|
||||||
|
let extra_css = displayStyle(note);
|
||||||
aliases_matched_html += li(alias_prefix + '_' + consumer.id,
|
aliases_matched_html += li(alias_prefix + '_' + consumer.id,
|
||||||
consumer.name,
|
consumer.name,
|
||||||
extra_css);
|
extra_css);
|
||||||
notes.push(note);
|
notes.push(note);
|
||||||
});
|
});
|
||||||
aliases_matched_obj.html(aliases_matched_html);
|
aliases_matched_obj.html(aliases_matched_html);
|
||||||
consumers.results.forEach(function(consumer){
|
consumers.results.forEach(function (consumer) {
|
||||||
let note = consumer.note;
|
let note = consumer.note;
|
||||||
let consumer_obj = $("#" + alias_prefix+ "_" + consumer.id);
|
let consumer_obj = $("#" + alias_prefix + "_" + consumer.id);
|
||||||
consumer_obj.hover(function(){
|
consumer_obj.hover(function () {
|
||||||
displayNote(consumer.note, consumer.name, user_note_field,profile_pic_field)
|
displayNote(consumer.note, consumer.name, user_note_field, profile_pic_field)
|
||||||
});
|
});
|
||||||
consumer_obj.click(function(){
|
consumer_obj.click(function () {
|
||||||
field.val(""); old_pattern = ""; // reset input field
|
field.val("");
|
||||||
|
old_pattern = ""; // reset input field
|
||||||
var disp = null;
|
var disp = null;
|
||||||
notes_display.forEach(function (d) {
|
notes_display.forEach(function (d) {
|
||||||
// We compare the note ids
|
// We compare the note ids
|
||||||
|
@ -347,7 +350,7 @@ function de_validate(id, validated) {
|
||||||
// error if this method doesn't exist. Please define it.
|
// error if this method doesn't exist. Please define it.
|
||||||
refreshHistory();
|
refreshHistory();
|
||||||
},
|
},
|
||||||
error: function(err) {
|
error: function (err) {
|
||||||
addMsg("Une erreur est survenue lors de la validation/dévalidation " +
|
addMsg("Une erreur est survenue lors de la validation/dévalidation " +
|
||||||
"de cette transaction : " + err.responseText, "danger");
|
"de cette transaction : " + err.responseText, "danger");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load render_table from django_tables2 %}
|
{% load render_table from django_tables2 %}
|
||||||
{% load crispy_forms_tags%}
|
{% load crispy_forms_tags %}
|
||||||
|
{% load i18n %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<input id="searchbar" type="text" class="form-control" placeholder="Nom/prénom/note/section ...">
|
<input id="searchbar" type="text" class="form-control" placeholder="Nom/prénom/note/section ...">
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue