diff --git a/src/admin/controllers/clubposition.json.php b/src/admin/controllers/clubposition.json.php index dc904c8..b946e53 100644 --- a/src/admin/controllers/clubposition.json.php +++ b/src/admin/controllers/clubposition.json.php @@ -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); + } + } diff --git a/src/admin/res/club/admin-club.css b/src/admin/res/club/admin-club.css index b34409d..5ed57ba 100644 --- a/src/admin/res/club/admin-club.css +++ b/src/admin/res/club/admin-club.css @@ -45,3 +45,7 @@ .form-disabled { overflow: hidden; } + +#hidden-id { + display: none; +} diff --git a/src/admin/res/club/club.js b/src/admin/res/club/club.js index 1b80421..ca4b89f 100644 --- a/src/admin/res/club/club.js +++ b/src/admin/res/club/club.js @@ -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'); + }); + }); diff --git a/src/admin/views/club/tmpl/default.php b/src/admin/views/club/tmpl/default.php index 51f57df..480d21d 100644 --- a/src/admin/views/club/tmpl/default.php +++ b/src/admin/views/club/tmpl/default.php @@ -86,7 +86,7 @@ defined('_JEXEC') or die; object->getUsers()) == 0 ): ?>
Dem Verein ist bisher kein Posten zugewiesen.
-assoc->getPosition()->getName()); ?> | +username; ?> | +usercity; ?> | +assoc->isAdmin()) echo ""; ?> | ++ + + | +assoc->getId(); ?> | diff --git a/src/admin/views/clubposition/view.html.php b/src/admin/views/clubposition/view.html.php index 3cc09cc..502125d 100644 --- a/src/admin/views/clubposition/view.html.php +++ b/src/admin/views/clubposition/view.html.php @@ -1,6 +1,7 @@ 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 = 'Derzeit vakant.'; + $this->usercity = ''; + if($this->assoc->getUser() !== null) + { + $u = $this->assoc->getUser(); + $this->username = htmlentities($u->getName()); + $this->usercity = htmlentities($u->getCity()); + } parent::display($tpl);