Commit 41cf5e75 by Etienne Freiss

develop

parent 47352168
......@@ -44,7 +44,7 @@ class CagetteMembersSpace(models.Model):
['state', '!=', 'replaced'],
['state', '!=', 'replacing'],
]
f = ['create_date', 'date_begin', 'shift_id', 'name', 'state', 'is_late', 'is_makeup']
f = ['create_date', 'date_begin', 'shift_id', 'name', 'state', 'is_late', 'is_makeup','associate_registered']
marshal_none_error = 'cannot marshal None unless allow_none is enabled'
try:
......
......@@ -66,6 +66,32 @@ function prepare_server_data(data) {
}
}
if(history_item.associate_registered == false || history_item.associate_registered == undefined){
history_item.associate_registered = ""
}
else{
if(partner_data.associated_partner_id != "False"){
if(history_item.associate_registered==="partner"){
history_item.associate_registered = partner_data.name
}else if(history_item.associate_registered==="associate"){
history_item.associate_registered = partner_data.associated_partner_name
}else if(history_item.associate_registered==="both"){
history_item.associate_registered = "Les deux"
}else{
history_item.associate_registered = ""
}
}else if(partner_data.parent_id != "False"){
if(history_item.associate_registered==="partner"){
history_item.associate_registered = partner_data.parent_name
}else if(history_item.associate_registered==="associate"){
history_item.associate_registered = partner_data.name
}else if(history_item.associate_registered==="both"){
history_item.associate_registered = "Les deux"
}else{
history_item.associate_registered = ""
}
}
}
history_item.details = '';
if (history_item.state === 'excused' || history_item.state === 'absent') {
history_item.details = "Absent.e";
......@@ -87,7 +113,6 @@ function prepare_server_data(data) {
function init_history() {
$(".loading-history").hide();
$("#history").show();
if (partner_history.length === 0) {
$("#history").empty()
.text("Aucun historique... pour l'instant !");
......@@ -103,7 +128,7 @@ function init_history() {
{
data: "shift_name",
title: "<spans class='dt-body-center'>Service</span>",
width: "60%",
width: "50%",
orderable: false
},
{
......@@ -111,6 +136,11 @@ function init_history() {
title: "Détails",
className: "tablet-l desktop",
orderable: false
},
{
data: "associate_registered",
title: "",
orderable: false
}
],
iDisplayLength: -1,
......@@ -146,7 +176,6 @@ function init_history() {
* Init the Incoming shifts section: display them
*/
function init_incoming_shifts() {
console.log(partner_data)
$(".loading-incoming-shifts").hide();
$("#incoming_shifts").show();
......@@ -158,27 +187,29 @@ function init_incoming_shifts() {
for (shift of incoming_shifts) {
let shift_line_template = prepare_shift_line_template(shift.date_begin);
if(partner_data.associated_partner_id != "False" && shift.associate_registered==="partner"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.name+'')
}else if(partner_data.associated_partner_id != "False" && shift.associate_registered==="associated"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.associated_partner_name+'')
}else if(partner_data.associated_partner_id != "False" && shift.associate_registered==="both"){
shift_line_template.find(".shift_line_associate").text(' - Les deux' )
if(partner_data.associated_partner_id != "False"){
if(shift.associate_registered==="partner"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.name+'')
}else if(shift.associate_registered==="associate"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.associated_partner_name+'')
}else if(shift.associate_registered==="both"){
shift_line_template.find(".shift_line_associate").text(' - Les deux')
}else{
shift_line_template.find(".shift_line_associate").text('A définir')
}
}else if(partner_data.parent_id != "False"){
if(shift.associate_registered==="partner"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.parent_name+'')
}else if(shift.associate_registered==="associate"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.name+'')
}else if(shift.associate_registered==="both"){
shift_line_template.find(".shift_line_associate").text(' - Les deux')
}else{
shift_line_template.find(".shift_line_associate").text('A définir')
}
}
else if(partner_data.parent_id != "False" && shift.associate_registered==="partner"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.parent_name+'')
}else if(partner_data.parent_id != "False" && shift.associate_registered==="associated"){
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.name+'')
}else if(partner_data.parent_id != "False" && shift.associate_registered==="both"){
shift_line_template.find(".shift_line_associate").text(' - Les deux' )
}
$("#incoming_shifts").append(shift_line_template.html());
}
......
......@@ -112,7 +112,6 @@ function add_or_change_shift(new_shift_id) {
}
function init_shifts_list() {
console.log(partner_data)
$(".loading-incoming-shifts").hide();
$("#shifts_list").show();
......@@ -202,6 +201,7 @@ function init_shifts_list() {
$(".affect_associate_registered").on("click", function(e) {
// Display modal
id = $(this).attr('id').split('_')[2]
let modal_template = $("#modal_affect_shift");
if(partner_data.associated_partner_id != "False") {
modal_template.find("#shift_partner").text(partner_data.name);
......@@ -219,15 +219,68 @@ function init_shifts_list() {
openModal(
modal_template.html(),
() => {
// add_or_change_shift(new_shift_id);
},
"Valider"
);
modal.find('#shift_partner').on("click", function(e) {
affect_shift("partner",id)
});
modal.find('#shift_associate').on("click", function(e) {
affect_shift("associate",id)
});
modal.find('#shift_both').on("click", function(e) {
affect_shift("both",id)
});
modal.find(".btn-modal-ok").hide()
});
}
}
/**
* Proceed to shift modification
* @param {string} partner
* @param {string} shift_id
*/
function affect_shift(partner, shift_id) {
tData = 'idShiftRegistration=' + shift_id
+'&idPartner=' + partner_data.partner_id
+ '&affected_partner=' + partner
+ '&verif_token=' + partner_data.verif_token;
tUrl = '/shifts/affect_shift';
$.ajax({
type: 'POST',
url: tUrl,
dataType:"json",
data: tData,
timeout: 3000,
success: function(data) {
load_partner_shifts(partner_data.concerned_partner_id)
.then(() => {
init_shifts_list();
closeModal();
});
},
error: function(error) {
init_shifts_list();
closeModal();
alert(`Une erreur est survenue. ` +
`Il est néanmoins possible que la requête ait abouti, ` +
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`);
}
});
}
/**
* Inits the page when the calendar is displayed
*/
......
......@@ -166,6 +166,25 @@ class CagetteShift(models.Model):
if res:
st_r_id = True
return st_r_id
def affect_shift(self, data):
"""Affect shift to partner, his associate or both"""
response = None
cond = [['partner_id', '=', int(data['idPartner'])],
['id', '=', int(data['idShiftRegistration'])]]
fields = ['id']
try:
print(cond)
shit_to_affect = self.o_api.search_read('shift.registration', cond, fields, 1)
print(shit_to_affect)
if (len(shit_to_affect) == 1):
shift_res = shit_to_affect[0]
print(shift_res)
fieldsDatas = { "associate_registered":data['affected_partner']}
response = self.o_api.update('shift.registration', [shift_res['id']], fieldsDatas)
except Exception as e:
coop_logger.error("Reopen shift : %s", str(e))
return response
def cancel_shift(self, idsRegisteur):
"""Annule un shift"""
......
......@@ -13,6 +13,7 @@ urlpatterns = [
url(r'^get_test', views.get_test),
# url(r'^get_list', views.get_list),
url(r'^change_shift', views.change_shift),
url(r'^affect_shift', views.affect_shift),
url(r'^add_shift', views.add_shift),
url(r'^request_delay', views.request_delay),
url(r'^reset_members_positive_points', views.reset_members_positive_points)
......
......@@ -232,6 +232,34 @@ def change_shift(request):
else:
return HttpResponseForbidden()
def affect_shift(request):
if 'verif_token' in request.POST:
if Verification.verif_token(request.POST.get('verif_token'), int(request.POST.get('idPartner'))) is True:
cs = CagetteShift()
if 'idShiftRegistration' in request.POST and 'affected_partner' in request.POST:
data = {
"idPartner": int(request.POST['idPartner']),
"idShiftRegistration": int(request.POST['idShiftRegistration']),
"affected_partner": request.POST['affected_partner'],
}
try:
st_r_id = cs.affect_shift(data)
except Exception as e:
coop_logger.error("affect shift : %s, %s", str(e), str(data))
if st_r_id:
response = {'result': True}
else:
response = {'msg': "Internal Error"}
return JsonResponse(response, status=500)
return(JsonResponse({'result': True}))
else:
response = {'msg': "Bad args"}
return JsonResponse(response, status=400)
else:
return HttpResponseForbidden()
else:
return HttpResponseForbidden()
def add_shift(request):
if 'verif_token' in request.POST:
if Verification.verif_token(request.POST.get('verif_token'), int(request.POST.get('idPartner'))) is True:
......
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