Commit c443f682 by Damien Moulard

WIP: delete shift template registration

parent b6673825
Pipeline #1940 passed with stage
in 1 minute 29 seconds
......@@ -405,4 +405,46 @@ def delete_shift_registration(request):
else:
res["message"] = "Unauthorized"
response = JsonResponse(res, status=403)
return response
def delete_shift_template_registration(request):
""" From BDM admin, delete a member shift template registration """
res = {}
is_connected_user = CagetteUser.are_credentials_ok(request)
if is_connected_user is True:
try:
data = json.loads(request.body.decode())
partner_id = int(data["partner_id"])
shift_template_id = int(data["shift_template_id"])
makeups_to_do = int(data["makeups_to_do"])
permanent_unsuscribe = data["permanent_unsuscribe"]
cm = CagetteMember(partner_id)
# Get partner nb of future makeup shifts
partner_makeups = cm.get_member_selected_makeups()
target_makeup = makeups_to_do + len(partner_makeups)
if target_makeup > 2:
target_makeup = 2
print(target_makeup)
# Update partner makeups to do
res_update_makeups = cm.update_member_makeups({'target_makeups_nb': target_makeup})
print(res_update_makeups)
except Exception as e:
print(str(e))
# Récupérer nb rattrapages sélectionnés, incrémenter makeups_to_do
# Delete all shift.registration
# Delete all shift.template.registration (et .line ?)
# si permanent_unsuscribe, set special status gone
response = JsonResponse(res, safe=False)
else:
res["message"] = "Unauthorized"
response = JsonResponse(res, status=403)
return response
\ No newline at end of file
......@@ -779,14 +779,15 @@ class CagetteMember(models.Model):
res = api.search_read('res.partner', cond, fields)
if res:
c = [['partner_id', '=', int(res[0]['id'])]]
f = ['shift_template_id']
shift_template_reg = api.search_read('shift.template.registration', c, f)
for partner in res:
c = [['partner_id', '=', int(partner['id'])], ['state', 'in', ('draft', 'open')]]
f = ['shift_template_id']
shift_template_reg = api.search_read('shift.template.registration', c, f)
if shift_template_reg:
res[0]['shift_template_name'] = shift_template_reg[0]['shift_template_id'][1]
else:
res[0]['shift_template_name'] = None
if shift_template_reg:
partner['shift_template_id'] = shift_template_reg[0]['shift_template_id']
else:
partner['shift_template_id'] = None
return res
else:
......@@ -880,6 +881,14 @@ class CagetteMember(models.Model):
return res
def get_member_selected_makeups(self):
res = {}
c = [["partner_id", "=", self.id], ["is_makeup", "=", True], ["state", "=", "open"]]
f=['id']
res = self.o_api.search_read("shift.registration", c, f)
return res
class CagetteMembers(models.Model):
"""Class to manage operations on all members or part of them."""
......
......@@ -73,3 +73,19 @@
.member_info {
font-weight: bold;
}
/* Actions */
#actions_on_member {
margin: 15px;
}
#remove_shift_template_button {
display: none;
}
.checkbox_area {
margin: 10px 0;
}
#permanent_unsuscribe {
margin-right: 5px;
}
\ No newline at end of file
......@@ -10,16 +10,76 @@ var selected_member = null,
};
/**
* Send request to remove partner from shift template
*/
function remove_from_shift_template() {
let permanent_unsuscribe = modal.find("#permanent_unsuscribe").prop('checked');
// openModal();
closeModal()
let data = {
partner_id: selected_member.id,
shift_template_id: selected_member.shift_template_id[0],
permanent_unsuscribe: permanent_unsuscribe,
makeups_to_do: selected_member.makeups_to_do,
};
$.ajax({
type: 'POST',
url: '/members/delete_shift_template_registration',
data: JSON.stringify(data),
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
closeModal();
},
error: function() {
err = {
msg: "erreur serveur lors de la suppression du membre du créneau",
ctx: 'members.admin.manage_regular_shifts.remove_from_shift_template'
};
report_JS_error(err, 'members.admin');
closeModal();
$.notify("Erreur lors de la suppression du membre du créneau.", {
globalPosition:"top right",
className: "error"
});
}
});
}
/**
* When a member is selected, display the selected member relevant info
*/
function display_member_info() {
$('.member_name').text(`${selected_member.barcode_base} - ${selected_member.name}`);
$('.member_shift').text(selected_member.shift_template_name);
$('.member_shift').text(selected_member.shift_template_id[1]);
$('.member_status').text(possible_cooperative_state[selected_member.cooperative_state]);
$('.member_makeups').text(selected_member.makeups_to_do);
$('#search_member_input').val();
$('#partner_data_area').css('display', 'flex');
if (selected_member.shift_template_id === undefined || selected_member.shift_template_id === null) {
$("#remove_shift_template_button").hide();
$("#remove_shift_template_button").off();
} else {
$("#remove_shift_template_button").show();
$("#remove_shift_template_button").off();
$("#remove_shift_template_button").on("click", () => {
let modal_template = $("#modal_remove_shift_template");
modal_template.find(".shift_template_name").text(selected_member.shift_template_id[1]);
openModal(
modal_template.html(),
remove_from_shift_template,
"Valider",
false
);
});
}
}
/**
......@@ -75,6 +135,38 @@ $(document).ready(function() {
if (coop_is_connected()) {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
$(".page_content").show();
// Set action to search for the member
$('#search_member_form').submit(function() {
let search_str = $('#search_member_input').val();
$.ajax({
url: `/members/search/${search_str}?search_type=shift_template_data`,
dataType : 'json',
success: function(data) {
$('#partner_data_area').hide();
if (data.res.length === 1) {
selected_member = data.res[0];
display_member_info();
} else {
members_search_results = data.res;
display_possible_members();
}
},
error: function() {
err = {
msg: "erreur serveur lors de la recherche de membres",
ctx: 'members.admin.manage_regular_shifts.search_members'
};
report_JS_error(err, 'members.admin');
$.notify("Erreur lors de la recherche de membre, il faut ré-essayer plus tard...", {
globalPosition:"top right",
className: "error"
});
}
});
});
} else {
$(".page_content").hide();
}
......@@ -83,35 +175,4 @@ $(document).ready(function() {
let base_location = window.location.href.split("manage_regular_shifts")[0].slice(0, -1);
window.location.assign(base_location);
});
// Set action to search for the member
$('#search_member_form').submit(function() {
let search_str = $('#search_member_input').val();
$.ajax({
url: `/members/search/${search_str}?search_type=shift_template_data`,
dataType : 'json',
success: function(data) {
if (data.res.length === 1) {
selected_member = data.res[0];
display_member_info();
} else {
members_search_results = data.res;
display_possible_members();
}
},
error: function() {
err = {
msg: "erreur serveur lors de la recherche de membres",
ctx: 'members.admin.manage_regular_shifts.search_members'
};
report_JS_error(err, 'members.admin');
$.notify("Erreur lors de la recherche de membre, il faut ré-essayer plus tard...", {
globalPosition:"top right",
className: "error"
});
}
});
});
});
......@@ -61,4 +61,5 @@ urlpatterns = [
url(r'^get_makeups_members$', admin.get_makeups_members),
url(r'^update_members_makeups$', admin.update_members_makeups),
url(r'^delete_shift_registration$', admin.delete_shift_registration),
url(r'^delete_shift_template_registration$', admin.delete_shift_template_registration),
]
......@@ -11,6 +11,7 @@
{% block additionnal_scripts %}
<script type="text/javascript" src="{% static 'jquery-ui-1.12.1/jquery-ui.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/datatables/datatables.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/notify.min.js' %}?v="></script>
{% endblock %}
{% block content %}
......
......@@ -11,6 +11,7 @@
{% block additionnal_scripts %}
<script type="text/javascript" src="{% static 'jquery-ui-1.12.1/jquery-ui.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/datatables/datatables.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/notify.min.js' %}?v="></script>
{% endblock %}
{% block content %}
......@@ -50,10 +51,23 @@
<p class="shift_name_container">Créneau : <span class="member_info member_shift"></span></p>
<p class="status_container">Statut : <span class="member_info member_status"></span></p>
<p class="makeups_container">Nb rattrapage(s) : <span class="member_info member_makeups"></span></p>
<div id="actions_on_member">
<button class="btn--primary" id="remove_shift_template_button">
Désinscrire du créneau
</button>
</div>
</div>
</div>
<div id="templates" style="display:none;"></div>
<div id="templates" style="display:none;">
<div id="modal_remove_shift_template">
<p>Voulez vraiment désinscrire ce membre du créneau <span class="shift_template_name"></span> ?</p>
<div class="checkbox_area">
<input type="checkbox" id="permanent_unsuscribe" name="permanent_unsuscribe">
<label for="permanent_unsuscribe">Désinscription définitive</label>
</div>
</div>
</div>
</div>
......
......@@ -11,6 +11,7 @@
{% block additionnal_scripts %}
<script type="text/javascript" src="{% static 'jquery-ui-1.12.1/jquery-ui.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/datatables/datatables.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/notify.min.js' %}?v="></script>
{% endblock %}
{% block content %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment