Sections dropdown is updated when changing network
This commit is contained in:
@@ -196,12 +196,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-form-label" for="networksection_id">Bauabschnitt</label>
|
||||||
|
<div class="col-lg-10">
|
||||||
|
<select class="select2 form-control " name="networksection_id" id="networksection_id">
|
||||||
|
<option></option>
|
||||||
|
<?php foreach($networksections as $section): ?>
|
||||||
|
<option value="<?=$section->id?>" <?=($building->networksection_id == $section->id) ? "selected='selected'" : ""?>><?=($section->network->name)?> - <?=($section->name)?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-lg-2 col-form-label" for="description">Bauabschnitt</label>
|
<label class="col-lg-2 col-form-label" for="description">Bauabschnitt</label>
|
||||||
<div class="col-lg-10">
|
<div class="col-lg-10">
|
||||||
<textarea id="description" class="form-control" name="description" rows="5"><?=$building->description?></textarea>
|
<textarea id="description" class="form-control" name="description" rows="5"><?=$building->description?></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-lg-2 col-form-label" for="status_id">Status</label>
|
<label class="col-lg-2 col-form-label" for="status_id">Status</label>
|
||||||
@@ -309,6 +324,7 @@
|
|||||||
},
|
},
|
||||||
function(success) {
|
function(success) {
|
||||||
if(success.status == "OK") {
|
if(success.status == "OK") {
|
||||||
|
//console.log(success);
|
||||||
pops = success.result.pops;
|
pops = success.result.pops;
|
||||||
if(typeof pops !== 'object' || pops === null) {
|
if(typeof pops !== 'object' || pops === null) {
|
||||||
return true;
|
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($("<option></option>").attr("value", pop_id).text(sections[section_id]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'json'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function updatePermissions() {
|
function updatePermissions() {
|
||||||
var network_id = $("#network_id").val();
|
var network_id = $("#network_id").val();
|
||||||
if(!network_id) {
|
if(!network_id) {
|
||||||
@@ -331,7 +374,6 @@
|
|||||||
|
|
||||||
var types = ["lineworker", "pipeworker"];
|
var types = ["lineworker", "pipeworker"];
|
||||||
|
|
||||||
// get new pops
|
|
||||||
$.get("<?=self::getUrl("Network","Api")?>",
|
$.get("<?=self::getUrl("Network","Api")?>",
|
||||||
{
|
{
|
||||||
"do": "getPermissions",
|
"do": "getPermissions",
|
||||||
@@ -341,6 +383,9 @@
|
|||||||
function(success) {
|
function(success) {
|
||||||
if(success.status == "OK") {
|
if(success.status == "OK") {
|
||||||
var perms = success.result.permissions;
|
var perms = success.result.permissions;
|
||||||
|
if(typeof perms !== 'object' || perms === null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
types.forEach(function(type) {
|
types.forEach(function(type) {
|
||||||
$("#" + type + "_id").empty();
|
$("#" + type + "_id").empty();
|
||||||
$("#" + type + "_id").append($("<option></option>"));
|
$("#" + type + "_id").append($("<option></option>"));
|
||||||
@@ -404,11 +449,13 @@
|
|||||||
$("#network_id").change(function() {
|
$("#network_id").change(function() {
|
||||||
updatePops();
|
updatePops();
|
||||||
updatePermissions();
|
updatePermissions();
|
||||||
|
updateSections();
|
||||||
});
|
});
|
||||||
|
|
||||||
$( document ).ready(function() {
|
$( document ).ready(function() {
|
||||||
updatePops();
|
updatePops();
|
||||||
updatePermissions();
|
updatePermissions();
|
||||||
|
updateSections();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class BuildingController extends mfBaseController {
|
|||||||
$this->layout()->set("statuses", BuildingstatusModel::getAll());
|
$this->layout()->set("statuses", BuildingstatusModel::getAll());
|
||||||
$this->layout()->set("pipeworkers", AddressModel::search(["addresstype" => ["pipeworker"]]));
|
$this->layout()->set("pipeworkers", AddressModel::search(["addresstype" => ["pipeworker"]]));
|
||||||
$this->layout()->set("lineworkers", AddressModel::search(["addresstype" => ["lineworker"]]));
|
$this->layout()->set("lineworkers", AddressModel::search(["addresstype" => ["lineworker"]]));
|
||||||
|
$this->layout()->set("networksections", NetworksectionModel::getAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function editAction() {
|
protected function editAction() {
|
||||||
|
|||||||
@@ -84,4 +84,44 @@ class NetworksectionController extends mfBaseController {
|
|||||||
$this->layout()->setFlash("Bauabschnitt gelöscht", "success");
|
$this->layout()->setFlash("Bauabschnitt gelöscht", "success");
|
||||||
$this->redirect("Network", "Index", [], "view=sections&net=".$network_id);
|
$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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,4 +7,7 @@ CREATE TABLE `Networksection` (
|
|||||||
`create` int(10) NOT NULL,
|
`create` int(10) NOT NULL,
|
||||||
`edit` int(10) NOT NULL,
|
`edit` int(10) NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
|
) 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`;
|
||||||
|
|||||||
Reference in New Issue
Block a user