function NutzerApp() {
|
var self = this;
|
var appMenu;
|
var vorlagen;
|
var api;
|
var userid;
|
var pfad = '';
|
var loc;
|
var modus = 'kacheln';
|
|
this.datei_neuer_text = function () {
|
self.meldung_mit_timeout("Neuer Text", 1500);
|
};
|
|
/* Funktionen aus App-Vorlage */
|
|
this.init = function () {
|
self.vorlagen = new Vorlagen();
|
self.appMenu = new AppMenu();
|
self.appMenu.init(
|
"data/menu/",
|
"hauptmenue.json",
|
"data/tpl/app-menu.tpl",
|
".west",
|
"8em");
|
document.querySelector('.hamburger').addEventListener('click', function (e) {
|
self.menue_umschalten();
|
});
|
var dlg = document.querySelector(".dialog");
|
dlg.style.flexBasis = '0em';
|
self.seitenleiste_umschalten();
|
self.um_get_login();
|
self.um_get_user_list();
|
self.loc = window.location.protocol + '//' + window.location.host;
|
};
|
|
this.login_zeigen = function() {
|
self.meldung_mit_timeout("Benutzer: " + self.userid, 1500);
|
};
|
|
this.menue_umschalten = function () {
|
var ham = document.querySelector(".hamburger");
|
ham.classList.toggle("is-active"); // hamburger-icon umschalten
|
self.appMenu.toggle(); // menue oeffnen/schliessen
|
};
|
|
this.info_dialog_zeigen = function () {
|
self.dialog_laden_und_zeigen('data/tpl/dlg-info.tpl', '');
|
self.menue_umschalten();
|
};
|
|
this.nutzer_neu_dialog_zeigen = function () {
|
self.dialog_laden_und_zeigen('data/tpl/dlg-nutzer-neu.tpl', '');
|
self.menue_umschalten();
|
};
|
|
this.seitenleiste_umschalten = function () {
|
var ostDiv = document.querySelector('.ost');
|
if (ostDiv.classList.contains('ost-open')) {
|
ostDiv.classList.remove('ost-open');
|
ostDiv.style.flexBasis = '0em';
|
} else {
|
ostDiv.classList.add('ost-open');
|
ostDiv.style.flexBasis = '6em';
|
}
|
self.menue_umschalten();
|
};
|
|
this.fusszeile_umschalten = function () {
|
var suedDiv = document.querySelector('.sued');
|
if (suedDiv.classList.contains('sued-open')) {
|
suedDiv.classList.remove('sued-open');
|
suedDiv.style.height = '0';
|
} else {
|
suedDiv.classList.add('sued-open');
|
suedDiv.style.height = '1.5em';
|
}
|
self.menue_umschalten();
|
};
|
|
this.meldung_mit_timeout = function (meldung, timeout) {
|
var s = document.querySelector('.sued');
|
s.textContent = meldung;
|
setTimeout(function () {
|
s.textContent = 'Bereit.';
|
setTimeout(function () {
|
var suedDiv = document.querySelector('.sued');
|
if (suedDiv.classList.contains('sued-open')) {
|
suedDiv.classList.remove('sued-open');
|
suedDiv.style.height = '0';
|
}
|
}, 500);
|
}, timeout);
|
};
|
|
/* Dialog-Funktionen */
|
|
/*
|
Einen Dialog aus Vorlagen erzeugen
|
|
vurl - URL zur Dialogvorlage
|
msgTpl - URL mit einer Vorlage eines Mitteilungstextes (optional)
|
*/
|
this.dialog_laden_und_zeigen = function (vurl, msgTpl) {
|
if (msgTpl !== '') {
|
fetch(msgTpl)
|
.then(data => {
|
// Handle data
|
self.dialog_zeigen(vurl, data);
|
}).catch(error => {
|
// Handle error
|
});
|
} else {
|
self.dialog_zeigen(vurl, '');
|
}
|
};
|
|
this.dialog_zeigen = function (vurl, inhalt) {
|
var dlg = document.querySelector(".dialog");
|
self.vorlagen.html_erzeugen(
|
vurl,
|
inhalt,
|
function (html) {
|
dlg.style.flexBasis = '14em';
|
setTimeout(function () {
|
dlg.innerHTML = html;
|
document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen);
|
}, 300);
|
});
|
};
|
|
this.dialog_schliessen = function () {
|
document.querySelector('.close-btn').removeEventListener('click', self.dialog_schliessen);
|
var dlg = document.querySelector('.dialog');
|
dlg.innerHTML = '';
|
dlg.style.flexBasis = '0em';
|
};
|
|
/* API functions */
|
|
this.um_get_user_list = function() {
|
//var m = 'getUserNameList';
|
var m = 'getUserNameList';
|
var u = '../svc/' + m;
|
self.um_get(u, "json", function (antwort) {
|
self.vorlagen.html_erzeugen(
|
'data/tpl/inhalt.tpl',
|
JSON.parse(antwort),
|
function (h) {
|
var elem = document.getElementById('nutzer');
|
elem.innerHTML = h;
|
});
|
});
|
};
|
|
/* -------- An- und Abmelden ------------- */
|
|
this.um_get_login = function() {
|
var m = '?c=de.uhilger.um.pub.SessionManager&m=getSessionUser';
|
var u = '../pub' + m;
|
self.um_get(u, "text", function (resp) {
|
self.userid = resp;
|
self.login_zeigen();
|
//document.querySelector("#userMenu").textContent = resp;
|
});
|
};
|
|
this.um_logout = function() {
|
var m = '?c=de.uhilger.um.pub.SessionManager&m=expireSession';
|
var u = '../pub' + m;
|
self.um_get(u, "text", function (resp) {
|
//$('#userMenu').text('nicht angemeldet');
|
window.location.href = '../logout.html';
|
});
|
};
|
|
/* -------- ajax helper functions ----------- */
|
|
this.um_get = function (u, dtype, scallback) {
|
var xmlhttp = new XMLHttpRequest();
|
var url = u;
|
xmlhttp.onreadystatechange = function() {
|
if (this.readyState == 4 && this.status == 200) {
|
scallback(this.responseText);
|
}
|
};
|
xmlhttp.open("GET", url, true);
|
xmlhttp.send();
|
};
|
|
/* ----- Hilfsfunktionen ----- */
|
|
this.serialisieren = function(obj) {
|
return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}';
|
};
|
|
}
|
|
|
/* ----- Objekte ----- */
|
|
function User(i, p, fn, ln, em) {
|
this.id = i;
|
this.pw = p;
|
this.firstName = fn;
|
this.lastName = ln;
|
this.email = em;
|
}
|