General jQuery based approach in frontend is working.

This commit is contained in:
Christian Wolf 2019-06-18 16:44:44 +02:00
parent a2eb141d5c
commit a30e5d76a1
7 changed files with 202 additions and 10 deletions

View File

@ -0,0 +1,59 @@
<?php
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Factory;
// No direct access.
defined('_JEXEC') or die;
abstract class UserException extends Exception {}
class InvalidUserDataException extends UserException {}
class ClubsControllerParts extends BaseController
{
public function edit()
{
$auth = new ClubsHelperAuth();
$user = $auth->getCurrentUser();
$app = Factory::getApplication();
$post = $app->input->post;
try
{
$ret = $this->callMethod($user, $post);
echo new JsonResponse($ret);
}
catch(UserException $e)
{
echo new JsonResponse($e);
}
}
/**
* @param CommonClubsModelUser $user
* @param JInput $post
*/
private function callMethod($user, $post)
{
switch($post->getCmd('partname'))
{
case 'user.name':
return $this->editUserName($user, $post);
}
}
private function editUserName($user, $post)
{
$name = $post->getString('name');
if(strlen($name) < 5)
throw new InvalidUserDataException("Der Name muss mindestens 5 Zeichen lang sein.");
$user->setName($name);
$user->save();
$this->setRedirect('index.php?option=com_clubs&view=mypage&layout=parts&type=name');
}
}

View File

@ -29,3 +29,18 @@ table.clubs > tbody > tr > th
{ {
display: none !important; display: none !important;
} }
.address-field
{
line-height: 120%;
}
.clubs_content_row .clubs-hidden
{
display: none;
}
.clubs_content_row:hover > a > .edit-icon
{
display: inline-block;
}

View File

