Skip to content

Commit

Permalink
NEW: custom-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JKoblitz committed Feb 21, 2024
1 parent 559261d commit b777175
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 15 deletions.
10 changes: 7 additions & 3 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,19 @@
<?= lang('General settings') ?>
</a>
<a href="<?= ROOTPATH ?>/admin/roles" class="with-icon <?= $pageactive('admin/roles') ?>">
<i class="ph ph-gear" aria-hidden="true"></i>
<i class="ph ph-shield-check" aria-hidden="true"></i>
<?= lang('Roles &amp; Rights', 'Rollen &amp; Rechte') ?>
</a>
<a href="<?= ROOTPATH ?>/admin/fields" class="with-icon <?= $pageactive('admin/fields') ?>">
<i class="ph ph-textbox" aria-hidden="true"></i>
<?= lang('Custom fields') ?>
</a>
<a href="<?= ROOTPATH ?>/admin/categories" class="with-icon <?= $pageactive('admin/categories') ?>">
<i class="ph ph-gear" aria-hidden="true"></i>
<i class="ph ph-bookmarks" aria-hidden="true"></i>
<?= lang('Activities', 'Aktivitäten') ?>
</a>
<a href="<?= ROOTPATH ?>/admin/features" class="with-icon <?= $pageactive('admin/features') ?>">
<i class="ph ph-gear" aria-hidden="true"></i>
<i class="ph ph-toolbox" aria-hidden="true"></i>
<?= lang('Features', 'Funktionen') ?>
</a>
</nav>
Expand Down
27 changes: 27 additions & 0 deletions pages/activity-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,33 @@ function run() {
label: lang('Updated by (Abbreviation)', 'Aktualisiert von (Kürzel)'),
type: 'string'
},
<?php
foreach ($osiris->adminFields->find() as $field) {
$f = [
'id'=> $field['id'],
'label'=> lang($field['name'], $field['name_de']??null),
'type'=> $field['format']
];

if ($field['format']=='boolean'){
$f['values'] = [
'true'=> 'yes',
'false'=> 'no'
];
$f['input'] = 'radio';
}

if ($field['format']=='list'){
$f['type'] = 'string';
$f['values'] = $field['values'];
$f['input'] = 'select';
}

echo json_encode($f);
echo ',';
}

