From d3e9835d3cca4515aeb0e1693671e62e4f771a83 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 7 Apr 2021 19:49:57 +0300 Subject: [PATCH] Refactor CO Person Attributes Block --- app/Controller/AppController.php | 6 + app/Controller/CoPeopleController.php | 1 + app/Controller/StandardController.php | 18 +- app/View/CoPeople/fields.inc | 243 ++++++++++++------ app/View/Elements/changelog.ctp | 8 +- app/View/Elements/inlineFieldEdit.ctp | 75 ++++++ app/View/Elements/javascript.ctp | 29 +++ app/View/Elements/pageTitleAndButtons.ctp | 57 +++- app/View/Helper/BadgeHelper.php | 109 +++++++- app/View/Layouts/lightbox.ctp | 3 + app/webroot/css/co-base.css | 89 ++++++- app/webroot/js/comanage.js | 14 +- ...nt-timezone-with-data-10-year-range.min.js | 1 + .../js/moment/moment-with-locales.min.js | 1 + 14 files changed, 564 insertions(+), 90 deletions(-) create mode 100644 app/View/Elements/inlineFieldEdit.ctp create mode 100644 app/webroot/js/moment/moment-timezone-with-data-10-year-range.min.js create mode 100644 app/webroot/js/moment/moment-with-locales.min.js diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 830f0fd18..db1255b95 100644 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -122,6 +122,12 @@ public function beforeFilter() { // XXX CO-351 Placeholder $this->Session->write('Config.language', 'eng'); + // CSRF token should expire along with the Session. This is the default in CAKEPHP 3.7.x+ + // https://book.cakephp.org/3/en/controllers/middleware.html#csrf-middleware + // https://github.com/cakephp/cakephp/issues/13532 + // - expiry, How long the CSRF token should last. Defaults to browser session. + $this->Security->csrfUseOnce = false; + Configure::write('Config.language', $this->Session->read('Config.language')); // Tell the Auth module to call the controller's isAuthorized() function. diff --git a/app/Controller/CoPeopleController.php b/app/Controller/CoPeopleController.php index 92f3e7cf7..d02db0029 100644 --- a/app/Controller/CoPeopleController.php +++ b/app/Controller/CoPeopleController.php @@ -252,6 +252,7 @@ public function canvas($id) { // This is pretty similar to the standard view or edit methods. if(!$this->request->is('restful') && $this->request->is('get')) { + $this->set('vv_title_status_bg', true); $this->edit($id); } } diff --git a/app/Controller/StandardController.php b/app/Controller/StandardController.php index b59c2e558..a96808014 100644 --- a/app/Controller/StandardController.php +++ b/app/Controller/StandardController.php @@ -538,7 +538,15 @@ function edit($id) { return; } - + + // Complete the request with the `status` field if it is of type PUT + // Usefull for asychronous single-field Requests + if($req === 'CoPerson' + && empty($this->request->data[$req]["status"]) + && !empty($curdata[$req]["status"])) { + $this->request->data[$req]["status"] = $curdata[$req]["status"]; + } + $data = $this->request->data; if(!isset($this->request->data[$req]['id'])) { @@ -633,6 +641,14 @@ function edit($id) { if($this->request->is('restful')) { $this->Api->restResultHeader(200, "OK"); + } elseif ($this->request->is('ajax')) { + // Return the new data + $this->layout = null; + $this->autoRender = false; + $this->response->type('json'); + $this->response->statusCode(201); + $this->response->body(json_encode(array(0 => $data))); + return $this->response; } else { // Redirect to index view diff --git a/app/View/CoPeople/fields.inc b/app/View/CoPeople/fields.inc index bb1dccef8..1b137e2ed 100644 --- a/app/View/CoPeople/fields.inc +++ b/app/View/CoPeople/fields.inc @@ -343,6 +343,10 @@