Sections dropdown is updated when changing network

This commit is contained in:
Frank Schubert
2021-07-20 22:25:02 +02:00
parent 329941faae
commit 2b936102f8
4 changed files with 93 additions and 2 deletions

View File

@@ -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];
}
}