From e2751c0597573c09d9ad3acae9961483511cf7af Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 1 May 2013 21:03:25 -0400 Subject: [PATCH] Initial ability to edit limited options of existing monitors --- web/app/Controller/MonitorsController.php | 26 +++++++++++++++++++++++ web/app/View/Monitors/edit.ctp | 10 +++++++++ web/app/View/Monitors/index.ctp | 8 ++++--- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 web/app/View/Monitors/edit.ctp diff --git a/web/app/Controller/MonitorsController.php b/web/app/Controller/MonitorsController.php index 76f0586c2..9fb9391f9 100644 --- a/web/app/Controller/MonitorsController.php +++ b/web/app/Controller/MonitorsController.php @@ -18,6 +18,32 @@ } $this->set('monitor', $monitor); } + +public function edit($id = null) { + if (!$id) { + throw new NotFoundException(__('Invalid monitor')); + } + + $monitor = $this->Monitor->findById($id); + if (!$monitor) { + throw new NotFoundException(__('Invalid monitor')); + } + + if ($this->request->is('put') || $this->request->is('post')) { + $this->Monitor->id = $id; + if ($this->Monitor->save($this->request->data)) { + $this->Session->setFlash('Your monitor has been updated.'); + $this->redirect(array('action' => 'index')); + } else { + $this->Session->setFlash('Unable to update your monitor.'); + } + } + + if (!$this->request->data) { + $this->request->data = $monitor; + } +} + } ?> diff --git a/web/app/View/Monitors/edit.ctp b/web/app/View/Monitors/edit.ctp new file mode 100644 index 000000000..a5bb9650a --- /dev/null +++ b/web/app/View/Monitors/edit.ctp @@ -0,0 +1,10 @@ +

Edit Monitor

+Form->create('Monitor'); + echo $this->Form->input('Name'); + $functionoptions = array('Modect' => 'Modect', 'Monitor' => 'Monitor', 'Record' => 'Record', 'None' => 'None', 'Nodect' => 'Nodect', 'Mocord' => 'Mocord'); + echo $this->Form->input('Function', array('type' => 'select', 'options' => $functionoptions)); + echo $this->Form->input('Enabled', array('type' => 'checkbox')); + echo $this->Form->input('Id', array('type' => 'hidden')); + echo $this->Form->end('Save Monitor'); +?> diff --git a/web/app/View/Monitors/index.ctp b/web/app/View/Monitors/index.ctp index 543ac5434..d72304e5e 100644 --- a/web/app/View/Monitors/index.ctp +++ b/web/app/View/Monitors/index.ctp @@ -9,9 +9,11 @@ - Html->link($monitor['Monitor']['Name'], -array('controller' => 'monitors', 'action' => 'view', $monitor['Monitor']['Id'])); ?> - + Html->link($monitor['Monitor']['Name'],array('controller' => 'monitors', 'action' => 'view', $monitor['Monitor']['Id'])); ?> + + + Html->link($monitor['Monitor']['Function'], array('action' => 'edit', $monitor['Monitor']['Id'])); ?> +