From 7dbbb24db40b4f63c9e07dfa795ce4902308c16d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 10 Sep 2020 13:31:39 -0400 Subject: [PATCH] Update api Zone Saving. Fixes #3037 --- web/api/app/Controller/ZonesController.php | 14 ++++++++------ web/api/app/Model/Zone.php | 4 ---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/web/api/app/Controller/ZonesController.php b/web/api/app/Controller/ZonesController.php index f01931f65..8d5e661bb 100644 --- a/web/api/app/Controller/ZonesController.php +++ b/web/api/app/Controller/ZonesController.php @@ -115,6 +115,7 @@ class ZonesController extends AppController { if ( !$this->Zone->exists($id) ) { throw new NotFoundException(__('Invalid zone')); } + $message = ''; if ( $this->request->is(array('post', 'put')) ) { global $user; $canEdit = (!$user) || $user['Monitors'] == 'Edit'; @@ -123,14 +124,15 @@ class ZonesController extends AppController { return; } if ( $this->Zone->save($this->request->data) ) { - return $this->flash(__('The zone has been saved.'), array('action' => 'index')); + $message = 'The zone has been saved.'; + } else { + $message = 'Error ' . print_r($this->Zone->invalidFields()); } - } else { - $options = array('conditions' => array('Zone.' . $this->Zone->primaryKey => $id)); - $this->request->data = $this->Zone->find('first', $options); } - $monitors = $this->Zone->Monitor->find('list'); - $this->set(compact('monitors')); + $this->set(array( + 'message' => $message, + '_serialize' => array('message') + )); } /** diff --git a/web/api/app/Model/Zone.php b/web/api/app/Model/Zone.php index 0f5e4d653..cdf8464e2 100644 --- a/web/api/app/Model/Zone.php +++ b/web/api/app/Model/Zone.php @@ -41,19 +41,15 @@ class Zone extends AppModel { //array('naturalNumber'), 'message' => 'Zones must have a valid MonitorId', 'allowEmpty' => false, - 'required' => true, //'last' => false, // Stop validation after this rule //'on' => 'create', // Limit validation to 'create' or 'update' operations ), 'Name' => array( 'required' => array( - //'on' => 'create', 'rule' => 'notBlank', 'message' => 'Zone Name must be specified for creation', - 'required' => true, ), ) - ); //The Associations below have been created with all possible keys, those that are not needed can be removed