Skip to content
Snippets Groups Projects
Commit 27ed3bd7 authored by nicrausaz's avatar nicrausaz
Browse files

Nouvelle gestion des places ok

parent 284cf7a3
No related branches found
No related tags found
No related merge requests found
......@@ -108,7 +108,8 @@ class PositionsController extends Controller
$has_permitted_role = AccessLevelHelper::hasPermittedRole($this->user_role, 'responsable');
$position_access_groups = $this->request->input('access_groups');
$position_access_groups = $this->request->input('access_group_cleared');
$position_access_groups_to_create = $this->request->input('new_groups');
$position_spot_number = $this->request->input('position_spot_number');
$location_id = $this->request->input('location_id');
$job_id = $this->request->input('job_id');
......@@ -116,7 +117,6 @@ class PositionsController extends Controller
$wanted_position_exists = DB::table('position')->where('position_id', $id)->exists();
if ($wanted_position_exists && $has_permitted_role) {
// TODO: new value for access group ?
DB::table('position')->where('position_id', $id)->update([
"position_spot_number" => $position_spot_number,
"fk_location" => $location_id,
......@@ -134,6 +134,16 @@ class PositionsController extends Controller
]);
}
foreach ($position_access_groups_to_create as $group) {
DB::table('access_group')->insertGetId([
"access_group_value" => $group
]);
DB::table('has_access')->insert([
"fk_access_group" => $group,
"fk_position" => $id
]);
}
return ["message" => lang::get('http.success.updated.position'), "id" => $id];
} else {
return response()->json(['error' => 403, 'message' => lang::get('http.unauthorized')], 403);
......@@ -142,7 +152,6 @@ class PositionsController extends Controller
public function deletePosition($id) {
$has_permitted_role = AccessLevelHelper::hasPermittedRole($this->user_role, 'responsable');
$wanted_position_exists = DB::table('position')->where('position_id', $id)->exists();
$wanted_position_in_use = DB::table('applicant')->where('fk_position', $id)->exists();
......@@ -150,6 +159,7 @@ class PositionsController extends Controller
if ($wanted_position_in_use) {
return response()->json(['error' => 403, 'message' => lang::get('http.error.deleted.position')], 403);
} else {
DB::table('has_access')->where('fk_position', $id)->delete();
DB::table('position')->where('position_id', $id)->delete();
return ["message" => lang::get('http.success.deleted.position')];
}
......
......@@ -62,25 +62,39 @@ export function createPosition(context, data) {
}
export function updatePosition(context, data) {
axios({
method: 'patch',
url: '/position/' + data.position_id,
data: data
data.new_groups = []
data.access_group_cleared = []
data.access_groups.forEach(group => {
if (!group.access_group_value) {
data.new_groups.push(group)
} else {
data.access_group_cleared.push(group)
}
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
return new Promise(resolve => {
axios({
method: 'patch',
url: '/position/' + data.position_id,
data: data
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
resolve()
})
})
}
export function deletePosition(context, data) {
axios({
method: 'delete',
url: '/position/' + data.position_id,
data: data
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
return new Promise(resolve => {
axios({
method: 'delete',
url: '/position/' + data.position_id
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
resolve()
})
})
}
export function createJob(context, data) {
......
<template>
<div id="openjobs-view">
<h1>Places ouvertes</h1>
<template>
<template v-if="loaded">
<div>
<v-toolbar flat color="white">
<v-spacer></v-spacer>
......@@ -93,10 +93,10 @@
<template v-slot:items="props">
<td>{{ props.item.job_full_value }}</td>
<td>{{ props.item.location_site }}</td>
<!-- <td
<td
v-if="props.item.access_groups.length > 1"
>{{ props.item.access_groups[0].access_group_value }} + {{props.item.access_groups.length-1}} autre(s) groupes(s)</td>-->
<!-- <td v-else>{{props.item.access_groups[0].access_group_value }}</td> -->
>{{ props.item.access_groups[0].access_group_value }} + {{props.item.access_groups.length-1}} autre(s) groupes(s)</td>
<td v-else>{{props.item.access_groups[0].access_group_value }}</td>
<td>{{ props.item.position_spot_number }}</td>
<td>
<v-icon class="mr-2" @click="editItem(props.item)">edit</v-icon>
......@@ -114,6 +114,7 @@ export default {
name: 'openjobs-view',
data() {
return {
loaded: false,
dialog: false,
addJob: false,
addLocation: false,
......@@ -162,14 +163,17 @@ export default {
}
},
created() {
this.loadData()
this.loadData().then(this.loaded = true)
},
methods: {
loadData() {
this.$store.dispatch('modulePositions/getPositions')
this.$store.dispatch('modulePositions/getJobs')
this.$store.dispatch('modulePositions/getLocations')
this.$store.dispatch('modulePositions/getAccessGroups')
return new Promise(resolve => {
this.$store.dispatch('modulePositions/getPositions')
this.$store.dispatch('modulePositions/getJobs')
this.$store.dispatch('modulePositions/getLocations')
this.$store.dispatch('modulePositions/getAccessGroups')
resolve()
})
},
editItem(item) {
this.editedIndex = item.position_id
......@@ -178,8 +182,7 @@ export default {
},
deleteItem(item) {
if (confirm('Voulez-vous vraiment supprimer cette offre ?')) {
this.$store.dispatch('modulePositions/deletePosition', item)
this.loadData()
this.$store.dispatch('modulePositions/deletePosition', item).then(setTimeout(() => { this.loadData() }, 300))
}
},
close() {
......@@ -194,13 +197,13 @@ export default {
save() {
if (this.editedIndex != -1) {
// Edit
this.$store.dispatch('modulePositions/updatePosition', this.editedItem)
this.$store.dispatch('modulePositions/updatePosition', this.editedItem).then(setTimeout(() => { this.loadData() }, 300))
} else {
// create
this.$store.dispatch('modulePositions/createPosition', this.editedItem)
this.$store.dispatch('modulePositions/createPosition', this.editedItem).then(setTimeout(() => { this.loadData() }, 300))
}
this.close()
setTimeout(() => { this.loadData() }, 300)
// setTimeout(() => { this.loadData() }, 300)
},
addNewJob() {
if (this.addJob) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment