From 28494f6142212de186e121af9efb8e6a9dbc6f52 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 12 Jun 2019 18:15:06 +0200 Subject: [PATCH] User assiciations are changable from within the backend interface from the clubs. --- src/admin/controllers/clubposition.json.php | 74 ++++++++++++++++- src/admin/res/club/admin-club.css | 4 + src/admin/res/club/club.js | 81 +++++++++++++++---- src/admin/views/club/tmpl/default.php | 30 +++++-- src/admin/views/clubposition/tmpl/edit.php | 90 +++++++++++++++++++++ src/admin/views/clubposition/tmpl/new.php | 76 ----------------- src/admin/views/clubposition/tmpl/row.php | 17 ++++ src/admin/views/clubposition/view.html.php | 29 ++++++- 8 files changed, 299 insertions(+), 102 deletions(-) create mode 100644 src/admin/views/clubposition/tmpl/edit.php delete mode 100644 src/admin/views/clubposition/tmpl/new.php create mode 100644 src/admin/views/clubposition/tmpl/row.php 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.

- +
@@ -96,28 +96,42 @@ defined('_JEXEC') or die; object->getUsers() as $ua): ?> - + getUser(); + if($user == null) + { + $username = 'Derzeit vakant'; + $usercity = ''; + } + else + { + $username = htmlentities($user->getName()); + $usercity = htmlentities($user->getCity()); + } + ?> + - - + +
Rolle NameID
getPosition()->getName()); ?>getUser()->getName()); ?>getUser()->getCity()); ?> isAdmin()) echo ""; ?> - - + + getId(); ?>
-

' id='new-position'> Neuen Posten einfügen

+

Neuen Posten einfügen

-
'>Zurück zur Übersicht +
' class='form-exit'>Zurück zur Übersicht
Ein Test
+
object->getId(); ?>
diff --git a/src/admin/views/clubposition/tmpl/edit.php b/src/admin/views/clubposition/tmpl/edit.php new file mode 100644 index 0000000..877851e --- /dev/null +++ b/src/admin/views/clubposition/tmpl/edit.php @@ -0,0 +1,90 @@ + + +
+ + +

Posten bearbeiten

+ + + + + + + + + + + assoc->getState() === 'vacant') echo 'class="dialog-entry-hidden"'; ?>> + + + + + + + + + + + + + + + + + + + +
Funktion: + +
Status + +
Person: + +
Admin: + assoc->isAdmin() ? 'checked' : ''; ?>> +
Adresse (optional): + +
E-Mail (optional): + +
Telefon-Nr. (optional): + +
+ +
+ +Speichern +Abbrechen + diff --git a/src/admin/views/clubposition/tmpl/new.php b/src/admin/views/clubposition/tmpl/new.php deleted file mode 100644 index 61bfe03..0000000 --- a/src/admin/views/clubposition/tmpl/new.php +++ /dev/null @@ -1,76 +0,0 @@ - - -
- - -

Posten bearbeiten

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Person: - -
Funktion: - -
Status - -
Admin: - -
Adresse (optional): - -
E-Mail (optional): - -
Telefon-Nr. (optional): - -
- -
- -Speichern -Abbrechen - diff --git a/src/admin/views/clubposition/tmpl/row.php b/src/admin/views/clubposition/tmpl/row.php new file mode 100644 index 0000000..8f1543f --- /dev/null +++ b/src/admin/views/clubposition/tmpl/row.php @@ -0,0 +1,17 @@ + +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);