From 50f7531fa671876de66a4c53013a64564842e54b Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 22 Mar 2017 17:21:10 +0100 Subject: [PATCH] system/Users: saving stufe and gruppe via ajax --- application/controllers/system/Users.php | 22 +++++++++++---- application/views/system/users.php | 36 +++++++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/application/controllers/system/Users.php b/application/controllers/system/Users.php index aeef474ff..db58980ea 100644 --- a/application/controllers/system/Users.php +++ b/application/controllers/system/Users.php @@ -100,16 +100,22 @@ class Users extends VileSci_Controller // Load model PrestudentstatusModel $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); - $result = $this->PrestudentstatusModel->updateStufe($prestudentIdArray, $stufe); + $result = error("No valid parameters"); + if (isset($stufe) && isset($prestudentIdArray) && is_array($prestudentIdArray) && count($prestudentIdArray) >0) + { + $result = $this->PrestudentstatusModel->updateStufe($prestudentIdArray, $stufe); + } + + $this->output->set_header('Content-Type: application/json; charset=utf-8'); if (isSuccess($result)) { $href = str_replace("/system/Users/linkToStufe", "/system/Users", $_SERVER["REQUEST_URI"]); - echo "
Data correctly saved - Back
"; + echo '{"msg": "Data correctly saved"}'; } else { - echo "
Error occurred while saving data, please contact the administrator.
"; + echo '{"msg": "Error occurred while saving data, please contact the administrator"}'; } } @@ -121,16 +127,20 @@ class Users extends VileSci_Controller // Load model PrestudentstatusModel $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $result = $this->PrestudentModel->updateAufnahmegruppe($prestudentIdArray, $aufnahmegruppe); + $result = error("No valid parameters"); + if (isset($aufnahmegruppe) && isset($prestudentIdArray) && is_array($prestudentIdArray) && count($prestudentIdArray) >0) + { + $result = $this->PrestudentModel->updateAufnahmegruppe($prestudentIdArray, $aufnahmegruppe); + } if (isSuccess($result)) { $href = str_replace("/system/Users/linkToAufnahmegruppe", "/system/Users", $_SERVER["REQUEST_URI"]); - echo "
Data correctly saved - Back
"; + echo '{"msg": "Data correctly saved"}'; } else { - echo "
Error occurred while saving data, please contact the administrator.
"; + echo '{"msg": "Error occurred while saving data, please contact the administrator"}'; } } diff --git a/application/views/system/users.php b/application/views/system/users.php index e93177081..5bda4f1b5 100644 --- a/application/views/system/users.php +++ b/application/views/system/users.php @@ -198,22 +198,38 @@ if ($("#linkToStufe")) { $("#linkToStufe").click(function() { - if ($("#linkUsersForm")) - { - $("#linkUsersForm").attr("action", ""); - $("#linkUsersForm").submit(); - } + $.ajax({ + type: "POST", + dataType: "json", + url: "", + data: $("#linkUsersForm").serialize(), + success: function(data, textStatus, jqXHR) { + alert(data.msg); + $("#usersFiltersForm").submit(); + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(textStatus + " - " + errorThrown + " - " + jqXHR.responseText); + } + }); }); } if ($("#linkToGruppe")) { $("#linkToGruppe").click(function() { - if ($("#linkUsersForm")) - { - $("#linkUsersForm").attr("action", ""); - $("#linkUsersForm").submit(); - } + $.ajax({ + type: "POST", + dataType: "json", + url: "", + data: $("#linkUsersForm").serialize(), + success: function(data, textStatus, jqXHR) { + alert(data.msg); + $("#usersFiltersForm").submit(); + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(textStatus + " - " + errorThrown + " - " + jqXHR.responseText); + } + }); }); }