Compare commits

..

No commits in common. "c520c256ee58efa2b5c17bc998458d4518778985" and "ad18c7cb25d79d6c7cfa9546b5811e209f00871a" have entirely different histories.

4 changed files with 60 additions and 37 deletions

View File

@ -1,5 +1,5 @@
(function () { (function () {
const element = document.getElementById('newMember').elements['user_id']; const element = document.getElementById('new_member_user_id');
const choices = new Choices(element, { const choices = new Choices(element, {
noResultsText: 'No users found', noResultsText: 'No users found',
noChoicesText: 'Start typing to search users' noChoicesText: 'Start typing to search users'
@ -13,5 +13,50 @@
element.addEventListener('choice', function () { element.addEventListener('choice', function () {
choices.setChoices([], 'value', 'label', true); choices.setChoices([], 'value', 'label', true);
document.getElementById('new_member_button').disabled = false;
}); });
document.getElementById('new_member_button').addEventListener('click', function () {
document.getElementById('loading').style.visibility = 'visible';
let data = new FormData();
data.append('user_id', document.getElementById('new_member_user_id').value);
RVR.httpRequest('POST', newMemberUrl, function () {
window.location.reload();
}, data);
});
const ownerCheckboxesButtons = document.getElementsByClassName('member_owner');
for (const ownerCheckboxesButton of ownerCheckboxesButtons) {
ownerCheckboxesButton.addEventListener('change', function () {
document.getElementById('loading').style.visibility = 'visible';
let data = new FormData();
data.append('community_member_id', this.dataset.id);
data.append('owner', this.checked ? 1 : 0);
RVR.httpRequest('POST', editMemberUrl, function () {
document.getElementById('loading').style.visibility = 'hidden';
if (!this.response.success) {
ownerCheckboxesButton.checked = !ownerCheckboxesButton.checked;
}
}, data);
});
};
const deleteButtons = document.getElementsByClassName('delete_member');
for (const deleteButton of deleteButtons) {
deleteButton.addEventListener('click', function () {
document.getElementById('loading').style.visibility = 'visible';
let data = new FormData();
data.append('community_member_id', this.dataset.id);
RVR.httpRequest('POST', deleteMemberUrl, function () {
window.location.reload();
}, data);
});
};
})(); })();

View File

@ -163,14 +163,8 @@ var RVR = {
for (var i = 0; i < observedInputs.length; i++) { for (var i = 0; i < observedInputs.length; i++) {
var input = form.elements[observedInputs[i]]; var input = form.elements[observedInputs[i]];
if (input.type === 'checkbox') { if (input.defaultValue !== input.value) {
if (input.defaultChecked !== input.checked) { anyChanged = true;
anyChanged = true;
}
} else {
if (input.defaultValue !== input.value) {
anyChanged = true;
}
} }
} }

View File

@ -96,7 +96,6 @@ class CommunityController implements IAuthenticationRequired
$communityMember = new CommunityMember(); $communityMember = new CommunityMember();
$communityMember->setCommunity($community); $communityMember->setCommunity($community);
$communityMember->setUser($user); $communityMember->setUser($user);
$communityMember->setOwner((bool)\Container::$request->post('owner'));
\Container::$persistentDataManager->saveToDb($communityMember); \Container::$persistentDataManager->saveToDb($communityMember);
return new JsonContent(['success' => true]); return new JsonContent(['success' => true]);
@ -108,14 +107,14 @@ class CommunityController implements IAuthenticationRequired
return null; return null;
} }
$communityMember = $this->communityMemberRepository->getById(\Container::$request->query('community_member_id')); $communityMember = $this->communityMemberRepository->getById(\Container::$request->post('community_member_id'));
if ($communityMember->getUserId() === \Container::$request->user()->getUniqueId()) { if ($communityMember->getUserId() === \Container::$request->user()->getUniqueId()) {
return new JsonContent([ return new JsonContent([
'error' => ['errorText' => 'Own user cannot be edited.'] 'error' => ['errorText' => 'Own user cannot be edited.']
]); ]);
} }
$communityMember->setOwner((bool)\Container::$request->post('owner')); $communityMember->setOwner(\Container::$request->post('owner'));
\Container::$persistentDataManager->saveToDb($communityMember); \Container::$persistentDataManager->saveToDb($communityMember);
return new JsonContent(['success' => true]); return new JsonContent(['success' => true]);
@ -127,7 +126,7 @@ class CommunityController implements IAuthenticationRequired
return null; return null;
} }
$communityMember = $this->communityMemberRepository->getById(\Container::$request->query('community_member_id')); $communityMember = $this->communityMemberRepository->getById(\Container::$request->post('community_member_id'));
if ($communityMember->getUserId() === \Container::$request->user()->getUniqueId()) { if ($communityMember->getUserId() === \Container::$request->user()->getUniqueId()) {
return new JsonContent([ return new JsonContent([
'error' => ['errorText' => 'Own user cannot be deleted.'] 'error' => ['errorText' => 'Own user cannot be deleted.']

View File

@ -18,33 +18,15 @@
<?php foreach ($members as $member): ?> <?php foreach ($members as $member): ?>
<?php $editable = $member->getUserId() !== Container::$request->user()->getUniqueId(); ?> <?php $editable = $member->getUserId() !== Container::$request->user()->getUniqueId(); ?>
<tr> <tr>
<td> <td><?= $member->getUser()->getDisplayName() ?></td>
<form id="editMember_<?= $member->getId() ?>" action="<?= Container::$routeCollection->getRoute('community-members-edit')->generateLink(['communityId' => $community->getId(), 'community_member_id' => $member->getId()]) ?>" method="post" data-reload-on-success="true" data-observe-inputs="owner"></form> <td style="text-align: center;"><input type="checkbox" class="member_owner" data-id="<?= $member->getId() ?>" <?= $member->getOwner() ? 'checked' : '' ?> <?= !$editable ? 'disabled' : '' ?> /></td>
<form id="deleteMember_<?= $member->getId() ?>" action="<?= Container::$routeCollection->getRoute('community-members-delete')->generateLink(['communityId' => $community->getId(), 'community_member_id' => $member->getId()]) ?>" method="post" data-reload-on-success="true"></form> <td style="text-align: right;"><button type="button" class="small red delete_member" data-id="<?= $member->getId() ?>" <?= !$editable ? 'disabled' : '' ?>>Delete</button></td>
<?= $member->getUser()->getDisplayName() ?>
</td>
<td style="text-align: center;">
<input type="checkbox" form="editMember_<?= $member->getId() ?>" name="owner" <?= $member->getOwner() ? 'checked' : '' ?> <?= !$editable ? 'disabled' : '' ?> />
</td>
<td style="text-align: right;">
<?php if ($editable): ?>
<button type="submit" form="editMember_<?= $member->getId() ?>" name="submit" class="small marginRight" disabled>Save</button><!--
--><button type="submit" form="deleteMember_<?= $member->getId() ?>" class="small red delete_member" data-action="<?= Container::$routeCollection->getRoute('community-members-delete')->generateLink(['communityId' => $community->getId(), 'community_member_id' => $member->getId()]) ?>">Delete</button>
<?php endif; ?>
</td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr> <tr>
<td> <td><select type="text" id="new_member_user_id"></td>
<form id="newMember" action="<?= Container::$routeCollection->getRoute('community-members-new')->generateLink(['communityId' => $community->getId()]) ?>" method="post" data-reload-on-success="true" data-observe-inputs="user_id"></form> <td></td>
<select type="text" form="newMember" name="user_id"> <td style="text-align: right;"><button type="button" class="small" id="new_member_button" disabled>Add</button></td>
</td>
<td style="text-align: center;">
<input type="checkbox" form="newMember" name="owner" />
</td>
<td style="text-align: right;">
<button type="submit" form="newMember" name="submit" class="small" disabled>Add</button>
</td>
</tr> </tr>
</table> </table>
</div> </div>
@ -53,5 +35,8 @@
@section(pageScript) @section(pageScript)
<script> <script>
var searchUserUrl = '<?= Container::$routeCollection->getRoute('searchUser')->generateLink(['q' => 'QUERY']) ?>'; var searchUserUrl = '<?= Container::$routeCollection->getRoute('searchUser')->generateLink(['q' => 'QUERY']) ?>';
var newMemberUrl = '<?= Container::$routeCollection->getRoute('community-members-new')->generateLink(['communityId' => $community->getId()]) ?>';
var editMemberUrl = '<?= Container::$routeCollection->getRoute('community-members-edit')->generateLink(['communityId' => $community->getId()]) ?>';
var deleteMemberUrl = '<?= Container::$routeCollection->getRoute('community-members-delete')->generateLink(['communityId' => $community->getId()]) ?>';
</script> </script>
@endsection @endsection