272 lines
8.0 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();
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
2016-12-14 22:32:35 +01:00
case 'categoryAngebote':
this.LoadContent('/category/?cat=Angebote&view=List', 'list.tpl');
break
2016-12-12 22:20:21 +01:00
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
2016-12-14 22:32:35 +01:00
case 'newStudenten':
2016-12-12 22:20:21 +01:00
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
2016-12-14 22:32:35 +01:00
case 'newLehrender':
2016-12-12 22:20:21 +01:00
console.log("NewLehrender");
2016-12-14 22:32:35 +01:00
this.LoadContent('/category/?cat=Lehrender&view=Detail', 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
2016-12-14 22:32:35 +01:00
case 'newFirmen':
2016-12-12 22:20:21 +01:00
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
2016-12-14 22:32:35 +01:00
case 'newAngebote':
console.log("NewAngebote");
this.LoadContent('/category/?cat=Angebote&view=Detail', 'detail.tpl');
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 22:32:35 +01:00
case 'modifyLehrender':
2016-12-12 22:20:21 +01:00
2016-12-14 22:32:35 +01:00
console.log("modifyLehrender", selectedId);
2016-12-14 12:45:42 +01:00
this.LoadContent('/category/?cat=Lehrender&view=Detail&id='+ selectedId, 'detail.tpl');
2016-12-12 22:20:21 +01:00
break
2016-12-14 22:32:35 +01:00
case 'modifyFirmen':
2016-12-12 22:20:21 +01:00
2016-12-14 22:32:35 +01:00
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
2016-12-14 22:32:35 +01:00
case 'modifyAngebote':
console.log("modifyAngebote", selectedId);
this.LoadContent('/category/?cat=Angebote&view=Detail&id='+ selectedId, 'detail.tpl');
break
case 'choiceAnnehmen':
console.log("choiceAnnehmen", selectedId);
this.LoadContent('/choice/?view=Detail&id='+ selectedId, 'detailChoice.tpl');
break
case 'choiceNeu':
2016-12-12 22:20:21 +01:00
2016-12-14 22:32:35 +01:00
console.log("choiceNeu");
this.LoadContent('/choice/?view=Detail', 'detailChoice.tpl');
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 22:32:35 +01:00
case 'deleteLehrender':
2016-12-12 22:20:21 +01:00
2016-12-14 22:32:35 +01:00
console.log("deleteLehrender", selectedId);
2016-12-14 12:45:42 +01:00
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
2016-12-14 22:32:35 +01:00
case 'deleteFirmen':
2016-12-12 22:20:21 +01:00
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
2016-12-14 22:32:35 +01:00
case 'saveCategoryStudenten':
2016-12-14 12:45:42 +01:00
var data = $("#idForm").serialize();
this.SaveContent('/category/?cat=Studenten&'+data, 'categoryStudenten');
break
2016-12-14 22:32:35 +01:00
case 'saveCategoryLehrende':
2016-12-14 12:45:42 +01:00
var data = $("#idForm").serialize();
this.SaveContent('/category/?cat=Lehrender&'+data, 'categoryLehrender');
break
2016-12-14 22:32:35 +01:00
case 'saveCategoryFirmen':
2016-12-14 12:45:42 +01:00
var data = $("#idForm").serialize();
this.SaveContent('/category/?cat=Firmen&'+data, 'categoryFirmen');
2016-12-12 22:20:21 +01:00
break
2016-12-14 22:32:35 +01:00
case 'saveCategoryAngebote':
var data = $("#idForm").serialize();
this.SaveContent('/category/?cat=Angebote&'+data, 'categoryAngebote');
break
case 'saveChoice':
var data = $("#idForm").serialize();
this.SaveContent('/choice/?'+data, 'choice');
break
2016-12-12 22:20:21 +01:00
default:
alert ('[PPM] Unbekannte Anfrage: ' + message);
}
}
LoadContent ( path, template )
{
$.ajax({
dataType: "json",
url: path,
type: 'GET',
context: this
})
.done(function (json) {
2016-12-15 13:52:05 +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-15 13:52:05 +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");
});