diff --git a/include/projectsmanagement.php b/include/projectsmanagement.php
index 567fedc..1cc87cb 100644
--- a/include/projectsmanagement.php
+++ b/include/projectsmanagement.php
@@ -55,13 +55,13 @@ class Projectsmanagement extends Renderer {
WHERE caption = "Fortlaufende Projekte"', $newName);
mysqli_query($this->dbConnection, $query);
$id = mysqli_insert_id($this->dbConnection);
- $query = 'SELECT id, short_title FROM project p ORDER BY short_title';
+ $query = 'SELECT id, short_title, project_type_id FROM project p ORDER BY short_title';
$dbResult = mysqli_query($this->dbConnection, $query);
$list = [];
while ($row = mysqli_fetch_assoc($dbResult)) {
- $list[] = ['id' => $row['id'], 'title' => $row['short_title'] ];
+ $list[] = ['id' => $row['id'], 'title' => $row['short_title'], 'project_type_id' => $row['project_type_id'] ];
}
- echo json_encode(['list' => $list, 'id' => $id]);
+ echo json_encode(['list' => $list, 'id' => $id, 'types' => $this->getProjectTypes()]);
}
protected function setDescription(): void {
@@ -90,15 +90,10 @@ class Projectsmanagement extends Renderer {
}
protected function generateContent(): void {
- $typesQuery = 'SELECT * FROM project_type ORDER BY id';
- $typesResult = mysqli_query($this->dbConnection, $typesQuery);
- $types = [];
- while ($row = mysqli_fetch_assoc($typesResult)) {
- $types[$row['id'] ] = $row['caption'];
- }
+ $types = $this->getProjectTypes();
$query = 'SELECT * FROM project ORDER BY short_title';
$result = mysqli_query($this->dbConnection, $query);
- $overviewHtml = '
| Projekt | Projekttyp |
|---|
';
+ $overviewHtml = '| Projekt | Projekttyp |
|---|
';
while ($row = mysqli_fetch_assoc($result)) {
$overviewHtml .= '| ' . $row['short_title'] . ' | ';
$overviewHtml .= ' |
';
$this->content['projects'] = $overviewHtml;
}
+
+ protected function getProjectTypes(): array {
+ $typesQuery = 'SELECT * FROM project_type ORDER BY id';
+ $typesResult = mysqli_query($this->dbConnection, $typesQuery);
+ $types = [];
+ while ($row = mysqli_fetch_assoc($typesResult)) {
+ $types[$row['id'] ] = $row['caption'];
+ }
+ return $types;
+ }
}
diff --git a/templates/projectsmanagement.html b/templates/projectsmanagement.html
index d4852c3..68bcc98 100644
--- a/templates/projectsmanagement.html
+++ b/templates/projectsmanagement.html
@@ -19,6 +19,7 @@ $(document).ready(function() {
return;
}
$("#shorttitle > option:not(:first-child)").remove();
+ $("#projectoverview > tbody > tr").remove();
response.list.forEach(function(item) {
let newItem = $("");
newItem.attr("id", item.id);
@@ -26,7 +27,16 @@ $(document).ready(function() {
if (item.id == response.id) {
newItem.attr("selected", "selected");
}
- $("#shorttitle").append(newItem);
+ let newRow = $('| ' + item.title + ' |
');
+ let selectElement = $('');
+ for (let typeId in response.types) {
+ if (response.types.hasOwnProperty(typeId)) {
+ let option = $('');
+ selectElement.append(option);
+ }
+ }
+ newRow.append('' + selectElement.prop('outerHTML') + ' | ');
+ $("#projectoverview tbody").append(newRow);
});
}).fail(function(response) {
alert(response);