const poprackmodulesoption = {}; function checkendpoints() { let endpointcounter = $('.fiberplanpipe-label').length; let endpointtext; $('.fiberplanpipe-label').each(function (index) { $(this).find('.move-endpoint-up').remove(); $(this).find('.move-endpoint-down').remove(); $(this).find('.remove-endpoint').remove(); $(this).closest('.fiberplancablepipe-div').find('.fiberPlanPipe_id').data('index', index); if (index == 0 && endpointcounter - 1 == 0) { // endpointtext = "Startpunkt"; } else if (index == 0) { $(this).closest('.fiberplanpipe-label').find('.label-text').after(''); } else if (endpointcounter == 2) { endpointtext = 'Standort ' + index; $(this).closest('.fiberplanpipe-label').find('.label-text').after(''); $(this).find('.endpointsymbol').html(''); } else if (endpointcounter - 1 == index) { endpointtext = 'Standort ' + index; $(this).closest('.fiberplanpipe-label').find('.label-text').after(''); $(this).find('.endpointsymbol').html(''); } else if (index > 0) { endpointtext = 'Standort ' + index; $(this).closest('.fiberplanpipe-label').find('.label-text').after(''); $(this).find('.endpointsymbol').html(''); } // $(this).find('.label-text').text(endpointtext + ' *'); }); } function checkracks() { $.each($('.fiberplanpipe-pop-racks'), function (index, value) { var option = ""; var thisis = $(this); $.getJSON(poprackmoduleallUrl + "&pop_id=" + $(this).data('popid'), {}) .done(function (data) { if (data.success) { var plug; $.each(data.data, function (k, val) { option = option + ''; $.each(val, function (key, value) { if (value.plug == "1") { plug = " (LC/APC)"; } else if (value.plug == "2") { plug = " (SC/APC)"; } else if (value.plug == "3") { plug = " (E2000/APC)"; } option = option + ''; }) option = option + ""; }); } thisis.closest('.fiberplancableendpoint-div').find('.poprackmodule_id').html(option); $.each(thisis.closest('.fiberplancableendpoint-div').find('.poprackmodule_id'), function (index, value) { if ($(this).data('poprackmodule_id') != "undefined") { $(this).val($(this).data('poprackmodule_id')); $(this).trigger("change", "1"); } }); } ) .done(function (data) { }); }); } function checksleeves() { $.each($('.fiberplanpipe-dispatcher-sleeves'), function (index, value) { var option = ""; var thisis = $(this); $.getJSON(dispatchersleeveUrl + "&dispatcher_id=" + $(this).data('id'), {}) .done(function (data) { if (data.success) { $.each(data.data, function (k, val) { option = option + ''; }); thisis.closest('.fiberplancableendpoint-div').find('.sleeveid').html(option); $.each(thisis.closest('.fiberplancableendpoint-div').find('.fiberplandispatcher_id'), function (index, value) { if ($(this).data('id') != "undefined") { $(this).val($(this).data('id')); $(this).trigger("change", "1"); } }); } }); }); } function checkusedfibers(trigger) { var destination = trigger.closest('.fiberplanpipe-body-div').find('.module-row'); var fibercounter = 0; var sumstart; var sumend; destination.each(function (index) { sumstart = fibercounter + 1; if (parseInt($(this).find('.ports-end').val()) && parseInt($(this).find('.ports-start').val())) { fibercounter = fibercounter + parseInt($(this).find('.ports-end').val()) - parseInt($(this).find('.ports-start').val()) + 1; sumend = fibercounter; $(this).find('.fibersum').text('(' + sumstart + '-' + sumend + ')'); } }); trigger.closest('.destinationpoint').find('.fiber-used').text(fibercounter); } function checkusedpipes() { var counter = 0; $.each($('.fiberplanpipesub'), function (index, value) { $('.fiberplanpipe-subpipe').eq(counter).html($(this).next('span').find('.select2-selection__rendered').html()); counter++; }); } function formatState(state) { if (!state.id || !state.title) { return state.text; } const titleArray = state.title.split(";"); var title = titleArray[0]; var titlestripe = titleArray[1]; var border = 'border:none;' if (title == "#ffffff" || title == "#ffff01" || title == "#01ffff") { border = 'border:1px solid #9d9d9d;'; } var height = '10px'; var striped = ''; if (titlestripe == 1) { striped = 'style="background-color: #000;height: 100%;width: 45%;text-align: center;margin-left: auto;margin-right: auto;"'; } if (state.text.indexOf("14x10") != -1) { height = "12px"; } var returnstate = $( '
' + state.text + '
' ); return returnstate; }; function generateDestinationmid(destinations, destinationtype, destinationdiv, param = 0, append = 0) { var destination_typename = "Schächte/Verteiler"; var randid; $('#' + destinationdiv).append(`

` + destinationtype + ` (` + destination_typename + `)

`); $.each(destinations, function (index, destination) { var destination_typename = destination.typename; var destination_type = destination.type; if (destination.typename === undefined) { destination_type = "4"; } if (append === 0) { var addsleevebutton = ""; if (destination_type == "4") { addsleevebutton = ''; } } if (destination_type == "4") { randid = Math.floor(Math.random() * 10000); $('#' + destinationdiv).append(`
` + destination.name + `
`); var sleeveoptions = ''; $.each(destination.sleeves, function (k, val) { sleeveoptions = sleeveoptions + ''; }); $('#' + randid + '_sleeves_div').append(`
von
bis
`); } }); }; function generateDestination(destination, destinationtype, destinationdiv, param = 0, append = 0) { var destination_typename = destination.typename; var destination_type = destination.type; if (destination.typename === undefined) { destination_typename = "Schächte"; destination_type = "4"; } if (append === 0) { var addsleevebutton = ""; if (destination_type == "4") { addsleevebutton = ''; } $('#' + destinationdiv).append(`

` + destinationtype + ` (` + destination_typename + `)

` + destination.name + `
`); } if (destination_type == "4") { $.getJSON(dispatchersleeveUrl + "&dispatcher_id=" + destination.id, {}) .done(function (data) { if (data.success) { var sleeveoptions = ''; $.each(data.data, function (k, val) { sleeveoptions = sleeveoptions + ''; }); $('#' + destinationdiv).append(`
von
bis
`); } }) } if (destination_type == "2") { destinationname = destination.name; var popid = destination.id; $.getJSON(poprackUrl + "&pop_id=" + destination.id, {}) .done(function (data) { if (data.success) { var fibers = $('#fibers').find(':selected').data('fibers'); if (fibers === undefined) { fibers = 0; } var rackoptions = ''; $.each(data.data, function (k, val) { rackoptions = rackoptions + ''; }); if (append === 0) { $('#' + destinationdiv).append(`
0 von ` + fibers + ` Fasern aufgelegt
`); if (param == 0) { $('#' + destinationdiv).append(`
`); } else if (param == 1) { if (destinationdiv == 'destinationendpoint') { var dest = destinationendpoint; } if (destinationdiv == 'destinationstartpoint') { var dest = destinationstartpoint; } $('#' + destinationdiv).append(dest); checkusedfibers($('#' + destinationdiv)); } } else if (append === 1) { $('#' + destinationdiv).append(`
`); } } else { $('#' + destinationdiv).append(`
Keine Schränke vorhanden.
`); } } ) .done(function (data) { $('#' + destinationdiv).append(`
`); }); } } function addModule(thistrigger, poprackid, append = 0, param = 0, selected = null, startport = null, endport = null, popid = null) { if (popid) { $.getJSON(poprackUrl + "&pop_id=" + popid, {}) .done(function (data) { if (data.success) { var rackoptions = ''; $.each(data.data, function (k, val) { rackoptions = rackoptions + ''; }); $('#destinationstartpoint').append(`
`); $('#destinationstartpoint').append(`
`); thistrigger = thistrigger.nextAll().eq(1); } }); } $.getJSON(poprackmoduleUrl + "&poprack_id=" + poprackid, {}) .done(function (data) { if (data.success) { var options = ""; var rackoptions = ''; var systemoption; var plug; var portsstart = 1; var portsend; var counter = 1; $.each(data.data, function (k, val) { if (counter == 1) { portsend = val.ports; } if (val.plug == "1") { systemoption = " (LC/APC " + val.ports + "p)"; } else if (val.plug == "2") { systemoption = " (SC/APC " + val.ports + "p)"; } else if (val.plug == "3") { systemoption = " (E2000/APC " + val.ports + "p)"; } else { systemoption = ""; } if (selected && selected == val.id) { options = options + ''; } else { options = options + ''; } counter++; }); if (startport) { portsstart = startport; } if (endport) { portsend = endport; } var destinationpoint = thistrigger.closest('.destinationpoint').attr('id'); var html; if (append === 0) { html = `
`; } else if (append === 1) { html = `
`; } html = html + `
von
bis
`; if (append === 0) { thistrigger.closest('.form-group').next().html(html); } else if (append === 1) { thistrigger.append(html); } } else { thistrigger.closest('.form-group').next().html(`
Keine Einschübe in diesem Schrank vorhanden
`); } checkusedfibers(thistrigger); }) } $(document).ready(function () { $(".select2").select2({placeholder: ""}); $(".select2select").select2({placeholder: ""}); $("#fiberplanpipesub").select2({ placeholder: "", templateResult: formatState, templateSelection: formatState }); // disable mousewheel on a input number field when in focus $('form').on('focus', 'input[type=number]', function (e) { $(this).on('wheel.disableScroll', function (e) { e.preventDefault() }) }); $('form').on('blur', 'input[type=number]', function (e) { $(this).off('wheel.disableScroll') }); $("body").on("change", ".pipe-network", function (event, param = 0) { var thisis = $(this); var options = ''; $.getJSON(fiberPlanPipeUrl + "&network_id=" + $.trim($(this).val()), {}) .done(function (data) { if (data.success) { $.each(data.data, function (k, val) { options = options + ''; }); $(thisis).closest(".form-group").find('.pipe-div').html(''); if (param == 1 && pipes.length == $('.fiberPlanPipe_id').length) { var counter = 0; pipes.forEach(function (value, index) { $('.fiberPlanPipe_id').eq(counter).val(value); $('.fiberplanpipe_id').eq(counter).val(pipesid[counter]); $('.fiberPlanPipe_id').eq(counter).trigger("change", "1"); counter++; }); } else if (param == 0) { checkendpoints(); } $(".select2select").select2({placeholder: ""}); } checkendpoints(); }); }); $("body").on("change", "#network_id", function (event, param = 0) { var options = ''; $('#destination-div').empty(); $('#destination-div').append('
'); $.getJSON(fiberPlanPipeUrl + "&network_id=" + $.trim($(this).val()), {}) .done(function (data) { if (data.success) { $.each(data.data, function (k, val) { options = options + ''; }); $('#subpipe-div').empty(); $('#pipe-div').empty(); $('#pipe-div').append(''); if (param == 1) { // $("#fiberPlanPipe_id option[value=fiberPlanPipe_id; ?>]").attr('selected', 'selected'); if ($('#fiberPlanPipe_id').val()) { $("#fiberPlanPipe_id").trigger("change", "1") } } $(".select2").select2({placeholder: ""}); $("#fiberplanpipesub").select2({ placeholder: "", templateResult: formatState, templateSelection: formatState }); } else { $('#subpipe-div').empty(); $('#pipe-div').html('

Keine Rohre in diesem Netzgebiet vorhanden.

'); } }); }); $("body").on("change", ".fiberPlanPipe_id", function (event, param = 0) { // console.log(param); var options = ''; var thisis = $(this); var index = thisis.data('index'); $('#destination-div').empty(); $('#destination-div').append('
'); $.getJSON(fiberPlanPipeSubUrl + "&fiberplanpipe_id=" + $.trim($(thisis).val()), {}) .done(function (data) { if (data.success) { $.each(data.data, function (k, val) { var idcounter = 0; var color; // generateDestination(val.startpointname, "Startpunkt", "destinationstartpoint", param); // generateDestinationmid(val.midpointname, "Zwischenpunkte", "destinationmidpoint", param); //generateDestination(val.endpointname, "Endpunkt", "destinationendpoint", param); if (val.fiberPlanPipeTemplate_id != null) { var obj = jQuery.parseJSON(val.colors); if (val.pipe7x4 != "0" && val.pipe7x4 != null) { var counter = val.pipe7x4; } $.each(obj, function (key, col) { if (counter == 0) { return true; } color = col.color + ';0'; idcounter++; options = options + ''; counter--; }); if (counter != 0) { $.each(obj, function (key, col) { if (counter == 0) { return true; } color = col.color + ';1'; idcounter++; options = options + ''; counter--; }); } if (val.pipe14x10 != "0" && val.pipe14x10 != null) { var counter = val.pipe14x10; } $.each(obj, function (key, col) { if (counter == 0) { return true; } color = col.color + ';0'; idcounter++; options = options + ''; counter--; }); if (counter != 0) { $.each(obj, function (key, col) { if (counter == 0) { return true; } color = col.color + ';1'; idcounter++; options = options + ''; counter--; }); } } else { options = options + ''; } } ) ; $(thisis).closest(".form-group").next().find('.subpipe-div').html(''); $(".fiberplanpipesub").select2({ placeholder: "", templateResult: formatState, templateSelection: formatState }); if (param == 1 && subpipes.length == $('.fiberplanpipesub').length) { var counter = 0; subpipes.forEach(function (value, index) { $('.fiberplanpipesub').eq(counter).val(value); $('.fiberplanpipesub').eq(counter).trigger("change", "1"); counter++; }); checkusedpipes(); checkracks(); // $("#fiberplanpipesub option[value=fiberPlanPipe_sub; ?>]").attr('selected', 'selected'); } else if (param == 0) { $('.fiberplanpipe-main-div').eq(index).html('test'); } } } ) ; }); $('#rackModal').on('show.bs.modal', function (event) { var button = $(event.relatedTarget); var recipient = button.data('mdtype'); var destinationname = button.data('name'); var modal = $(this); if (recipient == "rack") { modal.find('.modal-title').text('Neuer Schrank (' + destinationname + ')'); } }) if ($('#network_id').val()) { $("#network_id").trigger("change", "1") } $("body").on("change", ".poprack_id", function (event, param = 0) { var thistrigger = $(this); var poprackid = $(this).val(); // console.log(param); if (param == 0) { addModule(thistrigger, poprackid); } }); $("body").on("click", ".add-module", function () { var thistrigger = $(this); thistrigger.closest('h5').next('div').append(`
von
bis
`); checkracks(); $(".select2select").select2({placeholder: ""}); if (thistrigger.closest('h5').next('div').length < 6) { } }); $("body").on("click", ".add-rack", function () { var thistrigger = $(this); var poprackid = $(this).data('poprackid'); // console.log(thistrigger); var destinationpoint = $(this).closest('.destinationpoint').attr('id'); $.getJSON(fiberPlanPipeSubUrl + "&fiberplanpipe_id=" + $.trim($("#fiberPlanPipe_id").val()), {}) .done(function (data) { if (data.success) { $.each(data.data, function (k, val) { var idcounter = 0; var color; if (destinationpoint == "destinationstartpoint") { generateDestination(val.startpointname, "Startpunkt", "destinationstartpoint", 0, 1); } else if (destinationpoint == "destinationendpoint") { generateDestination(val.endpointname, "Endpunkt", "destinationendpoint", 0, 1); } }) } }); }); $("body").on("click", ".add-sleeve", function () { var thistrigger = $(this); thistrigger.closest('h5').next('div').append(`
von
bis
`); checksleeves(); // checkusedfibers(); $(".select2select").select2({placeholder: ""}); if (thistrigger.closest('h5').next('div').length < 6) { } }); $("body").on("click", ".remove-module", function () { var trigger = $(this).closest('.destinationmodules'); $(this).closest('div').remove(); checkusedfibers(trigger); }); $("body").on("click", ".remove-rack", function () { var trigger = $(this); $(this).closest('.form-group').next().remove(); checkusedfibers(trigger); $(this).closest('.form-group').remove(); }); $("body").on("change", "#responsible", function () { if ($(this).val() == 1) { $('#responsible-div').show(); $('#responsible-row').show(); $("#address_id").prop("disabled", false); $(".select2select").select2({placeholder: ""}); } else { $('#responsible-div').hide(); $('#responsible-row').hide(); $("#address_id").prop("disabled", true); $(".select2select").select2({placeholder: ""}); } }); $("body").on("change", ".poprackmodule_id", function (event, param = 0) { // console.log('param'+param); var portsend = $(this).closest('.module-row').find('.ports-end').val(); // console.log(portsend); //Immer Ändern if (param == 0) { if ($(this).find(':selected').data('ports') != $(this).closest('.module-row').find('.ports-end').val()) { $(this).closest('.module-row').find('.ports-end').val($(this).find(':selected').data('ports')); $(this).closest('.module-row').find('.ports-start').val('1'); } } checkusedfibers($(this).closest('.module-row')); }); $("body").on("change blur", ".ports-end", function () { var maxports = $(this).closest('.module-row').find('.poprackmodule_id').find(':selected').data('ports'); var endports = $(this).val(); var startports = $(this).closest('.module-row').find('.ports-start').val(); if (!parseInt(endports) || endports > maxports) { $(this).val(maxports); } else if (parseInt(endports) < parseInt(startports)) { $(this).val(startports); } checkusedfibers($(this).closest('.module-row')); }); $("body").on("change", "#fibers", function () { $('.fiber-counter').text($('#fibers').find(':selected').data('fibers')); }) $("body").on("change blur", ".ports-start", function () { var startports = $(this).val(); var endports = $(this).closest('.module-row').find('.ports-end').val(); if (!parseInt(startports) || startports < 1) { $(this).val('1'); } else if (parseInt(startports) > parseInt(endports)) { $(this).val(endports); } checkusedfibers($(this).closest('.module-row')); }); $("body").on("click", ".destination-dropdown", function () { if ($(this).find('i').hasClass('fa-square-caret-down')) { $(this).find('i').removeClass('fa-square-caret-down'); $(this).find('i').addClass('fa-square-caret-up'); $(this).closest('.destinationpoint').find('.form-group').show(); } else { $(this).find('i').addClass('fa-square-caret-down'); $(this).find('i').removeClass('fa-square-caret-up'); $(this).closest('.destinationpoint').find('.form-group').hide(); } }); $.each($('.pipe-network'), function (index, value) { var thisis = $(this); $(this).trigger('change', '1') }) $('body').on('click', '.add-pipe', function () { var newindex = $('.fiberplancablepipe-div').length; console.log(newindex); $('#fiberplancablepipes-div').append(`
`); $('#fiberplancableendpoints').append(`
`); var fiberplancablepipelength = $('.fiberplancablepipe-div').length; $('.fiberplancablepipe-div').eq(fiberplancablepipelength - 1).find('.pipe-network').html($('.fiberplancablepipe-div').eq(fiberplancablepipelength - 2).find('.pipe-network').html()); $('.fiberplancablepipe-div').eq(fiberplancablepipelength - 1).find('.pipe-network').trigger('change'); $('.select2select').select2({placeholder: ""}); checkendpoints(); }); $("body").on("click", ".remove-endpoint", function () { let endpointcounter; $(this).closest('.fiberplancablepipe-div').remove(); $('.fiberplanpipe-main-div').eq($(this).data('index')).remove(); checkendpoints(); }); $("body").on("click", ".move-endpoint-up", function () { $(this).closest('.fiberplancablepipe-div').insertBefore($(this).closest('.fiberplancablepipe-div').prev()); $('.fiberplanpipe-main-div').eq($(this).data('index')).insertBefore($('.fiberplanpipe-main-div').eq($(this).data('index')).prev()); checkendpoints(); }); $("body").on("click", ".move-endpoint-down", function () { $(this).closest('.fiberplancablepipe-div').insertAfter($(this).closest('.fiberplancablepipe-div').next()); $('.fiberplanpipe-main-div').eq($(this).data('index')).insertAfter($('.fiberplanpipe-main-div').eq($(this).data('index')).next()); checkendpoints(); }); $("body").on("click", ".change-fiberplanpipe-body", function () { if ($(this).hasClass('fa-square-chevron-down')) { $(this).removeClass('fa-square-chevron-down'); $(this).addClass('fa-square-chevron-up'); $(this).closest('.fiberplanpipe-main-div').find('.fiberplanpipe-body-div').hide(); } else if ($(this).hasClass('fa-square-chevron-up')) { $(this).removeClass('fa-square-chevron-up'); $(this).addClass('fa-square-chevron-down'); $(this).closest('.fiberplanpipe-main-div').find('.fiberplanpipe-body-div').show(); } }); $("body").on("click", ".up-module", function () { $(this).closest('.module-row').insertBefore($(this).closest('.module-row').prev()); checkusedfibers($(this).closest('.module-row')); }); $("body").on("change", ".fiberplanpipesub", function () { checkusedpipes(); }); $("body").on("click", ".change-fiberplanpipe-main", function () { if ($(this).hasClass('fa-square-chevron-down')) { $(this).removeClass('fa-square-chevron-down'); $(this).addClass('fa-square-chevron-up'); $.each($('.change-fiberplanpipe-body'), function (index, value) { $(this).removeClass('fa-square-chevron-down'); $(this).addClass('fa-square-chevron-up'); }); $('.fiberplanpipe-body-div').hide(); } else if ($(this).hasClass('fa-square-chevron-up')) { $.each($('.change-fiberplanpipe-body'), function (index, value) { $(this).removeClass('fa-square-chevron-up'); $(this).addClass('fa-square-chevron-down'); }); $(this).removeClass('fa-square-chevron-up'); $(this).addClass('fa-square-chevron-down'); $('.fiberplanpipe-body-div').show(); } }); checksleeves(); });