Files
thetool/Layout/default/Pop/Detail.php
2023-11-14 15:22:08 +01:00

1146 lines
58 KiB
PHP

<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/header.php"); ?>
<link href="<?= self::getResourcePath() ?>assets/css/datatables-std.css" rel="stylesheet" type="text/css"/>
<style>
.card-border {
border-left: 1px solid #428bca;
border-left-width: 5px;
border-radius: 3px;
}
.font-weight-500 {
font-weight: 500;
}
.order-date-pill {
margin: 2px;
white-space: nowrap;
}
.rack-he:hover {
box-shadow: 2px 2px 5px 2px rgba(0, 0, 0, 0.31);
}
.rack-color-lwl {
background: rgb(159, 255, 96);
background: linear-gradient(180deg, rgb(129 237 58) 0%, rgb(92 211 15) 100%);
font-weight: 500;
padding-top: 2px;
}
.rack-color-device {
background: rgb(182, 198, 240);
background: linear-gradient(180deg, rgba(182, 198, 240, 1) 0%, rgb(131 158 255 / 82%) 100%);
font-weight: 500;
padding-top: 2px;
}
.rack-color-infra {
background: rgb(251 181 109);
background: linear-gradient(180deg, rgb(247 184 118) 0%, rgb(255 149 40) 100%);
font-weight: 500;
padding-top: 2px;
}
.rack-color-panel {
background: rgb(150, 243, 222);
background: linear-gradient(180deg, rgba(150, 243, 222, 1) 0%, rgba(87, 249, 212, 1) 100%);
font-weight: 500;
padding-top: 2px;
}
.rack-color-blocked {
background: rgb(255, 0, 0);
background: linear-gradient(180deg, rgba(255, 0, 0, 1) 0%, rgba(196, 0, 0, 1) 100%);
font-weight: 500;
padding-top: 2px;
color: #fff;
}
.rack-color-rpanel {
background: rgb(88, 201, 240);
background: linear-gradient(180deg, rgba(88, 201, 240, 1) 0%, rgba(64, 188, 231, 1) 100%);
font-weight: 500;
padding-top: 2px;
}
.user-select-none {
user-select: none;
}
.fa-edit {
margin-right: 5px;
margin-top: 2px;
cursor: pointer;
}
.rack-name {
}
.move-handle {
cursor: grab;
margin-left: 5px;
margin-top: 2px;
}
.move-handle:active {
cursor: grabbing;
}
.border-right {
border-right-color: #dee2e6 !important;
}
.form-control:disabled, .form-control[readonly] {
background-color: #d7d7d7;
opacity: 1;
}
</style>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?= self::getUrl("Dashboard") ?>"><?= MFAPPNAME_SLUG ?></a>
</li>
<li class="breadcrumb-item"><a href="<?= self::getUrl("Pop") ?>">Pops</a>
</li>
<li class="breadcrumb-item active">Pop Detail</li>
</ol>
</div>
<h4 class="page-title">Pop: <span class="font-weight-normal ml-1"><?= $pops->data->name ?></span> <span
class="ml-2">
<a href="<?= self::getUrl("Pop", "edit", ["id" => $pops->id, 'returnto' => "pop-detail"]) ?>">
<button class="btn btn-primary">Bearbeiten</button>
</a>
</span>
<button class="btn btn-success" data-popid="<?= $pops->id ?>" data-toggle="modal"
data-target="#rackModal"><i class="fas fa-plus"></i> Schrank hinzufügen
</button>
</h4>
</div>
</div>
</div>
<!-- end page title -->
<?php
$plugs[1] = "LC";
$plugs[2] = "SC";
$plugs[3] = "E2000";
$vlans = "";
if (!empty(trim($pops->vlan_public)))
$vlans .= '<span class="order-date-pill active mb-0">Public: <span class="font-weight-500">' . $pops->vlan_public . '</span class="font-weight-500"></span>';
if (!empty(trim($pops->vlan_nat)))
$vlans .= '<span class="order-date-pill active mb-0">Nat: <span class="font-weight-500">' . $pops->vlan_nat . '</span></span>';
if (!empty(trim($pops->vlan_ipv6)))
$vlans .= '<span class="order-date-pill active mb-0">IPv6: <span class="font-weight-500">' . $pops->vlan_ipv6 . '</span></span>';
?>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-5 card-border">
<div>
<h4>Allgemeine Informationen </h4>
</div>
<div>
<table class="table table-sm">
<tbody>
<tr>
<th style="min-width: 250px; width: 300px;">Netzgebiet</th>
<td><?= $pops->network->name ?> </td>
</tr>
<tr>
<th>Name</th>
<td><?= $pops->name ?> </td>
</tr>
<tr>
<th>Standort</th>
<td>
<a title="Google-Maps: <?= rtrim($pops->gps_lat, '0') ?> , <?= $pops->gps_long ?>"
class="mapsLink"
href="http://maps.google.com/?q=<?= $pops->gps_lat ?> , <?= $pops->gps_long ?>"
target="_blank"><?= rtrim($pops->gps_lat, '0') ?>
, <?= rtrim($pops->gps_long, 0) ?></a></td>
</tr>
<tr>
<th>Standort Info</th>
<td><?= nl2br($pops->location) ?> </td>
</tr>
<tr>
<th>Access VLANs</th>
<td><?= $vlans ?> </td>
</tr>
<tr>
<th>Interne Notiz</th>
<td><?= nl2br($pops->note) ?> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-7 card-border">
<div>
<h4>Pop Devices</h4>
</div>
<?php
if (!empty($devices)) {
?>
<div>
<table id="datatable" class="table table-striped table-hover">
<thead>
<tr>
<th>Geräte Name</th>
<th class="text-center">Geräte Typ</th>
<th class="text-center">Hersteller</th>
<th class="text-center">IP-Adresse</th>
<th class="text-center">Seriennummer</th>
<th class="text-center">Preis</th>
<th title="maximale Leistung" class="text-center text-nowrap">max. P.</th>
</tr>
<tr id="filterrow">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody class="font-13">
<?php
foreach ($devices as $device):
if (!empty($device->price)) {
$price = $device->price;
} else {
$price = $device->devicetype->price;
}
?>
<tr>
<td class="text-nowrap">
<a href="<?= self::getUrl("Device", "detail", ["id" => $device->id]) ?>"><?= $device->name ?></a>
</td>
<td class="text-center text-nowrap"><?= $device->devicetype->name ?></td>
<td class="text-center"><?= $device->devicetype->devicemanufactor->name ?></td>
<td class="text-center"><?= $device->ip ?></td>
<td class="text-center"><?= $device->serial ?></td>
<td class="text-right"><?= $price ?> €</td>
<td class="text-right"><?= $device->devicetype->power ?> Watt</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
} else {
?>
<h5 class="text-center">Keine Devices vorhanden</h5>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="rackModal" tabindex="-1" role="dialog" aria-labelledby="rackModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="rackModalLabel">Schrank</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="rack-name">Schrank Name*</label>
<div class="col-lg-6">
<input required="required" type="text" id="rack-name" name="rack-name"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="rack-he">Höheneinheiten*</label>
<div class="col-lg-3">
<input required="required" type="number" min="1" max="50" id="rack-he" name="rack-he"
class="form-control"/>
</div>
</div>
<div class="alert alert-danger text-center" role="alert" style="display: none"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="rack-add">Schrank hinzufügen</button>
<button type="button" class="btn btn-primary" id="rack-update" style="display:none">Schrank
speichern
</button>
<button type="button" class="btn btn-danger" id="rack-remove" style="display:none">Schrank
entfernen
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button>
</div>
</div>
</div>
</div>
<?php if ($popracks) : ?>
<div class="modal fade " id="rackModuleModal" tabindex="-1" role="dialog" aria-labelledby="rackModuleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="rackModuleModalLabel">Modul hinzufügen</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row " id="module-slot-div" style="display:none">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="module-slot">19 Zoll Position</label>
<div class="col-lg-3">
<select required="required" id="module-slot" name="module-slot"
class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="module-type">Modul Typ*</label>
<div class="col-lg-6">
<select required="required" id="module-type" name="module-type"
class="form-control">
<option value="0">LWL Patch Panel</option>
<option value="1">Device</option>
<option value="2">Rangierpanel</option>
<option value="4">CU Patch Panel</option>
<option value="3">Infrastruktur</option>
<option value="5">Geblockt</option>
</select>
</div>
</div>
<div class="form-group row" id="module-name-div">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="module-name">Modul Name*</label>
<div class="col-lg-6">
<input required="required" type="text" id="module-name" name="module-name"
class="form-control"/>
</div>
</div>
<div class="form-group row" id="module-device-div">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="module-device-id">Device*</label>
<div class="col-lg-6">
<select required="required" id="module-device-id" name="module-type"
class="form-control">
<?php foreach ($devices as $device): ?>
<option value="<?= $device->id ?>"><?= $device->name ?></option>
<?php endforeach; ?>
</select>
<label class="col-form-label" id="module-device-text"></label>
</div>
</div>
<div class="form-group row" id="module-ports-div">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="module-ports">Ports</label>
<div class="col-lg-6">
<select required="required" id="module-ports" name="module-ports"
class="form-control">
<option selected="selected" value="48" data-plugs="1;2">48</option>
<option value="24" data-plugs="2;3">24</option>
<option value="12" data-plugs="2;3">12</option>
</select>
</div>
</div>
<div class="form-group row" id="module-plug-div">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="module-plug">Stecker</label>
<div class="col-lg-6">
<select required="required" id="module-plug" name="module-plug"
class="form-control">
<option value="1">LC/APC</option>
<option value="2">SC/APC</option>
<option style="display: none" value="3">E2000/APC</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="he-start">Start HE*</label>
<div class="col-lg-3" id="he-start-div">
</div>
</div>
<div class="form-group row">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="he-count">Anzahl HE*</label>
<div class="col-lg-3" id="he-count-div">
</div>
</div>
<div class="form-group row">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="">Größe</label>
<div class="col-lg-4">
<select required="required" id="module-width" name="module-width"
class="form-control">
<option value="12">19 Zoll</option>
<option value="6">1/2 19 Zoll</option>
<option value="4">1/3 19 Zoll</option>
<option value="3">1/4 19 Zoll</option>
</select>
</div>
</div>
<div class="form-group row" id="module-position-div" style="display: none">
<div class="col-lg-1"></div>
<label class="col-lg-4 col-form-label" for="">Position</label>
<div class="col-lg-4">
<select required="required" id="module-position" name="module-position"
class="form-control">
</select>
</div>
</div>
<div class="alert alert-danger text-center" role="alert" style="display: none"></div>
</div>
<div class="modal-footer">
<button id="module-add" type="button" class="btn btn-primary">Modul hinzufügen</button>
<button id="module-update" type="button" class="btn btn-primary">Modul Speichern</button>
<button id="module-remove" type="button" class="btn btn-danger" style="display:none">Modul
entfernen
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button>
</div>
</div>
</div>
</div>
<div class="row" id="pop-rack-div" style="display:none">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-12 card-border">
<div>
<h4>Schränke </h4>
</div>
<div id="sortracklist" class="row" data-popid="<?= $pops->id ?>">
<?php foreach ($popracks as $poprack) : ?>
<div class="col-lg-2 list-group-item-move">
<table class="w-100 p-0 font-13"
style="max-width: 100%; box-shadow: 2px 2px 5px 2px rgba(0,0,0,0.31);border-radius: 5px 5px 5px 5px;">
<thead>
<tr>
<th colspan="13"
class="text-center border-bottom font-15 pt-1 pb-1"
data-rackhe="<?= $poprack['rack']['he'] ?>"
data-rackid="<?= $poprack['rack']['id']; ?>"><span
class="rack-name"><i
class="fa-regular fa-arrows-up-down-left-right move-handle float-left"></i><?= $poprack['rack']['name']; ?></span>
<i class="far fa-edit float-right" title="Bearbeiten"
data-toggle="modal" data-target="#rackModal"></i>
</th>
</tr>
</thead>
<tbody>
<?php
$cellwidth = 227;
$blocktd = 0;
for ($i = 1; $i <= $poprack['rack']['he']; $i++) : ?>
<tr>
<td class="border-right w-15 p-0 pl-1 pr-1 border-bottom font-13 rack-he user-select-none"
data-toggle="modal" data-target="#rackModuleModal"
style="cursor: pointer" data-he="<?= $i; ?>">He<?= $i; ?></td>
<?php
foreach ($poprack['modules'] as $module) {
if ($module['start_he'] == $i) {
$modulestart = 1;
$modulelenght = $module['end_he'] - $module['start_he'] + 1;
$position = 1;
$slotcounter = 0;
$calcwidth = 0;
$extText = "";
$extTextspan = "";
foreach ($module['slots'] as $slots) {
$extText = "";
if ($slots['type'] == '0') {
$color = '#9fff6e';
$colorclass = "rack-color-lwl";
if ($slots['plug']) {
$extText = " (" . $plugs[$slots['plug']] . "/" . $slots['ports'] . "P)";
$extTextspan = "<span style='font-size: 12px;font-weight: 400'>" . $extText . "</span>";
}
} else if ($slots['type'] == '1') {
?>
<script>
$("#module-device-id option[value='<?= $slots['device_id'] ?>']").remove();
</script>
<?php
$color = '#b6c6ff';
$colorclass = "rack-color-device";
} else if ($slots['type'] == '2') {
$color = '#ff8100';
$colorclass = "rack-color-rpanel";
} else if ($slots['type'] == '3') {
$color = '#ffad59';
$colorclass = "rack-color-infra";
} else if ($slots['type'] == '4') {
$color = '#96f3de';
$colorclass = "rack-color-panel";
} else if ($slots['type'] == '5') {
$color = '#96f3de';
$colorclass = "rack-color-blocked";
}
if ($slots['width'] == "12") {
$width = "85%";
$maxwidth = $cellwidth;
} else if ($slots['width'] == "6") {
$width = "42%";
$maxwidth = intval($cellwidth / 2);
} else if ($slots['width'] == "4") {
$width = "28%";
$maxwidth = intval($cellwidth / 3);
} else if ($slots['width'] == "3") {
$width = "21%";
$maxwidth = intval($cellwidth / 4);
}
if ($slots['width'] < 12 && $position != $slots['position']) {
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
$position++;
$calcwidth = $calcwidth + $slots['width'];
}
if ($slots['width'] < 12 && $position != $slots['position']) {
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-righttext-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
$position++;
$calcwidth = $calcwidth + $slots['width'];
}
if ($slots['width'] < 12 && $position != $slots['position']) {
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
$position++;
$calcwidth = $calcwidth + $slots['width'];
}
echo '<td title="' . $slots['modulname'] . $extText . '" colspan="' . $slots['width'] . '" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1 ' . $colorclass . '" data-id="' . $slots['moduleid'] . '" data-type="' . $slots['type'] . '" data-name="' . $slots['modulname'] . '" data-starthe="' . $module['start_he'] . '" data-ports="' . $slots['ports'] . '" data-plug="' . $slots['plug'] . '" rowspan="' . $modulelenght . '" style="width: ' . $width . '; background-color: ' . $color . ';border-color: #797979 !important; white-space: nowrap; text-overflow: ellipsis;max-width: ' . $maxwidth . 'px;"><span></span> ' . $slots['modulname'] . $extTextspan . '</td>';
$position++;
$calcwidth = $calcwidth + $slots['width'];
}
if ($calcwidth != 12) {
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
$calcwidth = $calcwidth + $slots['width'];
}
if ($calcwidth != 12) {
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
$calcwidth = $calcwidth + $slots['width'];
}
if ($calcwidth != 12) {
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
$calcwidth = $calcwidth + $slots['width'];
}
$blocktd = $modulelenght + $i;
}
}
if ($i >= $blocktd) {
echo '<td colspan="12" style="background-color: #fff;" class="text-center he-free" ><span></span> frei</td>';
}
?>
</tr>
<?php endfor; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/javascript" src="<?= self::getResourcePath() ?>assets/js/Sortable.js"></script>
<script type="text/javascript">
var hidesearch = [5, 6];
var trigger;
$(document).ready(function () {
if ($('#sortracklist').length > 0) {
Sortable.create(sortracklist, {
handle: '.move-handle',
onEnd: function () {
var popid = $('#sortracklist').data('popid');
var racksortids = [];
$('#sortracklist').find('th').each(function (index, value) {
racksortids.push($(this).data('rackid'));
});
$.post("<?= self::getUrl("Poprack", "api", ['do' => 'sortRack']) ?>&pop_id=" + popid, {
racksortids: racksortids
}, function (data) {
if (data.success === true) {
}
}, "json");
}
});
}
$('#pop-rack-div').show();
$('#rackModal').on('show.bs.modal', function (event) {
var thisclick = $(event.relatedTarget);
var rackhe = thisclick.closest('table').find('th').data('rackhe');
var rackid = thisclick.closest('table').find('th').data('rackid');
var rackname = $.trim(thisclick.closest('table').find('th').text());
var minhe = 1;
var modal = $(this);
var edit = 0;
modal.find('.alert').text('');
modal.find('.alert').hide();
if (rackid === undefined) {
$('#rack-name').val('');
$('#rack-he').val('');
var popid = thisclick.data('popid');
$('#rack-add').data('popid', popid);
$('#rack-update').hide();
$('#rack-remove').hide();
$('#rack-add').show();
} else {
edit = 1;
$('#rack-remove').hide();
$('#rack-add').hide();
$('#rack-update').show();
$('#rack-he').val(rackhe);
$('#rack-name').val(rackname);
for (let i = 1; i <= rackhe; i++) {
if (!thisclick.closest('table').find('tbody').find('tr').eq(i - 1).find('td').eq(1).hasClass('he-free')) {
minhe = i;
}
}
if (minhe === 1) {
$('#rack-remove').data('rackid', rackid);
$('#rack-remove').show();
}
$('#rack-update').data('rackid', rackid);
$('#rack-update').data('rackminhe', minhe);
}
}
)
;
$('#rackModuleModal').on('show.bs.modal', function (event) {
trigger = $(event.relatedTarget);
var destinationname = trigger.closest('table').find('th').text();
var rackhe = trigger.closest('table').find('th').data('rackhe');
var modal = $(this);
modal.find('.modal-title').html('<span id="module-info">Modul (' + destinationname + ')</span>');
modal.find('.alert').text('');
modal.find('.alert').hide();
var options;
var selected;
var hemaxcount = 1;
var hemaxcountactive = 1;
var edit = 0;
var parent = trigger.closest('tr');
if (trigger.closest('tr').find('td').eq(1).html() === undefined) {
edit = 1;
parent = trigger.closest('tr').prev();
for (let i = 1; i <= rackhe; i++) {
if (parent.find('td').eq(1).html() !== undefined) {
break;
} else {
parent = parent.prev();
}
}
}
if (parent.find('td').eq(1).data('id') || parent.find('td').eq(2).data('id') || parent.find('td').eq(3).data('id') || parent.find('td').eq(4).data('id')) {
var counttd = parent.find('td').length - 1;
var newmodule = false;
if (counttd > 1) {
var options;
for (let i = 1; i <= counttd; i++) {
options = options + '<option value="' + i + '">' + i + '</option>';
}
$('#module-slot').html(options);
$('#module-position').html(options);
$('#module-slot-div').show();
}
$('#module-width').attr('disabled', 'disabled');
$('#he-count-div').html(`<select required="required" id="module-he-count" name="module-he-count" class="form-control" disabled="disabled"><option value="` + parent.find('td').eq(1).attr('rowspan') + `">` + parent.find('td').eq(1).attr('rowspan') + `</option><select>`);
$('#he-start-div').html(`<select required="required" id="module-he-start" name="module-he-start" class="form-control" disabled="disabled"><option value="` + parent.find('td').eq(0).data('he') + `">` + parent.find('td').eq(0).data('he') + `</option></select>`);
if (parent.find('td').eq(1).data('id') === undefined) {
newmodule = true;
}
var modwidth = 12 / counttd;
$('#module-width').val(modwidth);
if (!newmodule) {
$('#module-remove').show();
$('#module-update').show();
$('#module-add').hide();
$('#module-type').val(parent.find('td').eq(1).data('type')).change();
if ($('#module-type').val() == "1") {
$('#module-device-id').hide();
$('#module-device-text').text(parent.find('td').eq(1).data('name'));
$('#module-device-text').show();
}
if (parent.find('td').eq(1).data('ports') != "") {
$('#module-ports').val(parent.find('td').eq(1).data('ports')).change();
$('#module-plug').val(parent.find('td').eq(1).data('plug'));
}
$('#module-type').attr('disabled', 'disabled');
$('#module-name').val(parent.find('td').eq(1).data('name'));
// $('#module-name').attr('disabled', 'disabled');
$('#module-remove').data('moduleid', parent.find('td').eq(1).data('id'));
$('#module-update').data('moduleid', parent.find('td').eq(1).data('id'));
} else {
$('#module-remove').hide();
$('#module-update').hide();
$('#module-add').show();
$('#module-name-div').show();
$('#module-name').removeAttr('disabled');
$('#module-device-div').hide();
$('#module-device-id').show();
$('#module-device-id').attr('disabled', 'disabled');
$('#module-type').val('0').change();
$('#module-type').removeAttr('disabled');
$('#module-plug').removeAttr('disabled');
$('#module-ports').removeAttr('disabled');
$('#module-name').val('');
$('#module-ports').val('48');
$('#module-ports').trigger("change");
$('#module-position-div').hide();
$('#module-update').hide();
$('#module-device-text').hide();
}
} else {
$('#module-remove').hide();
$('#module-update').hide();
$('#module-add').show();
for (let i = 1; i <= rackhe; i++) {
if (i == trigger.data('he')) {
selected = 'selected="selected"';
} else {
selected = '';
}
if (trigger.closest('tbody').find('tr').eq(i - 1).find('td').eq(1).hasClass('he-free')) {
options = options + '<option ' + selected + ' value="' + i + '">' + i + '</option>';
}
if (hemaxcountactive == 1 && i > trigger.data('he') && !trigger.closest('tbody').find('tr').eq(i - 1).find('td').eq(1).hasClass('he-free')) {
hemaxcountactive = 0;
}
if (hemaxcountactive == 1 && i > trigger.data('he') && trigger.closest('tbody').find('tr').eq(i - 1).find('td').eq(1).hasClass('he-free')) {
hemaxcount++;
}
}
$('#he-start-div').html(`<select required="required" id="module-he-start" name="module-he-start" class="form-control">` + options + `</select>`);
options = "";
selected = "";
for (let i = 1; i <= hemaxcount; i++) {
options = options + '<option ' + selected + ' value="' + i + '">' + i + '</option>';
}
$('#he-count-div').html(`<select required="required" id="module-he-count" name="module-he-count" class="form-control">` + options + `</select>`);
if (edit == 0) {
$('#module-name-div').show();
$('#module-name').removeAttr('disabled');
$('#module-device-div').hide();
$('#module-device-id').attr('disabled', 'disabled');
$('#module-type').val('0').change();
$('#module-type').removeAttr('disabled');
$('#module-width').removeAttr('disabled');
$('#module-plug').removeAttr('disabled');
$('#module-ports').removeAttr('disabled');
$('#module-name').val('');
$('#module-width').val('12');
$('#module-ports').val('48');
$('#module-ports').trigger("change");
$('#module-position').empty();
$('#module-position-div').hide();
$('#module-device-text').hide();
$('#module-device-id').show();
}
}
});
$("body").on("change", "#module-type", function () {
if (parseInt($(this).val()) === 1) {
$('#module-name-div').hide();
$('#module-name').attr('disabled', 'disabled');
$('#module-device-div').show();
$('#module-device-id').removeAttr('disabled');
$('#module-ports-div').hide();
$('#module-plug-div').hide();
} else if (parseInt($(this).val()) === 0) {
$('#module-name-div').show();
$('#module-name').removeAttr('disabled');
$('#module-device-div').hide();
$('#module-device-id').attr('disabled', 'disabled');
$('#module-ports-div').show();
$('#module-plug-div').show();
} else {
$('#module-name-div').show();
$('#module-name').removeAttr('disabled');
$('#module-device-div').hide();
$('#module-device-id').attr('disabled', 'disabled');
$('#module-ports-div').hide();
$('#module-plug-div').hide();
}
});
$("body").on("change", "#module-he-start", function () {
var rackhe = trigger.closest('table').find('th').data('rackhe');
var hemaxcount = 1;
var hemaxcountactive = 1
var options;
var selected;
for (let i = 1; i <= rackhe; i++) {
if (hemaxcountactive == 1 && i > $(this).val() && !trigger.closest('tbody').find('tr').eq(i - 1).find('td').eq(1).hasClass('he-free')) {
hemaxcountactive = 0;
}
if (hemaxcountactive == 1 && i > $(this).val() && trigger.closest('tbody').find('tr').eq(i - 1).find('td').eq(1).hasClass('he-free')) {
hemaxcount++;
}
}
for (let i = 1; i <= hemaxcount; i++) {
options = options + '<option ' + selected + ' value="' + i + '">' + i + '</option>';
}
$('#he-count-div').html(`<select required="required" id="module-he-count" name="module-he-count" class="form-control">` + options + `</select>`);
});
$("body").on("click", "#module-add", function () {
var error;
var rackid = trigger.closest('table').find('th').data('rackid');
var endhe = parseInt($.trim($('#module-he-start').val())) + parseInt($.trim($('#module-he-count').val())) - 1;
if (!$.trim($('#module-name').val()) && $.trim($('#module-type').val()) != "1") {
error = "Modul Name darf nicht leer sein";
}
if ($.trim($('#module-type').val()) == "1" && !$.trim($('#module-device-id').val())) {
error = "Kein Device ausgewählt";
}
if (!error) {
$.post("<?= self::getUrl("Poprackmodule", "api", ['do' => 'addModule']) ?>&poprack_id=" + rackid, {
type: $.trim($('#module-type').val()),
device_id: $.trim($('#module-device-id').val()),
name: $.trim($('#module-name').val()),
start_he: $.trim($('#module-he-start').val()),
end_he: endhe,
ports: $.trim($('#module-ports').val()),
plug: $.trim($('#module-plug').val()),
width: $.trim($('#module-width').val()),
position: $.trim($('#module-position').val())
}, function (data) {
if (data.success === true) {
$('#rackModuleModal').modal('toggle');
$.get("<?= self::getUrl("Poprack", "api", ['do' => 'generateRack']) ?>&id=" + rackid, function (data, status) {
trigger.closest('tbody').html(data);
});
}
}, "json");
} else {
$(this).closest('.modal').find('.alert').text(error);
$(this).closest('.modal').find('.alert').show();
}
});
$("body").on("click", "#module-remove", function () {
var moduleid = $(this).data('moduleid');
var rackid = trigger.closest('table').find('th').data('rackid');
if (confirm("Modul entfernen?")) {
$.post("<?= self::getUrl("Poprackmodule", "api", ['do' => 'removeModule']) ?>", {
id: moduleid
}, function (data) {
if (data.success === true) {
$('#rackModuleModal').modal('toggle');
$.get("<?= self::getUrl("Poprack", "api", ['do' => 'generateRack']) ?>&id=" + rackid, function (data, status) {
trigger.closest('tbody').html(data);
});
}
}, "json");
}
});
$("body").on("click", "#module-update", function () {
var moduleid = $(this).data('moduleid');
var rackid = trigger.closest('table').find('th').data('rackid');
var error;
if (!$.trim($('#module-name').val())) {
error = "Modul Name darf nicht leer sein";
}
if (!error) {
$.post("<?= self::getUrl("Poprackmodule", "api", ['do' => 'updateModule']) ?>", {
id: moduleid,
name: $.trim($('#module-name').val()),
ports: $.trim($('#module-ports').val()),
plug: $.trim($('#module-plug').val())
}, function (data) {
if (data.success === true) {
$('#rackModuleModal').modal('toggle');
$.get("<?= self::getUrl("Poprack", "api", ['do' => 'generateRack']) ?>&id=" + rackid, function (data, status) {
trigger.closest('tbody').html(data);
});
}
}, "json");
} else {
$(this).closest('.modal').find('.alert').text(error);
$(this).closest('.modal').find('.alert').show();
}
});
$("body").on("click", "#rack-update", function () {
var rackid = $(this).data('rackid');
var rackmin = $(this).data('rackminhe');
var error;
if ($('#rack-he').val() < rackmin) {
error = "Minimale Höheneinheiten: " + rackmin;
}
if ($('#rack-he').val() > 60) {
error = "Maximale Höheneinheiten: 60";
}
if (!$.isNumeric($('#rack-he').val())) {
error = "Bitte Zahl bei Höheneinheiten eingeben";
}
if (!$.trim($('#rack-he').val())) {
error = "Höheneinheiten darf nicht leer sein";
}
if (!$.trim($('#rack-name').val())) {
error = "Schrank Name darf nicht leer sein";
}
if (!error) {
$.post("<?= self::getUrl("Poprack", "api", ['do' => 'editRack']) ?>&poprack_id=" + rackid, {
name: $.trim($('#rack-name').val()),
he: $.trim($('#rack-he').val())
}, function (data) {
if (data.success === true) {
$('#rackModal').modal('toggle');
location.reload();
}
}, "json");
} else {
$(this).closest('.modal').find('.alert').text(error);
$(this).closest('.modal').find('.alert').show();
}
});
$("body").on("click", "#rack-add", function () {
var popid = $(this).data('popid');
var error;
if ($('#rack-he').val() < 1) {
error = "Minimale Höheneinheiten: " + 1;
}
if ($('#rack-he').val() > 60) {
error = error = "Maximale Höheneinheiten: 60";
}
if (!$.isNumeric($('#rack-he').val())) {
error = "Bitte Zahl bei Höheneinheiten eingeben";
}
if (!$.trim($('#rack-he').val())) {
error = "Höheneinheiten darf nicht leer sein";
}
if (!$.trim($('#rack-name').val())) {
error = "Schrank Name darf nicht leer sein";
}
if (!error) {
$.post("<?= self::getUrl("Poprack", "api", ['do' => 'addRack']) ?>&pop_id=" + popid, {
name: $.trim($('#rack-name').val()),
he: $.trim($('#rack-he').val())
}, function (data) {
if (data.success === true) {
$('#rackModal').modal('toggle');
location.reload();
}
}, "json");
} else {
$(this).closest('.modal').find('.alert').text(error);
$(this).closest('.modal').find('.alert').show();
}
});
$("body").on("click", "#rack-remove", function () {
var rackid = $(this).data('rackid');
$.post("<?= self::getUrl("Poprack", "api", ['do' => 'removeRack']) ?>", {
id: rackid
}, function (data) {
if (data.success === true) {
$('#rackModal').modal('toggle');
location.reload();
}
}, "json");
});
$("body").on("change", "#module-width", function () {
if ($(this).val() == "12") {
$('#module-position-div').hide();
} else if ($(this).val() == "6") {
$('#module-position').html(`<option value="1">1</option>
<option value="2">2</option>
`);
$('#module-position-div').show();
} else if ($(this).val() == "4") {
$('#module-position').html(`<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
`);
$('#module-position-div').show();
} else if ($(this).val() == "3") {
$('#module-position').html(`<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
`);
$('#module-position-div').show();
}
});
$("body").on("change", "#module-ports", function () {
var plugs = [];
if ($(this).find(':selected').data('plugs') !== undefined) {
plugs = $(this).find(':selected').data('plugs').split(';');
$("#module-plug option").each(function () {
if (plugs.includes($(this).val())) {
$(this).show();
} else {
if ($(this).val() == $('#module-plug').val()) {
$('#module-plug').val(plugs[0]);
}
$(this).hide();
}
});
}
});
$("body").on("change", "#module-slot", function () {
$('#module-position').val($(this).val());
var parent = trigger.closest('tr');
if (trigger.closest('tr').find('td').eq(1).html() === undefined) {
parent = trigger.closest('tr').prev();
for (let i = 1; i <= rackhe; i++) {
if (parent.find('td').eq(1).html() !== undefined) {
break;
} else {
parent = parent.prev();
}
}
}
var newmodule = false;
var tdnumber = parseInt($(this).val())
if (parent.find('td').eq(tdnumber).data('id') === undefined) {
newmodule = true;
}
if (!newmodule) {
$('#module-remove').show();
$('#module-update').show();
$('#module-add').hide();
$('#module-type').val(parent.find('td').eq(tdnumber).data('type')).change();
if ($('#module-type').val() == "1") {
$('#module-device-id').hide();
$('#module-device-text').text(parent.find('td').eq(tdnumber).data('name'));
$('#module-device-text').show();
}
if (parent.find('td').eq(tdnumber).data('ports') != "") {
$('#module-ports').val(parent.find('td').eq(tdnumber).data('ports')).change();
$('#module-plug').val(parent.find('td').eq(tdnumber).data('plug'));
}
$('#module-type').attr('disabled', 'disabled');
$('#module-name').val(parent.find('td').eq(tdnumber).data('name'));
// $('#module-name').attr('disabled', 'disabled');
$('#module-remove').data('moduleid', parent.find('td').eq(tdnumber).data('id'));
$('#module-update').data('moduleid', parent.find('td').eq(tdnumber).data('id'));
} else {
$('#module-remove').hide();
$('#module-update').hide();
$('#module-add').show();
$('#module-name-div').show();
$('#module-name').removeAttr('disabled');
$('#module-device-div').hide();
$('#module-device-id').show();
$('#module-device-id').attr('disabled', 'disabled');
$('#module-type').val('0').change();
$('#module-type').removeAttr('disabled');
$('#module-plug').removeAttr('disabled');
$('#module-ports').removeAttr('disabled');
$('#module-name').val('');
$('#module-ports').val('48');
$('#module-ports').trigger("change");
$('#module-position-div').hide();
$('#module-update').hide();
$('#module-device-text').hide();
}
});
});
</script>
<script type="text/javascript" src="<?= self::getResourcePath() ?>assets/js/datatables-std.js"></script>
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>