232 lines
6.7 KiB
JavaScript
Raw Normal View History

2016-12-12 22:20:21 +01:00
//------------------------------------------------------------------------------
// 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':
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Index&view=List', 'index.tpl');
2016-12-12 22:20:21 +01:00
break;
case 'categoryStudenten':
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Studenten&view=List', 'list.tpl');
2016-12-12 22:20:21 +01:00
break
case 'categoryLehrender':
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Lehrender&view=List', 'list.tpl');
2016-12-12 22:20:21 +01:00
break
case 'categoryFirmen':
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Firmen&view=List', 'list.tpl');
2016-12-12 22:20:21 +01:00
break
case 'choice':
2016-12-14 12:45:42 +01:00
this.LoadContent('/choice/?view=List', 'listChoice.tpl');
2016-12-12 22:20:21 +01:00
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");
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Studenten&view=Detail', 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
case 'NewLehrender':
console.log("NewLehrender");
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Lehrenden&view=Detail', 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
case 'NewFirmen':
console.log("NewFirmen");
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Firmen&view=Detail', 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
case 'ModifyStudenten':
console.log("ModifyStudenten: ", selectedId);
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Studenten&view=Detail&id='+ selectedId, 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
2016-12-14 12:45:42 +01:00
case 'ModifyLehrender':
2016-12-12 22:20:21 +01:00
2016-12-14 12:45:42 +01:00
console.log("ModifyLehrender", selectedId);
this.LoadContent('/category/?cat=Lehrender&view=Detail&id='+ selectedId, 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
case 'ModifyFirmen':
console.log("ModifyFirmen", selectedId);
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Firmen&view=Detail&id='+ selectedId, 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
case 'DeleteStudenten':
console.log("DeleteStudenten", selectedId);
2016-12-14 12:45:42 +01:00
if (confirm("Soll der Eintrag wirklich geloescht werden?")) {
console.log("DELETE");
this.DeleteContent('/category/?cat=Studenten&id='+selectedId, 'categoryStudenten');
}
2016-12-12 22:20:21 +01:00
break
2016-12-14 12:45:42 +01:00
case 'DeleteLehrender':
2016-12-12 22:20:21 +01:00
2016-12-14 12:45:42 +01:00
console.log("DeleteLehrender", selectedId);
if (confirm("Soll der Eintrag wirklich geloescht werden?")) {
console.log("DELETE");
this.DeleteContent('/category/?cat=Lehrender&id='+selectedId, 'categoryLehrender');
}
2016-12-12 22:20:21 +01:00
break
case 'DeleteFirmen':
console.log("DeleteFirmen", selectedId);
2016-12-14 12:45:42 +01:00
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');
2016-12-12 22:20:21 +01:00
break
default:
alert ('[PPM] Unbekannte Anfrage: ' + message);
}
}
LoadContent ( path, template )
{
$.ajax({
dataType: "json",
url: path,
type: 'GET',
context: this
})
.done(function (json) {
2016-12-14 12:45:42 +01:00
console.log("JSON: ", json);
2016-12-12 22:20:21 +01:00
var result = this.TemplateManager_o.execute_px( template, json );
2016-12-14 12:45:42 +01:00
console.log("RESULT: ", result);
2016-12-12 22:20:21 +01:00
//$( ".clContent" ).replaceWith(result);
$( ".clContent" ).empty();
$( ".clContent" ).append(result);
this.BodyTableSelect();
console.log("TM DONE");
})
2016-12-14 12:45:42 +01:00
.fail(function(jqXHR_opl, textStatus) {
alert( "[PPM] Fehler bei Anforderung: " + textStatus );
2016-12-12 22:20:21 +01:00
});
}
2016-12-14 12:45:42 +01:00
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 );
});
}
2016-12-12 22:20:21 +01:00
}
$(function() {
console.log("ONLOAD");
PPM_o = new PPM();
PPM_o.Menu("index");
});