Index/Add views for StockUnitType and ItemType, View/Update for Item, Style to apply on all tables, DataTables used on details and indexes

This commit is contained in:
mareksebera 2014-09-10 22:16:10 +02:00
parent be2b39c5eb
commit 5d4d209549
15 changed files with 322 additions and 313 deletions

View file

@ -1,104 +1,32 @@
<?php
App::uses('AppController', 'Controller');
/**
* ItemTypes Controller
*
* @property ItemType $ItemType
* @property PaginatorComponent $Paginator
*/
class ItemTypesController extends AppController {
class ItemTypesController extends AppController
{
/**
* Components
*
* @var array
*/
public $components = array('Paginator');
/**
* index method
*
* @return void
*/
public function index()
{
if ($this->request->is('post')) {
$this->ItemType->create();
if ($this->ItemType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
/**
* index method
*
* @return void
*/
public function index() {
$this->ItemType->recursive = 0;
$this->set('itemTypes', $this->Paginator->paginate());
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->ItemType->exists($id)) {
throw new NotFoundException(__('Invalid item type'));
}
$options = array('conditions' => array('ItemType.' . $this->ItemType->primaryKey => $id));
$this->set('itemType', $this->ItemType->find('first', $options));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->ItemType->create();
if ($this->ItemType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->ItemType->exists($id)) {
throw new NotFoundException(__('Invalid item type'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->ItemType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('ItemType.' . $this->ItemType->primaryKey => $id));
$this->request->data = $this->ItemType->find('first', $options);
}
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->ItemType->id = $id;
if (!$this->ItemType->exists()) {
throw new NotFoundException(__('Invalid item type'));
}
$this->request->allowMethod('post', 'delete');
if ($this->ItemType->delete()) {
$this->Session->setFlash(__('The item type has been deleted.'));
} else {
$this->Session->setFlash(__('The item type could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
}
$this->ItemType->recursive = 0;
$this->set('itemTypes', $this->ItemType->find('list'));
}
}

View file

@ -30,11 +30,19 @@ class ItemsController extends AppController
public function view($id = null)
{
if (!$this->ItemType->exists($id)) {
if (!$this->Item->exists($id)) {
throw new NotFoundException(__('Invalid item type'));
}
$options = array('conditions' => array('ItemType.id' => $id));
$this->set('itemType', $this->ItemType->find('first', $options));
if ($this->request->is(array('post', 'put'))) {
$this->StockHistory->create();
if ($this->StockHistory->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
$options = array('conditions' => array('Item.id' => $id));
$this->set('item', $this->Item->find('first', $options));
}
public function edit($id = null)
@ -50,8 +58,10 @@ class ItemsController extends AppController
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('ItemType.id' => $id));
$this->request->data = $this->ItemType->find('first', $options);
$options = array('conditions' => array('Item.id' => $id));
$this->request->data = $this->Item->find('first', $options);
$this->set('itemTypes', $this->ItemType->find('list'));
$this->set('stockUnitTypes', $this->StockUnitType->find('list'));
}
}

View file

@ -0,0 +1,22 @@
<?php
App::uses('AppController', 'Controller');
class StockUnitTypesController extends AppController
{
public function index()
{
if ($this->request->is('post')) {
$this->StockUnitType->create();
if ($this->StockUnitType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
$this->StockUnitType->recursive = 0;
$this->set('items', $this->StockUnitType->find('list'));
}
}