summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2017-12-28 13:46:55 +0100
committersteckbrief <steckbrief@chefmail.de>2017-12-28 13:46:55 +0100
commit391875ea8389d043360961cf2c5a69f2b6d7a91a (patch)
tree7bd8c535cd8c6912f34c193ece35a2efcd73530c /index.php
parent31ba0cea75b128a664e777a0a2f4180a19501ec3 (diff)
update and delete addedHEADv0.1master
Diffstat (limited to '')
-rw-r--r--index.php86
1 files changed, 83 insertions, 3 deletions
diff --git a/index.php b/index.php
index 1d1dbbe..ded66bd 100644
--- a/index.php
+++ b/index.php
@@ -2,6 +2,7 @@
include_once(__DIR__.'/lib/commons/functions.common.inc.php');
include_once(__DIR__.'/lib/commons/functions.http.inc.php');
+require_once(__DIR__.'/lib/commons/functions.files.inc.php');
include_once(__DIR__.'/lib/functions.stories.inc.php');
$config = require(__DIR__.'/config/config.inc.php');
@@ -44,6 +45,7 @@ ksort($stories, SORT_STRING);
$currentStoryName = visibleName($currentStory);
function printEntities($entities, $storyName = NULL) {
+ global $isAdmin, $isAuthenticated;
foreach ($entities as $entity=>$description) {
$name = visibleName($entity);
$imgName = (NULL != $storyName) ? 'passphoto.png' : 'logo.png';
@@ -56,8 +58,18 @@ function printEntities($entities, $storyName = NULL) {
<img class="img-fluid rounded mb-3 mb-md-0 figure-pic" src="<?=$imgPath.'/'.$imgName;?>" alt="<?=$name;?>" title="<?=$name;?>">
</div>
<div class="col-md-5">
- <h3><?=$name;?></h3>
- <p class="figure-desc"><?=$description;?></p>
+ <h3 id="name-<?=str_replace(' ', '-', $name);?>">
+ <?=$name;?>
+<?php
+if ($isAuthenticated && $isAdmin) {
+?>
+<button <?=((NULL != $storyName) ? ' data-storyname="'.$storyName.'"' : '');?> data-entityname="<?=$name;?>" class="delete-btn">-</button>
+<button <?=((NULL != $storyName) ? ' data-storyname="'.$storyName.'"' : '');?> data-entityname="<?=$name;?>" class="edit-btn">e</button>
+<?php
+}
+?>
+ </h3>
+ <p class="figure-desc" id="desc-<?=str_replace(' ', '-', $name);?>"><?=$description;?></p>
</div>
</div>
<!-- /.row -->
@@ -76,6 +88,74 @@ function printEntities($entities, $storyName = NULL) {
<script src="https://www.sl-its.de/js/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/stories.js"></script>
+ <script>
+ function editElement(elem) {
+ var storyName = $(elem).data('storyname');
+ var entityName = $(elem).data('entityname');
+ var data = new FormData();
+
+ var desc = $('#desc-' + entityName.replace(' ', '-')).text();
+ var modalName = 'newStoryModal';
+ var prefix = 'story';
+ var modalTitle = 'Kindergeschichte bearbeiten';
+
+ if (storyName) {
+ modalName = 'newCharacterModal';
+ prefix = 'char';
+ modalTitle = 'Charakter bearbeiten';
+ }
+ $('#' + modalName).modal('show');
+ $('#' + prefix + '-description').val(desc);
+ $('#' + prefix + '-name').val(entityName);
+ $('#' + prefix + '-action').val('edit');
+ $('#modal-title').text(modalTitle);
+ $('#create-' + prefix + '-btn').text('Bearbeiten');
+ }
+
+ $(document).ready(function() {
+ $('.delete-btn').click(function() {
+ if (confirm('Bist Du sicher?')) {
+ var storyName = $(this).data('storyname');
+ var entityName = $(this).data('entityname');
+ var url = '';
+ var data = new FormData();
+
+ if (storyName) {
+ url = 'deleteCharacter.php';
+ data.append('story-name', storyName);
+ data.append('char-name', entityName);
+ } else {
+ url = 'deleteStory.php';
+ data.append('story-name', entityName);
+ }
+ jQuery.ajax({
+ url: url,
+ data: data,
+ cache: false,
+ contentType: false,
+ processData: false,
+ method: 'POST'
+ }).done(function(data, textStatus) {
+ console.log('successfully deleted');
+ location.reload();
+ }).fail(function(jqXHR, textStatus) {
+ var errorObj = jqXHR.responseJSON;
+ switch (jqXHR.status) {
+ case 400:
+ console.log(errorObj.msg + ' ' + errorObj.parameters['missing_parameter']);
+ break;
+ }
+ console.log('error deleting entity');
+ console.log(jqXHR);
+ console.log(textStatus);
+ });
+ }
+ });
+ $('.edit-btn').click(function() {
+ editElement(this);
+ });
+ });
+ </script>
<style type="text/css">
.figure-desc {
text-align: justify;
@@ -147,7 +227,7 @@ function printEntities($entities, $storyName = NULL) {
</div>
</div>
<?php
- printEntities($characters);
+ printEntities($characters, $currentStory);
} else {
printEntities($stories);
}