Started to work on frontend code

This commit is contained in:
Christian Wolf 2019-06-19 12:03:26 +02:00
parent 20c5c9d147
commit 0048f63990
6 changed files with 192 additions and 1 deletions

View File

@ -8,7 +8,8 @@ defined('_JEXEC') or die;
JLoader::discover('Clubs', JPATH_ROOT . '/administrator/components/com_clubs/mymodels'); JLoader::discover('Clubs', JPATH_ROOT . '/administrator/components/com_clubs/mymodels');
JLoader::register("ClubsHelperAuth", JPATH_ROOT . "/components/com_clubs/helpers/auth.php"); JLoader::registerPrefix('ClubsHelper', JPATH_ROOT . '/components/com_clubs/helpers');
JLoader::registerPrefix('ClubsPart', JPATH_ROOT . '/components/com_clubs/parts');
JLoader::registerPrefix('AbstractClubs', JPATH_ROOT . '/administrator/components/com_clubs/abstract'); JLoader::registerPrefix('AbstractClubs', JPATH_ROOT . '/administrator/components/com_clubs/abstract');

View File

@ -0,0 +1,18 @@
<?php
// No direct access.
defined('_JEXEC') or die;
abstract class ClubsHelperPartTextarea extends ClubsHelperParts
{
public function getEditMarkup()
{
$ret = '<textarea name="value">';
$ret .= $this->getEditContent();
$ret .= '</textarea>';
return $ret;
}
}

View File

@ -0,0 +1,18 @@
<?php
// No direct access.
defined('_JEXEC') or die;
abstract class ClubsHelperPartTextfield extends ClubsHelperParts
{
public function getEditMarkup()
{
$ret = '<input type="text" name="value" value="';
$ret .= $this->getEditContent();
$ret .= '">';
return $ret;
}
}

View File

@ -0,0 +1,59 @@
<?php
// No direct access.
defined('_JEXEC') or die;
abstract class ClubsHelperParts
{
/**
* @return string
*/
abstract protected function getPartName();
/**
* @return string
*/
public function getEditPart()
{
$partname = $this->getPartName();
$ret = "<form method='POST' action='index.php?option=com_clubs&task=parts.edit&format=json' class='clubs-part'>";
$ret .= "<input type='hidden' name='partname' value='$partname'>";
$ret .= $this->getEditMarkup();
$ret .= '&nbsp;<a class="clubs-save" href="#"><span class="icon-ok"></span></a>&nbsp;';
$ret .= '<a class="clubs-abort" href="index.php?option=com_clubs&view=mypage&layout=parts&type='.$partname.'"><span class="icon-cancel-2"></span></a>';
$ret .= '</form>';
return $ret;
}
abstract protected function getEditMarkup();
/**
* @return string
*/
abstract protected function getEditContent();
/**
* @return string
*/
protected function getViewContent()
{
return $this->getEditContent();
}
/**
* @return string
*/
public function getViewPart()
{
$ret = '';
$ret = "<a class='clubs-edit' href='index.php?option=com_clubs&view=mypage&layout=parts&mode=edit&type=" . $this->getPartName();
$ret .= $this->getViewContent();
$ret .= "<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span></a>";
return $ret;
}
}

View File

@ -0,0 +1,21 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartUserName extends ClubsHelperPartTextfield
{
protected function getPartName()
{
return 'user.name';
}
protected function getEditContent()
{
$auth = new ClubsHelperAuth();
$user = $auth->getCurrentUser();
return htmlentities($user->getName());
}
}

View File

@ -0,0 +1,74 @@
<?php
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
// No direct access.
defined('_JEXEC') or die;
class ClubsViewPart extends HtmlView
{
public function display($tpl = null)
{
// $auth = new ClubsHelperAuth();
// $this->me = $auth->getCurrentUser();
// $this->clubsPresident = $this->me->getPresidentClubs();
// $this->positions = $this->me->getPositions();
// HTMLHelper::_('jquery.framework');
// Factory::getDocument()->addScript(Uri::base(true) . "components/com_clubs/js/edit.js");
// parent::display($tpl);
$app = Factory::getApplication();
$input = $app->input;
$mode = $input->get->getCmd('mode', 'view');
$type = $input->get->getCmd('type');
$parthandler = $this->getPart($type);
if($mode === 'view')
$this->view($parthandler);
else
$this->edit($parthandler);
jexit();
}
/**
* @param ClubsHelperParts $parthandler
*/
private function view($parthandler)
{
echo $parthandler->getViewPart();
}
/**
* @param ClubsHelperParts $parthandler
*/
private function edit($parthandler)
{
echo $parthandler->getEditPart();
}
private function getPart($type)
{
if(! preg_match('/.*\..*/', $type))
throw new Exception();
list($obj, $fcn) = explode('.', $type, 2);
switch($obj)
{
case 'user':
switch($fcn)
{
case 'name':
return new ClubsPartUserName();
}
}
}
}