update version id + currentDatabase when switching department

This commit is contained in:
xdrm-brackets 2018-05-09 15:12:26 +02:00
parent 3dfa1cc525
commit 13e545e5f9
2 changed files with 22 additions and 5 deletions

View File

@ -78,8 +78,26 @@ class departmentController
if( $dep['idDep'] == $department ){
$_SESSION['AvailableDepartments'] = $deps;
$_SESSION['CurrentDatabase'] = $dep['dbName'];
$_SESSION['CurrentDepartmentId'] = $dep['idDep'];
$_SESSION['VERSION'] = [
'list' => $dep['versions'],
'current' => null
];
// select version with default = 1
foreach($_SESSION['VERSION']['list'] as $v){
if( $v['default'] == 1 ){
$_SESSION['VERSION']['current'] = intval($v['iddatabase']);
$_SESSION['CurrentDatabase'] = $v['dbName'];
break;
}
}
// if no default -> select first
if( !is_int($_SESSION['VERSION']) ){
$_SESSION['VERSION']['current'] = intval($_SESSION['VERSION']['list'][0]['iddatabase']);
$_SESSION['CurrentDatabase'] = $_SESSION['VERSION']['list'][0]['dbName'];
}
return ['switched' => true];

View File

@ -125,7 +125,6 @@ export default {
// 3. Ask for department change
api.call(`GET department/version/switch/${id}`, {}, function(rs){
console.log(rs);
// 1. error -> do nothing
if( rs.error !== 0 )
@ -169,8 +168,8 @@ export default {
if( rs.error !== 0 || !rs.hasOwnProperty('created_id') ){
return popup.ask({
title: 'Error ('+err_code+')',
content: 'La création de sauvegarde à échoué.',
title: 'Erreur ('+err_code+')',
content: 'La création de version à échoué.',
action: 'OK',
type: 'neutral'
}, () => {});