?>
// {
// id: 'updated',
// label: lang('Updated', ''),
Expand Down
4 changes: 2 additions & 2 deletions pages/admin/categories.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* Page to browse all user groups
* Page to browse all categories
*
* This file is part of the OSIRIS package.
* Copyright (c) 2024, Julia Koblitz
*
* @link /groups
* @link /admin/categories
*
* @package OSIRIS
* @since 1.3.0
Expand Down
17 changes: 15 additions & 2 deletions pages/admin/category-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$name = str_replace('*', '', $name);
}
$f = $Modules->all_modules[$name] ?? array();
$EXAMPLE = array_merge($f['fields'], $EXAMPLE);
$EXAMPLE = array_merge($f['fields'] ?? [], $EXAMPLE);
}
include_once BASEPATH . "/php/Document.php";
$Document = new Document(false, 'print');
Expand Down Expand Up @@ -182,9 +182,22 @@
<select class="module-input form-control">
<option value="" disabled selected><?= lang('Add module ...', 'Füge Module hinzu ...') ?></option>
<?php
// read custom modules first
$custom_modules = $osiris->adminFields->distinct('id');
if (!empty($custom_modules)){
foreach ($custom_modules as $m) {
if (in_array($m, $module_lst)) continue;
?>
<option><?= $m ?></option>
<?php } ?>
<option disabled>---</option>
<?php
}
include_once BASEPATH . "/php/Modules.php";
$Modules = new Modules();
foreach ($Modules->all_modules as $m => $_) {
$all_modules = array_keys($Modules->all_modules);
sort($all_modules);
foreach ($all_modules as $m) {
if (in_array($m, $module_lst)) continue;
?>
<option><?= $m ?></option>
Expand Down
152 changes: 152 additions & 0 deletions pages/admin/field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php
$formaction = ROOTPATH;
// if (!empty($form) && isset($form['_id'])) {
// $formaction .= "/crud/fields/update/" . $form['_id'];
// $btntext = '<i class="ph ph-check"></i> ' . lang("Update", "Aktualisieren");
// $url = ROOTPATH . "/admin/fields/" . $form['id'];
// $title = $name;
// } else {
$formaction .= "/crud/fields/create";
$btntext = '<i class="ph ph-check"></i> ' . lang("Save", "Speichern");
$url = ROOTPATH . "/admin/fields";
$title = lang('New field', 'Neues Feld');
// }

?>
<style>
tr.ui-sortable-helper {
background-color: white;
border: 1px solid var(--border-color);
}
</style>

<form action="<?= $formaction ?>" method="post" id="group-form">

<div class="box">
<h4 class="header">
<?= $title ?>
</h4>

<div class="content">

<div class="form-group">
<label for="id">ID</label>
<input type="text" class="form-control" name="values[id]" id="id">
<small class="form-text">
<?= lang('Important! The ID will be used in the module list and in templates. Choose sth precise, unique and without spaces.', 'Wichtig! Die ID wird in der Modulliste gezeigt, wähle also etwas genaues, einzigartiges und nutze kein Leerzeichen!') ?>
</small>
</div>


<div class="row row-eq-spacing">
<div class="col-sm-6">
<label for="name" class="required ">Name (en)</label>
<input type="text" class="form-control" name="values[name]" required>
</div>
<div class="col-sm-6">
<label for="name_de" class="">Name (de)</label>
<input type="text" class="form-control" name="values[name_de]">
</div>
</div>

<div class="row row-eq-spacing">
<div class="col-sm-6">
<label for="format">Format</label>
<select class="form-control" name="values[format]" id="format" onchange="updateFields(this.value)">
<option value="string">Text</option>
<option value="text">Long text</option>
<option value="int">Integer</option>
<option value="float">Float</option>
<option value="list">List</option>
<option value="date">Date</option>
<option value="bool">Boolean</option>
<!-- <option value="user">User</option> -->
</select>
</div>
<div class="col-sm-6">

<label for="default">Default</label>
<input type="text" class="form-control" name="values[default]" id="default">

</div>
</div>



<fieldset id="values-field" style="display: none;">
<legend><?= lang('Possible values', 'Mögliche Werte') ?></legend>
<table class="table simple small">
<tbody id="possible-values">
<tr>
<td class="w-50">
<i class="ph ph-dots-six-vertical text-muted handle"></i>
</td>
<td>
<input type="text" class="form-control" name="values[values][]">
</td>
<td>
<a onclick="$(this).closest('tr').remove()"><i class="ph ph-trash"></i></a>
</td>
</tr>
</tbody>
</table>
<button class="btn" type="button" onclick="addValuesRow()"><i class="ph ph-plus-circle"></i></button>
</fieldset>


<button type="submit" class="btn success" id="submitBtn"><?= $btntext ?></button>

</div>


</form>


<script src="<?= ROOTPATH ?>/js/jquery-ui.min.js"></script>
<script>
function addValuesRow() {
$('#possible-values').append(`
<tr>
<td class="w-50">
<i class="ph ph-dots-six-vertical text-muted handle"></i>
</td>
<td>
<input type="text" class="form-control" name="values[values][]">
</td>
<td>
<a onclick="$(this).closest('tr').remove()"><i class="ph ph-trash"></i></a>
</td>
</tr>
`);
}

function updateFields(name) {
$('#values-field').hide()
switch (name) {
case 'string':
break;
case 'text':
break;
case 'int':
break;
case 'float':
break;
case 'list':
$('#values-field').show()
break;
case 'date':
break;
case 'bool':
break;
default:
break;
}
}

$(document).ready(function() {
$('#possible-values').sortable({
handle: ".handle",
// change: function( event, ui ) {}
});
})
</script>
59 changes: 59 additions & 0 deletions pages/admin/fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* Page to see and edit custom fields
*
* This file is part of the OSIRIS package.
* Copyright (c) 2024, Julia Koblitz
*
* @link /admin/fields
*
* @package OSIRIS
* @since 1.3.1
*
* @copyright Copyright (c) 2024, Julia Koblitz
* @author Julia Koblitz <[email protected]>
* @license MIT
*/

?>

<h1>
<i class="ph ph-textbox"></i>
Custom fields
</h1>

<div class="btn-toolbar">
<a class="btn" href="<?= ROOTPATH ?>/admin/fields/new">
<i class="ph ph-plus-circle"></i>
<?= lang('Add field', 'Feld hinzufügen') ?>
</a>
</div>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Format</th>
<th>Name</th>
<th></th>
</tr>
</thead>
<?php foreach ($osiris->adminFields->find() as $field) { ?>
<tr>
<td>
<?=$field['id']?>
</td>
<td>
<?=$field['format']?>
</td>
<td>
<?=lang($field['name'], $field['name_de'])?>
</td>
<td>
<form action="<?=ROOTPATH?>/crud/fields/delete/<?=$field['_id']?>" method="post">
<button type="submit" class="btn link"><i class="ph ph-trash text-danger"></i></button>
</form>
</td>
</tr>
<?php } ?>
</table>
Loading

0 comments on commit b777175

Please sign in to comment.