var colorboxWidth = '50%'; var colorboxHeight = '50%'; var colorboxInnerW = '425px'; var colorboxInnerH = '344px'; /******************************************************************************* * GENERIC FORM SUBMIT * * Sets the given fcode to the given formular and submits the formular. * If no formular is given, the formular of the first input field with name * fcode found is used for submit. * * @fcode fcode * @formular formular name * @ignoreParsley flag - ignore parsley validation on submit (optional, boolean) //802 * @loaderStyle string - optional loader style (smart, center) - default 'smart' //806 * *******************************************************************************/ function genericSubmit(fcode, formular, ignoreParsley, loaderStyle) { var $form, $fcodeInputEl; var formFound = false; // Formular name explicitly given if (formular !== undefined) { $form = $('form[name="' + formular + '"]').first(); if ($form.length > 0) { $fcodeInputEl = $form.find('input[name="fcode"]').first(); formFound = true; } } // Only fcode value given else { //there could be multiple input fields with name fcode $('input[name="fcode"]').each(function () { $fcodeInputEl = $(this); // check if a form exists if ($fcodeInputEl.closest('form').length > 0) { $form = $fcodeInputEl.closest('form'); formFound = true; return false; // break each loop } }); } if (formFound) { // 802 Parsley - suppress loader if form is not valid if (typeof $form.parsley === 'function') { // show loader if parsley validation can be ignored or parsley validation is valid if (ignoreParsley || (typeof $form.attr('data-weco-validation') !== 'undefined' && $form.parsley().isValid()) || typeof $form.attr('data-weco-validation') === 'undefined') { $form.parsley().destroy(); showLoader('smart', loadtext, 0); } // no Parsley validation } else { // 806 optional loader style var style = typeof loaderStyle === 'string' ? loaderStyle : 'smart'; showLoader(style, loadtext, 0); } $fcodeInputEl.val(fcode); $form.submit(); } else { console.log('No form found for fcode "' + fcode + '"'); } } /******************************************************************************* * GENERIC FORM SUBMIT VIA INDEX * * @coid controller id * @fcode fcode * @index selected index * @formular formular name * @ignoreParsley flag - ignore parsley validation on submit (optional, boolean) //802 *******************************************************************************/ function genericSubmitIndex(coid, fcode, index, formular, ignoreParsley) { $('form[name="' + formular + '"]').find('input[name="' + coid + 'GV_INDEX"]').first().val(index); genericSubmit(coid+fcode, formular, ignoreParsley); } /******************************************************************************* * GENERIC AJAX CALL * * Automatically re-initializes plugins and hides the loader after ajax call * is complete. * * @url * @postData data to post (default empty) * @successCallback function to execute after complete * @requestType get/post (default post) * @updateSIDs true/false update SID's (default true) * *******************************************************************************/ function genericAjax(url, postData, successCallback, requestType, updateSIDs) { var type = 'post'; var data = ''; var sid = true; if(requestType !== undefined) { type = requestType; } if(postData !== undefined) { data = postData; } if(updateSIDs !== undefined) { sid = updateSIDs; } $.ajax({ url: url, type: type, data: data, success: function(data, textStatus, jqXHR) { if(sid) { // enable nested ajax calls from success cb updateSID(jqXHR.getResponseHeader('X-CSRF-TOKEN')); } if(typeof successCallback === 'function') { successCallback(data); } }, complete: function(jqXHR) { //always called after success/error if(sid) { updateSID(jqXHR.getResponseHeader('X-CSRF-TOKEN')); } // Re-init plugins $('.tabbed_area').respTabs(); $('.table').respTable(); initQtipText(); initExpandAccordion(); hideLoader(); // 802 initParsley(); } }); } /******************************************************************************* * POST PARTIALS TO URL * * Send each entry of the postDataArray in a separate ajax request to the server. * An entry of the postDataArray consists of an arbitrary set of post data. * * @fcode * @postDataArray each entry contains a set of post data * @totalParts total number of parts to be sent (length of postDataArray) * @currPart index of current part * *******************************************************************************/ function sendPartials(fcode, postDataArray, totalParts, currPart) { var postData = 'gv_ajaxid=dummy&'; if(currPart < totalParts) { postData += postDataArray[currPart]; } postData = postData + '&gv_sid=' + sid + '&fcode=' + fcode; var cp = (currPart == totalParts) ? currPart : currPart + 1; showLoader('center', loadtext + " " + cp + "/" + totalParts); $.ajax({ url: host + '?', type: 'POST', data: postData, success: function(data, textStatus, jqXHR) { updateSID(jqXHR.getResponseHeader('X-CSRF-TOKEN')); if(currPart < totalParts) { currPart++; sendPartials(fcode, postDataArray, totalParts, currPart); } else { location.reload(); } } }); } // Enter-Taste unterdruecken function supprentr(Ereignis) { if (!Ereignis) { Ereignis = window.event; } if (Ereignis.which) { Tastencode = Ereignis.which; } else if (Ereignis.keyCode) { Tastencode = Ereignis.keyCode; } if (Tastencode == 13) { return false; } } // Flexibles Oeffnen von Popups function openWin(url, name, breite, hoehe, scroll) { if(scroll !== undefined && scroll.toUpperCase() == 'NO') { scroll = 'no'; } else{ scroll = 'yes'; } if (breite === undefined || hoehe === undefined) { breite = screen.width; hoehe = screen.height; } var fenster; var specs = "menubar=no,locationbar=no,scrollbars=" + scroll + ",resizable=yes,alwaysRaised=yes,dependent=no,width=" + breite + ",height=" + hoehe; // not MS IE if(navigator.appName.indexOf('Microsoft') < 0) { fenster = window.open(url, name, specs); fenster.focus(); } // MS IE else { fenster = window.open(url, name, specs); if (fenster.opener == null || fenster.opener === undefined) { fenster.opener = window; } fenster.opener.name = "opener"; fenster.focus(); } } // Flexibles Schlie�en function closeWin() { if(window.opener != null && window.opener !== undefined) { window.close(); } else { parent.$.fn.colorbox.close(); } } // Logoff Hinweis Dataloss function logoff(conf, url, porsid) { var appexit = confirm(conf); var url = ""; if(host != "") { url = host + "/"; } if(appexit == true) { if (porsid != "") { document.location.href = url + 'applogoff.do?PORTAL_SESSION=' + porsid; } else { document.location.href = url + 'applogoff.do'; } } } //--------------------------------------------------------------------------- // Navigation zur angegebenen URL mit �bergabe der angegebenen Felder // Diese Felder verschmutzen nicht als Get-Parameter die URL, sondern // werden im Request als POST-Felder gesendet. //--------------------------------------------------------------------------- function gotoURL(iURL, iFields) { var x, lField; var lSubmitter = createForm(iURL, iFields); lSubmitter.submit(); } //--------------------------------------------------------------------------- // Erstellen eines Form Elements mit �bergebenen input Feldern und URL // als action. Form wird am Ende des Body hinzugef�gt. //--------------------------------------------------------------------------- function createForm(iURL, iFields) { var x, lField; var lSubmitter = document.createElement("form"); lSubmitter.setAttribute("action", iURL); lSubmitter.setAttribute("method","post"); lSubmitter.setAttribute("id","dynamicpost"); for (x in iFields) { lField = document.createElement("input"); lField.setAttribute("type","hidden"); lField.setAttribute("name",x); lField.setAttribute("value",iFields[x]); lSubmitter.appendChild(lField); } var sidInput = document.createElement("input"); sidInput.setAttribute("name", "gv_sid"); sidInput.setAttribute("value", sid); sidInput.setAttribute("type", "hidden"); lSubmitter.appendChild(sidInput); document.body.appendChild(lSubmitter); return lSubmitter; } /******************************************************************************* * SHOW REGION INPUT FIELD DEPENDING ON SELECTED COUNTRY * * @cntry selected country * @fieldControl field control modifier for region (O/H/L...) * @idregio id of regions select element. Default: 'regio' * @iddivregio id of div wrapping the regions select element. Default: 'divregio' * *******************************************************************************/ function shregio(cntry, fieldControl, idregio, iddivregio) { var $divregio, $divregio_label, selreg, key; if(iddivregio !== undefined) { $divregio = $('#' + iddivregio); $divregio_label = $('#' + iddivregio + 'l'); } else { $divregio = $('#divregio'); $divregio_label = $('#divregiol'); } $divregio.hide(); $divregio_label.hide(); if(idregio !== undefined) { selreg = "#" + idregio; } else { selreg = "#regio"; } if(fieldControl !== undefined && fieldControl != '') { key = cntry + '#' + fieldControl; } else { key = cntry; } // fuellen Listbox fuer Region des gewaehlten Landes via Ajax var data = "gv_cmd=REGIO&gv_key=" + key + '&gv_sid=' + sid; genericAjax('appajax.do', data, function(data) { var $holder = $('
').html(data); // 802 Parsley $(selreg).removeAttr('data-parsley-required'); var $options = $holder.find('#ajaxregio-options').html(); $(selreg).html($options); var $oblig = $holder.find('#ajaxregio-oblig').html(); $divregio_label.find('.inputRequirement').html($oblig); // Anzeige div-Bereich fuer Region, wenn Werte vorhanden sind var cont = $(selreg).html(); if(cont != null && cont.length > 2) { // 802 Parsley if($holder.find('#ajaxregio-is-oblig').length > 0) { $(selreg).attr('data-parsley-required', true); } $divregio.show(); $divregio_label.show(); } // 802 Parsley if(typeof $(selreg).parsley === 'function' && $(selreg).parsley()) { $(selreg).parsley().reset(); } }, 'post', false); } // Geschaeftsbedingungen / Datenspeicherung akzeptieren function afocus(){ window.location.href='#gvfocus'; } function acccond(){ document.getElementById("noaccept").style.display = "none"; document.getElementById("noacceptp").style.display = "none"; document.getElementById("errormessage").style.display = "none"; if (document.appaccept.accept.checked == true && document.appaccept.acceptp.checked == true) { document.appaccept.submit(); } else{ document.getElementById("errormessage").style.display = "block"; if (document.appaccept.accept.checked != true) { document.getElementById("noaccept").style.display = "block"; } if (document.appaccept.acceptp.checked != true) { document.getElementById("noacceptp").style.display = "block"; } } } // Datenschutzerklaerung akzeptieren function accpolicy(fcode,formular){ document.getElementById("noacceptp").style.display = "none"; if (document.forms[formular].acceptp.checked == true){ genericSubmit(fcode,formular); } else{ document.getElementById("noacceptp").style.display = "block"; } } // Ajax Loader var showTime = 0; //zeit, wann showLoader aufgerufen wurde function showLoader(style, loadtext, delay, customclass) { var loadtextsave = loadtext; var $ajaxloadertext = $('.ajaxloader .text'); var $ajaxloader = $('.ajaxloader'); var now = new Date(); showTime = now.getTime(); if(isSmallWindow()) { style = 'center'; } $('#ajaximage').addClass('ajaximage_' + style); if(typeof loadtext !== undefined) { $ajaxloadertext.html(loadtext); } if(typeof delay === undefined) { delay = 0; } if(typeof customclass != "undefined") { $ajaxloader.addClass(customclass); } if(style == 'center') { $('#transbg').addClass('transbg'); $('#ajaxcontent').addClass('ajaxcontent'); } else if(style == 'smart') { $ajaxloader.addClass('ajaxloader_smart'); $ajaxloadertext.addClass('text_smart'); } loadtext = loadtextsave; if(style == 'smart') { $ajaxloader.show(); $ajaxloader.animate({ top:'+=40' },100); } else{ $ajaxloader.delay(delay).show(0); } } function hideLoader(hdelay) { //nur bei ajax; timeout setzen dass loader mindestens ms erscheint var delay = 0; var now = new Date(); var hideTime = now.getTime(); if(typeof hdelay !== undefined) { delay = hdelay; } if((hideTime - showTime) <= 1000 ) { delay = 500; } setTimeout(function() { $('#ajaxloader').removeAttr('style').removeClass().addClass('ajaxloader'); $('#transbg').removeClass(); $('#ajaxcontent').removeClass(); $('#ajaximage').removeClass(); $('#ajaxloader .text').removeClass('text_smart').html(''); },delay); } //Oeffne Popup via Colorbox in Iframe function openModal(url, name, breite, hoehe, scroll){ if (host != "") { url = host + '/' + url; } if(isSmallWindow()) { openWin(url, name); } else { $.colorbox({ iframe:true, href:url, width:breite, height:hoehe, transition:"none", overlayClose:true, escKey:false, opacity:0.65, fastIframe:false, className: 'modal' }); } } // Zeichenkette ersetzen function replaceCharacter( stringToSearch, searchFor, replaceWith ) { res = new RegExp(searchFor,"ig"); t = stringToSearch.replace( res, replaceWith ); return t; } // Replace all occurences function replaceAll(find, replace, string) { return string.replace(new RegExp(escapeRegExp(find), 'g'), replace); } function escapeRegExp(string) { return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } // Multiselect function ready_multiselect(selectedText, noneSelectedText, checkAllText, uncheckAllText){ $(document).ready(function() { $('#mselcust').width($('#mselcust').parent().width()-5); $("#mselcust").multiselect({ selectedText: selectedText, noneSelectedText: noneSelectedText, checkAllText: checkAllText, uncheckAllText: uncheckAllText, classes: "mselcust" }); }); } // 511 - Sprachwechsel (main0 und init0) function chglng(laiso, coid) { if(coid === undefined){ document.location.href= host +"?fcode=m_cl_chglng&m_cl_GV_LANGU="+laiso; } else{ document.location.href= host +"?fcode=" + coid + "cl_chglng&" + coid + "cl_GV_LANGU="+laiso; } } // Tabelle Sortieren function sortTable(coid, formularName, key) { document.forms[formularName].fcode.value = coid + "SORT"; document[formularName][coid + "GV_SORTFIELD"].value = key; document.forms[formularName].submit(); } // Update all input elements with name gv_sid and global variable sid function updateSID(csrfToken) { if(csrfToken !== null) { // update all input fields with name gv_sid $('input[name]').filter(function() { return $(this).attr('name').toLowerCase().indexOf('gv_sid') > -1; }).val(csrfToken); // update global variable sid if it exists try { sid = csrfToken; } catch(e) {} } } function getAjaxId(coid) { return coid.substring(0, coid.length - 1); } /******************************************************************************* * DETECT IE * * returns TRUE if browser is IE, FALSE otherwise * ******************************************************************************/ function isIE() { var ua = window.navigator.userAgent; var msie = ua.indexOf('MSIE '); if (msie > 0) { return true; } var trident = ua.indexOf('Trident/index.html'); if (trident > 0) { return true; } var edge = ua.indexOf('Edge/index.html'); if (edge > 0) { return true; } return false; } /******************************************************************************* * EXTERNAL NUMBER TO INTERNAL * * Converts an external number to a JS floating point number, based on the * current users decimal point format. Possible units (string) are cut off. * ******************************************************************************/ function extNumberToInt(iNumber) { if(decpt === undefined) { return iNumber; } var num = iNumber.toString(); if(num.indexOf(' ') > -1) { num = num.split(' ')[0]; } if(decpt == ',') { num = replaceAll('.', '', num); num = replaceAll(',', '.', num); } else { num = replaceAll(',', '', num); } return parseFloat(num); } /******************************************************************************* * INTERNAL NUMBER TO EXTERNAL * * Converts an internal number to an external number (string), based on the * current users decimal point format. * ******************************************************************************/ function intNumberToExt(iNumber) { var num = iNumber.toString(); if(decpt === undefined) { return iNumber; } if(decpt == ',') { num = replaceAll('.', ',', num); } return num; } /******************************************************************************* * SHOW TOAST (Text) * * @message Message text * @cssClass CSS class string: 'default', 'success', 'error' * @time Time in seconds until auto-hide. Default 3 sec. * ******************************************************************************/ var wecoToastTimeout; function showToast(message, cssClass, time) { if(time === undefined) {time = 3000;} else {time = time*1000;} hideToast(); $('#toast #toast-content').addClass(cssClass).html(message); $('#toast').fadeIn(300); wecoToastTimeout = setTimeout(function() { $('#toast').fadeOut(200); }, time); } /******************************************************************************* * SHOW TOAST (Html) * * @message HTML Content * @time Time in seconds until auto-hide. Default 3 sec. * ******************************************************************************/ var wecoToastTimeout; function showToastHtml(html, time) { if(time === undefined) {time = 3000;} else {time = time*1000;} hideToast(); $('#toast #toast-content').html($(html)); $('#toast').fadeIn(300); wecoToastTimeout = setTimeout(function() { $('#toast').fadeOut(200); }, time); } /******************************************************************************* * HIDE TOAST MANUALLY ******************************************************************************/ function hideToast() { $('#toast').hide(); $('#toast #toast-content').empty().removeClass(); clearTimeout(wecoToastTimeout); } /******************************************************************************* * HEX to RGB * Usage: hexToRgb("#0033ff").r ******************************************************************************/ function hexToRgb(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null; } /******************************************************************************* * JSON To Javascript * Usage: jsonToJs('{"dummy":"dummy"}') * * @json JSON-Object (String) to convert to a Javascript-Object * @return the parsed Javascript-Object ******************************************************************************/ function jsonToJs(json){ // replace JSON-Escape-Chars with Javascript-Escape-Chars (\ to \\) json.replace(/[\\]/g, '\\\\') .replace(/[\/]/g, '#\\/') .replace(/[\b]/g, '\\b') .replace(/[\f]/g, '\\f') .replace(/[\n]/g, '\\n') .replace(/[\r]/g, '\\r') .replace(/[\t]/g, '\\t') .replace(/[\"]/g, '\\"') .replace(/\\'/g, "\\'"); return JSON.parse(json); } /******************************************************************************* * Javascript To JSON * Usage: jsToJson({dummy:"dummy"}) * * @jsobj Javascript-Object to convert to a JSON-Object (String) * @return the parsed JSON-Object (String) ******************************************************************************/ function jsToJson(jsobj){ return JSON.stringify(jsobj); } /******************************************************************************* * Validate Parsley and trigger some action when no validation is needed or the validation is successful * When the validation fails, the parsley UI is updated automatically * Usage: triggerParsleyValidation({ formular: '#catconfigform', onSuccess: function() { // do some fancy stuff like... genericAjax(); } }); * * @options.onSuccess Callback when validation was successful or no validation was required * @options.onFailure Callback when validation failed * @options.ignoreParsley Flag to ignore parsley - when ignored, the success callback is triggered * @options.formular Formname - when no Jquery-Element is found, the success callback is triggered * @options.$formular The Jquery object of the formular ******************************************************************************/ function triggerParsleyValidation(options) { var $form; options.$formular ? $form = options.$formular : $form = $(options.formular).first(); if (!$form) { if (typeof options.onSuccess === 'function') options.onSuccess(); return; } if (($form.length > 0 && typeof $form.parsley === 'function' && typeof $form.attr('data-weco-validation') !== 'undefined' && $form.parsley().isValid()) || // Parsley and valid ($form.length > 0 && typeof $form.parsley === 'function' && typeof $form.attr('data-weco-validation') === 'undefined') || // no Parsley for this form ($form.length > 0 && typeof $form.parsley !== 'function') || // Parsley not found/loaded ($form.length < 1) || options.ignoreParsley) { if (typeof options.onSuccess === 'function') options.onSuccess(); } else { try { $form.parsley().validate(); } catch (e) { console.log(e); } if (typeof options.onFailure === 'function') options.onFailure(); } }