@ -15,6 +15,17 @@ class ClubsHelperAuth
return true; return true;
} }
/**
* @return CommonClubsModelUser
*/
public function getCurrentUser()
{
// FIXME This must be implemented
$userFactory = new CommonClubsModelFactoryUser();
$users = $userFactory->loadElements();
return $users[0];
}
public function checkUser($user, $pwd) public function checkUser($user, $pwd)
{ {
$userModel = BaseDatabaseModel::getInstance("user", "ClubsModel"); $userModel = BaseDatabaseModel::getInstance("user", "ClubsModel");

30
src/site/js/edit.js Normal file
View File

@ -0,0 +1,30 @@
jQuery(function($){
$(document).on('click', 'a.clubs-edit', function(ev){
ev.preventDefault();
var myA = $(this);
$.get(ev.currentTarget.href, function(d){
myA.replaceWith(d);
});
});
$(document).on('click', 'a.clubs-abort', function(ev){
ev.preventDefault();
var form = $(this).parent();
$.get(this.href, function(d){
form.replaceWith(d);
});
});
$(document).on('click', 'a.clubs-save', function(ev){
ev.preventDefault();
var form = $(this).parent();
$.post(form.attr('action'), form.serializeArray(), function(d){
form.replaceWith(d);
});
});
});

View File

@ -12,37 +12,60 @@ defined('_JEXEC') or die;
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Name</div> <div class='clubs_title_row'>Name</div>
<div class='clubs_content_row'><?php echo htmlentities($this->me->getName()); ?></div> <div class='clubs_content_row'>
<a class='clubs-edit' href='index.php?option=com_clubs&view=mypage&layout=parts&mode=edit&type=name'>
<?php echo htmlentities($this->me->getName()); ?>
<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span>
</a>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Benutzer-Alias</div> <div class='clubs_title_row'>Benutzer-Alias</div>
<div class='clubs_content_row'><?php echo htmlentities($this->me->getUsername()); ?></div> <div class='clubs_content_row'>
<?php echo htmlentities($this->me->getUsername()); ?>
<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Adresse</div> <div class='clubs_title_row'>Adresse</div>
<div class='clubs_content_row'><?php echo nl2br(htmlentities($this->me->getAddress())); ?></div> <div class='clubs_content_row address-field'>
<?php echo nl2br(htmlentities($this->me->getAddress())); ?>
<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Stadt</div> <div class='clubs_title_row'>Stadt</div>
<div class='clubs_content_row'><?php echo htmlentities($this->me->getCity()); ?></div> <div class='clubs_content_row'>
<?php echo htmlentities($this->me->getCity()); ?>
<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>E-Mail-Adresse</div> <div class='clubs_title_row'>E-Mail-Adresse</div>
<div class='clubs_content_row'><?php echo htmlentities($this->me->getMail()); ?></div> <div class='clubs_content_row'>
<?php echo htmlentities($this->me->getMail()); ?>
<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Telefon-Nr.</div> <div class='clubs_title_row'>Telefon-Nr.</div>
<div class='clubs_content_row'><?php echo $this->me->getPhone() !== null ? htmlentities($this->me->getPhone()) : '<i>nicht angegeben</i>'; ?></div> <div class='clubs_content_row'>
<?php echo $this->me->getPhone() !== null ? htmlentities($this->me->getPhone()) : '<i>nicht angegeben</i>'; ?>
<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Handy-Nr.</div> <div class='clubs_title_row'>Handy-Nr.</div>
<div class='clubs_content_row'><?php echo $this->me->getMobile() !== null ? htmlentities($this->me->getMobile()) : '<i>nicht angegeben</i>'; ?></div> <div class='clubs_content_row'>
<?php echo $this->me->getMobile() !== null ? htmlentities($this->me->getMobile()) : '<i>nicht angegeben</i>'; ?>
<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span>
</div>
</div> </div>

View File

@ -0,0 +1,50 @@
<?php
use Joomla\CMS\Factory;
// No direct access.
defined('_JEXEC') or die;
$input = Factory::getApplication()->input;
$type = $input->get->getCmd('type');
$mode = $input->get->getCmd('mode', 'view');
$auth = new ClubsHelperAuth();
$user = $auth->getCurrentUser();
if($mode === 'edit')
{
echo "<form method='POST' action='index.php?option=com_clubs&task=parts.edit&format=json'>";
switch($type)
{
case 'name':
$partname = 'user.name';
$value = $user->getName();
$value = htmlentities($value);
$content = "<input name='name' value='$value'>";
break;
}
echo "<input type='hidden' name='partname' value='$partname'>";
echo $content;
echo '&nbsp;<a class="clubs-save" href="#"><span class="icon-ok"></span></a>&nbsp;';
echo '<a class="clubs-abort" href="index.php?option=com_clubs&view=mypage&layout=parts&type='.$type.'"><span class="icon-cancel-2"></span></a>';
echo '</form>';
}
elseif ($mode === 'view')
{
switch ($type)
{
case 'name':
$content = htmlentities($user->getName());
$partname = 'name';
break;
}
echo "<a class='clubs-edit' href='index.php?option=com_clubs&view=mypage&layout=parts&mode=edit&type=$partname'>";
echo $content;
echo "<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span></a>";
}
jexit();

View File

@ -1,6 +1,9 @@
<?php <?php
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\HtmlView; use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
// No direct access. // No direct access.
defined('_JEXEC') or die; defined('_JEXEC') or die;
@ -10,13 +13,14 @@ class ClubsViewMyPage extends HtmlView
public function display($tpl = null) public function display($tpl = null)
{ {
$userFactory = new CommonClubsModelFactoryUser(); $auth = new ClubsHelperAuth();
$users = $userFactory->loadElements(); $this->me = $auth->getCurrentUser();
$this->me = $users[0];
$this->clubsPresident = $this->me->getPresidentClubs(); $this->clubsPresident = $this->me->getPresidentClubs();
$this->positions = $this->me->getPositions(); $this->positions = $this->me->getPositions();
HTMLHelper::_('jquery.framework');
Factory::getDocument()->addScript(Uri::base(true) . "components/com_clubs/js/edit.js");
parent::display($tpl); parent::display($tpl);
} }
} }