diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index bb4f1d407..b1bb8887a 100755 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -46,15 +46,9 @@ class ProfilUpdate extends Auth_Controller } public function getProfilUpdates($status=null){ - $this->load->library('PermissionLib'); - $studentBerechtigung = $this->permissionlib->isBerechtigt('student/stammdaten','s'); - $mitarbeiterBerechtigung = $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','s'); - $options = ["mitarbeiterView"=>$mitarbeiterBerechtigung,"studentView"=>$studentBerechtigung]; - if(isset($status)){ - $options['status'] = $status; - } - $res = $this->ProfilChangeModel->getProfilUpdate($options); + + $res = $this->ProfilChangeModel->getProfilUpdate(isset($status)?['status'=>$status]:null); echo json_encode($res); } diff --git a/application/models/person/Profil_change_model.php b/application/models/person/Profil_change_model.php index e364b33e2..104f17974 100755 --- a/application/models/person/Profil_change_model.php +++ b/application/models/person/Profil_change_model.php @@ -15,6 +15,8 @@ class Profil_change_model extends DB_Model $this->load->model('crm/Student_model','StudentModel'); $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); + + $this->load->library('PermissionLib'); } /** @@ -53,8 +55,12 @@ class Profil_change_model extends DB_Model * returns all profil updates if id is set to null */ public function getProfilUpdate($whereClause=null){ + + $studentBerechtigung = $this->permissionlib->isBerechtigt('student/stammdaten','s'); + $mitarbeiterBerechtigung = $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','s'); + $res =[]; - if($whereClause["studentView"]) { + if($studentBerechtigung) { $this->addJoin('tbl_student','tbl_student.student_uid=tbl_cis_profil_update.uid'); $studentRequests = $this->loadWhere(isset($whereClause['status']) && $whereClause['status']? ['status'=>$whereClause['status']]:[]); if(isError($studentRequests)) return error("db error: ". getData($studentRequests)); @@ -63,7 +69,7 @@ class Profil_change_model extends DB_Model array_push($res,$request); } } - if($whereClause["mitarbeiterView"]) { + if($mitarbeiterBerechtigung) { $this->addJoin('tbl_mitarbeiter','tbl_mitarbeiter.mitarbeiter_uid=tbl_cis_profil_update.uid'); $mitarbeiterRequests = $this->loadWhere(isset($whereClause['status']) && $whereClause['status']? ['status'=>$whereClause['status']]:[]); if(isError($mitarbeiterRequests)) return error("db error: ". getData($mitarbeiterRequests)); diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js index 0d936fe97..9a6b9548f 100755 --- a/public/js/apps/Cis/ProfilUpdateRequests.js +++ b/public/js/apps/Cis/ProfilUpdateRequests.js @@ -1,26 +1,26 @@ import fhcapifactory from "../api/fhcapifactory.js"; import { CoreFilterCmpt } from "../../components/filter/Filter.js"; import AcceptDenyUpdate from "../../components/Cis/ProfilUpdate/AcceptDenyUpdate.js"; +import Alert from "../../components/Bootstrap/Alert.js"; Vue.$fhcapi = fhcapifactory; -const sortProfilUpdates = (ele1,ele2)=>{ - +const sortProfilUpdates = (ele1, ele2) => { let result = 0; - if(ele1.status === 'pending'){ - result= -1; - } - else if(ele1.status === 'accepted'){ - result= ele2.status ==='rejected'? -1 : 1; - } - else{ - result= 1; + if (ele1.status === "pending") { + result = -1; + } else if (ele1.status === "accepted") { + result = ele2.status === "rejected" ? -1 : 1; + } else { + result = 1; } //? if they have the same status the insert date is used for ordering - if(ele1.status === ele2.status){ - result= new Date(ele2.insertamum.split('.').reverse().join('-')) - new Date(ele1.insertamum.split('.').reverse().join('-')); + if (ele1.status === ele2.status) { + result = + new Date(ele2.insertamum.split(".").reverse().join("-")) - + new Date(ele1.insertamum.split(".").reverse().join("-")); } return result; - }; +}; const app = Vue.createApp({ components: { @@ -30,109 +30,110 @@ const app = Vue.createApp({ return { showAll: false, profil_updates_table_options: { - - ajaxResponse:function(url, params, response){ - //url - the URL of the request - //params - the parameters passed with the request - //response - the JSON object returned in the body of the response. - //? sorts the response data from the backend - if(response) - response.sort(sortProfilUpdates); - - return response; + ajaxResponse: function (url, params, response) { + //url - the URL of the request + //params - the parameters passed with the request + //response - the JSON object returned in the body of the response. + //? sorts the response data from the backend + if (response) response.sort(sortProfilUpdates); + + return response; }, //? adds tooltip with the status message of a profil update request if its status is not pending - columnDefaults:{ - tooltip:function(e, cell, onRendered){ - //e - mouseover event - //cell - cell component - //onRendered - onRendered callback registration function - let statusMessage = cell.getData().status_message; - let statusDate = cell.getData().status_timestamp; - let status = cell.getData().status; - if(!statusMessage){ - return null; - } - let el = document.createElement("div"); - el.classList.add("border","border-dark"); - - let statusDateEl = document.createElement("p"); - statusDateEl.innerHTML = "Request was "+ status + " on " + statusDate ; - let statusMessageEl = document.createElement("span"); - statusMessageEl.innerHTML = "Status message: " + statusMessage ; - - el.appendChild(statusDateEl); - el.appendChild(statusMessageEl); - return el; - }, - }, - rowContextMenu: (e, component)=>{ + columnDefaults: { + tooltip: function (e, cell, onRendered) { + //e - mouseover event + //cell - cell component + //onRendered - onRendered callback registration function + let statusMessage = cell.getData().status_message; + let statusDate = cell.getData().status_timestamp; + let status = cell.getData().status; + if (!statusMessage) { + return null; + } + let el = document.createElement("div"); + el.classList.add("border", "border-dark"); - let menu =[]; - if(component.getData().status === "pending"){ - menu.push( - - { - label:" Accept Request", - action:(e, column)=>{ - Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(column.getData()).then((res) => { - this.$refs.UpdatesTable.tabulator.setData(); - }); - - } - }, - { - separator:true, - }, - { - label:" Deny Request", - action:(e, column)=>{ - - Vue.$fhcapi.ProfilUpdate.denyProfilRequest(column.getData()).then((res) => { - this.$refs.UpdatesTable.tabulator.setData(); - }); - } - }, - { - separator:true, - }, - { - label:" Show Request", - action:(e, column)=>{ - this.showModal(column.getData()); - } - } - - ); - }else{ + let statusDateEl = document.createElement("p"); + statusDateEl.innerHTML = + "Request was " + status + " on " + statusDate; + let statusMessageEl = document.createElement("span"); + statusMessageEl.innerHTML = "Status message: " + statusMessage; + + el.appendChild(statusDateEl); + el.appendChild(statusMessageEl); + return el; + }, + }, + rowContextMenu: (e, component) => { + let menu = []; + if (component.getData().status === "pending") { menu.push( { - label:" Show Request", - action:(e, column)=>{ + label: " Accept Request", + action: (e, column) => { + Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(column.getData()) + .then((res) => { + console.log("here"); + this.$refs.UpdatesTable.tabulator.setData(); + }) + .catch((e) => { + Alert.popup(Vue.h('div',{innerHTML:e.response.data})); + }); + }, + }, + { + separator: true, + }, + { + label: + " Deny Request", + action: (e, column) => { + Vue.$fhcapi.ProfilUpdate.denyProfilRequest( + column.getData() + ).then((res) => { + this.$refs.UpdatesTable.tabulator.setData(); + }).catch((e) => { + Alert.popup(Vue.h('div',{innerHTML:e.response.data})); + }); + }, + }, + { + separator: true, + }, + { + label: " Show Request", + action: (e, column) => { this.showModal(column.getData()); - } + }, } - ) + ); + } else { + menu.push({ + label: " Show Request", + action: (e, column) => { + this.showModal(column.getData()); + }, + }); } return menu; + }, + ajaxURL: + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/Cis/ProfilUpdate/`, - } , - ajaxURL:FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/`, - - ajaxURLGenerator: (url,config,params)=>{ + ajaxURLGenerator: (url, config, params) => { //? this function needs to be an array function in order to access the this properties of the Vue component - if(this.showAll){ - return url +"getProfilUpdates"; - }else{ - return url +"getProfilUpdates/pending"; + if (this.showAll) { + return url + "getProfilUpdates"; + } else { + return url + "getProfilUpdates/pending"; } - }, height: 600, layout: "fitColumns", - + columns: [ { title: "UID", @@ -172,7 +173,6 @@ const app = Vue.createApp({ hozAlign: "center", headerFilter: true, formatter: function (cell, para) { - switch (cell.getValue()) { case "pending": return "