Fixed organization CRD

This commit is contained in:
Dennis Eichhorn 2016-11-15 16:54:43 +01:00
parent 50991ef655
commit 65788f9a13
8 changed files with 55 additions and 34 deletions

View File

@ -222,6 +222,8 @@ class Controller extends ModuleAbstract implements WebInterface
$view->setTemplate('/Modules/Organization/Theme/Backend/position-list'); $view->setTemplate('/Modules/Organization/Theme/Backend/position-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004704001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004704001, $request, $response));
$view->addData('list:elements', PositionMapper::getAll());
return $view; return $view;
} }
@ -241,6 +243,8 @@ class Controller extends ModuleAbstract implements WebInterface
$view->setTemplate('/Modules/Organization/Theme/Backend/position-profile'); $view->setTemplate('/Modules/Organization/Theme/Backend/position-profile');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004704001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004704001, $request, $response));
$view->addData('position', PositionMapper::get((int) $request->getData('id')));
return $view; return $view;
} }
@ -301,21 +305,30 @@ class Controller extends ModuleAbstract implements WebInterface
$response->set('unit', $unit->jsonSerialize()); $response->set('unit', $unit->jsonSerialize());
} }
public function apiPositionCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) private function validatePositionCreate(RequestAbstract $request) : array
{ {
$val = []; $val = [];
if ( if (
($val['name'] = empty($request->getData('name'))) ($val['name'] = empty($request->getData('name')))
|| ($val['parent'] = ( || ($val['parent'] = (
$request->getData('parent') !== null !empty($request->getData('parent'))
&& !is_numeric($request->getData('parent')) && !is_numeric($request->getData('parent'))
)) ))
|| ($val['status'] = ( || ($val['status'] = (
$request->getData('status') === null $request->getData('status') === null
|| !Status::isValidValue((int) $request->getData('status')) || !Status::isValidValue((int) $request->getData('status'))
)) ))
) { ) {
$response->set('position_create_validation', new FormValidation($val)); return $val;
}
return [];
}
public function apiPositionCreate(RequestAbstract $request, ResponseAbstract $response, $data = null)
{
if (!empty($val = $this->validatePositionCreate($request))) {
$response->set('position_create', new FormValidation($val));
return; return;
} }
@ -323,28 +336,36 @@ class Controller extends ModuleAbstract implements WebInterface
$position = new Position(); $position = new Position();
$position->setName($request->getData('name')); $position->setName($request->getData('name'));
$position->setStatus((int) $request->getData('status')); $position->setStatus((int) $request->getData('status'));
$position->setDescription($request->getData('desc')); $position->setDescription($request->getData('description') ?? '');
PositionMapper::create($position); PositionMapper::create($position);
$response->set('position', $position->jsonSerialize()); $response->set('position', $position->jsonSerialize());
} }
public function apiDepartmentCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) private function validateDepartmentCreate(RequestAbstract $request) : array
{ {
$val = []; $val = [];
if ( if (
($val['name'] = empty($request->getData('name'))) ($val['name'] = empty($request->getData('name')))
|| ($val['parent'] = ( || ($val['parent'] = (
$request->getData('parent') !== null !empty($request->getData('parent'))
&& !is_numeric((int) $request->getData('parent')) && !is_numeric($request->getData('parent'))
)) ))
|| ($val['status'] = ( || ($val['unit'] = (
$request->getData('status') === null !is_numeric((int) $request->getData('unit'))
|| !Status::isValidValue($request->getData('status'))) ))
)
) { ) {
$response->set('department_create_validation', new FormValidation($val)); return $val;
}
return [];
}
public function apiDepartmentCreate(RequestAbstract $request, ResponseAbstract $response, $data = null)
{
if (!empty($val = $this->validateDepartmentCreate($request))) {
$response->set('department_create', new FormValidation($val));
return; return;
} }
@ -352,7 +373,7 @@ class Controller extends ModuleAbstract implements WebInterface
$department = new Department(); $department = new Department();
$department->setName($request->getData('name')); $department->setName($request->getData('name'));
$department->setStatus((int) $request->getData('status')); $department->setStatus((int) $request->getData('status'));
$department->setDescription($request->getData('desc')); $department->setDescription($request->getData('description') ?? '');
DepartmentMapper::create($department); DepartmentMapper::create($department);

View File

@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>
<section class="box w-33"> <section class="box w-33">
<header><h1><?= $this->getText('Department'); ?></h1></header> <header><h1><?= $this->getText('Department'); ?></h1></header>
<div class="inner"> <div class="inner">
<form> <form id="fDepartmentCreate" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/base}{/rootPath}{/lang}/api/organization/department'); ?>">
<table class="layout wf-100"> <table class="layout wf-100">
<tr><td><label for="iName"><?= $this->getText('Name'); ?></label> <tr><td><label for="iName"><?= $this->getText('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" placeholder="&#xf040; R&D" required> <tr><td><input type="text" name="name" id="iName" placeholder="&#xf040; R&D" required>

View File

@ -39,7 +39,7 @@ echo $this->getData('nav')->render(); ?>
<tr><td colspan="4"><?= $footerView->render(); ?> <tr><td colspan="4"><?= $footerView->render(); ?>
<tbody> <tbody>
<?php $c = 0; foreach ($this->getData('list:elements') as $key => $value) : $c++; <?php $c = 0; foreach ($this->getData('list:elements') as $key => $value) : $c++;
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/business/department/profile?id=' . $value->getId()); ?> $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/organization/department/profile?id=' . $value->getId()); ?>
<tr> <tr>
<td><a href="<?= $url; ?>"><?= $value->getId(); ?></a> <td><a href="<?= $url; ?>"><?= $value->getId(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->getName(); ?></a> <td><a href="<?= $url; ?>"><?= $value->getName(); ?></a>

View File

@ -22,7 +22,7 @@ $department = $this->getData('department');
echo $this->getData('nav')->render(); ?> echo $this->getData('nav')->render(); ?>
<section class="box w-33"> <section class="box w-33">
<h1><?= $this->getText('Position'); ?></h1> <header><h1><?= $this->getText('Department'); ?></h1></header>
<div class="inner"> <div class="inner">
<form> <form>
<table class="layout wf-100"> <table class="layout wf-100">

View File

@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>
<section class="box w-33"> <section class="box w-33">
<header><h1><?= $this->getText('Position'); ?></h1></header> <header><h1><?= $this->getText('Position'); ?></h1></header>
<div class="inner"> <div class="inner">
<form> <form id="fPositionCreate" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/base}{/rootPath}{/lang}/api/organization/position'); ?>">
<table class="layout wf-100"> <table class="layout wf-100">
<tr><td><label for="iName"><?= $this->getText('Name'); ?></label> <tr><td><label for="iName"><?= $this->getText('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" placeholder="&#xf040; Orange Management" required> <tr><td><input type="text" name="name" id="iName" placeholder="&#xf040; Orange Management" required>
@ -30,8 +30,8 @@ echo $this->getData('nav')->render(); ?>
<tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" name="parent" id="iParent"></span> <tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" name="parent" id="iParent"></span>
<tr><td><label for="iStatus"><?= $this->getText('Status'); ?></label> <tr><td><label for="iStatus"><?= $this->getText('Status'); ?></label>
<tr><td><select name="status" id="iStatus"> <tr><td><select name="status" id="iStatus">
<option><?= $this->getText('Active'); ?> <option value="<?= \Modules\Organization\Models\Status::ACTIVE; ?>"><?= $this->getText('Active'); ?>
<option><?= $this->getText('Inactive'); ?> <option value="<?= \Modules\Organization\Models\Status::INACTIVE; ?>"><?= $this->getText('Inactive'); ?>
</select> </select>
<tr><td><label for="iDescription"><?= $this->getText('Description'); ?></label> <tr><td><label for="iDescription"><?= $this->getText('Description'); ?></label>
<tr><td><textarea name="description" id="iDescription" placeholder="&#xf040;"></textarea> <tr><td><textarea name="description" id="iDescription" placeholder="&#xf040;"></textarea>

View File

@ -40,7 +40,7 @@ echo $this->getData('nav')->render(); ?>
<tr><td colspan="3"><?= $footerView->render(); ?> <tr><td colspan="3"><?= $footerView->render(); ?>
<tbody> <tbody>
<?php $count = 0; foreach($listElements as $key => $value) : $count++; <?php $count = 0; foreach($listElements as $key => $value) : $count++;
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/business/unit/profile?id=' . $value->getId()); ?> $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/organization/position/profile?id=' . $value->getId()); ?>
<tr> <tr>
<td><a href="<?= $url; ?>"><?= $value->getId(); ?></a> <td><a href="<?= $url; ?>"><?= $value->getId(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->getName(); ?></a> <td><a href="<?= $url; ?>"><?= $value->getName(); ?></a>

View File

@ -17,7 +17,7 @@
* @var \phpOMS\Views\View $this * @var \phpOMS\Views\View $this
*/ */
$unit = $this->getData('unit'); $position = $this->getData('position');
echo $this->getData('nav')->render(); ?> echo $this->getData('nav')->render(); ?>
@ -27,16 +27,16 @@ echo $this->getData('nav')->render(); ?>
<form> <form>
<table class="layout wf-100"> <table class="layout wf-100">
<tr><td><label for="iName"><?= $this->getText('Name'); ?></label> <tr><td><label for="iName"><?= $this->getText('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" value="<?= $unit->getName(); ?>"> <tr><td><input type="text" name="name" id="iName" value="<?= $position->getName(); ?>">
<tr><td><label for="iParent"><?= $this->getText('Parent'); ?></label> <tr><td><label for="iParent"><?= $this->getText('Parent'); ?></label>
<tr><td><input type="text" name="parent" id="iParent" value="<?= $unit->getParent(); ?>"> <tr><td><input type="text" name="parent" id="iParent" value="<?= $position->getParent(); ?>">
<tr><td><label for="iStatus"><?= $this->getText('Status'); ?></label> <tr><td><label for="iStatus"><?= $this->getText('Status'); ?></label>
<tr><td><select name="status" id="iStatus"> <tr><td><select name="status" id="iStatus">
<option><?= $this->getText('Active'); ?> <option><?= $this->getText('Active'); ?>
<option><?= $this->getText('Inactive'); ?> <option><?= $this->getText('Inactive'); ?>
</select> </select>
<tr><td><label for="iDescription"><?= $this->getText('Description'); ?></label> <tr><td><label for="iDescription"><?= $this->getText('Description'); ?></label>
<tr><td><textarea name="description" id="iDescription"><?= $unit->getDescription(); ?></textarea> <tr><td><textarea name="description" id="iDescription"><?= $position->getDescription(); ?></textarea>
<tr><td><input type="submit" value="<?= $this->getText('Save', 0) ?>"> <tr><td><input type="submit" value="<?= $this->getText('Save', 0) ?>">
</table> </table>
</form> </form>

View File

@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>
<section class="box w-33"> <section class="box w-33">
<header><h1><?= $this->getText('Unit'); ?></h1></header> <header><h1><?= $this->getText('Unit'); ?></h1></header>
<div class="inner"> <div class="inner">
<form method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/base}{/rootPath}{/lang}/api/organization/unit'); ?>"> <form id="fUnitCreate" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/base}{/rootPath}{/lang}/api/organization/unit'); ?>">
<table class="layout wf-100"> <table class="layout wf-100">
<tr><td><label for="iName"><?= $this->getText('Name'); ?></label> <tr><td><label for="iName"><?= $this->getText('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" placeholder="&#xf040; Orange Management" required> <tr><td><input type="text" name="name" id="iName" placeholder="&#xf040; Orange Management" required>