User assiciations are changable from within the backend interface from the clubs.

This commit is contained in:
Christian Wolf 2019-06-12 18:15:06 +02:00
parent 7210dff28c
commit 28494f6142
8 changed files with 299 additions and 102 deletions

View File

@ -2,6 +2,7 @@
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Factory;
// No direct access.
defined('_JEXEC') or die;
@ -11,9 +12,80 @@ class ClubsControllerClubposition extends BaseController
public function save()
{
echo new JsonResponse('abc', null, false, true);
$app = Factory::getApplication();
$input = $app->input->post;
$id = $input->getCmd('id', 'new');
$clubid = $input->getInt('clubid');
$positionid = $input->getInt('positionid');
$state = $input->getCmd('state', 'regular');
$admin = $input->getCmd('admin', '0');
$userid = $input->getInt('userid', -1);
$address = $input->getString('address');
$mail = $input->getString('mail');
$phone = $input->getString('phone');
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($clubid);
$positionFactory = new CommonClubsModelFactoryPosition();
$position = $positionFactory->loadById($positionid);
$assocFactory = new CommonClubsModelFactoryUserassoc();
if($id === 'new')
{
$assoc = $assocFactory->createNew();
}
else
{
$assoc = $assocFactory->loadById((int) $id);
}
if($userid != -1)
{
$userFactory = new CommonClubsModelFactoryUser();
$user = $userFactory->loadById($userid);
}
else
{
$user = null;
}
if($state === 'vacant')
$user = null;
$assoc->setUser($user);
$assoc->setState($state);
$assoc->setAddress($address === '' ? null : $address);
$assoc->setMail($mail === '' ? null : $mail);
$assoc->setPhone($phone === '' ? null : $phone);
$assoc->setClub($club);
$assoc->setAdmin($admin);
$assoc->setPosition($position);
$assoc->save();
$ret = array('new' => ($id === 'new'), 'id' => $assoc->getId());
echo new JsonResponse($ret, null, false, true);
// jexit();
}
public function delete()
{
$app = Factory::getApplication();
$input = $app->input->get;
$id = $input->getInt('id');
$factory = new CommonClubsModelFactoryUserassoc();
$ua = $factory->loadById($id);
$ua->delete();
$ret = array('id' => $id);
echo new JsonResponse($ret, null, false, true);
}
}

View File

@ -45,3 +45,7 @@
.form-disabled {
overflow: hidden;
}
#hidden-id {
display: none;
}

View File

