Initial Commit after switching from SVN to git
This commit is contained in:
@@ -0,0 +1,686 @@
|
||||
(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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user