// Auto update layout
if (window.layoutHelpers) {
window.layoutHelpers.setAutoUpdate(true);
}
$(function() {
// Initialize sidenav
$('#layout-sidenav').each(function() {
new SideNav(this, {
orientation: $(this).hasClass('sidenav-horizontal') ? 'horizontal' : 'vertical'
});
});
// Initialize sidenav togglers
$('body').on('click', '.layout-sidenav-toggle', function(e) {
e.preventDefault();
window.layoutHelpers.toggleCollapsed();
});
// Swap dropdown menus in RTL mode
if ($('html').attr('dir') === 'rtl') {
$('#layout-navbar .dropdown-menu').toggleClass('dropdown-menu-right');
}
$('[data-toggle="tooltip"]').tooltip();
$('[data-toggle="popover"]').popover();
});
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// custom js code
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$('body').on('click', "button.trRemoveStock", function(){
$(this).parent().parent().remove();
recalculateStocksRows();
});
$('body').on('click', "button.trRemoveStock2d", function(){
$(this).parent().parent().remove();
recalculateStocksRows2d();
});
$('body').on('click', "button.trRemove", function(){
$(this).parent().parent().remove();
recalculatePartsRows();
});
$('body').on('click', "button.trRemove2d", function(){
$(this).parent().parent().remove();
recalculatePartsRows2d();
});
$('body').on('click', "button.trRemoveLinearGroup", function(){
$(this).parent().parent().remove();
recalculateLinearGroupRows();
});
$('body').on('click', "button.trRemovePanelGroup", function(){
$(this).parent().parent().remove();
recalculatePanelGroupRows();
});
$("#submitDeleteForm").on('click', function(){
var action = $('#deleteForm').attr('action');
$('#deleteForm').attr('action', action + "/" + $('#ids').attr('value'));
$('#deleteForm').submit();
});
$(".doc-sidenav-link").on('click', function(){
$(".doc-link-wrapper").find(".sidenav-item").removeClass('active');
$(this).parent().addClass('active');
});
function addStocksRow(count, text, metric) {
var groupVisibleFlag = "";
if (!isGroupsVisible()) {
groupVisibleFlag = "d-none";
}
for (var i=0; i < count; i++) {
var lengthInput = "";
if (metric) {
lengthInput = "";
}
var stockGroupCell = "
| ";
$(" | " + lengthInput + " | | " + stockGroupCell + " |
" ).insertBefore("#stocksTable tr:last");
var groupSelect = $("#stocksTable tr:last").prev().find("td:first").next().next().next().children('select');
populateGroupDropdown(groupSelect, '');
}
recalculateStocksRows();
}
function addRequirementsRow(count, text, metric) {
var labelVisibleFlag = "";
if (!isLabelsVisible()) {
labelVisibleFlag = "d-none";
}
var groupVisibleFlag = "";
if (!isGroupsVisible()) {
groupVisibleFlag = "d-none";
}
for (var i=0; i < count; i++) {
var lengthInput = "";
if (metric) {
lengthInput = "";
}
var stockGroupCell = " | ";
$(" | " + lengthInput + " | | | " + stockGroupCell + " |
" ).insertBefore("#planReqTable tr:last");
var groupSelect = $("#planReqTable tr:last").prev().find("td:first").next().next().next().next().children('select');
populateGroupDropdown(groupSelect, '');
}
recalculatePartsRows();
}
function addStocksRow2d(count, text, horizontalText, verticalText, metric) {
var grainVisibleFlag = "";
if (!isGrainVisible()) {
grainVisibleFlag = "d-none";
}
for (var i=0; i < count; i++) {
var inputs = "";
if (metric) {
inputs = " | ";
}
var timestamp = Date.now();
var grainElement = " | | ";
$(" | " + inputs + " | | " + grainElement + " |
" ).insertBefore("#stocksTable tr:last");
var $select = createGrainSelect(horizontalText, verticalText);
$select.appendTo('.grainElement' + timestamp).selectpicker('refresh');
}
recalculateStocksRows2d();
}
function addRequirementsRow2d(count, deleteText, horizontalText, verticalText, metric) {
var visibleFlag = "";
if (!isLabelsVisible()) {
visibleFlag = "d-none";
}
var grainVisibleFlag = "";
if (!isGrainVisible()) {
grainVisibleFlag = "d-none";
}
for (var i=0; i < count; i++) {
var inputs = "";
if (metric) {
inputs = " | ";
}
var timestamp = Date.now();
var grainElement = " | | ";
$(" | " + inputs + " | | | " + grainElement + " |
" ).insertBefore("#planReqTable tr:last");
var $select = createGrainSelect(horizontalText, verticalText);
$select.appendTo('.grainElement' + timestamp).selectpicker('refresh');
}
recalculatePartsRows2d();
}
function addLinearGroupRow(text, maxCount) {
if ($("#linearGroupTable tr.partsRow").length < maxCount) {
$(" | | |
" ).insertBefore("#linearGroupTable tr:last");
recalculateLinearGroupRows();
} else {
$('#modal-groups').modal();
}
}
function addPanelGroupRow(text, maxCount) {
if ($("#panelGroupTable tr.partsRow").length < maxCount) {
$(" | | |
" ).insertBefore("#panelGroupTable tr:last");
recalculatePanelGroupRows();
} else {
$('#modal-groups').modal();
}
}
function createGrainSelect(horizontalText, verticalText) {
var $select = $('', {
'class':"selectpicker grainDirectionSelect"
});
$select.attr('data-style', 'btn-default');
$select.attr('data-icon-base', 'fas');
$select.append('');
$select.append('');
$select.append('');
return $select;
}
function recalculatePartsRows() {
var index = 0;
var firstEmptyFound = false;
$("#planReqTable tr.partsRow").each(function() {
$this = $(this);
var lengthInput = $this.find("td:first").next().children('input');
lengthInput.attr('id', 'requirements[' + index + '].length');
lengthInput.attr('name', 'requirements[' + index + '].length');
if (!firstEmptyFound) {
if (!lengthInput.val()) {
lengthInput.focus();
firstEmptyFound = true;
}
}
var countInput = $this.find("td:first").next().next().children('input');
countInput.attr('id', 'requirements[' + index + '].count');
countInput.attr('name', 'requirements[' + index + '].count');
if (!firstEmptyFound) {
if (!countInput.val()) {
countInput.focus();
firstEmptyFound = true;
}
}
var labelInput = $this.find("td:first").next().next().next().children('input');
labelInput.attr('id', 'requirements[' + index + '].label');
labelInput.attr('name', 'requirements[' + index + '].label');
var labelParent = labelInput.parent();
if (labelParent.length > 0 && !labelParent.hasClass('d-none') && !firstEmptyFound) {
if (!labelInput.val()) {
labelInput.focus();
firstEmptyFound = true;
}
}
var groupSelect = $this.find("td:first").next().next().next().next().children('select');
groupSelect.attr('id', 'requirements[' + index + '].group');
groupSelect.attr('name', 'requirements[' + index + '].group');
$this.find("td:first").html(++index);
});
}
function recalculateStocksRows() {
var index = 0;
var firstEmptyFound = false;
$("#stocksTable tr.partsRow").each(function() {
$this = $(this);
var lengthInput = $this.find("td:first").next().children('input');
lengthInput.attr('id', 'stocks[' + index + '].length');
lengthInput.attr('name', 'stocks[' + index + '].length');
if (!firstEmptyFound) {
if (!lengthInput.val()) {
lengthInput.focus();
firstEmptyFound = true;
}
}
var countInput = $this.find("td:first").next().next().children('input');
countInput.attr('id', 'stocks[' + index + '].count');
countInput.attr('name', 'stocks[' + index + '].count');
if (!firstEmptyFound) {
if (!countInput.val()) {
countInput.focus();
firstEmptyFound = true;
}
}
var groupSelect = $this.find("td:first").next().next().next().children('select');
groupSelect.attr('id', 'stocks[' + index + '].group');
groupSelect.attr('name', 'stocks[' + index + '].group');
$this.find("td:first").html(++index);
});
}
function populateGroupDropdown(selectEl, value) {
for (var i = 0; i<=defaultGroups.length - 1; i++){
//console.log(defaultGroups[i]);
selectEl.append($('