@ -1,25 +1,29 @@
jQuery(function($){
$('#new-position').click(function(ev){
ev.preventDefault();
var url = $('#new-position').attr('href');
$.get(url, function(data){
// console.log(data);
$('#dialog-club > .dialog').html(data);
$('body').addClass('form-disabled');
$('#dialog-club').removeClass('dialog-hidden');
});
});
function closeDialog() {
$('#dialog-club > .dialog').html('');
$('body').removeClass('form-disabled');
$('#dialog-club').addClass('dialog-hidden');
}
function openDialog(data) {
// console.log(data);
$('#dialog-club > .dialog').html(data);
$('body').addClass('form-disabled');
$('#dialog-club').removeClass('dialog-hidden');
}
$('#new-position').click(function(ev){
ev.preventDefault();
var url = $('#new-position').attr('href');
$.get(url, function(data){
openDialog(data);
});
});
$(document).on('click', '#clubposition-abort', function(ev){
ev.preventDefault();
closeDialog();
@ -34,18 +38,65 @@ jQuery(function($){
$(document).on('click', '#clubposition-save', function(ev){
ev.preventDefault();
//alert('Not yet implemented');
var data = $('#clubposition-form').serializeArray();
$.post($('#clubposition-form').attr('action'), data, function(data){
console.log(data)
// console.log(data)
if(data.success)
{
console.log("all right!");
var url = "index.php?option=com_clubs&view=clubposition&layout=row&id=" + data.data.id + "&club=" + $('#hidden-id').html();
console.log(url);
if(data.data.new) {
$.get(url, function(data2){
$("#userassocs").append(data2);
closeDialog();
});
} else {
$.get(url, function(data2){
$('#userassoc-' + data.data.id).html(data2);
closeDialog();
});
}
}
else
{
alert(data.message);
}
});
});
$(document).on('click', '.edit-position', function(ev){
ev.preventDefault();
var url = ev.currentTarget.href;
$.get(url, function(data){
openDialog(data);
});
});
$(document).on('click', '.del-position', function(ev){
ev.preventDefault();
if(confirm("Der Eintrag wird endgültig gelöscht werden. OK?")) {
var url = ev.currentTarget.href;
$.get(url, function(d){
if(d.success) {
$('#userassoc-' + d.data.id).remove();
}
});
}
});
$(window).on('beforeunload', function(){return "Wollen Sie die Seite wirklich verlassen? Möglicherweise sind nicht alle Daten gesichert.";});
$('.form-exit').click(function(){
$(window).off('beforeunload');
});
});

View File

@ -86,7 +86,7 @@ defined('_JEXEC') or die;
<?php if(sizeof($this->object->getUsers()) == 0 ): ?>
<p>Dem Verein ist bisher kein Posten zugewiesen.</p>
<?php else: ?>
<table width='100%' class='table table-stiped, table-hover'>
<table width='100%' class='table table-stiped, table-hover' id='userassocs'>
<tr>
<th width='20%'>Rolle</th>
<th width='25%'>Name</th>
@ -96,28 +96,42 @@ defined('_JEXEC') or die;
<th width='5%'>ID</th>
</tr>
<?php foreach($this->object->getUsers() as $ua): ?>
<tr>
<?php
$user = $ua->getUser();
if($user == null)
{
$username = '<i>Derzeit vakant</i>';
$usercity = '';
}
else
{
$username = htmlentities($user->getName());
$usercity = htmlentities($user->getCity());
}
?>
<tr id='userassoc-<?php echo $ua->getId(); ?>'>
<td><?php echo htmlentities($ua->getPosition()->getName()); ?></td>
<td><?php echo htmlentities($ua->getUser()->getName()); ?></td>
<td><?php echo htmlentities($ua->getUser()->getCity()); ?></td>
<td><?php echo $username; ?></td>
<td><?php echo $usercity; ?></td>
<td style='text-align: center;'><?php if($ua->isAdmin()) echo "<span class='icon-checkmark'></span>"; ?></td>
<td>
<a href='#'><span class='icon-edit'></span></a>
<a href='#'><span class='icon-delete'></span></a>
<a href='<?php echo Route::_("index.php?option=com_clubs&view=clubposition&layout=edit&club={$this->object->getId()}&id={$ua->getId()}"); ?>' class='edit-position'><span class='icon-edit'></span></a>
<a href='<?php echo Route::_("index.php?option=com_clubs&task=clubposition.delete&format=json&id={$ua->getId()}"); ?>' class='del-position'><span class='icon-delete'></span></a>
</td>
<td><?php echo $ua->getId(); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<p><a href='<?php echo Route::_('index.php?option=com_clubs&view=clubposition&layout=new'); ?>' id='new-position'><span class='icon-new'></span> Neuen Posten einf&uuml;gen</a></p>
<p><a href='<?php echo Route::_("index.php?option=com_clubs&view=clubposition&layout=edit&club={$this->object->getId()}&id=new"); ?>' id='new-position'><span class='icon-new'></span> Neuen Posten einf&uuml;gen</a></p>
<?php endif; ?>
<input type='submit' value='Speichern'> <br /><a href='<?php echo Route::_('index.php?option=com_clubs&view=clubs'); ?>'>Zur&uuml;ck zur &Uuml;bersicht</a>
<input type='submit' value='Speichern' class='form-exit'> <br /><a href='<?php echo Route::_('index.php?option=com_clubs&view=clubs'); ?>' class='form-exit'>Zur&uuml;ck zur &Uuml;bersicht</a>
</form>
<div id='dialog-club' class='dialog-hidden'>
<div class='background'></div>
<div class='dialog'>Ein Test</div>
<div id='hidden-id'><?php echo $this->object->getId(); ?></div>
</div>

View File

@ -0,0 +1,90 @@
<?php
use Joomla\CMS\Router\Route;
// No direct access.
defined('_JEXEC') or die;
?>
<form id='clubposition-form' method="post" action="<?php echo Route::_('index.php?option=com_clubs&task=clubposition.save&format=json') ?>">
<input type='hidden' name='id' value='<?php echo $this->id; ?>'>
<input type='hidden' name='clubid' value='<?php echo $this->clubid; ?>'>
<h1>Posten bearbeiten</h1>
<table>
<tr>
<td>Funktion: </td>
<td>
<select name='positionid'>
<?php foreach($this->positions as $p): ?>
<?php
if($this->assoc->getPosition() !== null)
$selected = $this->assoc->getPosition()->getId() == $p->getId();
else
$selected = false;
?>
<option value='<?php echo $p->getId(); ?>' <?php if($selected) echo 'selected'; ?>>
<?php echo $p->getName(); ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td>Status</td>
<td>
<select name='state' id='clubposition-state'>
<option value='regular' <?php echo $this->assoc->getState() === 'regular' ? 'selected' : ''; ?>>regul&auml;r</option>
<option value='temporary' <?php echo $this->assoc->getState() === 'temporary' ? 'selected' : ''; ?>>kommisarisch</option>
<option value='vacant' <?php echo $this->assoc->getState() === 'vacant' ? 'selected' : ''; ?>>vakant</option>
</select>
</td>
</tr>
<tr id='clubposition-user' <?php if($this->assoc->getState() === 'vacant') echo 'class="dialog-entry-hidden"'; ?>>
<td>Person: </td>
<td>
<select name='userid'>
<?php foreach($this->users as $u): ?>
<?php
$uid = $this->assoc->getUser() === null ? -1 : $this->assoc->getUser()->getId();
$selected = ($u->getId() == $uid);
?>
<option value='<?php echo $u->getId();?>' <?php echo $selected ? 'selected' : ''; ?>>
<?php echo $u->getName(); ?> (<?php echo $u->getCity(); ?>)
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td>Admin: </td>
<td>
<input type='checkbox' name='admin' value='1' <?php echo $this->assoc->isAdmin() ? 'checked' : ''; ?>>
</td>
</tr>
<tr>
<td>Adresse (optional): </td>
<td>
<textarea name='address' rows='4'><?php echo $this->assoc->getAddress(); ?></textarea>
</td>
</tr>
<tr>
<td>E-Mail (optional): </td>
<td>
<input type='text' name='mail' value='<?php echo $this->assoc->getMail(); ?>'>
</td>
</tr>
<tr>
<td>Telefon-Nr. (optional): </td>
<td>
<input type='text' name='phone' value='<?php echo $this->assoc->getPhone(); ?>'>
</td>
</tr>
</table>
</form>
<a href='#' id='clubposition-save'>Speichern</a>
<a href='#' id='clubposition-abort'>Abbrechen</a>

View File

@ -1,76 +0,0 @@
<?php
use Joomla\CMS\Router\Route;
// No direct access.
defined('_JEXEC') or die;
?>
<form id='clubposition-form' method="post" action="<?php echo Route::_('index.php?option=com_clubs&task=clubposition.save&format=json') ?>">
<input type='hidden' name='id' value='<?php echo $this->id; ?>'>
<h1>Posten bearbeiten</h1>
<table>
<tr id='clubposition-user'>
<td>Person: </td>
<td>
<select>
<?php foreach($this->users as $u): ?>
<option value='<?php echo $u->getId();?>'><?php echo $u->getName(); ?> (<?php echo $u->getCity(); ?>)</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td>Funktion: </td>
<td>
<select>
<?php foreach($this->positions as $p): ?>
<option value='<?php echo $p->getId(); ?>'><?php echo $p->getName(); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td>Status</td>
<td>
<select name='state' id='clubposition-state'>
<option value='regular'>regul&auml;r</option>
<option value='temporary'>kommisarisch</option>
<option value='vacant'>vakant</option>
</select>
</td>
</tr>
<tr>
<td>Admin: </td>
<td>
<input type='checkbox' name='admin' value='1'>
</td>
</tr>
<tr>
<td>Adresse (optional): </td>
<td>
<textarea name='address' rows='4'></textarea>
</td>
</tr>
<tr>
<td>E-Mail (optional): </td>
<td>
<input type='text' name='mail'>
</td>
</tr>
<tr>
<td>Telefon-Nr. (optional): </td>
<td>
<input type='text' name='phone'>
</td>
</tr>
</table>
</form>
<a href='#' id='clubposition-save'>Speichern</a>
<a href='#' id='clubposition-abort'>Abbrechen</a>

View File

@ -0,0 +1,17 @@
<?php
// No direct access.
use Joomla\CMS\Router\Route;
defined('_JEXEC') or die;
?>
<td><?php echo htmlentities($this->assoc->getPosition()->getName()); ?></td>
<td><?php echo $this->username; ?></td>
<td><?php echo $this->usercity; ?></td>
<td style='text-align: center;'><?php if($this->assoc->isAdmin()) echo "<span class='icon-checkmark'></span>"; ?></td>
<td>
<a href='<?php echo Route::_("index.php?option=com_clubs&view=clubposition&layout=edit&club={$this->clubid}&id={$this->assoc->getId()}"); ?>' class='edit-position'><span class='icon-edit'></span></a>
<a href='<?php echo Route::_("index.php?option=com_clubs&task=clubposition.delete&format=json&id={$this->assoc->getId()}"); ?>' class='del-position'><span class='icon-delete'></span></a>
</td>
<td><?php echo $this->assoc->getId(); ?></td>

View File

@ -1,6 +1,7 @@
<?php
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Factory;
// No direct access.
defined('_JEXEC') or die;
@ -12,13 +13,37 @@ class ClubsViewClubPosition extends HtmlView
function display($tpl = null)
{
$input = Factory::getApplication()->input->get;
$positonFactory = new CommonClubsModelFactoryPosition();
$userFactory = new CommonClubsModelFactoryUser();
$this->positions = $positonFactory->loadElements();
$this->users = $userFactory->loadElements();
$this->id = 'new';
$id = $input->getCmd('id', 'new');
$assocFactory = new CommonClubsModelFactoryUserassoc();
if($id !== 'new')
{
$id = (int) $id;
$this->assoc = $assocFactory->loadById($id);
}
else
{
$this->assoc = $assocFactory->createNew();
}
$this->id = $id;
$this->clubid = $input->getInt('club');
$this->username = '<i>Derzeit vakant.</i>';
$this->usercity = '';
if($this->assoc->getUser() !== null)
{
$u = $this->assoc->getUser();
$this->username = htmlentities($u->getName());
$this->usercity = htmlentities($u->getCity());
}
parent::display($tpl);