diff --git a/Layout/default/Building/Form.php b/Layout/default/Building/Form.php
index 2be0e3670..11b7dad89 100644
--- a/Layout/default/Building/Form.php
+++ b/Layout/default/Building/Form.php
@@ -196,12 +196,27 @@
+
+
+
+
@@ -309,6 +324,7 @@
},
function(success) {
if(success.status == "OK") {
+ //console.log(success);
pops = success.result.pops;
if(typeof pops !== 'object' || pops === null) {
return true;
@@ -323,6 +339,33 @@
);
}
+ function updateSections() {
+ var network_id = $("#network_id").val();
+ if(!network_id) {
+ return true;
+ }
+
+ $.get("=self::getUrl("Networksection","Api")?>",
+ {
+ "do": "getSections",
+ network_id: network_id
+ },
+ function(success) {
+ if(success.status == "OK") {
+ sections = success.result.sections;
+ if(typeof sections !== 'object' || sections === null) {
+ return true;
+ }
+ $("#networksection_id option:gt(0)").remove();
+ for(var section_id in sections) {
+ $("#networksection_id").append($("").attr("value", pop_id).text(sections[section_id]));
+ }
+ }
+ },
+ 'json'
+ );
+ }
+
function updatePermissions() {
var network_id = $("#network_id").val();
if(!network_id) {
@@ -331,7 +374,6 @@
var types = ["lineworker", "pipeworker"];
- // get new pops
$.get("=self::getUrl("Network","Api")?>",
{
"do": "getPermissions",
@@ -341,6 +383,9 @@
function(success) {
if(success.status == "OK") {
var perms = success.result.permissions;
+ if(typeof perms !== 'object' || perms === null) {
+ return true;
+ }
types.forEach(function(type) {
$("#" + type + "_id").empty();
$("#" + type + "_id").append($(""));
@@ -404,11 +449,13 @@
$("#network_id").change(function() {
updatePops();
updatePermissions();
+ updateSections();
});
$( document ).ready(function() {
updatePops();
updatePermissions();
+ updateSections();
});
diff --git a/application/Building/BuildingController.php b/application/Building/BuildingController.php
index 6b84f28fc..2efac4e0f 100644
--- a/application/Building/BuildingController.php
+++ b/application/Building/BuildingController.php
@@ -26,6 +26,7 @@ class BuildingController extends mfBaseController {
$this->layout()->set("statuses", BuildingstatusModel::getAll());
$this->layout()->set("pipeworkers", AddressModel::search(["addresstype" => ["pipeworker"]]));
$this->layout()->set("lineworkers", AddressModel::search(["addresstype" => ["lineworker"]]));
+ $this->layout()->set("networksections", NetworksectionModel::getAll());
}
protected function editAction() {
diff --git a/application/Networksection/NetworksectionController.php b/application/Networksection/NetworksectionController.php
index 5e2dc4609..f9b01d812 100644
--- a/application/Networksection/NetworksectionController.php
+++ b/application/Networksection/NetworksectionController.php
@@ -84,4 +84,44 @@ class NetworksectionController extends mfBaseController {
$this->layout()->setFlash("Bauabschnitt gelöscht", "success");
$this->redirect("Network", "Index", [], "view=sections&net=".$network_id);
}
+
+ protected function apiAction() {
+ $do = $this->request->do;
+ $data = [];
+
+ switch($do) {
+ case "getSections":
+ $return = $this->getSectionsApi();
+ break;
+ default:
+ $return = false;
+ }
+
+ if(!is_array($return) || !count($return)) {
+ $data = ["status" => "error"];
+ $this->returnJson($data);
+ }
+ $data['status'] = "OK";
+ $data['result'] = $return;
+ $this->returnJson($data);
+ }
+
+ private function getSectionsApi() {
+ $network_id = $this->request->network_id;
+ if(!is_numeric($network_id) || $network_id < 1) {
+ return false;
+ }
+
+ $network = new Network($network_id);
+ if(!$network->id) {
+ return false;
+ }
+
+ $sections = NetworksectionModel::search(['network_id' => $network_id]);
+ $return = [];
+ foreach($sections as $section) {
+ $return[$section->id] = $section->network->name." - ".$section->name;
+ }
+ return ["sections" => $return];
+ }
}
\ No newline at end of file
diff --git a/contrib/migrations/2021-07-20-networksection.sql b/contrib/migrations/2021-07-20-networksection.sql
index cfc27541f..11252b8d0 100644
--- a/contrib/migrations/2021-07-20-networksection.sql
+++ b/contrib/migrations/2021-07-20-networksection.sql
@@ -7,4 +7,7 @@ CREATE TABLE `Networksection` (
`create` int(10) NOT NULL,
`edit` int(10) NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
\ No newline at end of file
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
+
+ALTER TABLE `Building` CHANGE `description` `description` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NULL DEFAULT NULL;
+ALTER TABLE `Building` ADD `networksection_id` INT NULL DEFAULT NULL AFTER `lineworker_id`;