Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
23109cf5
Commit
23109cf5
authored
Mar 08, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete future registration
parent
9298c1f1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
206 additions
and
73 deletions
+206
-73
members-space-shifts-exchange.css
members_space/static/css/members-space-shifts-exchange.css
+8
-0
members-space-shifts-exchange.js
members_space/static/js/members-space-shifts-exchange.js
+163
-69
urls.py
shifts/urls.py
+1
-0
views.py
shifts/views.py
+31
-0
index.html
templates/members_space/index.html
+3
-4
No files found.
members_space/static/css/members-space-shifts-exchange.css
View file @
23109cf5
...
@@ -90,6 +90,14 @@
...
@@ -90,6 +90,14 @@
border-radius
:
5px
;
border-radius
:
5px
;
}
}
.delete_registration_button
{
justify-content
:
center
;
align-items
:
center
;
margin
:
0.75rem
15px
;
color
:
#d9534f
;
cursor
:
pointer
;
display
:
none
;
}
/* -- Calendar screen, makeups message */
/* -- Calendar screen, makeups message */
...
...
members_space/static/js/members-space-shifts-exchange.js
View file @
23109cf5
...
@@ -2,6 +2,8 @@ var calendar = null,
...
@@ -2,6 +2,8 @@ var calendar = null,
selected_shift
=
null
,
selected_shift
=
null
,
vw
=
null
;
vw
=
null
;
/* - Logic */
/**
/**
* A partner can exchange shifts if:
* A partner can exchange shifts if:
* - s.he doesn't have to choose a makeup shift
* - s.he doesn't have to choose a makeup shift
...
@@ -23,6 +25,8 @@ function should_select_makeup() {
...
@@ -23,6 +25,8 @@ function should_select_makeup() {
return
partner_data
.
makeups_to_do
>
0
||
(
partner_data
.
makeups_to_do
>
0
&&
partner_data
.
is_associated_people
===
"True"
&&
block_actions_for_attached_people
===
"False"
);
return
partner_data
.
makeups_to_do
>
0
||
(
partner_data
.
makeups_to_do
>
0
&&
partner_data
.
is_associated_people
===
"True"
&&
block_actions_for_attached_people
===
"False"
);
}
}
/* - Server requests */
/**
/**
* Proceed to shift exchange or registration
* Proceed to shift exchange or registration
* @param {int} new_shift_id
* @param {int} new_shift_id
...
@@ -118,6 +122,7 @@ function add_or_change_shift(new_shift_id) {
...
@@ -118,6 +122,7 @@ function add_or_change_shift(new_shift_id) {
`Si tu ne peux vraiment pas venir, tu seras noté.e absent.e à ton service. `
+
`Si tu ne peux vraiment pas venir, tu seras noté.e absent.e à ton service. `
+
`Tu devras alors sélectionner un service de rattrapage sur ton espace membre.`
);
`Tu devras alors sélectionner un service de rattrapage sur ton espace membre.`
);
}
else
if
(
error
.
status
===
500
&&
error
.
msg
===
"Fail to create shift"
)
{
}
else
if
(
error
.
status
===
500
&&
error
.
msg
===
"Fail to create shift"
)
{
// TODO differentiate error cases!
alert
(
`Une erreur est survenue. `
+
alert
(
`Une erreur est survenue. `
+
`Il est néanmoins possible que la requête ait abouti, `
+
`Il est néanmoins possible que la requête ait abouti, `
+
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`
);
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`
);
...
@@ -141,6 +146,138 @@ function add_or_change_shift(new_shift_id) {
...
@@ -141,6 +146,138 @@ function add_or_change_shift(new_shift_id) {
}
}
}
}
/**
* Send request to delete (cancel) a shift registration.
* @param {Int} shift_registration_id shift registration to cancel
*/
function
delete_shift_registration
(
shift_registration_id
)
{
if
(
is_time_to
(
'delete_shift_registration'
))
{
openModal
();
tData
=
'idPartner='
+
partner_data
.
concerned_partner_id
+
'&idRegister='
+
shift_registration_id
+
'&extra_shift_done='
+
partner_data
.
extra_shift_done
;
if
(
partner_data
.
is_associated_people
===
"False"
)
{
tData
+=
'&verif_token='
+
partner_data
.
verif_token
;
}
else
if
(
partner_data
.
is_associated_people
===
"True"
&&
block_actions_for_attached_people
===
"False"
)
{
tData
+=
'&verif_token='
+
partner_data
.
parent_verif_token
;
}
else
{
return
false
;
}
$
.
ajax
({
type
:
'POST'
,
url
:
"/shifts/cancel_shift"
,
dataType
:
"json"
,
data
:
tData
,
timeout
:
3000
,
success
:
function
()
{
partner_data
.
extra_shift_done
-=
1
;
// Refetch partner shifts list & update DOM
load_partner_shifts
(
partner_data
.
concerned_partner_id
)
.
then
(()
=>
{
init_shifts_list
();
if
(
partner_data
.
extra_shift_done
>
0
)
{
$
(
".extra_shift_done"
).
text
(
partner_data
.
extra_shift_done
);
init_delete_registration_buttons
();
}
else
{
$
(
"#can_delete_future_registrations_area"
).
hide
();
$
(
".delete_registration_button"
).
off
();
$
(
".delete_registration_button"
).
hide
();
}
closeModal
();
setTimeout
(()
=>
{
alert
(
"La présence a bien été annulée !"
);
},
100
);
});
// Redraw calendar
calendar
.
refetchEvents
();
},
error
:
function
()
{
closeModal
();
alert
(
"Une erreur est survenue."
);
}
});
}
}
/**
* Proceed affecting a shift registration to a/both member(s) of a pair
* @param {string} partner
* @param {string} shift_id
*/
function
affect_shift
(
partner
,
shift_id
)
{
if
(
is_time_to
(
'affect_shift'
))
{
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
()
{
load_partner_shifts
(
partner_data
.
concerned_partner_id
)
.
then
(()
=>
{
init_shifts_list
();
modal
.
find
(
".btn-modal-ok"
).
show
();
closeModal
();
});
},
error
:
function
()
{
init_shifts_list
();
modal
.
find
(
".btn-modal-ok"
).
show
();
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.`
);
}
});
}
}
/**
* Reset a member extra_shift_done to 0
*/
function
offer_extra_shift
()
{
if
(
is_time_to
(
'offer_extra_shift'
))
{
openModal
();
$
.
ajax
({
type
:
'POST'
,
url
:
"/members_space/offer_extra_shift"
,
dataType
:
"json"
,
data
:
{
partner_id
:
partner_data
.
concerned_partner_id
},
timeout
:
3000
,
success
:
function
()
{
$
(
"#can_delete_future_registrations_area"
).
hide
();
closeModal
();
alert
(
"Don de service effectué"
);
},
error
:
function
()
{
closeModal
();
alert
(
"Une erreur est survenue"
);
}
});
}
}
/* - DOM */
function
init_shifts_list
()
{
function
init_shifts_list
()
{
$
(
".loading-incoming-shifts"
).
hide
();
$
(
".loading-incoming-shifts"
).
hide
();
$
(
"#shifts_list"
).
show
();
$
(
"#shifts_list"
).
show
();
...
@@ -175,7 +312,7 @@ function init_shifts_list() {
...
@@ -175,7 +312,7 @@ function init_shifts_list() {
if
(
partner_data
.
associated_partner_id
===
"False"
&&
partner_data
.
parent_id
===
"False"
)
{
if
(
partner_data
.
associated_partner_id
===
"False"
&&
partner_data
.
parent_id
===
"False"
)
{
shift_line_template
.
find
(
'.affect_associate_registered'
).
hide
();
shift_line_template
.
find
(
'.affect_associate_registered'
).
hide
();
}
else
{
}
else
{
shift_line_template
.
find
(
'.affect_associate_registered'
).
attr
(
'id'
,
'shift_id_'
+
shift
.
id
);
shift_line_template
.
find
(
'.affect_associate_registered'
).
closest
(
".shift_line_container"
).
attr
(
'id'
,
'shift_id_'
+
shift
.
id
);
if
(
shift
.
associate_registered
===
"both"
)
{
if
(
shift
.
associate_registered
===
"both"
)
{
shift_line_template
.
find
(
'.affect_associate_registered'
).
text
(
"Les deux"
);
shift_line_template
.
find
(
'.affect_associate_registered'
).
text
(
"Les deux"
);
}
else
if
(
shift
.
associate_registered
===
"partner"
)
{
}
else
if
(
shift
.
associate_registered
===
"partner"
)
{
...
@@ -228,7 +365,7 @@ function init_shifts_list() {
...
@@ -228,7 +365,7 @@ function init_shifts_list() {
$
(
".affect_associate_registered"
).
on
(
"click"
,
function
()
{
$
(
".affect_associate_registered"
).
on
(
"click"
,
function
()
{
// Display modal
// Display modal
id
=
$
(
this
).
attr
(
'id'
)
let
id
=
$
(
this
).
closest
(
".shift_line_container"
).
attr
(
'id'
)
.
split
(
'_'
)[
2
];
.
split
(
'_'
)[
2
];
let
modal_template
=
$
(
"#modal_affect_shift"
);
let
modal_template
=
$
(
"#modal_affect_shift"
);
...
@@ -267,71 +404,6 @@ function init_shifts_list() {
...
@@ -267,71 +404,6 @@ function init_shifts_list() {
}
}
}
}
/**
* 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
()
{
load_partner_shifts
(
partner_data
.
concerned_partner_id
)
.
then
(()
=>
{
init_shifts_list
();
modal
.
find
(
".btn-modal-ok"
).
show
();
closeModal
();
});
},
error
:
function
()
{
init_shifts_list
();
modal
.
find
(
".btn-modal-ok"
).
show
();
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.`
);
}
});
}
function
offer_extra_shift
()
{
openModal
();
$
.
ajax
({
type
:
'POST'
,
url
:
"/members_space/offer_extra_shift"
,
dataType
:
"json"
,
data
:
{
partner_id
:
partner_data
.
concerned_partner_id
},
timeout
:
3000
,
success
:
function
()
{
$
(
"#can_delete_future_registrations_area"
).
hide
();
closeModal
();
alert
(
"Don de service effectué"
);
},
error
:
function
()
{
closeModal
();
alert
(
"Une erreur est survenue"
);
}
});
}
/**
/**
* Inits the page when the calendar is displayed
* Inits the page when the calendar is displayed
*/
*/
...
@@ -378,8 +450,10 @@ function init_calendar_page() {
...
@@ -378,8 +450,10 @@ function init_calendar_page() {
offer_extra_shift
,
offer_extra_shift
,
"Confirmer"
,
"Confirmer"
,
false
false
)
);
})
});
$
(
"#delete_future_registration"
).
on
(
"click"
,
init_delete_registration_buttons
);
}
}
let
default_initial_view
=
""
;
let
default_initial_view
=
""
;
...
@@ -606,6 +680,26 @@ function init_read_only_calendar_page() {
...
@@ -606,6 +680,26 @@ function init_read_only_calendar_page() {
calendar
.
render
();
calendar
.
render
();
}
}
function
init_delete_registration_buttons
()
{
$
(
".delete_registration_button"
).
css
(
'display'
,
'flex'
);
$
(
".delete_registration_button"
).
off
();
$
(
".delete_registration_button"
).
on
(
"click"
,
function
()
{
let
shift_name
=
$
(
this
).
closest
(
"div"
).
siblings
(
".selectable_shift_line"
).
text
().
trim
();
let
shift_id
=
$
(
this
).
closest
(
".shift_line_container"
).
attr
(
'id'
)
.
split
(
'_'
)[
2
];
openModal
(
`Je m'apprête supprimer ma présence au service du <b>
${
shift_name
}
</b>`
,
()
=>
{
delete_shift_registration
(
shift_id
);
},
"Confirmer"
,
false
)
});
}
function
init_shifts_exchange
()
{
function
init_shifts_exchange
()
{
$
(
".shifts_exchange_page_content"
).
hide
();
$
(
".shifts_exchange_page_content"
).
hide
();
vw
=
window
.
innerWidth
;
vw
=
window
.
innerWidth
;
...
...
shifts/urls.py
View file @
23109cf5
...
@@ -15,6 +15,7 @@ urlpatterns = [
...
@@ -15,6 +15,7 @@ urlpatterns = [
url
(
r'^change_shift'
,
views
.
change_shift
),
url
(
r'^change_shift'
,
views
.
change_shift
),
url
(
r'^affect_shift'
,
views
.
affect_shift
),
url
(
r'^affect_shift'
,
views
.
affect_shift
),
url
(
r'^add_shift'
,
views
.
add_shift
),
url
(
r'^add_shift'
,
views
.
add_shift
),
url
(
r'^cancel_shift'
,
views
.
cancel_shift
),
url
(
r'^request_delay'
,
views
.
request_delay
),
url
(
r'^request_delay'
,
views
.
request_delay
),
url
(
r'^reset_members_positive_points'
,
views
.
reset_members_positive_points
)
url
(
r'^reset_members_positive_points'
,
views
.
reset_members_positive_points
)
]
]
shifts/views.py
View file @
23109cf5
...
@@ -310,6 +310,37 @@ def add_shift(request):
...
@@ -310,6 +310,37 @@ def add_shift(request):
else
:
else
:
return
HttpResponseForbidden
()
return
HttpResponseForbidden
()
def
cancel_shift
(
request
):
""" Annule une présence à un shift """
if
'verif_token'
in
request
.
POST
:
partner_id
=
int
(
request
.
POST
.
get
(
'idPartner'
))
if
Verification
.
verif_token
(
request
.
POST
.
get
(
'verif_token'
),
partner_id
)
is
True
:
cs
=
CagetteShift
()
listRegister
=
[
int
(
request
.
POST
[
'idRegister'
])]
try
:
response
=
cs
.
cancel_shift
(
listRegister
)
# decrement extra_shift_done if param exists
if
'extra_shift_done'
in
request
.
POST
:
target
=
int
(
request
.
POST
[
"extra_shift_done"
])
-
1
# extra security
if
target
<
0
:
target
=
0
cm
=
CagetteMember
(
partner_id
)
cm
.
update_extra_shift_done
(
target
)
return
JsonResponse
({
"res"
:
'response'
})
except
Exception
as
e
:
return
JsonResponse
({
"error"
:
str
(
e
)},
status
=
500
)
else
:
return
HttpResponseForbidden
()
else
:
return
HttpResponseForbidden
()
def
request_delay
(
request
):
def
request_delay
(
request
):
if
'verif_token'
in
request
.
POST
:
if
'verif_token'
in
request
.
POST
:
if
Verification
.
verif_token
(
request
.
POST
.
get
(
'verif_token'
),
int
(
request
.
POST
.
get
(
'idPartner'
)))
is
True
:
if
Verification
.
verif_token
(
request
.
POST
.
get
(
'verif_token'
),
int
(
request
.
POST
.
get
(
'idPartner'
)))
is
True
:
...
...
templates/members_space/index.html
View file @
23109cf5
...
@@ -36,16 +36,15 @@
...
@@ -36,16 +36,15 @@
</div>
</div>
<div
id=
"selectable_shift_line_template"
>
<div
id=
"selectable_shift_line_template"
>
<div
class=
"d-flex"
>
<div
class=
"d-flex
shift_line_container
"
>
<div
class=
"selectable_shift_line btn--primary"
>
<div
class=
"selectable_shift_line btn--primary"
>
<input
type=
"checkbox"
class=
"checkbox"
>
<input
type=
"checkbox"
class=
"checkbox"
>
<div
class=
"selectable_shift_line_text"
>
<div
class=
"selectable_shift_line_text"
>
<span
class=
"shift_line_date"
></span>
-
<span
class=
"shift_line_time"
></span>
<span
class=
"shift_line_date"
></span>
-
<span
class=
"shift_line_time"
></span>
</div>
</div>
</div>
</div>
<div
class=
"affect_associate_registered button--warning"
>
<div
class=
"affect_associate_registered button--warning"
></div>
<div
class=
"delete_registration_button"
><i
class=
"fas fa-lg fa-trash"
></i></div>
</div>
</div>
</div>
</div>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment