Files

3072 lines
124 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var $t = {
lng: 'de-DE',
dn: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], mn: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'], ma: ['Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
datepattern: '(0[1-9]|1[0-9]|2[0-9]|3[01]).(0[1-9]|1[012]).[0-9]{4}',
datetimepattern: '(0[1-9]|1[0-9]|2[0-9]|3[01]).(0[1-9]|1[012]).[0-9]{4}\\s([0-5][0-9]):([0-5][0-9])',
dateplaceholder: 'dd.MM.yyyy',
datetimeplaceholder: 'dd.MM.yyyy HH:mm',
dateformat: 'dd.MM.yyyy',
datetimeformat: 'dd.MM.yyyy HH:mm',
f1: 'Der Server hat einen Fehler gemeldet: \n',
f2: 'Bitte versuchen Sie es erneut.',
m0: 'Diese Internet-Seite benötigt einen html5-kompatiblen Browser.',
m0b: 'Unterstützt werden bspw: Internet Explorer ab Version 10, Firefox ab Version 31, Chrome ab Version 31, Safari ab Version 7, Opera ab Version 27',
m1: 'Dieser Datensatz ist momentan von jemand anderem zur Bearbeitung gesperrt.',
m2: 'Diese Funktion ist zur Zeit nicht verfügbar',
t1: 'Eingabe erforderlich.',
t2: 'Eingabe ist nicht erforderlich.',
true: 'Ja',
false: 'Nein',
alert: 'Hinweis',
confirm: 'Bestätigen',
open: 'Öffnen',
'not implemented': 'Diese Funktion in zur Zeit noch nicht verfügbar.',
l0: 'Anmeldung',
l1: 'Email / Anmeldename',
l2: 'Email-Adresse / Anmeldename',
l3: 'Passwort',
l4: 'Benutzer',
l5: 'Wird vom System ermittelt...',
l6: 'Anmelden',
l7: 'Passwort vergessen?',
//l7a: 'Die Passwort vergessen Funktion wird aus Sicherheitsgründen auch dann einen erfolgreichen Versand bestätigen, wenn die Kombination aus Email-Adresse und Nachname nicht gefunden wurde.',
l7a: 'Die "Passwort vergessen"-Funktion läuft in zwei Schritten ab:\n \nIm ersten Schritt wird eine SMS mit einem Code an die hinterlegte Mobilfunk-Nummer versandt.\nIm zweiten Schritt geben Sie bitte diesen Code in das Formular ein und übermitteln es erneut.\n \nIn beiden Schritten wird aus Sicherheitsgründen kein Fehler angezeigt und auch dann ein erfolgreicher Versand bestätigt, wenn die Kombination aus Email-Adresse und Nachname nicht gefunden wurde und/oder der code falsch ist.',
l8: 'Keinen Account?',
l9: 'Anmeldenamen der Email-Adresse wurde nicht erkannt.',
l10: 'Nachname',
l11: 'Email-Adresse',
l12: 'Passwort zusenden',
l13: 'Das Passwort wurde erfolgreich verschickt',
l14: 'Das Passwort konnte nicht verschickt werden',
l15: 'Sie sind nicht berechtigt, diese Funktion auszuführen.',
l16: 'Sie müssen zunächst einen Account angeben.',
l17: 'Die Kombination aus Anmeldenamen und Passwort konnte nicht bestätigt werden.',
l18: 'Es gibt ein Problem mit dem Formular.\nEs kann momentan nicht verarbeitet und versendet werden.',
name: 'Name',
submit: 'Senden',
cancel: 'Abbrechen',
noop: 'Diese Funktion is noch nicht verfügar.'
};
$.extend($t, {
t1: 'Eingabe erforderlich',
t2: 'Bitte überprüfen Sie Ihre Eingaben im Formular.',
'b0': 'Erstellt',
'b1': 'Zuletzt geändert',
'b2': 'von',
't12': 'Der Server hat einen Fehler zurückgegeben. Bitte versuchen Sie es erneut.',
't17': 'Eine Email mit einem Aktivierungs-Link wurde an deine Adresse versandt.',
't18': 'Ein Account mit deinem Namen existiert bereits. Dennoch erstellen?',
't19': 'Einträge sind entweder unngültig oder zu kurz.',
't20': 'Der Server hat einen Fehler gemeldet. Bitte versuch es erneut.',
't21': 'Der Zugang wurde nicht gefunden.',
't30a': 'Als erledigt markieren.',
't30b': 'Als unerledigt markieren.',
't55': 'Ein Email mit einem Aktivierungs-Link wurde an Ihre Adresse versandt.',
't56': 'Ein Zugang für diesen Namen besteht bereits. Trotzdem erstellen?',
't57': 'Ein bestehender Zugang wurde für diese Serie registriert.',
't60': 'Bitte geben Sie Email-Adresse an, die Sie hier hinterlegt haben.',
't61': 'Ihr Passwort wurde erfolgreich versandt.',
't62': 'Die angegebene Email-Adresse stimmt nicht mit der hier hinterlegten überein.',
ov: 'Persönliche Übersicht',
});
'use strict';
var $v = {
};
/*! loadCSS. [c]2020 Filament Group, Inc. MIT License */
(function(w){
"use strict";
/* exported loadCSS */
var loadCSS = function( href, before, media, attributes ){
// Arguments explained:
// `href` [REQUIRED] is the URL for your CSS file.
// `before` [OPTIONAL] is the element the script should use as a reference for injecting our stylesheet <link> before
// By default, loadCSS attempts to inject the link after the last stylesheet or script in the DOM. However, you might desire a more specific location in your document.
// `media` [OPTIONAL] is the media type or query of the stylesheet. By default it will be 'all'
// `attributes` [OPTIONAL] is the Object of attribute name/attribute value pairs to set on the stylesheet's DOM Element.
var doc = w.document;
var ss = doc.createElement( "link" );
var ref;
if( before ){
ref = before;
}
else {
var refs = ( doc.body || doc.getElementsByTagName( "head" )[ 0 ] ).childNodes;
ref = refs[ refs.length - 1];
}
var sheets = doc.styleSheets;
// Set any of the provided attributes to the stylesheet DOM Element.
if( attributes ){
for( var attributeName in attributes ){
if( attributes.hasOwnProperty( attributeName ) ){
ss.setAttribute( attributeName, attributes[attributeName] );
}
}
}
ss.rel = "stylesheet";
ss.href = href;
// temporarily set media to something inapplicable to ensure it'll fetch without blocking render
ss.media = "only x";
// wait until body is defined before injecting link. This ensures a non-blocking load in IE11.
function ready( cb ){
if( doc.body ){
return cb();
}
setTimeout(function(){
ready( cb );
});
}
// Inject link
// Note: the ternary preserves the existing behavior of "before" argument, but we could choose to change the argument to "after" in a later release and standardize on ref.nextSibling for all refs
// Note: `insertBefore` is used instead of `appendChild`, for safety re: http://www.paulirish.com/2011/surefire-dom-element-insertion/
ready( function(){
ref.parentNode.insertBefore( ss, ( before ? ref : ref.nextSibling ) );
});
// A method (exposed on return object for external use) that mimics onload by polling document.styleSheets until it includes the new sheet.
var onloadcssdefined = function( cb ){
var resolvedHref = ss.href;
var i = sheets.length;
while( i-- ){
if( sheets[ i ].href === resolvedHref ){
return cb();
}
}
setTimeout(function() {
onloadcssdefined( cb );
});
};
function loadCB(){
if( ss.addEventListener ){
ss.removeEventListener( "load", loadCB );
}
ss.media = media || "all";
}
// once loaded, set link's media back to `all` so that the stylesheet applies once it loads
if( ss.addEventListener ){
ss.addEventListener( "load", loadCB);
}
ss.onloadcssdefined = onloadcssdefined;
onloadcssdefined( loadCB );
return ss;
};
// commonjs
if( typeof exports !== "undefined" ){
exports.loadCSS = loadCSS;
}
else {
w.loadCSS = loadCSS;
}
}( typeof global !== "undefined" ? global : this ));
/*! onloadCSS. (onload callback for loadCSS) [c]2017 Filament Group, Inc. MIT License */
/* global navigator */
/* exported onloadCSS */
function onloadCSS(ss, options ) {
options = options || {};
let f = function (si) {
return new Promise((resolve, reject) => {
let called, success = false;
function newcbs() {
if (!called) {
called = true;
resolve(true);
}
} function newcbe() {
if (!called && callback) {
called = true;
resolve(false);
}
}
if (ss.addEventListener) {
si.addEventListener('load', newcb);
} else if (ss.attachEvent) {
si.attachEvent('onload', newcb);
}
// This code is for browsers that dont support onload
// No support for onload (it'll bind but never fire):
// * Android 4.3 (Samsung Galaxy S4, Browserstack)
// * Android 4.2 Browser (Samsung Galaxy SIII Mini GT-I8200L)
// * Android 2.3 (Pantech Burst P9070)
// Weak inference targets Android < 4.4
if ('isApplicationInstalled' in navigator && 'onloadcssdefined' in ss) {
si.onloadcssdefined(newcb);
}
});
};
let fin = async function (success) {
if (success === true && typeof options.success === 'function') {
options.success();
} else if (success === true && typeof options.success === 'object' && options.success instanceof Promise) {
await options.success();
}
options.complete()
}
if (Array.isArray(ss)) {
let total = ss.length;
Promise.all(ss.map(f)).then(function (resolveValues) {
var ok = resolveValues.reduce((sum, x) => sum + (x === true ? 1 : 0));
fin(total === ok);
});
} else {
f(ss);
}
}
const isIE = /MSIE\/|Trident/ig.test(window.navigator.userAgent) || typeof window.document.documentMode !== 'undefined';
const isfileapi = (window.File && window.FileReader && window.FileList && window.Blob) ? true : false;
var $ocms = {
auth: {}, no: function (e) {
e.stopPropagation();
}, vmin: function (f) {
var w = $(window).width * (f || 1), h = $(window).height * (f || 1);
return w < h ? w : h;
}, rpx: function (rem) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
}, pattern: {
date_ger: '^(0?[1-9]|[12][0-9]|3[01])[\\.\\-](0?[1-9]|1[012])[\\.\\-]\\d{4}$',
date_us: '^(0?[1-9]|1[012])[\\\\](0?[1-9]|[12][0-9]|3[01])[\\\\]\\d{4}$',
date_serial: '\\d{4}[\\-]^(0?[1-9]|1[012])[\\-](0?[1-9]|[12][0-9]|3[01])$'
}, rdm: function (ln) {
var c = typeof ln === 'number' ? ln : (typeof ln === 'string' ? parseInt(ln) : 7);
if (isNaN(c) === true || typeof c === 'undefined') {
c = 7;
}
return Math.random().toString(36).substring(c);
}, login: {}, t: {
dn: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], mn: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'], ma: ['Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
}, failure: function (jqXHR) {
alert($t.f1 + '\n' + (jqXHR.internalText || ''));
}, baseurl: '/do', url: (c) => ($ocms.baseurl + '/' + (c || '')).replace(/\/\//, '/'),
cexi: null
};
function deepCopy (inObject) {
var outObject, value, key
if (typeof inObject !== "object" || inObject === null) {
return inObject // Return the value if inObject is not an object
}
// Create an array or object to hold the values
outObject = Array.isArray(inObject) ? [] : {};
for (key in inObject) {
value = inObject[key];
// Recursively (deep) copy for nested objects, including arrays
outObject[key] = deepCopy(value);
}
return outObject;
};
function fields_definition(p1, label_pl, flds) {
this.label_sng = Array.isArray(p1) === true ? '' : p1 ||'';
this.label_pl = Array.isArray(p1) === true ? '' : label_pl || '';
this.fields = Array.isArray(p1) === true ? p1 : (flds || []);
this.itm = function (name) {
for (var fi = 0; fi < this.fields.length; fi++) {
if (this.fields[fi].name === name) {
return this.fields[fi];
}
}
return null;
}
this.lbl = function (name) {
var ld = {}, n = typeof name === 'string';
for (var fi = 0; fi < this.fields.length; fi++) {
if (n ===true) {
if (this.fields[fi].name === name) {
return this.fields[fi];
}
} else {
ld[this.fields[fi].name] = this.fields[fi].label;
}
}
return (n === true ? null : ld);
}
this.contains = function (name) {
for (var fi = 0; fi < this.fields.length; fi++) {
if (this.fields[fi].name === name) {
return true;
}
}
return false;
}
this.rem = function (name) {
var r = false, f = function (nme) {
for (var fi = 0; fi < this.fields.length; fi++) {
if (this.fields[fi].name === nme) {
this.fields.splice(fi, 1);
r = true;
break;
}
}
}
if (typeof (name) === 'string') {
f.call(this, name);
} else if (Array.isArray(name) === true) {
for (var ai = 0; ai < name.length; ai++) {
f.call(this, name[ai]);
}
}
return r;
}
this.replace = function (name, newfield) {
for (var fi = 0; fi < this.fields.length; fi++) {
if (this.fields[fi].name === name) {
this.fields.splice(fi, 1, newfield);
return newfield;
}
}
return null;
}
this.set = function (name, value, prop) {
prop = prop || 'value';
for (var fi = 0; fi < this.fields.length; fi++) { /* loop through array */
if (this.fields[fi].name === name) {
this.fields[fi][prop] = value;
return this.fields[fi]; /* return if found = break loop */
}
}
return null;
}
this.sets = function (name, obj) {
if (typeof obj === 'object' && Object.keys(obj).length > 0) {
for (var fi = 0; fi < this.fields.length; fi++) { /* loop through array */
if (this.fields[fi].name === name) {
$.extend(this.fields[fi], obj);
return this.fields[fi]; /* return if found = break loop */
}
}
}
return null;
}
this.applyValues = function (vals) {
var t = this;
$.each(vals || {}, function (ri, rx) {
t.set(ri, rx);
});
return t;
}
this.clone = function (names) {
let c = [];
if (Array.isArray(names || '')) {
let value, key;
for (key in (this.fields || [])) {
value = this.fields[key];
if ((value.name ||'') !== '' && names.includes(value.name) === true) {
// Recursively (deep) copy for nested objects, including arrays
c.push(deepCopy(value));
}
}
} else {
c = deepCopy(this.fields || []);
}
return new fields_definition(this.label_sng || '', this.label_pl || '', c);
}
}
function rpx(rem) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
}
function vw(f) {
return $(window).width() * (f || 1);
}
function vh(f) {
return $(window).height() * (f || 1);
}
function hh() {
return $('header:first').height() || 0;
}
function ne(inp, alt) {
return (inp || '') === '' ? (alt || '') : inp;
}
function pad(i, n) { return (i || '').toString().padStart(n, '0').substr(-1 * n); }
function parseISO(s) {
let si = s || '';
if (si === '') { return null };
if (/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/.test(si) === true) {
return new Date(si);
} else {
var b = s.split(/\D/);
return new Date(b[0], b[1] - 1, b[2], b[3], b[4], b[5]);
}
}
function parseISOLocal(s) {
let si = s || '';
if (si === '') { return null };
var b = s.split(/\D/);
return new Date(b[0], b[1] - 1, b[2], b[3], b[4], b[5]);
}
function fnum(i, style) {
/* { style: 'decimal/currency/percent', currency: 'USD/EUR', currencyDisplay: 'symbol/code/name', minimumIntegerDigits: 1, minimumFractionDigits: 2, maximumFractionDigits: 3, useGrouping: true } */
return new Intl.NumberFormat(($t.lng || 'de-DE'), style || {}).format(i);
}
function fdt(i, fmt) {
if (typeof i === 'undefined') { return ''; }
try {
var f = fmt || 'DD.MM.YYYY HH:mm';
if (f === 'dts') {
f = 'yyyy-MM-dd';
}
if (f === 'iso') {
if (typeof i === 'string') { i = parseISO(i); }
return i.toISOString();
} else if (typeof moment === 'function') {
return (typeof i !== 'undefined' && (typeof i === 'string' && i !== '')) ? moment(i).format(f) : '';
} else {
if (typeof i === 'string') { i = parseISO(i); }
var pd = function (i, n) { var t = ('0000' + i.toString()); return t.slice(t.length - (n || 2)); }
var t = f + '';
t = t.replace(/ddd/ig, ($t.dn || $ocms.t.dn)[i.getDay()]);
t = t.replace(/dd/ig, pd(i.getDate()));
t = t.replace(/MMMM/g, ($t.mn || $ocms.t.mn)[i.getMonth()]);
t = t.replace(/MMM/g, ($t.ma || $ocms.t.ma)[i.getMonth()]);
t = t.replace(/MM/g, pd(i.getMonth() + 1));//January is 0!
t = t.replace(/yyyy/ig, pd(i.getFullYear(), 4));
t = t.replace(/yy/ig, pd(i.getFullYear()));
t = t.replace(/hh/ig, pd(i.getHours()));
t = t.replace(/mm/g, pd(i.getMinutes()));
t = t.replace(/ss/ig, pd(i.getSeconds()));
return t;
}
} catch (e) {
return '';
}
}
Date.prototype.isValid = function () {
return !isNaN(this);
};
Date.prototype.format = function (fmt) {
return fdt(this,fmt);
};
Date.prototype.addDays = function (days) {
this.setDate(this.getDate() + days);
return this;
};
Date.prototype.isBetween = function (date1, date2) {
return this > date1 && this < date2;
};
Date.prototype.diff = function (date1) {
var diffTime = Math.abs(date1 - this), diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
return diffDays;
};
Date.prototype.year = function () {
return this.getFullYear();
};
Date.prototype.month = function () {
return this.getMonth() + 1;
};
Date.prototype.date = function () {
return this.getDate();
};
String.prototype.ne = function (alt) {
let t = (this || '').trim();
return t === '' ? (alt || '') : t;
};
/* eine = extend if not empty */
String.prototype.eine = function(pre, su) {
let t = (this || '').trim();
return t === '' ? '' : ((pre || '') + t + (su || ''));
};
function jine(a, sep) { return a.map((v, i) => (v || '')).filter((v, i) => v !== '').join(sep) };
function parseDt(datestring, format, newformat) {
datestring = (datestring || '').substr(0, format.length);
var cvalid = function (fmt) {
var result, reg = /[^yMdhms0-9]/ig, valid = true;
while ((result = reg.exec(fmt)) !== null) {
valid = valid && fmt.substr(result.index, 1) === datestring.substr(result.index, 1);
}
var vr = (datestring.length === fmt.length) && valid;
if (vr === true) {
vfmt = fmt;
}
return vr;
}, vfmt = format, isvalid = datestring.length > 0 && format.split(';').some(cvalid);
if (isvalid === true) {
var ndt = [0, 0, 0, 0, 0, 0, 0], np = 'yMdhms';
var result, reg = /(mm{1,2}|dd{1,2}|MM{1,2}|(yy){2,4}|ss{1,2}|hh{1,2})(?!\w)/g, valid = true;
while ((result = reg.exec(vfmt)) !== null) {
ndt[np.indexOf(result[0].substr(0, 1))] = parseInt((result[0] === 'yy' ? '20' : '') + datestring.substr(result.index, result[0].length)) - (result[0].substr(0, 1) === 'M' ? 1 : 0);
}
var dt = new (Function.prototype.bind.apply(Date, [null].concat(ndt)))();
return (typeof newformat === 'string') ? fdt(dt, newformat) : dt;
} else {
return false;
}
}
function bool(i, alt) {
return typeof i === 'boolean' ? i : (typeof alt === 'boolean' ? alt : false);
}
function booln(i, alt) {
var r = false;
if (typeof i === 'boolean') {
r = i;
} else if (typeof i === 'number') {
r = (i === 1);
} else {
r = (typeof alt === 'boolean' ? alt : false);
}
return r;
}
/* set getHash method, IE9 safe */
var h = (typeof window.location.hash === 'undefined');
$ocms.getHash = h ? function () {
return document.URL.substr(document.URL.indexOf('#'));
} : function () { return window.location.hash; };
$ocms.initNav = function () {
$('body').click(function (e) {
$('#toggle-nav').removeClass('active');
});
var nbtn = $('#toggle-nav');
$('.nav_menu').click(function (e) {
if (nbtn.hasClass('active') === true) {
e.stopPropagation();
}
});
nbtn.click(function (e) {
e.stopPropagation();
$(this).toggleClass('active');
});
};
$ocms.initScroll = function () {
let hd = $('header');
let initialHeaderHeight = hd.height(), sec = $('main > section');
$(window).scroll(function (e) {
let scrollTop = $(window).scrollTop(), b = $('body');
b.toggleClass('unfocus', scrollTop > (vh() - initialHeaderHeight * 1.2));
b.toggleClass('btb', scrollTop > (vh() * 0.5 - initialHeaderHeight));
});
};
$ocms.cf_reset = function () {
return $('#contentframe').empty();
};
(function ($) {
/* @description: jQuery - scrollTo
* @author: Dr. Stefan Ott
* @version: 1.0
*/
$.fn.scrollTo = function (key) {
if ($(this).length > 0) {
var ost = $(this).offset().top || 0;
if (ost > 0) {
$('html, body').animate({
scrollTop: ost - hh()
}, 2000);
}
}
};
$.fn.ldng = function (onoff) {
var st = true;
if (typeof onoff === 'boolean') {
st = onoff;
} else if (typeof onoff === 'number') {
st = onoff > 0;
}
return $(this).toggleClass('loading', st);
};
if (typeof $.noop !== 'function') {
$.noop = function () {};
}
/* @description: determines if element has the attribute
* @author: Dr. Stefan Ott
* @version: 1.0
*/
$.fn.hasAttr = function (AttName) {
var attr = $(this).attr(AttName);
return (typeof attr !== 'undefined' && attr !== false);
};
$.fn.parseCssPx = function (key) {
try {
return parseFloat($(this).css(key).replace('px', '') || 0);
} catch (e) {
return 0.0;
}
};
/* @description: returns the higher value
* @author: Dr. Stefan Ott
* @version: 1.0
*/
$.max = function (val1, val2) {
if (isNaN(val1) && isNaN(val2)) { return null; }
else if (isNaN(val1) && !isNaN(val2)) { return val2; }
else if (!isNaN(val2) && isNaN(val2)) { return val1; }
else if (val1 >= val2) { return val1; }
else { return val2; }
};
/* @description: returns the lower value
* @author: Dr. Stefan Ott
* @version: 1.0
*/
$.min = function (val1, val2) {
if (isNaN(val1) && isNaN(val2)) { return null; }
else if (isNaN(val1) && !isNaN(val2)) { return val2; }
else if (!isNaN(val2) && isNaN(val2)) { return val1; }
else if (val1 <= val2) { return val1; }
else { return val2; }
};
/* @description: returns the value to the limit
* @author: Dr. Stefan Ott
* @version: 1.0
*/
$.lim = function (val, lim) {
if (isNaN(val)) { return null; }
else if (isNaN(lim)) { return val; }
else if (lim <= val) { return lim; }
else { return val; }
};
$.fn.enterKey = function (fnc) {
return this.each(function () {
$(this).keypress(function (ev) {
var keycode = (ev.keyCode ? ev.keyCode : ev.which).toString();
if (keycode === '13') {
fnc.call(this, ev);
}
})
})
};
})(jQuery);
/*_________ ajax ________________________________________________*/
$ocms.defaultTimeout = 30000; /* 30s */
/* @description: processes jqXHR from Ajax response and adds new infos (needs to be called with jqXHR as context)
* @author: Dr. Stefan Ott
* @version: 2.0
*/
$ocms.AjaxEX = function (textStatus) {
var jqXHR = this;
jqXHR.responseText = jqXHR.responseText || '';
var ic = jqXHR.getResponseHeader('x-ocms-code') || '';
jqXHR.internalCode = (ic !== '' && isNaN(ic) === false) ? parseInt(ic) : -1;
jqXHR.isInternal = jqXHR.internalCode > -1;
jqXHR.internalText = decodeURIComponent((jqXHR.getResponseHeader('x-ocms-desc') ||'').replace(/\+/g, '%20') || '');
var t = jqXHR.internalText || textStatus;
var c = jqXHR.internalCode || jqXHR.status;
jqXHR.logtext = t + ' (' + c + ')';
};
/* @description: custom jquery ajax post for simplification
* @author: Dr. Stefan Ott
* @version: 1.0
*/
$ocms.postXTS = function (options) {
$ocms.postXT.call(this, $.extend(options, { sync: true }));
};
/* @description: custom jquery ajax post for simplification
* @author: Dr. Stefan Ott
* @version: 2.0
*/
$ocms.postXT = function (options) {
options = options || {};
options.trycount = options.trycount || 0;
if ((options.url || '') === '') { return; }
options.url = (options.url.indexOf('&yy=') !== -1) ? options.url : ((options.url.indexOf('?') > -1) ? (options.url + '&yy=' + (new Date()).getTime()) : (options.url + '?yy=' + (new Date()).getTime()));
var context = options.context || this;
options.context = context;
options.retryLimit = options.retryLimit || 0;
options.timeout = options.timeout || $ocms.defaultTimeout;
if (options.timeout < 100) { options.timeout = options.timeout * 1000; }
options.data = options.data || {};
options.contentType = options.contentType || 'multipart/form-data; charset=UTF-8';
options.islogin = typeof options.islogin === 'boolean' ? options.islogin : false; /* this is used to prevent loop */
switch (options.contentType) {
case '':
case 'json':
options.contentType = 'application/json; charset=utf-8';
break;
case 'form':
options.contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
break;
case 'multi':
options.contentType = 'multipart/form-data';
break;
case 'text':
options.contentType = 'text/plain; charset=UTF-8';
break;
/* default = leave as defined */
}
if (options.form instanceof jQuery) {
options.data = options.form.serializeObject();
options.contentType = 'form-data';
} else if (options.lzw instanceof jQuery) {
options.data.lzw = $.ccLZW(options.lzw.serializeAnything(true)).join(',');
}
var senddata;
if ((options.contentType.substr(0, 19) === 'multipart/form-data' || options.contentType.substr(0, 9) === 'form-data') && options.data instanceof FormData === false) {
options.contentType = false;
var fd = new FormData();
$.each(options.files || [], function (fi, file) {
fd.append('upload_file', file);
});
$.each(options.data || {}, function (di, dx) {
fd.append(di, dx);
});
options.data = fd;
options.processData = false;
} else if (options.data instanceof FormData) {
options.contentType = false;
options.processData = false;
}
var ajo = {
type: options.method || 'post',
url: options.url,
data: options.data,
processData: typeof options.processData !== 'boolean' ? true : options.processData,
contentType: options.contentType,
cache: options.cache || false,
timeout: options.timeout,
beforeSend: function (jqXHR) {
$(options.loading).ldng();
$('body').addClass('ldng');
if (typeof options.beforesend === 'function') { options.beforesend.apply(context, [jqXHR]); }
},
success: function (response, textStatus, jqXHR) {
if (response === 'false' || response === 'not authorized') {
if (typeof options.error === 'function') { options.error.apply(context, [jqXHR, textStatus, response]); }
if (typeof $.status === 'function') { $.status(textStatus + ' - ' + response); }
} else {
if (typeof options.success === 'function') { options.success.apply(context, [response, textStatus, jqXHR]); }
}
},
error: function (jqXHR, textStatus, response) {
$ocms.AjaxEX.call(jqXHR, textStatus);
if (options.url.indexOf('doc.ashx') !== -1 && options.url.indexOf('ftest') === -1) { return; }
if (jqXHR.status === 401 && jqXHR.internalCode === 111 && options.islogin === false && typeof $ocms.login.dlg === 'function') {
$ocms.login.dlg({ ajo: options });
} else if (textStatus === 'timeout' || jqXHR.status === 302) {
options.tryCount++;
if (options.tryCount <= options.retryLimit) {
/* try again */
$ocms.postXT(options);
return;
}
return;
}
/*if (typeof $.log === 'function' && (jqXHR.internalCode + '') !== '1101') { $.log('Server error: ' + jqXHR.logtext + '', 'error', options.url); }*/
if (typeof options.error === 'function') {
options.error.apply(context, [jqXHR, textStatus, response]);
} else if (typeof $ocms.failure === 'function') {
$ocms.failure.apply(context, [jqXHR]);
} else if (typeof $.status === 'function') {
$.status('Server error: ' + textStatus + ' - ' + response + '');
}
},
dataType: options.datatype || 'json',
complete: function (jqXHR, textStatus) {
if (typeof options.complete === 'function') { options.complete.apply(context, [jqXHR, textStatus]); }
$(options.loading).ldng(0);
$('body').removeClass('ldng');
let tm = $('body > .timer');
if (tm.length > 0) {
let cec = new Date(jqXHR.getResponseHeader('ocms_cec') || ''), cex = new Date(jqXHR.getResponseHeader('ocms_cex') || '');
if (cec.isValid() && cex.isValid()) {
let d = new Date(), dd = Math.abs(cex - cec);
d.setMilliseconds(d.getMilliseconds() + dd);
tm.data({ 'cex': d, 'ctt': dd });
$ocms.cex_timer();
}
}
},
context: context,
async: true
};
if (typeof options.sync === 'boolean') {
ajo.async = (options.sync === false);
}
if ((typeof options.contentType === 'boolean' ? options.contentType === false : false) === true) {
ajo.contentType = false; /* needed for file uploads */
}
$.ajax(ajo);
};
$ocms.cex_timer = function () {
if (!$ocms.cexi) {
$ocms.cexi = setInterval($ocms.cex_timer, 15000);
}
let tm = $('body > .timer'), c = tm.data('cex'), t = tm.data('ctt'), n = new Date();
if (c instanceof Date && c.isValid() && typeof t === 'number' && t > 0 && c > n) {
let p = (Math.abs(n - c) / t * 100);
tm.css('width', p.toString() + '%');
if (p < 98 && (!$ocms.cex_lp || Math.abs(n - $ocms.cex_lp) > 600000 )) {
$ocms.postXT({ url: $ocms.url('ping'), success: () => { $ocms.cex_lp = n; }, timeout: 5000, error: () => { }});
}
}
};
$ocms.vbl_send = function (ev) {
var options = ev.data || {};
if ((options.url || '') === '') { return; }
var frm = $('#contentframe form:first');
var postoptions = {
url: options.url, data: new FormData(), success: function (response) {
if (typeof options.success === 'function') { options.success(response); } else if (typeof options.success === 'string') { alert(options.success); }
}, error: function (jqXHR, textStatus, response) {
if (typeof options.error === 'function') { options.error(response); } else if (typeof options.error === 'string') { alert(options.error); }
}, complete: function () {
frm.ldng(0);
}
};
var valid = true;
frm.find('input').each(function () {
var t = $(this), nm = t.nza('name'), val = t.val(), req = $(this).prop('required') || false;
if (nm !== '') {
var tv = (val !== '' || req === false);
valid = valid && tv;
if (tv === true) {
postoptions.data.append(nm, val);
t[0].setCustomValidity('');
} else if ($(this).nza('ocms-nvnote') !== '') {
t[0].setCustomValidity($(this).nza('ocms-nvnote'));
}
}
});
if (valid === true) {
frm.ldng(1);
$ocms.postXT.call(this, postoptions);
}
};
(function ($) {
$.fn.nza = function (attributeName, alternative) {
var attr = $(this).attr(attributeName);
return (typeof attr !== 'undefined' && attr !== false) ? attr : (alternative || '');
};
$.fn.serializeObject = function (checkvalidity, options) {
var
rbracket = /\[\]$/,
rCRLF = /\r?\n/g,
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
rsubmittable = /^(?:input|select|textarea|keygen)/i,
rcheckableType = (/^(?:checkbox|radio)$/i);
options = options || {};
var typedvalues = bool(options.typedvalues, false);
var result = {}, c= $(this), inp = c.find(':input:not([nosend],[type="file"])').addBack(':input'), valid = true;
$.each(inp.not('.tinymce').get(), function (i, ii) {
var t = $(this), e = this, type = (this.type || '').toLowerCase(), req = t.prop('required') || false;
if ((e.name && !t.is(':disabled') && rsubmittable.test(e.nodeName) && !rsubmitterTypes.test(type)) === true) {
var val = t.val(), nme = e.name, dtf = t.nza('data-format').split(':'), pattern = t.nza('pattern') || '.*', cat = false;
if (rcheckableType.test(type) === true) {
val = e.checked ? (val !== '' ? val : 'true') : '';
}
if (dtf[0].substr(0, 4) === 'date' && dtf.length > 1) {
val = parseDt(val, dtf.slice(1).join(':')); /* should result in date object */
if (typeof val === 'boolean') {
val = null;
}
if (val === null && t.prop('type').substr(0, 4) === 'date' && isNaN(new Date(t.val())) === false) { /* is can be parsed by Date object */
val = new Date(t.val());
}
if (val instanceof Date === true && typeof val.getMonth === 'function') { /* if really a Date */
if (typedvalues === false) { val = fdt(val, dtf[0] === 'date' ? 'dts' : 'iso'); } /* if string result awaited, format to string */
} else {
val = null;
}
} else if (type === 'number' && typedvalues === true ) {
let v;
if (dtf[0] === 'integer') {
v = parseInt(val);
} else {
v = parseFloat(val);
}
val = isNaN(v) ? val : v;
}
if (req === true && ((val || '') === '' || (val.match(pattern) === null))) {
if (cat === false && bool(checkvalidity, false) === true) { e.setCustomValidity(t.nza('ocms-nvnote', $ocms.t.inv || 'Invalid field')); }
val = null;
} else if (cat=== false && bool(checkvalidity, false) === true) {
e.setCustomValidity('');
}
if (typeof val !=='undefined' && val !== null && typeof val === 'string') {
let node = result[nme];
if (typeof node !== 'undefined' && node !== null) {
if (Array.isArray(node)) {
node.push(val.replace(rCRLF, '\r\n'));
} else {
result[nme] = [node, val.replace(rCRLF, '\r\n')];
}
} else {
result[nme] = val.replace(rCRLF, '\r\n');
}
} else if (typeof val !== 'undefined' && val !== null) {
let node = result[nme];
if (typeof node !== 'undefined' && node !== null) {
if (Array.isArray(node)) {
node.push(val);
} else {
result[nme] = [node, val];
}
} else {
result[nme] = val;
}
} else {
valid = false;
}
}
});
inp.filter('.tinymce').each(function (ei, ex) {
var t = $(this), e = this, type = (this.type || '').toLowerCase(), req = t.prop('required') || false
try {
var te = tinymce.get($(ex).attr('id'));
if (te) {
var enm = $(ex).attr('name');
var val = te.getContent();
if (req === false || (val || '') !== '') {
result[enm] = val;
} else {
valid = false;
}
}
} catch (ee) { $.noop(); }
});
c.toggleClass('invalid', !valid);
return valid ? result : null;
};
$.fn.sendForm = function (url, success, options) {
var form = $(this);
options = options || {};
var postoptions = {
url: url, success: function (response) {
options.response = response;
if (typeof success === 'function') {
var _e = success(response);
}
form.closest('div.modal').remove();
}, error: function (jqXHR, textStatus, response) {
if (typeof options.error === 'function') { options.error.call(this, jqXHR); } else {
$ocms.failure.call(this, jqXHR);
}
}, complete: function () {
form.ldng(0);
if (typeof options.complete === 'function') { options.complete.call(this, jqXHR); }
}
};
var fle = form.find('input[type="file"]');
postoptions.data = new FormData();
if (fle.length > 0) {
$.each(fle[0].files, function (key, value) {
postoptions.data.append(key, value);
postoptions.data.append('file_lastmodified', $ocms.isodt(value.lastModifiedDate));
});
}
var formdata = form.serializeObject();
$.each(formdata || {}, function (di, dx) {
postoptions.data.append(di, dx);
});
form.ldng();
$ocms.postXT.call(this, postoptions);
};
$.fn.checkValidity = function () {
var t = $(this), valid = true;
t.each(function (i,e) {
valid = valid && e.checkValidity();
});
return valid;
};
$.fn.wrap = function (cls, attr) {
var t = $(this), n = $$.dc(cls).attr(attr || {}).insertAfter(t);
t.append(n);
return n;
};
})(jQuery);
$ocms.logout = function () {
$ocms.postXT({
url: $ocms.url('logout'), complete: function () { window.location.reload(); }
});
};
$ocms.login = {
send: function (e) {
e.preventDefault();
var f = $(this);
if (f.find('#dbtn-confirm').hasClass('disabled') === true) {
return false;
} else {
var qs = f.serializeObject();
qs.loginaccount = ne(qs.loginaccount, $ocms.auth.account || $ocms.auth.requestedaccount || '');
qs.loginaccount = ne(qs.loginaccount, $ocms.auth.account || $ocms.auth.requestedaccount || '');
if (ne(qs.loginaccount) === '' && bool($ocms.auth.accountrequired, true) === true ) {
alert($t.l16);
return false;
} else {
$ocms.postXT({ url: $ocms.url('login'), data: qs, success: function () { window.location.reload(); }});
return false;
}
}
}, uichange: function () {
let inp_ui = $(this), form = inp_ui.closest('form'), accountrequired = bool($ocms.auth.accountrequired, true);
let loginaccount = ne(form.find('[name="loginaccount"]').val(), $ocms.auth.account || $ocms.auth.requestedaccount || '');
if (loginaccount !== '' || accountrequired === false) {
var ul = form.find('[name="userlogin"]').empty().val('');
var un = form.find('[name="username"]').empty().val('');
var nsel = $('#dlg_userlogin_sel').empty().val('');
var ui = inp_ui.val() || '';
if (inp_ui.checkValidity() === false && ui === '') { return; }
var ftbl = inp_ui.closest('table').ldng();
$ocms.postXT.call(this, {
url: $ocms.url('auth'), data: { 'userinfo': ui, account: (loginaccount ||'') }, success: function (response, textStatus, jqXHR) {
if (response.length === 1) {
var sx = response[0];
ul.val(sx.login).change().attr('required', '').removeAttr('nosend');
un.val(sx.name).change().attr('required', '').show();
nsel.removeAttr('required').attr('nosend', '').hide();
} else if (response.length > 0) {
un.hide().removeAttr('required');
ul.removeAttr('required').attr('nosend', '');
if (nsel.length === 0) {
nsel = $('<select></select>').attr({ name: 'userlogin', size: response.length, id: 'dlg_userlogin_sel', class: 'form-control', required: '' }).css({ width: '100%', 'max-width': '100%', padding: '2px' }).insertAfter(un);
}
$.each(response, function (ni, sx) {
var io = $('<option></option>').attr({ value: sx.login, style: 'padding-top: 2px; padding-bottom: 5px;', 'border-bottom': '1px solid #EEE;' }).text(sx.name).appendTo(nsel);
if (ni % 2 === 0) { io.css({ 'background-color': '#F9F9F9' }); }
});
nsel.attr('required', '').removeAttr('nosend');
} else {
nsel.hide().attr('nosend', '');
un.attr('required', '').show();
ul.attr('required', '').removeAttr('nosend');
alert($t.l9);
}
}, error: function (jqXHR) {
$ocms.failure.call(this, jqXHR);
}, complete: function () {
ftbl.ldng(0);
}
});
} else {
alert($t.l18);
}
}, sendpassword: function (ev) {
var d = $('<div class="modal"><div class="modal-dialog in" style="height: 500px; width: 600px;"><div class="modal-content" style="height: auto;" novalidate="true"><div class="modal-header"><h3>Vereinsmanager</h3></div></div><div class="modal-close"></div><div class="modal-content"><form role="form"><div class="modal-header"><h3></h3></div><div class="modal-body"><div class="frm"><div class="form-body stacked"><div class="form-group"><div class="form-itm"><label for="dlg_lastname">Nachname<span class="ind_required">*</span></label></div><div class="form-itm"><input id="dlg_lastname" name="lastname" type="string" class="form-control" required=""></div></div><div class="form-group"><div class="form-itm"><label for="dlg_email">Email<span class="ind_required">*</span></label></div><div class="form-itm"><input id="dlg_email" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$" type="string" class="form-control" required=""></div></div></div></div></div><div class="modal-footer"><div class="note_required"><span class="ind_required">*</span><span>Eingabe erforderlich</span></div><button type="submit" class="btn confirm" role="confirm">Senden</button></div><div class="modal-note"></div></form></div></div></div>');
var fb = d.find('.form-body'), code = null;
d.find('form').submit(function (e) {
e.preventDefault();
var qs = $(this).serializeObject(true), s2 = code === null, u = s2 ?'spwc':'spw';
$ocms.postXT.call(this, {
url: $ocms.url(u), data: qs, complete: function () {
if (s2) {
fb.append('<div class="form-group"><div class="form-itm"></div><div class="form-itm">Ihnen wurde ein Code per SMS zugesandt. <br />Bitte tragen Sie den hier ein:</div></div>');
code = $('<div class="form-group"><div class="form-itm"><label for="dlg_code">SMS-Code<span class="ind_required">*</span></label></div><div class="form-itm"><input id="dlg_code" name="code" type="string" class="form-control" required></div></div>').appendTo(fb);
} else {
alert($t.l13);
d.remove();
}
}, error: () => { } /* prevent default */
});
return false;
});
d.find('.modal-close').click(function () {
d.remove();
});
var l17a = [];
$.each($t.l7a.split('\n'), (i, t) => {
Array.prototype.push.apply(l17a, [$('<br/>'), $('<span></span>').text(t)]);
});
d.find('.modal-note').append($('<span style="text-decoration: underline;"></span>').text($t.alert)).append(l17a);
d.appendTo('body');
setTimeout(function () {
$('.modal').find('input[name="lastname"]').focus();
}, 600);
}
};
var $$ = {
s: function (ct) { return $('<span></span>').text(ct); },
br: function () { return $('<br />'); },
sc: function (cls, ct) { return $('<span></span>').addClass(cls).text(ct); },
td: function (param1, param2) {
var td = $('<td></td>');
if ((param1 instanceof jQuery) === true) {
td.appendTo(param1);
} else if (typeof param1 === 'object') {
td.attr(param1);
} else if (typeof param1 === 'string') {
td.text(param1);
}
if (typeof param2 === 'object') {
td.attr(param2);
} else if (typeof param2 === 'string') {
td.text(param2);
}
return td;
},
th: function (param1, param2) {
var th = $('<th></th>');
if ((param1 instanceof jQuery) === true) {
th.appendTo(param1);
} else if (typeof param1 === 'object') {
th.attr(param1);
} else if (typeof param1 === 'string') {
th.text(param1);
}
if (typeof param2 === 'object') {
th.attr(param2);
} else if (typeof param2 === 'string') {
th.text(param2);
}
return th;
},
tdc: function (cls, param1, param2) { return $$.td(param1, param2).addClass(cls); },
td2: function (ct) {
var _td3 = $('<td colspan="2" />');
if ($.type(ct) === 'string') { _td3.text(ct); } else if (ct instanceof jQuery) { _td3.append(ct); } else if (typeof ct === 'function') { ct.call(_td3); } else { _td3.html('&nbsp;'); }
return _td3;
},
td3: function (ct) {
var _td3 = $('<td colspan="3" />');
if ($.type(ct) === 'string') { _td3.text(ct); } else if (ct instanceof jQuery) { _td3.append(ct); } else if (typeof ct === 'function') { ct.call(_td3); } else { _td3.html('&nbsp;'); }
return _td3;
},
tdtr: function (ct, tbl) {
var tr = $$.tr().appendTo(tbl);
if ((ct instanceof jQuery) === true || typeof ct === 'string') {
ct.appendTo($$.td().appendTo(tr));
} else if (Array.isArray(ct) === true) {
$.each(ct, function (ci, cx) {
$(cx).appendTo($$.td().appendTo(tr));
});
}
return tr;
},
tr: function (param1, param2) {
var tr = $('<tr></tr>');
if ((param1 instanceof jQuery) === true) {
tr.appendTo(param1);
} else if (typeof param1 === 'object') {
tr.attr(param1);
}
if (typeof param2 === 'object') {
tr.attr(param2);
}
return tr;
},
trc: function (cls, param1) {
var tr = $('<tr></tr>').addClass(cls);
if ((param1 instanceof jQuery) === true) {
tr.appendTo(param1);
} else if (typeof param1 === 'object') {
tr.attr(param1);
}
return tr
},
d: function (att) { return $('<div></div>').attr(att || {}); },
dc: function (cls, param1, param2, param3) {
var d = $('<div></div>').addClass(cls);
if ((param1 instanceof jQuery) === true) {
d.appendTo(param1);
} else if (typeof param1 === 'object') {
d.attr(param1);
} else if (typeof param1 === 'function') {
d.click(param1);
} else if (typeof param1 === 'string') {
d.text(param1);
}
if (typeof param2 === 'string') {
d.text(param2);
} else if (typeof param2 === 'object') {
d.attr(param2);
} else if (typeof param2 === 'function') {
d.click(param2);
}
if (typeof param3 === 'string') {
d.text(param3);
} else if (typeof param3 === 'object') {
d.attr(param3);
} else if (typeof param3 === 'function') {
d.click(param3);
}
return d;
},
df: function (att) { return $('<div>&nbsp;</div>').attr(att || {}); },
opt: function (param1, param2, param3) {
var d = $('<option></option>');
if (typeof param1 === 'string') {
d.attr('value', param1);
} else if (typeof param1 === 'object') {
d.attr(param1);
}
if (typeof param2 === 'string') {
d.text(param2);
} else if (typeof param2 === 'object') {
d.attr(param2);
}
if (typeof param3 === 'object') {
d.attr(param3);
}
return d;
},
eOpt: function (selected) {
var _eOpt = $('<option value="">&nbsp;</option>');
if (selected || false) { _eOpt.attr('selected', 'selected'); }
return _eOpt;
},
tbl: function (att) { return $('<table></table>').attr(att || {}); },
tblc: function (cls) { return $('<table></table>').addClass(cls); },
thead: function (tbl) { let h = $('<thead></thead>'); if (tbl instanceof jQuery) { h.prependTo(tbl); } return h; },
tbody: function (tbl) { let b = $('<tbody></tbody>'); if (tbl instanceof jQuery) { b.appendTo(tbl); } return b; },
tblset: function (att, parent) {
let b = $$.tbl(att || {});
if (parent instanceof jQuery) {
parent.append(b);
}
return { tbl: b, hd: $$.thead().appendTo(b), bdy: $$.tbody().appendTo(b) };
},
i: function (att) { return $('<input />').attr(att || {}); },
img: function (src, att) { return $('<img />').attr('src', src).attr(att || {}); },
sel: function (att) { return $('<select></select>').attr(att || {}); },
btn: function (att) { return $('<button></button>').attr(att || {}); },
a: function (att) { return $('<a></a>').attr(att || {}); },
li: function (att) { return $('<li></li>').attr(att || {}); },
ul: function (att) { return $('<ul></ul>').attr(att || {}); },
nav: function (att) { return $('<nav></nav>').attr(att || {}); },
lbl: function (ct, att) {
var l = $('<label></label>');
if (typeof ct === 'string') {
l.text(ct);
}
if (typeof ct === 'object') {
l.attr(ct);
} else if (typeof att === 'object') {
l.attr(att);
}
return l;
},
txt: function (att) { return $('<textarea></textarea>').attr(att || {}); },
0: function (tag, att) { return $('<' + tag + '></' + tag + '>').attr(att || {}); },
/* bootstrap */
bbtn: function (txt, cls) { return $$.btn({ type: 'button', class: 'btn' }).addClass(cls).text(txt); },
svg: (tag) => {
return $(document.createElementNS('http://www.w3.org/2000/svg', tag));
}
};
String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.left = function (n) {
if ($.type(n) === 'string') {
var i = this.indexOf(n);
if (i > 0)
return this.slice(0, i);
else
return "";
} else {
return this.substring(0, n);
}
};
String.prototype.right = function (n) {
if ($.type(n) === 'string') {
var i = this.indexOf(n);
if (i > 0)
return this.substring(this.length - i);
else
return "";
} else {
return this.substring(this.length - n);
}
};
Array.prototype.move = function (old_index, new_index) {
if (new_index >= this.length) {
var k = new_index - this.length;
while ((k--) + 1) {
this.push(undefined);
}
}
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
return this; // for testing purposes
};
function getMonday(d) {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
(function ($) {
$.fn.appendToIf = function (target, condition) {
var t = $(this), c = (typeof condition === 'function' ? condition(t) : condition);
if ((typeof c === 'boolean' ? c : true) === true) {
t.appendTo(target);
}
return t;
};
$.fn.appendIf = function (content, condition) {
var t = $(this), c = (typeof condition === 'function' ? condition(t) : condition);
if ((typeof c === 'boolean' ? c : true) === true) {
t.append(content);
}
return t;
};
$.fn.rwText = function (text, addtitle, options) {
var tgt = $(this).empty();
options = $.extend({ wrap: true }, options);
var sa = Array.isArray(text) === true ? text : (text || '').split('\n');
$.each(sa, function (ti, tx) {
if ((tx || '') !== '') {
if (ti > 0) {
tgt.append($$.br());
}
tgt.append(options.wrap === true ? $$.s(tx) : tx);
}
});
if (addtitle || false) { tgt.attr('title', addtitle); }
return tgt;
};
$.fn.loadSel = function (url, data, complete) {
if ($(this).prop('tagName').toUpperCase() === 'SELECT') {
var sel = $(this);
$ocms.postXT.call(this, {
url: url, data: data || {}, success: function (response) {
$.each(response, function () {
sel.append($$.opt(response.value, response.text));
});
}, complete: function () {
sel.ldng(0);
if (typeof complete === 'function') {
complete.call(sel);
}
}
});
}
};
$.fn.emptyWithEditors = function (parent) {
var t = $(this);
t.find(':input.tinymce').each(function (ei, ex) {
try {
var te = tinymce.get($(ex).attr('id'));
if (te) { te.remove(); }
} catch (ee) {
$.noop();
}
});
return t.empty();
};
$.fn.cssValue = function (styleName) {
if (this.length > 0) {
var cv = this.css(styleName) || '';
if (cv === '') {
return 0;
} else {
var v, r = (/(^[\d\.]*)(\D{1,3}$)/ig).exec(cv);
if (r !== null) {
switch (r[2]) {
case 'rem':
return $ocms.rpx(parseFloat(r[1]));
default:
return parseFloat(r[1]);
}
} else if (isNaN(cv) === false) {
return parseFloat(cv)
} else { return 0; }
}
} else { return 0; }
};
/* @description: gets very inner height excluding borders and padding */
$.fn.veryInnerHeight = function () {
let c = (p) => $(this).cssValue(p);
return ($(this).innerHeight() - c('padding-top') - c('padding-bottom'));
};
/* @description: gets very inner width excluding borders and padding */
$.fn.veryInnerWidth = function () {
let c = (p) => $(this).cssValue(p);
return ($(this).innerWidth() - c('padding-left') - c('padding-right'));
};
$.fn.marginWidth = function() {
let c = (p) => $(this).cssValue(p);
return (c('margin-left') + c('margin-right'));
};
$.fn.marginHeight = function () {
let c = (p) => $(this).cssValue(p);
return (c('margin-top') + c('margin-bottom'));
};
$.inArrayRegEx = function (search, array, start) {
var regex = (($.type(search) === 'regexp') ? search : (new RegExp(search)));
if (!array) return -1;
start = start || 0;
for (var i = start; i < array.length; i++) {
if (regex.test(array[i])) {
return i;
}
}
return -1;
};
/* @Desciption: Programmatically Lighten or Darken a hex color (or rgb, and blend colors)
* @author: Pimp Trizkit
* @source: internet http://stackoverflow.com/a/13542669
*
* usage:
* var color1 = "#FF343B";
* var color2 = "#343BFF";
* var color3 = "rgb(234,47,120)";
* var color4 = "rgb(120,99,248)";
* var shadedcolor1 = shadeBlend(0.75,color1);
* var shadedcolor3 = shadeBlend(-0.5,color3);
* var blendedcolor1 = shadeBlend(0.333,color1,color2);
* var blendedcolor34 = shadeBlend(-0.8,color3,color4); // Same as using 0.8
*/
$.shadeBlend = function (p, c0, c1) {
var n = p < 0 ? p * -1 : p, u = Math.round, w = parseInt;
var f, t;
if (c0.length > 7) {
f = c0.split(',');
t = (c1 ? c1 : p < 0 ? 'rgb(0,0,0)' : 'rgb(255,255,255)').split(',');
var R = w(f[0].slice(4)), G = w(f[1]), B = w(f[2]);
return 'rgb(' + (u((w(t[0].slice(4)) - R) * n) + R) + ',' + (u((w(t[1]) - G) * n) + G) + ',' + (u((w(t[2]) - B) * n) + B) + ')';
} else {
f = w(c0.slice(1), 16);
t = w((c1 ? c1 : p < 0 ? '#000000' : '#FFFFFF').slice(1), 16);
var R1 = f >> 16, G1 = f >> 8 & 0x00FF, B1 = f & 0x0000FF;
return '#' + (0x1000000 + (u(((t >> 16) - R1) * n) + R1) * 0x10000 + (u(((t >> 8 & 0x00FF) - G1) * n) + G1) * 0x100 + (u(((t & 0x0000FF) - B1) * n) + B1)).toString(16).slice(1);
}
};
$.fn.IN = function (complete) {
$(this).fadeIn(400, complete);
return $(this);
};
$.fn.OUT = function (complete) {
$(this).fadeOut(400, complete);
return $(this);
};
$.fn.tooltip = function (mouse, tree) {
var target = (typeof mouse === 'boolean' ? mouse : false) === true ? 'mouse' : false;
var cascade = typeof tree === 'boolean' ? tree : false;
var t = $(this);
t.each(function () {
var elem = cascade ? $(this).find('.tooltiptext') : $(this).children('.tooltiptext');
if ($(elem).length > 0) {
elem.each(function () {
var e = $(this), p = $(this).filter(':not(:empty)').parent();
p.qtip({
suppress: false,
content: {
text: e.clone()
},
position: {
target: target,
adjust: { x: 2, y: 2 },
viewport: true
},
events: {
hidden: $ocms.tooltip_hidden
}, show: { effect: false }, hide: { effect: false }
});
e.remove()
});
} else {
$(this).qtip({
position: {
target: target,
adjust: { x: 2, y: 2 },
viewport: true
},
events: {
hidden: $ocms.tooltip_hidden
}, effect: false
});
}
});
return t;
};
$.fn.rC = function (arg) {
return $(this).removeClass(arg);
};
$.fn.aC = function (arg) {
return $(this).addClass(arg);
};
$.fn.tC = function (arg, state) {
return $(this).toggleClass(arg, state);
};
})(jQuery);
function $lf(vis) {
var ts = typeof vis === 'undefined' ? null : ((typeof vis === 'number' && vis !== 1) || (typeof cl === 'boolean' && vis === false));
return $('#listframe').tC('hd', ts).is('.hd');
};
function $nuf(e) {
if (e) { e.stopPropagation(); }
if ($(this).is('.disabled')) {
return;
}
/* close any nav */
var f = function (nav) { nav.removeClass('vis').find('li.dropdown').removeClass('open').removeClass('vis').attr('aria-expanded', 'false'); }
var p = $(this).parent('li.dropdown');
if (p.length > 0) {
p.tC('open'), navs = p.is('.open') === true ? 'true' : 'false';
p.attr('aria-expanded', navs);
/* close any other branch */
var thisnav = p.closest('nav');
thisnav.find('li.dropdown').not(p.parentsUntil('nav')).not(p).removeClass('open').attr('aria-expanded', 'false');
if (p.is('.open') === false) {
p.find('li.dropdown').removeClass('open').attr('aria-expanded', 'false');
}
f($('nav').not(thisnav));
} else {
f($('nav'));
}
};
function $tbr() {
$lf(0);
return $('#topbar').ocmsmenu([]);
};
//function $sbr(empty) {
// return $('#sidebar').ocmsmenu([], empty);
//};
function $lfr() {
$('#sidebar').empty();
return $('#listframe').removeClass('fix').addClass('hd').empty();
};
function $cfr() {
$tbr();
return $('#contentframe').empty();
};
function jObj(jsstr, key) {
let jo = {};
if ((jsstr || '').substr(0, 1) === '{') {
try {
jo = JSON.parse(jsstr);
} catch (e) {
jo = {};
}
}
return jo[key] || '';
};
(function ($) {
$.fn.ocmsmenu = function (menu, empty) {
var tgt = $(this);
$ocms.menu.call(tgt, menu, empty);
return tgt;
};
$.fn.activatemenu = function () {
var tgt = $(this).filter('nav');
tgt.find('a').not('.on').addClass('on').click($nuf);
tgt.find('.nav-btn').not('.on').addClass('on').click(function (e) {
e.stopPropagation();
var t = $(this); $(t.attr('data-target')).tC(t.attr('data-toggle'));
});
return tgt;
};
})(jQuery);
function string(inp, vals) {
var ret = inp || '', rx;
$.each(vals || [], function (vi, vx) {
rx = new RegExp('\\{' + vi.toString() + '\\}', 'ig');
ret = ret.replace(rx, vx);
});
return ret;
};
function init_tooltip(mouse) {
var target = (typeof mouse === 'boolean' ? mouse : false) === true ? 'mouse' : false;
$('[title]').qtip({
position: {
target: target,
adjust: { x: 2, y: 2 },
viewport: true
},
events: {
hidden: $ocms.tooltip_hidden
}, effect: false
});
$('div.tooltiptext').each(function () {
var p = $(this).filter(':not(:empty)').parent();
p.qtip({
suppress: false,
content: {
text: $(this).clone()
},
position: {
target: target,
adjust: { x: 2, y: 2 },
viewport: true
},
events: {
hidden: $ocms.tooltip_hidden
}
});
});
}
class ObjectArray extends Array {
/**
* Get whether the Array is empty
* */
isEmpty() {
return this[0].length === 0;
}
// built-in methods will use this as the constructor
static get [Symbol.species]() {
return Array;
}
/**
* returns a new new array of items where function applied to currentvalue returns true
* @param {function(currentValue[, index[, array]])} fnc
*/
filter(fnc) {
if (typeof fnc === 'function') {
return new ObjectArray(this[0].filter(fnc));
} else {
return this;
}
}
/**
* removes items where function applied to currentvalue is true
* changes the ObjectArray itself and returns it
* @param {function(currentValue[, index[, array]])} fnc
*/
remove(fnc) {
if (typeof fnc === 'function') {
let i = this[0].findIndex(fnc);
while (i > -1) {
this[0].splice(i);
i = this[0].findIndex(fnc);
};
} else {
return this;
}
}
/**
* sorts the ObjectArray using the Array.sort function and returns it
* @param {function(element)} fnc
*/
sortBy(fnc) {
if (typeof fnc === 'function') {
this[0].sort(fnc);
}
return this;
}
/**
* sorts the ObjectArray using the Array.sort function and String.localeCompare function and returns it
* The compared strings are converted to upper case to make function case-insensitive
* undefined values are treated as empty strings
* @param {string} property
*/
sortString(property) {
this[0].sort((a, b) => {
let nameA = (a[property] || '').toString().toUpperCase(); // ignore upper and lowercase
let nameB = (b[property] || '').toString().toUpperCase(); // ignore upper and lowercase
console.debug(nameA.localeCompare(nameB));
return nameA.localeCompare(nameB);
});
return this;
}
/**
* sorts the ObjectArray using the Array.sort function and value comparison and returns it
* empty or non-numeric values are identified by isNaN and put to End of array
* @param {string} property
*/
sortNum(property) {
this[0].sort((a, b) => {
let nameA = a[property], nameB = b[property];
if ((isNaN(nameB) === true && isNaN(nameA) === false) || nameA < nameB) {
return -1;
} else if ((isNaN(nameB) === false && isNaN(nameA) === true) || nameA > nameB) {
return 1;
} else {
// names must be equal
return 0;
}
});
return this;
}
/**
* sums the value of the objects parameter, if value is valid number
* @param {string} property
*/
sum(property) {
return this[0].reduce((accumulator, currentValue) => accumulator + (isNaN(currentValue[property]) === true ? 0 : currentValue[property]), 0)
}
/**
* returns new object with array by named property value
* @param {string} property
*/
groupBy(property) {
return this[0].reduce(function (acc, obj) {
let key = obj[property];
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(obj);
return acc;
}, {});
}
/**
*
* @param {function(value, index, array)} fnc
*/
each(fnc) {
if (typeof fnc === 'function') {
let stop = false;
this[0].forEach((value, index, array) =>{
if (stop === false) {
let r = fnc(value, index, array);
if (typeof r === 'boolean' && r === false) {
stop = true;
}
}
});
}
}
get toArray() {
return this[0];
}
}
class NumArray extends Array {
sum() {
return this.reduce((accumulator, currentValue) => accumulator + currentValue);
};
first() {
return this[0];
};
last() {
return this[this.length - 1];
};
average() {
return this.sum() / this.length;
};
range() {
let self = this.map(x => x).sort(); /* do not change original */
return {
min: self[0],
max: self[this.length - 1]
}
};
// built-in methods will use this as the constructor
static get [Symbol.species]() {
return Array;
}
}
(function () {
$ocms.ocmsmenu = [
{ lbl: '', id: 'm_home', ico: 'glyphicon glyphicon-home', fnc: 'init:home' }
, { fnc: 'separator' }
//, { fnc: 'separator' }
//, { lbl: $t.m_efa, id: 'm_efa', fnc: 'init:efa' }
];
})();
(function ($ocms) {
$ocms.multline = function (txt) {
let s = txt.split('\n'), div = $$.d();
$.each(s, (si, sx) => {
div.append($$.s(sx));
});
return div.html();
};
$ocms.tooltip_hidden = function (event, api) {
/*console.log('%o', [event, api, this]);*/
$(this).remove();
api.rendered = false;
};
$ocms.isDateString = function (inp) {
if (typeof inp !== 'string') { return false; } else {
return isNaN(new Date(inp)) === false;
}
}
$ocms.failure = function (jqXHR) {
if ((jqXHR.internalCode || -1) === 11110) { /* not authenticated */
$ocms.login.dlg();
} else {
alert($t.f1 + '\n' + (jqXHR.internalText || ''));
}
}
$ocms.getScript = function (def, success) {
var cu = [], su = [], validstring = function (obj) { return (typeof obj === 'string' && (obj || '') !== ''); }, adddef = function (di, dx) {
if (bool(dx.condition, true) === true) {
if ((dx.script || '') !== '') {
su.push({ url: dx.script, module: dx.module || '' });
}
if (validstring(dx.css || '') === true) {
cu.push(dx.css);
} else if (Array.isArray(dx.css) === true) {
Array.prototype.push.apply(cu, dx.css.filter(validstring));
}
}
};
if (validstring(def || '') === true) {
su.push(def);
} else if (Array.isArray(def) === true) {
$.each(def, adddef);
} else if (typeof def === 'object' && (def.script || '') !== '') {
adddef(0, def);
}
let cssarray = [];
$.each(cu, function (ci, cui) {
if ((cui || '') !== '') {
cssarray.push(loadCSS(cui));
}
});
let spa = su.map(
function (sx, si) {
let url = sx.url, mdl = sx.module || '';
if (mdl === '') {
let p = new Promise(function (resolve, reject) {
try {
(async function () {
$.ajax({
url: url,
dataType: 'script',
success: function () { resolve(su); }, error: function () { reject(su) }, timeout: 30000
});
})();
} catch (e) {
console.debug(e.message + '%o', e);
}
});
return p;
} else {
let p = $ocms.loadmodule(mdl, url, sx.alias);
return p;
}
});
Promise.all(spa).then(success);
};
$ocms.loadmodule = function (module, url, alias) {
let p = new Promise(function (resolve, reject) {
(async function () {
try {
let url2 = (url.startsWith('/') || url.startsWith('.') ? '' : '/') + url;
import(url2).then(x => { $ocms[module] = x[alias ||'default']; resolve(module); }).catch(e2 => { console.debug(e2.message + '%o', e2); reject(module); });
} catch (e) {
console.debug(e.message + '%o', e);
}
})()
});
return p
};
$ocms.ocms_auth = function (module, min, person_guid, fnc) {
var r = false;
if ($.isPlainObject($ocms.auth.modules) === false) { $ocms.auth.modules = {}; }
var ma = 0;
if ($ocms.auth.modules[module + (person_guid || '')] || false) {
ma = $ocms.auth.modules[module + (person_guid || '')];
if (ma < 2 && (person_guid || '') === auth.guid) {
ma = 2;
}
if (ma >= (min || 0)) { fnc(r); };
} else {
$ocms.postXT({
url: $ocms.url('auth'), data: { module: module, person_guid: (person_guid || '') }, success: function (res) {
ma = res[module];
$ocms.auth.modules[module + (person_guid || '')] = ma;
if (ma < 2 && (person_guid || '') === $ocms.auth.person_guid) {
ma = 2;
}
if (ma >= (min || 0)) { fnc(r); };
}, error: function (jqXHR) {
$ocms.failure.call(this, jqXHR);
}
});
}
};
$ocms.auth.locale = 'de';
$ocms.ocms_prepauth = function (modules, person_guid, fnc) {
$ocms.postXT({
url: $ocms.url('auth'), data: { fn: 'csv', modules: modules, person_guid: (person_guid || '') }, success: function (res) {
$ocms.ocms_regauth(res);
}, error: function (jqXHR) {
$ocms.failure.call(this, jqXHR);
}, complete: function () { fnc(); }
});
};
$ocms.ocms_regauth = function (object) {
$.each(object || {}, function (module, res) { auth.modules[module] = parseInt(res); });
};
$ocms.init = function (ev) {
var mdl = typeof ev === 'string' ? ev : ((ev.data || {}).fn || '');
if (mdl === '') {
return;
} else if (mdl === 'home') {
$cfr(); $lfr();
$('#topbar').ocmsmenu([], true);
$('#activemodule').text($t.ov);
$ocms.ov.call($('#contentframe'));
} else {
$cfr(); $lfr();
$('#topbar').ocmsmenu([]);
$ocms.postXT({
url: $ocms.url(mdl + '/auth'), success: function (auth) {
if (typeof $ocms[mdl] === 'undefined') {
$ocms[mdl] = {};
}
$ocms[mdl].auth = auth;
if (auth.manage > 0) {
$ocms.getScript({
module: mdl, script: ['web/imdl', mdl, $ocms.auth.locale || 'de', 'js'].join('.'), css: ['web/imdl', mdl, 'css'].join('.'), condition: typeof $ocms[mdl].init2 !== 'function' }, function () { $ocms[mdl].init2(); });
}
}, error: function () {
$('#contentframe').empty();
}
});
}
};
$ocms.menuarray = function (itm) {
this.array = [];
this.sep = function () {
if (this.length > 0 && this.array[array.length - 1].fnc !== 'separator') {
this.push({ fnc: 'separator' });
}
};
this.push = function (newitm) {
if (typeof newitm === 'undefined') {
return null;
} else if (Array.isArray(newitm) === true) {
Array.prototype.push.apply(this.array, newitm);
} else if (typeof newitm === 'object') {
this.array.push(newitm);
}
return newitm;
};
this.unshift = function (newitm) {
if (typeof newitm === 'undefined') {
return null;
} else if (Array.isArray(newitm) === true) {
Array.prototype.unshift.apply(this.array, newitm);
} else if (typeof newitm === 'object') {
this.array.unshift(newitm);
}
return newitm;
};
this.push(itm);
};
$ocms.menu = function (menu, empty) {
/*
* create menu based on definition in form of [ { id: '', lbl: '', ico: '', fnc: function() { }, itm: [ ], data: {} } ]
*/
menu = menu || [];
var bar = $(this).removeClass('vis');
if (bool(empty, true) === true && bar.is('#mainmenu') === false) { bar.empty(); }
if (bool(empty, false) === false && bar.is('#sidebar,#topbar')) { menu.unshift({ id: 'sbctrl', glyph: 'glyphicon-th-list', aclass: 'fbtn', fnc: function () { $lf(); } }); $lf(0); }
if ((menu || []).length === 0) {
bar.empty().addClass('hd');
} else {
bar.removeClass('hd');
var nav = bar.is('nav') === true ? bar : bar.children('nav');
if (nav.length !== 1) {
nav = $('<nav></nav>').tC('nv', bar.is('#sidebar')).tC('ctxt', bar.is('#topbar')).appendTo(bar);
}
var nul = $$.ul().appendTo(nav);
var subi, subm = function (la, ix) {
var li = $(this).addClass('dropdown submenu');
la.append($$.sc('caret dd')).addClass('dds dropdown-toggle').attr({ 'aria-expanded': 'false' });
if ((ix.ico || '') !== '') { la.prepend($$.sc('ico ' + ix.ico)); }
var lul = $$.ul({ class: 'dropdown-menu', role: 'menu' }).appendTo(li);
$.each(ix.itm || [], function (mi, mx) {
subi.call(lul, mx);
});
};
var dis = function (ix) {
$(this).tC('disabled', (typeof ix.disabled === 'boolean' ? ix.disabled : (typeof ix.disabled === 'string' && ix.disabled === 'subs' && (ix.itm || []).length === 0 ? true : false)))
};
subi = function (mx) {
var ml = $$.li({ id: mx.id }).attr(mx.attr || {}).addClass(mx.lclass).appendTo($(this)), ma, role = (typeof mx.fnc === 'string' && mx.fnc !== '') ? mx.fnc.split(':')[0] : '';
if (role !== '' && role !== 'init') {
ml.attr('role', role).appendIf($$.s(mx.lbl), ne(mx.lbl) !== '');
} else {
ma = $$.a({ class: 'on', role: 'button' }).addClass(mx.aclass).appendTo(ml).append($$.s(mx.lbl));
dis.call(ma, mx);
if ((mx.itm || []).length > 0) {
subm.call(ml, ma, mx);
}
ma.click($nuf);
if (typeof mx.fnc === 'function') {
ma.click(mx.data || {}, mx.fnc);
} else if (role === 'init') {
ma.click($.extend({}, mx.data || {}, { fn: mx.fnc.split(':')[1] }), $ocms.init);
}
}
};
$.each(menu, function (ii, ix) {
var li = $$.li({ id: ix.id }).attr(ix.attr || {}).addClass(ix.lclass), la, role = (typeof ix.fnc === 'string' && ix.fnc !== '') ? ix.fnc.split(':')[0] : '';
if (role !== '' && role !== 'init') {
li.attr('role', role).appendIf($$.s(ix.lbl), ne(ix.lbl) !== '');
} else {
la = $$.a({ class: 'on', role: 'button' }).addClass(ix.aclass).appendTo(li);
dis.call(la, ix);
if ((ix.lbl || '') !== '') { la.append($$.s(ix.lbl)); }
if ((ix.ico || '') !== '') { la.prepend($$.sc('ico ' + ix.ico)); }
if ((ix.glyph || '') !== '') { la.prepend($$.sc('glyphicon ' + ix.glyph)); }
if ((ix.itm || []).length > 0) {
li.addClass('dropdown');
la.append($$.sc('caret dd')).addClass('dds dropdown-toggle').attr({ 'aria-expanded': 'false' });
var lul = $$.ul({ class: 'dropdown-menu', role: 'menu' }).appendTo(li);
$.each(ix.itm || [], function (mi, mx) {
subi.call(lul, mx);
});
}
if ((ix.sel || []).length > 0) {
} else {
la.click($nuf);
if (typeof ix.fnc === 'function') {
la.click(ix.data || {}, ix.fnc);
} else if (role === 'init') {
la.click($.extend({}, ix.data || {}, { fn: ix.fnc.split(':')[1] }), $ocms.init);
}
}
}
li.appendTo(nul);
});
nav.activatemenu();
}
};
/* DIALOGS & POPUPS ********************************************************************************************************************************/
$ocms.easytbl = (array, options) => {
options = options || {};
let tbl = $$.tbl().addClass(options.class).css('border-collapse', 'collapse'), bdy = $$.tbody(tbl), basecss = (bool(options.frame, false) === true) ? { padding: '5px', border: '1px solid #727272' } : {};
if (Array.isArray(options.header) === true) {
let hd = $$.thead(tbl);
$.each(options.header, (hi, hx) => $$.th(hd).css(options.cellcss || basecss).rwText(hx));
} else if (bool(options.header, false) === true && (array || []).length > 0) {
let hd = $$.thead(tbl);
$.each(Object.keys(array[0]), (hi, hx) => $$.th(hd).css(options.cellcss || basecss).rwText(hx));
}
$.each(array || [], (ai, ax) => {
let tr = $$.tr();
$.each(ax, (bi, bx) => {
bx = bx || '';
let td = $$.td(tr).css(options.cellcss || basecss);
if (bx instanceof jQuery) {
td.append(bx);
} else if (typeof bx === 'string') {
if (bx.substring(0, 1) === '<') {
td.append(bx);
} else { td.text(bx); }
}
});
tbl.append(tr);
});
return tbl;
};
$ocms.dlgtbl = (array, title, options) => {
options = options || {};
let tbl = $ocms.easytbl(array, options)
$ocms.dlg(tbl, $.extend({ title: title }, options));
};
$ocms.dlg = function (content, options) {
options = options || {}
let mexist = $('body > .modal').length > 0;
let t = (n) => typeof options[n], f = (n) => t(n) === 'function';
if (bool(options.exclusive, true) === true && mexist === true) {
alert($t.dbldlg || 'Es ist bereits ein Dialog geöffnet');
return;
}
let modal = $$.dc('modal', $('body')), dlg = $$.dc('modal-dialog', modal);
if (isNaN(options.zindex) === false) {
modal.css('zIndex', options.zindex);
} else if (mexist === true) {
modal.css('zIndex', parseInt($('body > .modal:last').cssValue('zIndex')) + 200);
}
if (isNaN(options.zindex_min) === false) {
if (modal.cssValue('zIndex') < options.zindex_min) {
modal.css('zIndex', options.zindex_min);
}
}
if (t('size') === 'string') {
dlg.addClass('sz' + ne(options.size));
} else if (Array.isArray(options.size)) {
dlg.css('height', (options.size[0] || -1) < 0 ? null : options.size[0].toString() + 'px');
dlg.css('width', (options.size[1] || -1) < 0 ? null : options.size[1].toString() + 'px');
}
let clbtn = $$.dc('modal-close').appendTo(dlg), ct = $$.dc('modal-content', dlg);
let c = ct, hd, isform = bool(options.form, false);
if (isform === true) { /* squeeze in a form */
c = $('<form role="form"></form>').appendTo(c);
}
if (ne(options.title) !== '') {
hd = $$.dc('modal-header', c);
$('<h3></h3>').text(options.title).appendTo(hd);
}
let bdy = $$.dc('modal-body', c), ft = $$.dc('modal-footer', c);
if ((content instanceof jQuery) === true) {
bdy.append(content);
}
let close = function (be) {
if (!!be && typeof be.stopPropagation === 'function') {
be.stopPropagation();
}
dlg.removeClass('in');
if (f('closing')===true) {
options.closing.call(c);
}
bdy.hide().emptyWithEditors();
modal.remove();
if (f('close') === true) {
options.close.call(c);
}
};
if (c.find(':input[required]').length > 0) {
$$.dc('note_required', ft).append($$.sc('ind_required', '*')).append($$.s($t.t1 || 'Eingabe erforderlich'));
$$.dc('note_invalid', ft).append($$.s($t.t2 || 'Bitte überprüfen Sie Ihre Eingaben im Formular.'));
}
if (f('cancel') === true) {
let ccb = $$.bbtn(options.cancelbutton || 'Abbrechen', 'cancel').attr({ type: 'button', role: 'cancel' }).appendTo(ft);
ccb.click(function (e) {
var r = options.cancel.call(c, e);
e.stopPropagation();
close();
});
}
if (f('confirm') === true) {
let cfb = $$.bbtn(options.button || 'OK', 'confirm').attr({ type: bool(options.form, false) === true ? 'submit' : 'button', role: 'confirm' }).appendTo(ft);
if (isform === true) {
c.submit(function (e) {
try {
var r = options.confirm.call(c, e);
} finally {
e.preventDefault();
}
return false;
});
c.on('modal_submit', function () {
var r = options.confirm.call(c, e);
});
} else {
cfb.click(function (e) {
var r = options.confirm.call(c, e);
e.stopPropagation();
});
c.on('modal_submit', function () {
cfb.click()
});
}
} else if (isform === true) {
c.submit(function (e) { e.preventDefault(); return false; });
}
c.on('modal_close', function () {
close();
});
clbtn.click(close);
if (f('opening') === true) {
options.opening.call(c);
}
dlg.addClass('in');
if (ne(options.mode).indexOf('maxbody') > -1) {
bdy.css('min-height', (ct.height() - hd.outerHeight() - ft.outerHeight()).toString() + 'px');
}
if (f('open') === true) {
options.open.call(c);
}
return { hd: hd, bdy: bdy, ft: ft, ct: ct, dlg: dlg, c: c };
};
$ocms.mform = function (fields) { /* modal form */
let fb = $$.dc('form-body');
let flds = Array.isArray(fields) ? fields : (fields instanceof fields_definition ? fields.fields : []);
/* EXAMPLE !!
var flds = [
{ name: 'userinfo', label: $t.l1, type: 'string', value: $ocms.auth.login, change: $ocms.login.uichange, required: true },
{ name: 'userlogin', type: 'hidden', required: true, value: $ocms.auth.login },
{ name: 'username', type: 'string', label: $t.l4, required: true, readonly: true, placeholder: $t.l5, value: $ocms.auth.fullname_rev },
{ name: 'userpass', type: 'password', label: $t.l3, required: true, placeholder: $t.l3 },
];
*/
$.each(flds || [], function (ff, f) {
let ftyp = f.type || '';
if (ftyp === 'ignore') {
return true;
}
let fg = $$.dc('form-group', fb), id = f.id || 'dlg_' + (f.name || '') + (f.type === 'html' ? '_' + (((1 + Math.random()) * 0x10000) || 0).toString(16).substr(9) : '');
let lbl = $$.lbl(f.label || f.name, { for: id }).appendTo($$.dc('form-itm', fg));
let fi = $$.dc('form-itm', fg), inp = $$.i({ id: id, name: f.name, placeholder: f.placeholder, type: f.type });
switch (ftyp) {
case 'email':
f.pattern = ne(f.pattern, '[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$');
break;
case 'url':
f.pattern = ne(f.pattern, 'https?://.+');
break;
case 'number':
f.pattern = ne(f.pattern, '[-+]?[0-9]*[.,]?[0-9]*');
inp.attr('step', f.precision || 'any');
inp.attr('data-format', 'float');
break;
case 'integer':
case 'int':
f.pattern = ne(f.pattern, '[-+]?[0-9]*');
inp.attr('type', 'number');
inp.attr('data-format', 'integer');
break;
case 'date':
var dbp = '|([0-9]{4}.(0[1-9]|1[012]).(0[1-9]|1[0-9]|2[0-9]|3[01]))'
if (ne(f.pattern, $t.datepattern) !== '') {
f.pattern = ne(f.pattern, '(' + $t.datepattern + ')' + dbp);
}
if (ne(f.placeholder, $t.dateplaceholder) !== '') {
inp.attr('placeholder', ne(f.placeholder, $t.dateplaceholder))
}
if (typeof f.value === 'string') {
var dtv = f.value.substr(0, 10);
f.value = inp.prop('type') !== 'date' ? fdt(dtv + 'T00:00:00', ne(f.dateformat, $t.dateformat)) : dtv;
}
inp.attr('data-format', 'date:' + ne(f.dateformat, $t.dateformat) + ';yyyy-MM-dd'); /* alternative format, bc some browsers internally use english standard */
break;
case 'datetime':
var dtbp = '|([0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])\\s([0-5][0-9]):([0-5][0-9]))'
inp.attr('type', 'datetime-local');
if (ne(f.pattern, $t.datetimepattern) !== '') {
f.pattern = ne(f.pattern, '(' + $t.datetimepattern + ')' + dtbp);
}
if (ne(f.placeholder, $t.datetimeplaceholder) !== '') {
inp.attr('placeholder', ne(f.placeholder, $t.datetimeplaceholder))
}
if (typeof f.value === 'string' && f.value.substr(10, 1) === 'T') {
f.value = inp.prop('type').substr(0, 8) !== 'datetime' ? fdt(f.value, ne(f.datetimeformat, $t.datetimeformat)) : f.value;
}
inp.attr('data-format', 'datetime:' + ne(f.datetimeformat, $t.datetimeformat) + ';yyyy-MM-dd HH:mm:ss'); /* alternative format, bc some browsers internally use english standard */
break;
case 'hidden':
fg.addClass('hd');
break;
case 'html': /* dropthrough by intention */
case 'text':
inp = $$.txt({ id: id, name: f.name, placeholder: f.placeholder, type: f.type });
inp.tC('tinymce', f.type === 'html');
break;
case 'bool': /* dropthrough by intention */
case 'boolean':
f.url = [
{ value: 'true', label: ($t || {}).true || 'Yes' },
{ value: 'false', label: ($t || {}).false || 'No' }
];
if (typeof f.value === 'boolean') {
f.value = f.value ? 'true' : 'false';
} /* dropthrough by intention */
case 'select':
inp = $$.sel({ id: id, name: f.name, type: f.type });
if (bool(f.required, false) === false) {
$$.eOpt().appendTo(inp);
}
try {
var ffo = function (opt) {
if (Array.isArray(opt) === true) {
$.each(opt, function (oi, ox) {
if (typeof ox === 'string') {
$$.opt(ox, ox).appendTo(inp);
} else if (Array.isArray(ox) === true) {
$$.opt(ox[0], ox[1]).appendTo(inp);
} else if (typeof ox === 'object') {
$$.opt(ox.value, ox.label || ox.text).appendTo(inp);
}
});
}
}
if (Array.isArray(f.url) === true) {
ffo(f.url);
} else if (typeof f.url === 'function') {
f.url.call(inp);
} else if (typeof f.url === 'string') {
$ocms.postXT({
url: f.url, success: ffo
});
}
} catch (eo) {
$.noop();
}
break;
default:
if (ne(f['max-length']) !== '') { inp.attr('max-length', f['max-length']); }
}
if (ne(f.pattern) !== '') { inp.attr('pattern', f.pattern); }
inp.val(f.value).change();
inp.change(function () { $(this)[0].setCustomValidity(''); }); /* reset invalidity state on change */
inp.addClass('form-control').prop('required', bool(f.required, false)).prop('readonly', bool(f.readonly, false)).appendTo(fi); /* not too early so that inp can be replaced */
if (bool(f.required, false) === true) { lbl.append($$.sc('ind_required', '*')); }
if (typeof f.attr === 'object') { inp.attr(f.attr); }
if (typeof f.prop === 'object') { inp.prop(f.prop); }
if (typeof f.class === 'string') { inp.addClass(f.class); }
if (typeof f.change === 'function') {
inp.change(f.change);
if (bool(f.applychange, false) === true && typeof f.value !== 'undefined') {
inp.change();
}
}
if ((f.note || '') !== '') {
$$.dc('form-note', fi).rwText(f.note);
}
if (typeof f.complete === 'function') {
f.complete.call(inp);
}
});
//let tinys = fb.find('.tinymce');
//if (tinys.length > 0) {
// pa = [new Promise((resolve, reject) => {
// $ocms.initMCE(tinys);
// resolve();
// })];
// await Promise.all(pa);
//}
return fb;
};
$ocms.initMCE = function (tgt, options) {
//if ($vm.nl.option_individualized) { $vm.nl.nkit_custMCE_plugins.push('nkit_vm_variables'); }
tgt = $(tgt);
options = options || {};
try {
let sets = {
target: tgt[0],
inline: false,
width: options.width || '100%',
statusbar: false,
//valid_children: '+p[ph]',
//custom_elements: 'ph',
//extended_valid_elements: 'span[class,style,title],div[class,style,title]',
document_base_url: window.location.origin + '/',
//file_picker_callback: function (callback, value, meta) {
// if (meta.filetype === 'image') {
// $nkit.imageFilePicker(callback, value, meta);
// }
//},
content_style: 'ph:before {content: \'«\'; color: #BBB; font-style:italic; } ph:after {content: \'»\'; color: #BBB; font-style:italic; } ph { color: #AAA; font-style:italic; }',
relative_urls: false,
remove_script_host: false,
//plugins: ($nkit.nkit_custMCE_plugins || []).join(' ')
};
if (bool(options.hidemenu, false) === true) {
sets.menubar = false;
sets.menu = {};
}
if (bool(options.hidetoolbar, false) === true) {
sets.toolbar = false
}
$.extend(sets, options || {}); /* merge options into settings -> allows to overwrite these defaults */
tinymce.init(sets);
} catch (e) {
alert(e.message);
}
};
$ocms.dlgform = function (flds, options) {
options = options || {};
let gf1 = $$.dc('frm').append($ocms.mform(flds || []).addClass('stacked'));
if (options.addcontent instanceof jQuery) { gf1.append(options.addcontent); }
let cfm;
if (typeof options.submit === 'function') {
cfm = options.submit;
} else if (typeof options.success === 'function') {
cfm = function (e) {
var c = $(this).ldng(1);
var qs = $.extend({ loginaccount: $ocms.auth.account || '' }, c.serializeObject(bool(options.checkvalidity, true), { typedvalues: bool(options.typedvalues, false) }));
if ((options.url || '') !== ''){
$ocms.postXT({
url: options.url, data: qs, success: function (response) {
options.success.call(this, response);
c.trigger('modal_close');
}, error: function () {
alert($t.l17);
}, complete: function () {
c.ldng(0);
}, timeout: 60000
});
} else {
options.success.call(this, qs);
c.trigger('modal_close');
}
};
}
let opt = {
form: true, title: options.title || '', button: options.button || $t.submit, confirm: cfm, size: options.size || [500, 600], open: function () {
let c = $(this);
let tinys = c.find('.tinymce');
if (tinys.length > 0) {
$ocms.initMCE(tinys, options.tinymce || {});
}
}
};
let d = $ocms.dlg.call(this, gf1, opt);
return d;
};
$ocms.login.dlg = function (options) {
options = options || {};
let flds = [
{ name: 'userinfo', label: $t.l1, type: 'string', value: $ocms.auth.login, change: $ocms.login.uichange, required: true },
{ name: 'userlogin', type: 'hidden', required: true, value: $ocms.auth.login },
{ name: 'username', type: 'string', label: $t.l4, required: true, readonly: true, placeholder: $t.l5, value: $ocms.auth.fullname_rev },
{ name: 'userpass', type: 'password', label: $t.l3, required: true, placeholder: $t.l3 },
];
if (($ocms.auth.account || '') === '') {
flds.unshift({ id: 'dlg_loginaccount', name: 'loginaccount', type: 'string', required: true, value: $ocms.auth.account });
}
let gf1 = $$.dc('frm').append($ocms.mform(flds).addClass('stacked'));
let f_submit = function (e) {
var c = $(this).ldng(1);
var qs = $.extend({ loginaccount: $ocms.auth.account || '' }, c.serializeObject());
$ocms.postXT({
url: '/vt/login', data: qs, success: function (response) {
if (((response || {}).login || '') !== '') {
c.trigger('modal_close');
$ocms.auth = response;
/* try to resend the rejected post*/
if (typeof options.ajo === 'object') {
options.ajo.islogin === true; /* prevent loop */
$.ajax(options.ajo);
}
}
}, error: function () {
alert($t.l17);
}, complete: function () {
c.ldng(0);
}, timeout: 60000
});
};
let d = $ocms.dlg.call(this, gf1, { form: true, title: $t.l0, button: $t.submit, confirm: f_submit, size: [500, 600] });
let ah = $$.dc('modal-content').css('height', 'auto').attr('novalidate', 'true').append($$.dc('modal-header').appendIf($('<h2></h2>').text($ocms.auth.accountname), ($ocms.auth.accountname || '') !== '').append($('<h3>Vereinsmanager</h3>')));
d.dlg.prepend(ah);
};
$ocms.addNoEntryInfo = function (txt) {
$(this).append($$.dc('noentryinfo').text(txt || $t.t11));
};
})($ocms);
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
Element.prototype.closest = function (s) {
var el = this;
do {
if (Element.prototype.matches.call(el, s)) return el;
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
}
(function (name, factory) {
if (typeof window === "object") {
// add to window
window[name] = factory();
// add jquery plugin, if available
if (typeof jQuery === "function") {
jQuery.fn[name] = function (options) {
return this.each(function () {
new window[name](this, options);
});
};
}
}
})("Sortable", function () {
// get position of mouse/touch in relation to viewport
var getPoint = function (e) {
var _w = window,
_b = document.body,
_d = document.documentElement;
var scrollX = Math.max(0, _w.pageXOffset || _d.scrollLeft || _b.scrollLeft || 0) - (_d.clientLeft || 0),
scrollY = Math.max(0, _w.pageYOffset || _d.scrollTop || _b.scrollTop || 0) - (_d.clientTop || 0),
pointX = e ? (Math.max(0, e.pageX || e.clientX || 0) - scrollX) : 0,
pointY = e ? (Math.max(0, e.pageY || e.clientY || 0) - scrollY) : 0;
return { x: pointX, y: pointY };
};
// class constructor
var Factory = function (container, options) {
if (container && container instanceof Element) {
this._container = container;
this._options = options || {}; /* nothing atm */
this._clickItem = null;
this._dragItem = null;
this._showDragItem = (typeof this._options.dragItem === 'boolean' && this._options.dragItem === false) ? false : true;
this._hovItem = null;
this._sortLists = [];
this._click = {};
this._dragging = false;
this._dragHandleClass = this._options.dragHandleClass || '';
this._parentident = this._options.parentident || '';
this._swapdone = typeof this._options.swapdone === "function" ? this._options._swapdone : null;
this._container.setAttribute("data-is-sortable", 1);
this._container.classList.add("sortable");
this._container.style["position"] = "static";
window.addEventListener("mousedown", this._onPress.bind(this), true);
window.addEventListener("touchstart", this._onPress.bind(this), true);
window.addEventListener("mouseup", this._onRelease.bind(this), true);
window.addEventListener("touchend", this._onRelease.bind(this), true);
window.addEventListener("mousemove", this._onMove.bind(this), true);
window.addEventListener("touchmove", this._onMove.bind(this), true);
}
};
// class prototype
Factory.prototype = {
constructor: Factory,
// serialize order into array list
toArray: function (attr) {
attr = attr || "id";
var data = [],
item = null,
uniq = "";
for (var i = 0; i < this._container.children.length; ++i) {
item = this._container.children[i],
uniq = item.getAttribute(attr) || "";
uniq = uniq.replace(/[^0-9]+/gi, "");
data.push(uniq);
}
return data;
},
// serialize order array into a string
toString: function (attr, delimiter) {
delimiter = delimiter || ":";
return this.toArray(attr).join(delimiter);
},
// checks if mouse x/y is on top of an item
_isOnTop: function (item, x, y) {
var box = item.getBoundingClientRect(),
isx = (x > box.left && x < (box.left + box.width)),
isy = (y > box.top && y < (box.top + box.height));
return (isx && isy);
},
// manipulate the className of an item (for browsers that lack classList support)
_itemClass: function (item, task, cls) {
var list = item.className.split(/\s+/),
index = list.indexOf(cls);
if (task === "add" && index == -1) {
list.push(cls);
item.className = list.join(" ");
}
else if (task === "remove" && index != -1) {
list.splice(index, 1);
item.className = list.join(" ");
}
},
// swap position of two item in sortable list container
_swapItems: function (item1, item2) {
var parent1 = item1.parentNode,
parent2 = item2.parentNode;
if (item2.className.indexOf('nosort') < 0) {
if (parent1 !== parent2) {
// move to new list
parent2.insertBefore(item1, item2);
}
else {
// sort is same list
var temp = document.createElement("div");
parent1.insertBefore(temp, item1);
parent2.insertBefore(item1, item2);
parent1.insertBefore(item2, temp);
parent1.removeChild(temp);
}
if (typeof this._swapdone === 'function') {
this._swapdone(parent1, parent2, item1, item2);
}
}
},
// update item position
_moveItem: function (item, x, y) {
item.style["-webkit-transform"] = "translateX( " + x + "px ) translateY( " + y + "px )";
item.style["-moz-transform"] = "translateX( " + x + "px ) translateY( " + y + "px )";
item.style["-ms-transform"] = "translateX( " + x + "px ) translateY( " + y + "px )";
item.style["transform"] = "translateX( " + x + "px ) translateY( " + y + "px )";
},
// make a temp fake item for dragging and add to container
_makeDragItem: function (item) {
this._trashDragItem();
this._sortLists = document.querySelectorAll("[data-is-sortable]");
this._clickItem = item;
this._itemClass(this._clickItem, "add", "sortactive");
this._dragItem = document.createElement(item.tagName);
this._dragItem.className = "dragging";
this._dragItem.innerHTML = item.innerHTML;
this._dragItem.style["position"] = "absolute";
this._dragItem.style["z-index"] = "999";
this._dragItem.style["left"] = (item.offsetLeft || 0) + "px";
this._dragItem.style["top"] = (item.offsetTop || 0) + "px";
this._dragItem.style["width"] = (item.offsetWidth || 0) + "px";
if (this._showDragItem === true) {
this._container.appendChild(this._dragItem);
}
},
// remove drag item that was added to container
_trashDragItem: function () {
if (this._dragItem && this._clickItem) {
this._itemClass(this._clickItem, "remove", "sortactive");
this._clickItem = null;
if (this._showDragItem === true) {
this._container.removeChild(this._dragItem);
}
this._dragItem = null;
}
},
// on item press/drag
_onPress: function (e) {
if (!e) { return; }
function op(tgt) {
if (tgt && tgt.parentNode === this._container && (this._dragHandleClass === '' || e.target.className.indexOf(this._dragHandleClass) > -1) && tgt.className.indexOf("nosort") < 0) {
e.preventDefault();
this._dragging = true;
this._click = getPoint(e);
this._makeDragItem(tgt);
this._onMove(e);
return true;
} else {
return false;
}
}
if (op.call(this, e.target) === false && this._parentident !== '' && e.target.closest(this._parentident)) {
op.call(this, e.target.closest(this._parentident))
}
},
// on item release/drop
_onRelease: function (e) {
this._dragging = false;
this._trashDragItem();
},
// on item drag/move
_onMove: function (e) {
if (this._dragItem && this._dragging) {
e.preventDefault();
var point = getPoint(e);
var container = this._container;
// drag fake item
if (this._showDragItem === true) {
this._moveItem(this._dragItem, (point.x - this._click.x), (point.y - this._click.y));
}
// keep an eye for other sortable lists and switch over to it on hover
for (var a = 0; a < this._sortLists.length; ++a) {
var subContainer = this._sortLists[a];
if (this._isOnTop(subContainer, point.x, point.y)) {
container = subContainer;
}
}
// container is empty, move clicked item over to it on hover
if (this._isOnTop(container, point.x, point.y) && container.children.length === 0) {
container.appendChild(this._clickItem);
return;
}
// check if current drag item is over another item and swap places
for (var b = 0; b < container.children.length; ++b) {
var subItem = container.children[b];
if (subItem === this._clickItem || subItem === this._dragItem) {
continue;
}
if (this._isOnTop(subItem, point.x, point.y)) {
this._hovItem = subItem;
if (subItem.className.indexOf('nosort') < 0) {
this._dragItem.className = this._dragItem.className.replace(/\bnotgt\b/g, '');
this._swapItems(this._clickItem, subItem);
} else {
var arr = this._dragItem.className.split(' ');
if (arr.indexOf('notgt') === -1) {
this._dragItem.className += ' notgt';
}
}
}
}
}
},
};
// export
return Factory;
});
//// helper init function
//initSortable(list) {
// var listObj = $(list);
// var sortable = [];
// listObj.each(function (i, d) {
// sortable.push(new Sortable(d));
// });
//}
(function ($) {
$.fn.draggable = function (controlelement) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
var elmnt = $(this), ce = controlelement instanceof jQuery ? controlelement : elmnt.find(controlelement);
function dragMouseDown(e) {
e.stopPropagation();
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.css('top', (elmnt.offset().top - pos2) + 'px');
elmnt.css('left', (elmnt.offset().left - pos1) + 'px');
}
function closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
if (typeof controlelement !== 'undefined' && ce.length > 0) {
ce.mousedown(dragMouseDown).addClass('dctrl');
} else {
elmnt.mousedown(dragMouseDown).addClass('dctrl');
}
return $(this);
}
})(jQuery);
$(document).ready(function () {
$('html').click(function (e) {
$nuf();
});
$('#listframe').click(function (e) {
e.stopPropagation();
$nuf();
});
$('#mainmenu').ocmsmenu($ocms.ocmsmenu);
$('#mainmenu').activatemenu();
//$ocms.init('cal');
});
$.extend($t, {
m_inv: 'Rechnungen'
, m_req: 'Aufträge'
, m_rep: 'Berichte'
, m_todo: 'ToDos'
, m_bcd: 'BankBuchungen'
, rsp: 'Passwort ändern'
, pnm: 'Die Passwörter stimmen nicht überein'
, cps: 'Das neue Passwort wurde gespeichert.'
, pwr: 'Bitte wählen Sie ein starkes Passwort (min 8 Zeichen, davon jeweils min 2 Zahlen, kleine und große Buchstaben, Sonderzeichen sind optional).'
, smsc: 'Sie beötigen für diese Funktion einen SMS-Code.\nSoll dieser nun versandt werden?'
, wdc: 'Doppelt klicken, um die Box zu aktualisieren.'
, wdg: {}
});
$t.rspf = { sms: 'Der SMS-Code konnte nicht bestätigt werden', valid: 'Das alte Passwort ist nicht korrekt', requirements: 'Das Passwort entspricht nicht den Anforderungen.\n' + $t.pwr}
$fd = {
rsp: new fields_definition('', '', [
{ name: 'opw', label: 'aktuelles Passwort', type: 'password', required: true, attr: { 'auto-complete': 'current-password' }}
, {
name: 'npw', label: 'neues Passwort', type: 'password', required: true, pattern: '(.{6,})', attr: { 'auto-complete': 'new-password' }}
, { name: 'npwc', label: 'neues Passwort (Bestätigung)', type: 'password', required: true, attr: { 'auto-complete': 'new-password' }, note: $t.pwr}
, { name: 'code', label: 'SMS-Code', type: 'string', required: true, attr: { 'auto-complete': 'one-time-code' }}
])
};
$ocms.init = function (ev) {
var mdl = typeof ev === 'string' ? ev : ((ev.data || {}).fn || '');
if (mdl === '') {
return;
} else if (mdl === 'home') {
$cfr(); $lfr();
$('#topbar').ocmsmenu([], true);
$('#activemodule').text($t.ov);
$fis.ov();
} else {
$cfr(); $lfr();
$('#topbar').ocmsmenu([]);
$ocms.postXT({
url: $ocms.url(mdl + '/auth'), success: function (auth) {
if (typeof $ocms[mdl] === 'undefined') {
$ocms[mdl] = {};
}
$ocms[mdl].auth = auth;
if (auth.manage > 0) {
$ocms.getScript({
module: mdl, script: ['/web/fis', mdl, $ocms.auth.locale || 'de', 'js'].join('.'), css: ['/web/fis', mdl, 'css'].join('.'), condition: typeof $ocms[mdl].init2 !== 'function'
}, function () { $ocms[mdl].init2(); });
}
}, error: function () {
$('#contentframe').empty();
}
});
}
};
var $fis = { auth: {} };
$fis.db = function () {
$('#mainmenu_activemodule').text($t.ov);
let cf = $(this).empty(), ovf = $$.d({ id: 'dashboard_frame' }).appendTo(cf);
$ocms.postXT({
url: $ocms.url('wdg/my'), success: function (wx) {
$.each(wx, function (ii, wi) {
var wf = $$.dc('wdg_frame', ovf, { 'data-wdg': wi }).ldng(1);
$ocms.wdg.call(wf, { wdg: wi });
});
}, loading: ovf
});
};
$fis.ValidateEmail = function (mail) {
if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(mail)) {
return true;
} else {
return false;
}
};
$fis.cf = (reset) => {
let cf = $('#contentframe'); if (bool(reset, false) === true) { cf.empty().rC('hd'); } return cf;
}
$fis.lf = (reset) => {
let lf = $('#listframe'); if (bool(reset, false) === true) { lf.empty().aC('hd').rC('fix'); } return lf;
};
$fis.frm_edit = function (resethd) {
let cf = $fis.cf(false), cf2 = cf.children('.cfrm'), edf = cf.children('.edit_frm');
if (cf2.length < 1) {
cf2 = $$.dc('cfrm hd').prependTo(cf);
} else if (bool(resethd, false) === true) {
cf2.empty();
}
if (edf.length < 1) {
edf = $$.dc('edit_frm').insertAfter(cf2); //must be before list
}
return edf.empty();
};
$fis.frm_list = function (resethd, remedit) {
let cf = $fis.cf(false), cf2 = cf.children('.cfrm'), lf = cf.children('.list_frm');
if (cf2.length < 1) {
cf2 = $$.dc('cfrm hd').prependTo(cf);
} else if (bool(resethd, false) === true) {
cf2.empty();
}
if (bool(remedit, false) === true) {
cf.children('.edit_frm').remove();
}
if (lf.length < 1) {
lf = $$.dc('list_frm').appendTo(cf); //must be after list
}
return lf.empty();
};
$fis.lfm = () => {
let lf = $fis.lf(false) , h = lf.children('.lfrm');
if (h.length < 1) {
h = $$.dc('lfrm').prependTo(lf);
}
return h;
};
$fis.getAuth = (module, force) => {
return new Promise((resolve, reject) => {
if ($fis.auth[module] && bool(force, false) === false) {
resolve($fis.auth[module] || -1);
} else {
$ocms.postXT({
url: $ocms.url('auth'), data: { module: module }, success: (response) => {
$fis.auth[module] = response.auth || -1;
resolve($fis.auth[module] || -1);
}, error: () => {
reject();
}
});
}
});
};
$fis.prepAuth = (modules) => {
return new Promise((resolve, reject) => {
$ocms.postXT({
url: $ocms.url('auth'), data: { module: modules, array: 1 }, success: (response) => {
$.extend($fis.auth, response || {});
}, complete: () => {
resolve();
}
});
});
};
$fis.isAuth = (module, min) => {
return ($fis.auth[module] || -1) >= (min || 1);
};
$fis.resetPass = function (id, fds) {
if (confirm($t.smsc)) {
$ocms.postXT({ url: $ocms.url('account/sms'), data: { fn: 'pwc'} });
$ocms.dlgform($fd.rsp.clone(), {
title: $t.rsp || '',
submit: function (e) {
var c = $(this).ldng(1);
var qs = $.extend({ loginaccount: $ocms.auth.account || '' }, c.serializeObject(true, { typedvalues: true }));
if ((qs.npw || '') !== (qs.npwc || '')) {
c.find('input[name="npw"]:first')[0].setCustomValidity($t.pnm);
} else {
$ocms.postXT({
url: $ocms.url('account/changepassword'), data: qs, success: function (response) {
alert($t.cps);
c.trigger('modal_close');
}, error: function (x) {
alert($t.rspf[x.getResponseHeader('x-ocms-std')]);
}, complete: function () {
c.ldng(0);
}, timeout: 60000
});
}
}
});
}
};
$fis.wdg = function (options) {
let wf = $(this).empty();
$ocms.postXT({
url: $ocms.url('wdg/one'), data: { short_name: options.wdg }, success: function (response, textStatus, jqXHR) {
let wi = options.wdg, wx = response[wi];
if (!wx) { wf.ldng(0); return; }
let dbl = $.inArrayRegEx('dblwidth', wx.rendering_options) > -1, tiny = $.inArrayRegEx('tiny', wx.rendering_options) > -1;
wf.toggleClass('dbl', dbl && !tiny).toggleClass('tny', tiny);
let whd = $$.dc('wdg_hd', wf, { title: ne(wx.description, $t.wdc) }).toggleClass('dbl', dbl).text(ne(wx.name, options.wdg)).dblclick(function (ev) {
ev.stopPropagation();
$fis.wdg.call(wf, { wdg: wi });
});
let wct = $$.dc('wdg_cnt', wf).toggleClass('dbl', dbl).hide();
let bgcolix = $.inArrayRegEx('bgcolor', wx.rendering_options);
if (bgcolix > -1) { wct.css('backgroundColor', wx.rendering_options[bgcolix].toString().right(':')); }
switch (wx.type) {
case 'table':
var tblset = $$.tblset({}, wct);
var thr = $$.tr().appendTo(tblset.hd);
var $cc = $t.wdg[wi.indexOf('wdg_ev_') >= 0 ? 'wdg_ev_' : wi] || {};
$.each(wx.columns, function (ci, col) {
var cc = (!$cc[col]) ? col : $cc[col].label;
var thc = $$.th().text(cc).appendTo(thr);
});
$.each(wx.data, function (di, dx) {
var tdr = $$.tr().appendTo(tblset.bdy);
$.each(wx.columns, function (ci, col) {
var tdc = $$.td().appendTo(tdr);
if (dx[col] instanceof Date || $ocms.isDateString(dx[col]) === true) {
tdc.text(fdt(dx[col], $t.dateformat));
} else {
tdc.rwText(dx[col]);
}
});
//if (dx.person_guid || false) { tdr.addClass('clickable').dblclick($.proxy($fis.i_vmm, tdr, dx.person_guid[1])); }
});
if ($.inArray('firstrow_bold', wx.rendering_options) > -1) { thr.nextAll('tr:first').css('font-weight', 'bold'); }
break;
case 'ind':
$$.dc('ind', wct).addClass('sts_' + (wx.data.status || '')).append([$$.dc('ind').text(wx.data.value), $$.lbl(wx.data.label)]);
break;
case 'image_url':
wct.css('background', 'url(\'' + wx.url + '\') no-repeat center center transparent');
break;
case 'image_base64':
wct.css('background', 'url(\'data:image/png;base64,' + wx.image + '\') no-repeat center center transparent');
break;
case 'html':
wct.html(wx.html);
if ($.inArray('reload_10min', wx.rendering_options) > -1) {
var ifr = wct.find('iframe');
setTimeout(function () { ifr.attr('src', function (i, val) { return val; }); }, (10 * 60 * 1000));
}
break;
default:
}
if ($.inArray('reload_30min', wx.rendering_options) > -1 && wx.type !== 'html') {
setTimeout(function () { $fis.wdg.call(wf, { wdg: wi }); }, (30 * 60 * 1000));
}
wct.slideDown(150);
}, error: function (jqXHR) {
wf.slideUp(150);
$fis.failure.call(this, jqXHR);
}, complete: function () {
wf.ldng(0);
}
});
};
$fis.ov = function () {
//$('#mainmenu_activemodule').text("");
$fis.lf(true);
let cf = $('#contentframe').empty(), ovf = $$.d({ id: 'dashboard_frame' }).appendTo(cf);
$ocms.postXT({
url: $ocms.url('wdg/my'), success: function (wx) {
$.each(wx, function (ii, wi) {
var wf = $$.dc('wdg_frame', ovf, { 'data-wdg': wi }).ldng(1);
$fis.wdg.call(wf, { wdg: wi });
});
}, loading: ovf
});
};
(function () {
Array.prototype.push.apply($ocms.ocmsmenu,[
{ lbl: $t.m_inv, id: 'm_inv', fnc: 'init:inv', ico: 'glyphicon glyphicon-list-alt'}
,{ lbl: $t.m_req, id: 'm_req', fnc: 'init:req', ico: 'glyphicon glyphicon-eur' }
, { lbl: $t.m_bcd, id: 'm_bcd', fnc: 'init:bam', ico: 'glyphicon glyphicon-indent-right' }
, { fnc: 'separator' }
, { lbl: $t.m_rep, id: 'm_rep', fnc: 'init:rep', ico: 'glyphicon glyphicon-dashboard' }
, { fnc: 'separator' }
, { lbl: $t.m_todo, id: 'm_todo', fnc: () => { $('#contentframe').empty().load($ocms.url('todos')); $('#listframe').rC('fix').aC('hd'); }, ico: 'glyphicon glyphicon-sunglasses' }
//, { lbl: $t.m_efa, id: 'm_efa', fnc: 'init:efa' }
]);
})();
$(document).ready(function () {
$fis.ov();
});