//------------------------------------------------------------------------------ // PPM - Hauptfunktion //------------------------------------------------------------------------------ class PPM { constructor () { this.BodyDataAction(); this.TemplateManager_o = new TemplateManager_cl(); this.TemplateManager_o; console.log("PPM LOADED"); } BodyDataAction () { $('body').on('click', '[data-action]', function() { var action = $(this).data('action'); PPM_o.Menu(action); return false; }); } BodyTableSelect () { $('#idList tr').click(function(){ $(".selected").removeClass('selected'); $(this).addClass('selected'); this.selectedId = $(this).attr('id'); console.log("SELECT ID: ", this.selectedId); return false; }); } Menu (message) { var selectedId = $(".selected").attr('id'); switch (message) { case 'index': this.LoadContent('/category/?cat=Index&view=List', 'index.tpl'); break; case 'categoryStudenten': this.LoadContent('/category/?cat=Studenten&view=List', 'list.tpl'); break case 'categoryLehrender': this.LoadContent('/category/?cat=Lehrender&view=List', 'list.tpl'); break case 'categoryFirmen': this.LoadContent('/category/?cat=Firmen&view=List', 'list.tpl'); break case 'choice': this.LoadContent('/choice/?view=List', 'listChoice.tpl'); break case 'evalStudenten': this.LoadContent('/eval/?cat=Studenten', 'listEval.tpl'); break case 'evalLehrender': this.LoadContent('/eval/?cat=Lehrender', 'listEval.tpl'); break case 'evalFirmen': this.LoadContent('/eval/?cat=Firmen', 'listEval.tpl'); break case 'NewStudenten': console.log("NewStudenten"); this.LoadContent('/category/?cat=Studenten&view=Detail', 'detail.tpl'); break case 'NewLehrender': console.log("NewLehrender"); this.LoadContent('/category/?cat=Lehrenden&view=Detail', 'detail.tpl'); break case 'NewFirmen': console.log("NewFirmen"); this.LoadContent('/category/?cat=Firmen&view=Detail', 'detail.tpl'); break case 'ModifyStudenten': console.log("ModifyStudenten: ", selectedId); this.LoadContent('/category/?cat=Studenten&view=Detail&id='+ selectedId, 'detail.tpl'); break case 'ModifyLehrender': console.log("ModifyLehrender", selectedId); this.LoadContent('/category/?cat=Lehrender&view=Detail&id='+ selectedId, 'detail.tpl'); break case 'ModifyFirmen': console.log("ModifyFirmen", selectedId); this.LoadContent('/category/?cat=Firmen&view=Detail&id='+ selectedId, 'detail.tpl'); break case 'DeleteStudenten': console.log("DeleteStudenten", selectedId); if (confirm("Soll der Eintrag wirklich geloescht werden?")) { console.log("DELETE"); this.DeleteContent('/category/?cat=Studenten&id='+selectedId, 'categoryStudenten'); } break case 'DeleteLehrender': console.log("DeleteLehrender", selectedId); if (confirm("Soll der Eintrag wirklich geloescht werden?")) { console.log("DELETE"); this.DeleteContent('/category/?cat=Lehrender&id='+selectedId, 'categoryLehrender'); } break case 'DeleteFirmen': console.log("DeleteFirmen", selectedId); if (confirm("Soll der Eintrag wirklich geloescht werden?")) { console.log("DELETE"); this.DeleteContent('/category/?cat=Firmen&id='+selectedId, 'categoryFirmen'); } break case 'SaveCategoryStudenten': var data = $("#idForm").serialize(); this.SaveContent('/category/?cat=Studenten&'+data, 'categoryStudenten'); break case 'SaveCategoryLehrende': var data = $("#idForm").serialize(); this.SaveContent('/category/?cat=Lehrender&'+data, 'categoryLehrender'); break case 'SaveCategoryFirmen': var data = $("#idForm").serialize(); this.SaveContent('/category/?cat=Firmen&'+data, 'categoryFirmen'); break default: alert ('[PPM] Unbekannte Anfrage: ' + message); } } LoadContent ( path, template ) { $.ajax({ dataType: "json", url: path, type: 'GET', context: this }) .done(function (json) { console.log("JSON: ", json); var result = this.TemplateManager_o.execute_px( template, json ); console.log("RESULT: ", result); //$( ".clContent" ).replaceWith(result); $( ".clContent" ).empty(); $( ".clContent" ).append(result); this.BodyTableSelect(); console.log("TM DONE"); }) .fail(function(jqXHR_opl, textStatus) { alert( "[PPM] Fehler bei Anforderung: " + textStatus ); }); } SaveContent( path, menu ) { $.ajax({ dataType: "json", url: path, type: 'POST', context: this }) .done(function (json) { this.Menu(menu); }) .fail(function(jqXHR_opl, textStatus) { alert( "[PPM] Fehler bei Anforderung: " + textStatus ); }); } DeleteContent( path, menu ) { $.ajax({ dataType: "json", url: path, type: 'DELETE', context: this }) .done(function (json) { this.Menu(menu); }) .fail(function(jqXHR_opl, textStatus) { alert( "[PPM] Fehler bei Anforderung: " + textStatus ); }); } } $(function() { console.log("ONLOAD"); PPM_o = new PPM(); PPM_o.Menu("index"); });