Added ability to delete a lock
git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@1040 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -75,10 +75,10 @@ class LocksController extends AppController {
|
||||
function view($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('controller' => 'accounts', 'action'=>'index'));
|
||||
$this->redirect(array('controller' => 'locks', 'action'=>'index'));
|
||||
}
|
||||
|
||||
// Get the UnitSize and related fields
|
||||
// Get the lock and related fields
|
||||
$this->Lock->id = $id;
|
||||
$lock = $this->Lock->find
|
||||
('first', array
|
||||
@@ -91,6 +91,10 @@ class LocksController extends AppController {
|
||||
array('action' => 'edit', $id), null,
|
||||
'ACTION');
|
||||
|
||||
$this->addSideMenuLink('Delete',
|
||||
array('action' => 'delete', $id), null,
|
||||
'ACTION');
|
||||
|
||||
$this->set(compact('lock'));
|
||||
|
||||
// Prepare to render.
|
||||
@@ -158,4 +162,55 @@ class LocksController extends AppController {
|
||||
$this->edit();
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: delete
|
||||
* - Deletes an old lock
|
||||
*/
|
||||
function delete($id) {
|
||||
if (isset($this->data)) {
|
||||
// Check to see if the operation was cancelled.
|
||||
if (isset($this->params['form']['cancel'])) {
|
||||
if (isset($this->data['Lock']['id']))
|
||||
$this->redirect(array('action'=>'view', $this->data['Lock']['id']));
|
||||
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
|
||||
// Delete the lock and all associated data
|
||||
if (!$this->Lock->destroy($this->data['Lock']['id'])) {
|
||||
$this->Session->setFlash(__('Failed to delete lock.', true));
|
||||
$this->redirect(array('action'=>'view', $this->data['Lock']['id']));
|
||||
}
|
||||
|
||||
// It's gone. Go back to the list of locks
|
||||
$this->redirect(array('controller' => 'locks', 'action'=>'index'));
|
||||
}
|
||||
|
||||
// User must specify an ID.
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('controller' => 'locks', 'action'=>'index'));
|
||||
}
|
||||
|
||||
// Get the lock and related fields
|
||||
$this->Lock->id = $id;
|
||||
$lock = $this->Lock->find
|
||||
('first', array
|
||||
('contain' => array('Unit'),
|
||||
));
|
||||
|
||||
// Make sure the lock isn't in use.
|
||||
if (isset($lock['Unit']) && count($lock['Unit']) > 0) {
|
||||
$this->Session->setFlash(__('Lock currently on units. Cannot be deleted!', true));
|
||||
$this->redirect(array('action'=>'view', $id));
|
||||
}
|
||||
|
||||
// Prepare to render.
|
||||
$this->data = $lock;
|
||||
$title = "Delete Lock : {$lock['Lock']['name']}";
|
||||
$this->set(compact('title'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,41 @@ class Lock extends AppModel {
|
||||
return $this->prReturn($this->save($data, false));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: destroy
|
||||
* - destroys a lock
|
||||
*/
|
||||
|
||||
function destroy($id) {
|
||||
$this->prEnter(compact('id'));
|
||||
|
||||
// Can't delete a lock that's in use... check.
|
||||
$this->id = $id;
|
||||
$lock = $this->find
|
||||
('first', array
|
||||
('contain' => array('Unit'),
|
||||
));
|
||||
|
||||
// If it's in use, bail with error
|
||||
$this->pr(1, $lock);
|
||||
if (isset($lock['Unit']) && count($lock['Unit']) > 0)
|
||||
return $this->prReturn(false);
|
||||
|
||||
// Otherwise, attempt to delete the lock from the database
|
||||
return $this->prReturn($this->delete());
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: lockList
|
||||
* - list of all locks in the system
|
||||
*/
|
||||
|
||||
function lockList() {
|
||||
return $this->find('list',
|
||||
array('order' =>
|
||||
|
||||
18
site/views/locks/delete.ctp
Normal file
18
site/views/locks/delete.ctp
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
; // alignment
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
* Lock Delete
|
||||
*/
|
||||
|
||||
echo '<div class="lock delete">' . "\n";
|
||||
|
||||
echo $form->create('Lock', array('action' => 'delete')) . "\n";
|
||||
echo $form->input('id') . "\n";
|
||||
echo $form->submit('Delete Lock') . "\n";
|
||||
echo $form->submit('Cancel', array('name' => 'cancel')) . "\n";
|
||||
echo $form->end() . "\n";
|
||||
echo '</div>' . "\n";
|
||||
Reference in New Issue
Block a user