From ea14cc5dcad843a725936dec012e37eb024baced 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 | 94 +++------------ app/View/Elements/changelog.ctp | 8 +- app/View/Elements/inlineFieldEdit.ctp | 75 ++++++++++++ app/View/Elements/javascript.ctp | 34 ++++++ app/View/Elements/pageTitleAndButtons.ctp | 57 ++++++++- app/View/Helper/BadgeHelper.php | 109 ++++++++++++++++- app/View/Layouts/default.ctp | 2 + app/View/Layouts/lightbox.ctp | 3 + app/webroot/css/co-base.css | 137 ++++++++++++++++++---- app/webroot/js/comanage.js | 12 ++ app/webroot/js/luxon/license.txt | 4 + app/webroot/js/luxon/luxon.min.js | 1 + 15 files changed, 454 insertions(+), 107 deletions(-) create mode 100644 app/View/Elements/inlineFieldEdit.ctp create mode 100644 app/webroot/js/luxon/license.txt create mode 100644 app/webroot/js/luxon/luxon.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 ec1aa9add..1b590b495 100644 --- a/app/View/CoPeople/fields.inc +++ b/app/View/CoPeople/fields.inc @@ -418,7 +418,7 @@ ); $linkparams = array( 'class' => 'addbutton', - //'escape' => false + 'escape' => false ); print $this->Html->link(_txt('op.add'), @@ -566,9 +566,11 @@ _txt('fd.name.primary_name'), $this->Badge->getBadgeColor('Secondary'), false, - true + true, + null, null, + 'ml-1' ); - $cn = $n['primary_name'] ? filter_var(generateCn($n),FILTER_SANITIZE_SPECIAL_CHARS) . " " . $primary_name_with_bg + $cn = $n['primary_name'] ? filter_var(generateCn($n),FILTER_SANITIZE_SPECIAL_CHARS) . $primary_name_with_bg : filter_var(generateCn($n),FILTER_SANITIZE_SPECIAL_CHARS); if($perm == PermissionEnum::ReadWrite) { print $this->Html->link( @@ -945,59 +947,20 @@
  • Form->create('CoPerson', array('url' => array('action'=>'edit','id'=>'CoPersonEditAttributesForm'))); - print $this->Form->hidden('CoPerson.co_id', array('default' => $co_people[0]['CoPerson']['co_id'],'id'=>'CoPersonCoIdAgain')). "\n"; + print $this->Form->create('CoPerson', + array( + 'url' => array( + 'action'=>'edit', + 'id'=>'CoPersonEditAttributesForm', + $co_people[0]['CoPerson']['id'], + ))); + print $this->Form->hidden('CoPerson.co_id', array('default' => $co_people[0]['CoPerson']['co_id'],'id'=>'CoPersonCoIdAgain')). PHP_EOL; ?> indeterminate_check_box