diff --git a/Controller/ActAsPeopleController.php b/Controller/ActAsPeopleController.php index aafa563..5a07210 100644 --- a/Controller/ActAsPeopleController.php +++ b/Controller/ActAsPeopleController.php @@ -113,7 +113,7 @@ public function add(): void if($ret) { $this->Api->restResultHeader(HttpStatusCodesEnum::HTTP_CREATED, 'Added'); // I am registering a flash message. It will render after the frontend triggers a reload - $this->Flash->set("Act As {$fullName}" , ['key' => 'success']); + $this->Flash->set("Act As {$fullName} Enabled" , ['key' => 'success']); $args = []; $args['conditions']['ActAsPerson.id'] = $this->ActAsPerson->id; @@ -159,12 +159,12 @@ public function add(): void public function delete():void { - $this->layout = null; - $this->autoRender = false; + $this->request->allowMethod('ajax'); + $this->layout = 'ajax'; if(!$this->request->is('delete') - || $this->request->is('ajax') - || $this->request->is('restful')) { + && !$this->request->is('ajax') + ) { throw new RuntimeException('HTTP Method Not Allowed', HttpStatusCodesEnum::HTTP_METHOD_NOT_ALLOWED); } @@ -190,19 +190,33 @@ public function delete():void $ret = $this->ActAsPerson->deleteAll($conditions, true, true); } catch(Exception $e) { - $err = filter_var($e->getMessage(),FILTER_SANITIZE_SPECIAL_CHARS); - $this->Flash->set($err, ['key' => 'error']); + $error = filter_var($e->getMessage(),FILTER_SANITIZE_SPECIAL_CHARS); + $this->Api->restResultHeader(HttpStatusCodesEnum::HTTP_INTERNAL_SERVER_ERROR, 'Other Error'); + $this->set(compact('error')); + $this->set('_serialize', 'error'); + return; } // Set flash message - if($ret) { - $this->Flash->set(_txt('er.deleted-a', ['Person']) , ['key' => 'success']); - } else { - $this->Flash->set(_txt('er.delete'), ['key' => 'error']); + if(!$ret) { + $error = ErrorsEnum::NotDeleted; + $this->Api->restResultHeader(HttpStatusCodesEnum::HTTP_BAD_REQUEST, 'Bad Request'); + $this->set(compact('error')); + $this->set('_serialize', 'error'); + return; } - // Redirect back to the plugin - $this->redirect($redirect); + // We will register a Flash message here. The frontend will reload and it will be rendered + $this->Flash->set('Act As Disabled', ['key' => 'success']); + + // We do not redirect but we pass data back to the frontend because we + // want to keep the view structure as simple as possible. If we redirect we will + // have to add more JSON view infrastructure. We will let the frontend + // handle the redirect + $this->Api->restResultHeader(HttpStatusCodesEnum::HTTP_OK, 'Success'); + $success = ['status' => 'Success', 'message' => 'Succeeded']; + $this->set(compact('success')); + $this->set('_serialize', 'success'); } diff --git a/Lib/enum.php b/Lib/enum.php index dd8185b..76a5413 100644 --- a/Lib/enum.php +++ b/Lib/enum.php @@ -1,11 +1,11 @@ 'ERROR', 'message' => 'Already Exists']; const Error = ['status' => 'ERROR', 'message' => 'Error']; const Exception = ['status' => 'ERROR', 'message' => 'Exception']; const NoAccess = ['status' => 'ERROR', 'message' => 'No Access']; const NotAdded = ['status' => 'ERROR', 'message' => 'Not Added']; - const Conflict = ['status' => 'ERROR', 'message' => 'Already Exists']; const NotDeleted = ['status' => 'ERROR', 'message' => 'Not Deleted']; } diff --git a/View/Elements/ActAsPeopleAutocomplete.ctp b/View/Elements/ActAsPeopleAutocomplete.ctp index 2769d92..6929cee 100644 --- a/View/Elements/ActAsPeopleAutocomplete.ctp +++ b/View/Elements/ActAsPeopleAutocomplete.ctp @@ -147,8 +147,9 @@ $suffix = Configure::read('debug') > 0 ? '?time=' . time() : ''; return } this.rawData = await resp.json(); - this.loading = false - + // Since we are reloading, we do not want to stop the spinner + // this.loading = false + // Force reload here window.location.reload(); }, diff --git a/View/Elements/ActionItem.ctp b/View/Elements/ActionItem.ctp index fe8719f..6ab0182 100644 --- a/View/Elements/ActionItem.ctp +++ b/View/Elements/ActionItem.ctp @@ -1,61 +1,186 @@ 0 ? '?time=' . time() : ''; + ?> - -
-
-
- -
- -
- -
-
- Form->create('ActAsPeople', [ - 'id' => 'ActAsPeopleDeleteForm' . $person['value'], - 'inputDefaults' => [ - 'label' => false, - 'div' => false - ], - 'url' => [ - 'plugin' => 'grouper_lite_widget', - 'controller' => 'act_as_people', - 'action' => 'delete', - 'co' => $vv_coid, - 'glid' => $vv_config['CoGrouperLiteWidget']['id'], - 'act_as_copersonid' => $person['value'], - 'copersonid' => $vv_copersonid - ], - 'type' => 'delete' - ]); - $options = [ - 'label' => 'Disable', - 'onclick' => 'javascript:handleActionRedirect(event)', - 'class' => 'btn btn-grouper btn-fit btn-block btn-danger btn-sm m-1 text-nowrap member-del-btn', - ]; - echo $this->Form->end($options); - ?> -
+ + diff --git a/View/Elements/ActionSideBar.ctp b/View/Elements/ActionSideBar.ctp index 8658819..339bcfb 100644 --- a/View/Elements/ActionSideBar.ctp +++ b/View/Elements/ActionSideBar.ctp @@ -6,7 +6,7 @@ }) -