ulrich@undisclosed
2020-05-11 f9d0c4a3da9d183c90bc7351f233fa67ea3c66a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
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);
  };
  
  /* Nutzerverwaltung */
  
  this.nutzerliste_klick = function(event) {
    var target = event.target;
    var gewaehlterNutzer = document.querySelector(".nutzer-gewaehlt");
    if(gewaehlterNutzer !== null) {
      gewaehlterNutzer.classList.remove("nutzer-gewaehlt");
    }
    target.classList.add("nutzer-gewaehlt");
  };
 
  /* 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;
        
        var absaetze = document.querySelectorAll('p.nutzer-liste-eintrag');
        var index;
        for (index = 0; index < absaetze.length; index++) {
          absaetze[index].addEventListener("click", self.nutzerliste_klick);
        }
        
      });
    });
  };
 
  /* -------- 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;
}