Sammlung
This commit is contained in:
116
Sammlung/Praktikum/4/js/edit_discussion.js
Normal file
116
Sammlung/Praktikum/4/js/edit_discussion.js
Normal file
@ -0,0 +1,116 @@
|
||||
// ----------------------------------------------
|
||||
// edit_discussion.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.DiscussionDetailView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
// Basis-Markup des Formulars anfordern
|
||||
var that = this;
|
||||
$.get('/html/edit_discussion.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idDiscussionEditContent").hide();
|
||||
that.initHandler_p();
|
||||
|
||||
that.storeFormContent_p();
|
||||
});
|
||||
|
||||
},
|
||||
canClose_px: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
return (this.isModified_p() ? confirm("Es gibt nicht gespeicherte Änderungen - verwerfen?") : true);
|
||||
},
|
||||
close_px: function () {
|
||||
$("#idDiscussionEditContent").hide();
|
||||
},
|
||||
render_px: function (ids) {
|
||||
tId_ = ids[0];
|
||||
id_ = ids[1];
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/discussion/' + tId_ + '/' + (id_ == null?'0':id_),
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Form] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
doRender_p: function (data_opl) {
|
||||
// in das Formular übertragen
|
||||
var data_o = data_opl['data'];
|
||||
$('#dEditName').val(data_o['name']);
|
||||
this.id_s = data_opl['id'];
|
||||
this.tId = data_opl['tId'];
|
||||
|
||||
this.storeFormContent_p();
|
||||
|
||||
$("#idDiscussionEditContent").show();
|
||||
},
|
||||
initHandler_p: function () {
|
||||
// Ereignisverarbeitung für das Formular einrichten
|
||||
$("#idDiscussionEditContent").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var do_b = false;
|
||||
var path_s;
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
switch (action_s) {
|
||||
case "back":
|
||||
// Weiterleiten
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionList', this.tId]);
|
||||
break;
|
||||
case "save":
|
||||
// Formularinhalt prüfen
|
||||
if (this.isModified_p()) {
|
||||
if (this.checkContent_p()) {
|
||||
// kein klassisches submit, es wird auch keine neue Anzeige vorgenommen
|
||||
var data_s = $("#idDiscussionDetail").serialize();
|
||||
data_s += "&owner=" + FORUM.user_o.name_s;
|
||||
$.ajax({
|
||||
context: this,
|
||||
dataType: "json",
|
||||
data: data_s,
|
||||
url: '/discussion/' + this.tId + '/' + (this.id_s != 0?'/' + this.id_s:''),
|
||||
type: (this.id_s != 0?'POST':'PUT')
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
// aktuellen Formularinhalt speichern
|
||||
// (das Formular wird ja nicht mehr neu geladen!)
|
||||
this.storeFormContent_p();
|
||||
alert("Speichern ausgeführt!");
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionList', this.tId]);
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
|
||||
} else {
|
||||
alert("Bitte prüfen Sie die Eingaben in den Formularfeldern!")
|
||||
}
|
||||
}
|
||||
else {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionList', null]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Weiterleitung und Standardbearbeitung unterbinden
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
isModified_p: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
return (this.FormContentOrg_s != $("#idDiscussionDetail").serialize());
|
||||
},
|
||||
checkContent_p: function () {
|
||||
// hier nur zur Demonstration Prüfung des Typs gegen eine Werteliste
|
||||
// (das realisiert man besser mit einer Liste)
|
||||
var status_b = true;
|
||||
return status_b;
|
||||
},
|
||||
storeFormContent_p: function () {
|
||||
this.FormContentOrg_s = $("#idDiscussionDetail").serialize();
|
||||
}
|
||||
});
|
||||
// EOF
|
128
Sammlung/Praktikum/4/js/edit_post.js
Normal file
128
Sammlung/Praktikum/4/js/edit_post.js
Normal file
@ -0,0 +1,128 @@
|
||||
// ----------------------------------------------
|
||||
// edit_Topic.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.PostDetailView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
// Basis-Markup des Formulars anfordern
|
||||
var that = this;
|
||||
$.get('/html/edit_post.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idPostEditContent").hide();
|
||||
that.initHandler_p();
|
||||
|
||||
that.storeFormContent_p();
|
||||
});
|
||||
|
||||
},
|
||||
canClose_px: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
return (this.isModified_p() ? confirm("Es gibt nicht gespeicherte Änderungen - verwerfen?") : true);
|
||||
},
|
||||
close_px: function () {
|
||||
$("#idPostEditContent").hide();
|
||||
},
|
||||
render_px: function (ids) {
|
||||
tId_ = ids[0];
|
||||
dId_ = ids[1];
|
||||
id_ = ids[2];
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/post/' + tId_ + '/' + dId_ + '/' + (id_ == null?'0':id_),
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Form] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
doRender_p: function (data_opl) {
|
||||
// in das Formular übertragen
|
||||
var data_o = data_opl['data'];
|
||||
$('#pEditTitle').val(data_o['title']);
|
||||
$('#pEditText').val(data_o['text']);
|
||||
this.id_s = data_opl['id'];
|
||||
this.tId = data_opl['tId'];
|
||||
this.dId = data_opl['dId'];
|
||||
|
||||
if (parseInt(this.dId) == 0)
|
||||
$("#idPostDetailContentHeader").text("Neue Diskussion");
|
||||
else if (parseInt(this.id_s) != 0)
|
||||
$("#idPostDetailContentHeader").text("Beitrag ändern");
|
||||
|
||||
this.storeFormContent_p();
|
||||
|
||||
$("#idPostEditContent").show();
|
||||
},
|
||||
initHandler_p: function () {
|
||||
// Ereignisverarbeitung für das Formular einrichten
|
||||
$("#idPostEditContent").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var do_b = false;
|
||||
var path_s;
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
switch (action_s) {
|
||||
case "back":
|
||||
// Weiterleiten
|
||||
if (this.dId != 0)
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussion', this.tId, this.dId]);
|
||||
else
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionList', this.tId]);
|
||||
break;
|
||||
case "save":
|
||||
// Formularinhalt prüfen
|
||||
if (this.isModified_p()) {
|
||||
if (this.checkContent_p()) {
|
||||
// kein klassisches submit, es wird auch keine neue Anzeige vorgenommen
|
||||
var data_s = $("#idPostDetail").serialize();
|
||||
data_s += "&owner=" + FORUM.user_o.name_s;
|
||||
$.ajax({
|
||||
context: this,
|
||||
dataType: "json",
|
||||
data: data_s,
|
||||
url: '/post/' + this.tId + '/' + this.dId + (this.id_s != 0?'/' + this.id_s:''),
|
||||
type: (this.id_s != 0?'POST':'PUT')
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
// aktuellen Formularinhalt speichern
|
||||
// (das Formular wird ja nicht mehr neu geladen!)
|
||||
this.storeFormContent_p();
|
||||
this.dId = data_opl['dId'];
|
||||
alert("Speichern ausgeführt!");
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussion', this.tId, this.dId]);
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
|
||||
} else {
|
||||
alert("Bitte prüfen Sie die Eingaben in den Formularfeldern!")
|
||||
}
|
||||
}
|
||||
else {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussion', this.tId, this.dId]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Weiterleitung und Standardbearbeitung unterbinden
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
isModified_p: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
return (this.FormContentOrg_s != $("#idPostDetail").serialize());
|
||||
},
|
||||
checkContent_p: function () {
|
||||
// hier nur zur Demonstration Prüfung des Typs gegen eine Werteliste
|
||||
// (das realisiert man besser mit einer Liste)
|
||||
var status_b = true;
|
||||
return status_b;
|
||||
},
|
||||
storeFormContent_p: function () {
|
||||
this.FormContentOrg_s = $("#idPostDetail").serialize();
|
||||
}
|
||||
});
|
||||
// EOF
|
117
Sammlung/Praktikum/4/js/edit_topic.js
Normal file
117
Sammlung/Praktikum/4/js/edit_topic.js
Normal file
@ -0,0 +1,117 @@
|
||||
// ----------------------------------------------
|
||||
// edit_Topic.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.TopicDetailView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
// Basis-Markup des Formulars anfordern
|
||||
var that = this;
|
||||
$.get('/html/edit_topic.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idTopicEditContent").hide();
|
||||
that.initHandler_p();
|
||||
|
||||
that.storeFormContent_p();
|
||||
});
|
||||
|
||||
},
|
||||
canClose_px: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
return (this.isModified_p() ? confirm("Es gibt nicht gespeicherte Änderungen - verwerfen?") : true);
|
||||
},
|
||||
close_px: function () {
|
||||
$("#idTopicEditContent").hide();
|
||||
},
|
||||
render_px: function (id_) {
|
||||
this.id_ = id_;
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/topic/' + (id_ == null?'0':id_),
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Form] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
doRender_p: function (data_opl) {
|
||||
// in das Formular übertragen
|
||||
var data_o = data_opl['data'];
|
||||
$('#tEditName').val(data_o['name']);
|
||||
this.id_s = data_opl['id'];
|
||||
|
||||
if (this.id_s != 0)
|
||||
$("#idTopicDetailContentHeader").text("Thema ändern");
|
||||
|
||||
this.storeFormContent_p();
|
||||
|
||||
$("#idTopicEditContent").show();
|
||||
},
|
||||
initHandler_p: function () {
|
||||
// Ereignisverarbeitung für das Formular einrichten
|
||||
$("#idTopicEditContent").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var do_b = false;
|
||||
var path_s;
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
switch (action_s) {
|
||||
case "back":
|
||||
// Weiterleiten
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
break;
|
||||
case "save":
|
||||
// Formularinhalt prüfen
|
||||
if (this.isModified_p()) {
|
||||
if (this.checkContent_p()) {
|
||||
// kein klassisches submit, es wird auch keine neue Anzeige vorgenommen
|
||||
var data_s = $("#idTopicDetail").serialize();
|
||||
data_s += "&owner=" + FORUM.user_o.name_s;
|
||||
$.ajax({
|
||||
context: this,
|
||||
dataType: "json",
|
||||
data: data_s,
|
||||
url: '/topic' + (this.id_s != 0?'/' + this.id_s:''),
|
||||
type: (this.id_s != 0?'POST':'PUT')
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
// aktuellen Formularinhalt speichern
|
||||
// (das Formular wird ja nicht mehr neu geladen!)
|
||||
this.storeFormContent_p();
|
||||
alert("Speichern ausgeführt!");
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
|
||||
} else {
|
||||
alert("Bitte prüfen Sie die Eingaben in den Formularfeldern!")
|
||||
}
|
||||
}
|
||||
else {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Weiterleitung und Standardbearbeitung unterbinden
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
isModified_p: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
return (this.FormContentOrg_s != $("#idTopicDetail").serialize());
|
||||
},
|
||||
checkContent_p: function () {
|
||||
// hier nur zur Demonstration Prüfung des Typs gegen eine Werteliste
|
||||
// (das realisiert man besser mit einer Liste)
|
||||
var status_b = true;
|
||||
return status_b;
|
||||
},
|
||||
storeFormContent_p: function () {
|
||||
this.FormContentOrg_s = $("#idTopicDetail").serialize();
|
||||
}
|
||||
});
|
||||
// EOF
|
91
Sammlung/Praktikum/4/js/es.js
Normal file
91
Sammlung/Praktikum/4/js/es.js
Normal file
@ -0,0 +1,91 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Event-Service: asynchroner Nachrichtenaustausch
|
||||
//------------------------------------------------------------------------------
|
||||
// depends-on:
|
||||
// jquery
|
||||
// inheritance
|
||||
// underscore
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function defer_p (notifier_ppl, entry_opl, message_spl, data_opl) {
|
||||
return setTimeout(function() {
|
||||
return notifier_ppl.apply(entry_opl, [entry_opl, message_spl, data_opl]);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
function each(object_opl, iterator, context) {
|
||||
for (var key in object_opl) {
|
||||
iterator.call(context, object_opl[key], key);
|
||||
}
|
||||
}
|
||||
|
||||
function findAll(object_opl, iterator, context) {
|
||||
var results = [];
|
||||
each(object_opl, function(value, index) {
|
||||
if (iterator.call(context, value, index))
|
||||
results.push(value);
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
function compact(object_opl) {
|
||||
return findAll(object_opl, function(value) {
|
||||
return value != null;
|
||||
});
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
var EventService_cl = Class.create({
|
||||
//------------------------------------------------------------------------------
|
||||
initialize: function () {
|
||||
this.Data_o = null;
|
||||
this.Subscriber_o = {};
|
||||
this.Method_o = null;
|
||||
},
|
||||
subscribe_px: function (Subscriber_opl, Message_spl) {
|
||||
if (Message_spl in this.Subscriber_o) {
|
||||
// Message bekannt, Liste der Subscriber untersuchen
|
||||
if (this.Subscriber_o[Message_spl].indexOf(Subscriber_opl) == -1) {
|
||||
this.Subscriber_o[Message_spl].push(Subscriber_opl);
|
||||
}
|
||||
} else {
|
||||
// Message noch nicht vorhanden, neu eintragen
|
||||
this.Subscriber_o[Message_spl] = [Subscriber_opl];
|
||||
}
|
||||
},
|
||||
unSubscribe_px: function (Subscriber_opl, Message_spl) {
|
||||
if (Message_spl in this.Subscriber_o) {
|
||||
// Message bekannt, Liste der Subscriber untersuchen
|
||||
var Entry_a = this.Subscriber_o[Message_spl];
|
||||
var index_i = Entry_a.indexOf(Subscriber_opl);
|
||||
if (index_i >= 0) {
|
||||
// Eintrag entfernen
|
||||
Entry_a[index_i] = null;
|
||||
Entry_a = compact(Entry_a); // compact liefert Kopie!
|
||||
if (Entry_a.length == 0) {
|
||||
// keine Subscriber mehr, kann entfernt werden
|
||||
delete this.Subscriber_o[Message_spl];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Message nicht vorhanden, falsche Anforderung
|
||||
}
|
||||
},
|
||||
publish_px: function (Message_spl, Data_opl) {
|
||||
console.info('es - publish ' + Message_spl);
|
||||
each(this.Subscriber_o, function (value_apl, key_spl) {
|
||||
// geliefert wird jeweils ein Wert, hier ein Array, und der Key
|
||||
if (key_spl == Message_spl) {
|
||||
// an alle Subscriber weitergeben
|
||||
each(value_apl, function (entry_opl, index_ipl) {
|
||||
// geliefert wird hier das Element und der Index
|
||||
//_.defer(entry_opl.notify_px, entry_opl, Message_spl, Data_opl);
|
||||
defer_p(entry_opl.notify_px, entry_opl, Message_spl, Data_opl);
|
||||
}, this
|
||||
);
|
||||
}
|
||||
}, this
|
||||
)
|
||||
}
|
||||
});
|
||||
// EOF
|
178
Sammlung/Praktikum/4/js/forum.js
Normal file
178
Sammlung/Praktikum/4/js/forum.js
Normal file
@ -0,0 +1,178 @@
|
||||
// ----------------------------------------------
|
||||
// forum.js
|
||||
// ----------------------------------------------
|
||||
// Verwendung von jquery, inheritance, Single-Page / Ajax, Event-Service
|
||||
// REST-Interface
|
||||
// ----------------------------------------------
|
||||
|
||||
|
||||
var FORUM = {};
|
||||
|
||||
//********************************************** USER-object
|
||||
FORUM.User_cl = Class.create({
|
||||
initialize: function () {
|
||||
this.name_s = '';
|
||||
this.password = '';
|
||||
this.loggedin = false;
|
||||
$('.clLoggedInText #idLoggedIn').hide();
|
||||
|
||||
},
|
||||
logout: function () {
|
||||
this.id_s = "";
|
||||
this.name_s = "niemand";
|
||||
this.loggedin = false;
|
||||
this.items = [];
|
||||
|
||||
|
||||
$('#idNav .clLinkToLogin').show();
|
||||
$('#idNav .clLinkToSignup').show();
|
||||
$('#idNav .clLinkToLogout').hide();
|
||||
$('.clLoggedInText #idNotLoggedIn').show();
|
||||
$('.clLoggedInText #idLoggedIn').hide();
|
||||
$('.clLoggedInText #idLoggedIn').text('Sie sind eingeloggt als: ');
|
||||
},
|
||||
login: function (data_o) {
|
||||
this.name_s = data_o['username'];
|
||||
this.password = data_o['password'];
|
||||
this.loggedin = true;
|
||||
|
||||
$('#idNav .clLinkToLogin').hide();
|
||||
$('#idNav .clLinkToSignup').hide();
|
||||
$('#idNav .clLinkToLogout').show();
|
||||
$('.clLoggedInText #idNotLoggedIn').hide();
|
||||
$('.clLoggedInText #idLoggedIn').show();
|
||||
$('.clLoggedInText #idLoggedIn').text($('.clLoggedInText #idLoggedIn').text() + data_o['username']);
|
||||
},
|
||||
register: function () {
|
||||
this.id_s = "";
|
||||
this.name_s = "niemand";
|
||||
this.loggedin = false;
|
||||
|
||||
$('#idNav .clLinkToLogin').show();
|
||||
$('#idNav .clLinkToSignup').show();
|
||||
$('#idNav .clLinkToLogout').hide();
|
||||
}
|
||||
});
|
||||
//**********************************************
|
||||
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.Application_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
this.content_o = null; // das jeweils aktuelle Objekt im Contentbereich
|
||||
this.nav_o = new FORUM.Nav_cl();
|
||||
//this.discussionView_o = new FORUM.PostlistView_cl();
|
||||
this.topicListView_o = new FORUM.TopicListView_cl();
|
||||
this.topicDetailView_o = new FORUM.TopicDetailView_cl();
|
||||
this.discussionListView_o = new FORUM.DiscussionListView_cl();
|
||||
this.discussionDetailView_o = new FORUM.DiscussionDetailView_cl();
|
||||
this.postListView_o = new FORUM.PostListView_cl();
|
||||
this.postDetailView_o = new FORUM.PostDetailView_cl();
|
||||
this.postView_o = new FORUM.PostView_cl();
|
||||
|
||||
//this.discussionlistView_o = new FORUM.DiscussionlistView_cl();
|
||||
//this.postView_o = new FORUM.PostView_cl();
|
||||
this.loginView_o = new FORUM.LoginView_cl();
|
||||
|
||||
// Registrierungen
|
||||
FORUM.es_o.subscribe_px(this, 'ContentChanged');
|
||||
},
|
||||
notify_px: function (self_opl, message_spl, data_apl) {
|
||||
switch (message_spl) {
|
||||
case 'ContentChanged':
|
||||
switch (data_apl[0]) {
|
||||
case 'init':
|
||||
FORUM.tm_o = new TELIB.TemplateManager_cl();
|
||||
break;
|
||||
|
||||
case 'showRegister':
|
||||
self_opl.setContent_p(self_opl.registerView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'showLogin':
|
||||
self_opl.setContent_p(self_opl.loginView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'logout':
|
||||
FORUM.user_o.logout();
|
||||
self_opl.setContent_p(self_opl.topicListView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'login':
|
||||
self_opl.setContent_p(self_opl.loginView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'register':
|
||||
FORUM.user_o.register();
|
||||
self_opl.setContent_p(self_opl.topicListView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'topicList':
|
||||
self_opl.setContent_p(self_opl.topicListView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'topicEdit':
|
||||
self_opl.setContent_p(self_opl.topicDetailView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'discussionList':
|
||||
self_opl.setContent_p(self_opl.discussionListView_o, data_apl[1]);
|
||||
break;
|
||||
|
||||
case 'discussionEdit':
|
||||
self_opl.setContent_p(self_opl.discussionDetailView_o, [data_apl[1], data_apl[2]]);
|
||||
break;
|
||||
|
||||
case 'discussion':
|
||||
self_opl.setContent_p(self_opl.postListView_o, [data_apl[1], data_apl[2]]);
|
||||
break;
|
||||
|
||||
case 'postEdit':
|
||||
self_opl.setContent_p(self_opl.postDetailView_o, [data_apl[1], data_apl[2], data_apl[3]]);
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
self_opl.setContent_p(self_opl.postView_o, [data_apl[1], data_apl[2], data_apl[3]]);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn('[Application_cl] unbekannte app-Notification: ' + data_apl[0]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.warn('[Application_cl] unbekannte Notification: ' + message_spl);
|
||||
break;
|
||||
}
|
||||
},
|
||||
setContent_p: function (newContent_opl, data_opl) {
|
||||
if (this.content_o != null) {
|
||||
if (this.content_o.canClose_px()) {
|
||||
this.content_o.close_px();
|
||||
this.content_o = newContent_opl;
|
||||
this.content_o.render_px(data_opl);
|
||||
}
|
||||
} else {
|
||||
this.content_o = newContent_opl;
|
||||
this.content_o.render_px(data_opl);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------
|
||||
$(document).ready(function () {
|
||||
// ----------------------------------------------
|
||||
// wird ausgeführt, wenn das Dokument vollständig geladen wurde
|
||||
FORUM.es_o = new EventService_cl();
|
||||
FORUM.app_o = new FORUM.Application_cl();
|
||||
FORUM.user_o = new FORUM.User_cl();
|
||||
FORUM.es_o.publish_px('ContentChanged', ['init', null]);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// EOF
|
122
Sammlung/Praktikum/4/js/inheritance.js
Normal file
122
Sammlung/Praktikum/4/js/inheritance.js
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
Class, version 2.7
|
||||
Copyright (c) 2006, 2007, 2008, Alex Arnell <alex@twologic.com>
|
||||
Licensed under the new BSD License. See end of file for full license terms.
|
||||
*/
|
||||
|
||||
var Class = (function() {
|
||||
var __extending = {};
|
||||
|
||||
return {
|
||||
extend: function(parent, def) {
|
||||
if (arguments.length == 1) { def = parent; parent = null; }
|
||||
var func = function() {
|
||||
if (arguments[0] == __extending) { return; }
|
||||
this.initialize.apply(this, arguments);
|
||||
};
|
||||
if (typeof(parent) == 'function') {
|
||||
func.prototype = new parent( __extending);
|
||||
}
|
||||
var mixins = [];
|
||||
if (def && def.include) {
|
||||
if (def.include.reverse) {
|
||||
// methods defined in later mixins should override prior
|
||||
mixins = mixins.concat(def.include.reverse());
|
||||
} else {
|
||||
mixins.push(def.include);
|
||||
}
|
||||
delete def.include; // clean syntax sugar
|
||||
}
|
||||
if (def) Class.inherit(func.prototype, def);
|
||||
for (var i = 0; (mixin = mixins[i]); i++) {
|
||||
Class.mixin(func.prototype, mixin);
|
||||
}
|
||||
return func;
|
||||
},
|
||||
mixin: function (dest, src, clobber) {
|
||||
clobber = clobber || false;
|
||||
if (typeof(src) != 'undefined' && src !== null) {
|
||||
for (var prop in src) {
|
||||
if (clobber || (!dest[prop] && typeof(src[prop]) == 'function')) {
|
||||
dest[prop] = src[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
},
|
||||
inherit: function(dest, src, fname) {
|
||||
if (arguments.length == 3) {
|
||||
var ancestor = dest[fname], descendent = src[fname], method = descendent;
|
||||
descendent = function() {
|
||||
var ref = this.parent; this.parent = ancestor;
|
||||
var result = method.apply(this, arguments);
|
||||
ref ? this.parent = ref : delete this.parent;
|
||||
return result;
|
||||
};
|
||||
// mask the underlying method
|
||||
descendent.valueOf = function() { return method; };
|
||||
descendent.toString = function() { return method.toString(); };
|
||||
dest[fname] = descendent;
|
||||
} else {
|
||||
for (var prop in src) {
|
||||
if (dest[prop] && typeof(src[prop]) == 'function') {
|
||||
Class.inherit(dest, src, prop);
|
||||
} else {
|
||||
dest[prop] = src[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
},
|
||||
singleton: function() {
|
||||
var args = arguments;
|
||||
if (args.length == 2 && args[0].getInstance) {
|
||||
var klass = args[0].getInstance(__extending);
|
||||
// we're extending a singleton swap it out for it's class
|
||||
if (klass) { args[0] = klass; }
|
||||
}
|
||||
|
||||
return (function(args){
|
||||
// store instance and class in private variables
|
||||
var instance = false;
|
||||
var klass = Class.extend.apply(args.callee, args);
|
||||
return {
|
||||
getInstance: function () {
|
||||
if (arguments[0] == __extending) return klass;
|
||||
if (instance) return instance;
|
||||
return (instance = new klass());
|
||||
}
|
||||
};
|
||||
})(args);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
// finally remap Class.create for backward compatability with prototype
|
||||
Class.create = function() {
|
||||
return Class.extend.apply(this, arguments);
|
||||
};
|
||||
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without modification, are
|
||||
permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
* Neither the name of typicalnoise.com nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
4
Sammlung/Praktikum/4/js/jquery-2.2.0.min.js
vendored
Normal file
4
Sammlung/Praktikum/4/js/jquery-2.2.0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
196
Sammlung/Praktikum/4/js/list_discussion.js
Normal file
196
Sammlung/Praktikum/4/js/list_discussion.js
Normal file
@ -0,0 +1,196 @@
|
||||
// ----------------------------------------------
|
||||
// list_discussion.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.DiscussionListView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
switch (action_s) {
|
||||
|
||||
case 'addDiscussion':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['postEdit', this.tId, 0, 0]);
|
||||
break;
|
||||
|
||||
case 'discussion':
|
||||
if (this.rowId_s != "") {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussion', this.tId, this.rowId_s]);
|
||||
this.updateButtons_p();
|
||||
} else {
|
||||
alert("Wählen Sie bitte einen Eintrag in der Tabelle aus!");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'deleteDiscussion':
|
||||
if (this.rowId_s != "") {
|
||||
if (confirm("Soll der Datensatz gelöscht werden?")) {
|
||||
var path_s = "/discussion/" + this.rowId_s;
|
||||
$.ajax({
|
||||
context: this,
|
||||
// dataType: "json",
|
||||
url: path_s,
|
||||
type: 'DELETE'
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
$('#d' + this.rowId_s + ' .clName').text('>>Gelöscht durch ' + $('#d' + this.rowId_s + ' .clOwner').text() + '<<');
|
||||
$('.clSelected').removeClass('clSelected');
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionList', this.tId]);
|
||||
this.initList_p();
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[ThemenListe] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
alert("Wählen Sie bitte einen Eintrag in der Tabelle aus!");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'editDiscussion':
|
||||
if (this.rowId_s != "") {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionEdit', this.tId, this.rowId_s]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'back':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
break;
|
||||
}
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
|
||||
|
||||
getContentFromEditForm_p: function () {
|
||||
return content_o = {
|
||||
'title': $('#idDiscussionFormEdit #edittitle_s').text(),
|
||||
'username': FORUM.user_o.name_s,
|
||||
'userid': FORUM.user_o.id_s
|
||||
}
|
||||
},
|
||||
storeContentToEditForm_p: function () {
|
||||
content_s = $('#idDiscussionList .clSelected #idDiscussionTitle').text();
|
||||
|
||||
$('#idDiscussionDetailContentHeader #edittitle_s').text(content_s);
|
||||
},
|
||||
onClickList_p: function (event_opl) {
|
||||
this.initList_p();
|
||||
|
||||
if ($(event_opl.target).parent().attr('id') != 'deleted') {
|
||||
this.rowId_s = $(event_opl.target).parent().attr('id').substring(1);
|
||||
$("#d" + this.rowId_s).addClass("clSelected");
|
||||
|
||||
this.updateButtons_p();
|
||||
}
|
||||
},
|
||||
initialize: function () {
|
||||
var that = this;
|
||||
$.get('/html/list_discussion.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idDiscussionListContent").hide();
|
||||
that.initHandler_p();
|
||||
that.initList_p();
|
||||
});
|
||||
},
|
||||
render_px: function (data_opl) {
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/discussion/' + data_opl,
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Liste] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
doRender_p: function (data_opl) {
|
||||
var unsorted = {};
|
||||
var sorted = [];
|
||||
for (key in data_opl['data']) {
|
||||
var lowest = parseInt(data_opl['data'][key]['posts'][0])
|
||||
for (lower in data_opl['data'][key]['posts']) {
|
||||
if (parseInt(data_opl['data'][key]['posts'][lower]) < lowest) {
|
||||
lowest = parseInt(data_opl['data'][key]['posts'][lower]);
|
||||
}
|
||||
}
|
||||
unsorted[lowest.toString()] = key;
|
||||
sorted.push(lowest);
|
||||
}
|
||||
sorted.sort(function (a, b) { return a - b; });
|
||||
for (key in sorted) {
|
||||
sorted[key] = unsorted[sorted[parseInt(key)]];
|
||||
}
|
||||
data_opl['indices'] = sorted;
|
||||
|
||||
var rows_s = FORUM.tm_o.execute_px('list_discussion.tpl', data_opl);
|
||||
this.tId = data_opl['tId'];
|
||||
this.initList_p();
|
||||
|
||||
$("#idDiscussionList tbody tr[class!='listheader']").remove();
|
||||
$("#idDiscussionList tbody").append(rows_s);
|
||||
$("#idDiscussionListContent").show();
|
||||
console.log("[ListView_cl] doRender");
|
||||
this.updateButtons_p();
|
||||
},
|
||||
initList_p: function () {
|
||||
$(".clSelected").removeClass("clSelected");
|
||||
this.rowId_s = '';
|
||||
this.updateButtons_p();
|
||||
},
|
||||
initHandler_p: function () {
|
||||
$("#idDiscussionList").on("click", "td", $.proxy(this.onClickList_p, this));
|
||||
$("#idDiscussionListContent").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
enableButtons_p: function () {
|
||||
|
||||
$("#idDiscussionListContent .clButtonArea button[data-action=back]").prop("disabled", false);
|
||||
|
||||
if (FORUM.user_o.loggedin) {
|
||||
this.enableAddButton_p();
|
||||
}
|
||||
if (this.rowId_s != '') {
|
||||
this.enableViewButton_p();
|
||||
}
|
||||
if (this.rowId_s != '' && FORUM.user_o.loggedin && $("#d" + this.rowId_s + " .clOwner").text() == FORUM.user_o.name_s) {
|
||||
this.enableEditButtons_p();
|
||||
}
|
||||
},
|
||||
enableViewButton_p: function () {
|
||||
$("#idDiscussionListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "discussion") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
enableAddButton_p: function () {
|
||||
$("#idDiscussionListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "addDiscussion") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
enableEditButtons_p: function () {
|
||||
$("#idDiscussionListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "deleteDiscussion" || $(this).attr("data-action") == "editDiscussion") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
updateButtons_p: function () {
|
||||
$("#idDiscussionListContent .clButtonArea button").each(function () {
|
||||
$(this).prop("disabled", true);
|
||||
});
|
||||
this.enableButtons_p();
|
||||
},
|
||||
canClose_px: function () {
|
||||
return true;
|
||||
},
|
||||
close_px: function () {
|
||||
this.updateButtons_p();
|
||||
$('.clSelected').removeClass("clSelected");
|
||||
|
||||
$("#idDiscussionListContent").hide();
|
||||
}
|
||||
});
|
||||
// EOF
|
191
Sammlung/Praktikum/4/js/list_post.js
Normal file
191
Sammlung/Praktikum/4/js/list_post.js
Normal file
@ -0,0 +1,191 @@
|
||||
// ----------------------------------------------
|
||||
// list_post.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.PostListView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
switch (action_s) {
|
||||
|
||||
case 'addPost':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['postEdit', this.tId, this.dId, 0]);
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
if (this.rowId_s != "") {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['post', this.tId, this.dId, this.rowId_s]);
|
||||
this.updateButtons_p();
|
||||
} else {
|
||||
alert("Wählen Sie bitte einen Eintrag in der Tabelle aus!");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'deletePost':
|
||||
if (this.rowId_s != "") {
|
||||
if (confirm("Soll der Datensatz gelöscht werden?")) {
|
||||
var path_s = "/post/" + this.rowId_s;
|
||||
$.ajax({
|
||||
context: this,
|
||||
// dataType: "json",
|
||||
url: path_s,
|
||||
type: 'DELETE'
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
$('#p' + this.rowId_s + ' .clName').text('>>Gelöscht durch ' + $('#p' + this.rowId_s + ' .clOwner').text() + '<<');
|
||||
$('.clSelected').removeClass('clSelected');
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussion', this.tId, this.dId]);
|
||||
this.initList_p();
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[ThemenListe] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
alert("Wählen Sie bitte einen Eintrag in der Liste aus!");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'editPost':
|
||||
if (this.rowId_s != "") {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['postEdit', this.tId, this.dId, this.rowId_s]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'back':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionList', this.tId]);
|
||||
break;
|
||||
}
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
|
||||
|
||||
getContentFromEditForm_p: function () {
|
||||
return content_o = {
|
||||
'title': $('#idPostFormEdit #edittitle_s').text(),
|
||||
'username': FORUM.user_o.name_s,
|
||||
'userid': FORUM.user_o.id_s
|
||||
}
|
||||
},
|
||||
storeContentToEditForm_p: function () {
|
||||
content_s = $('#p' + this.rowId_s + ' #idPostTitle').text();
|
||||
|
||||
$('#idPostDetailContentHeader #edittitle_s').text(content_s);
|
||||
},
|
||||
onClickList_p: function (event_opl) {
|
||||
this.initList_p();
|
||||
|
||||
if ($(event_opl.target).parent().parent().parent().attr('id') != 'deleted') {
|
||||
this.rowId_s = $(event_opl.target).parent().parent().parent().attr('id').substring(1);
|
||||
$("#p" + this.rowId_s).addClass("clSelected");
|
||||
|
||||
this.updateButtons_p();
|
||||
}
|
||||
},
|
||||
initialize: function () {
|
||||
var that = this;
|
||||
$.get('/html/list_post.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idPostListContent").hide();
|
||||
that.initHandler_p();
|
||||
that.initList_p();
|
||||
});
|
||||
},
|
||||
render_px: function (data_opl) {
|
||||
$("#pEditTitle").val('');
|
||||
$("#pEditText").val('');
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/post/' + data_opl[0] + '/' + data_opl[1],
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Liste] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
doRender_p: function (data_opl) {
|
||||
var sorted = [];
|
||||
for (key in data_opl['data']) {
|
||||
if (data_opl['data'][key] != 'nextID') {
|
||||
sorted.push(key);
|
||||
}
|
||||
}
|
||||
sorted.sort(function (a, b) { return a - b; });
|
||||
data_opl['indices'] = sorted;
|
||||
|
||||
var rows_s = FORUM.tm_o.execute_px('list_post.tpl', data_opl);
|
||||
this.tId = data_opl['tId'];
|
||||
this.dId = data_opl['dId'];
|
||||
this.initList_p();
|
||||
|
||||
$("#idPostList li").remove();
|
||||
$("#idPostList").append(rows_s);
|
||||
$("#idPostList li:last-of-type").addClass("newest");
|
||||
$("#idPostListContent").show();
|
||||
console.log("[PostListView_cl] doRender");
|
||||
this.updateButtons_p();
|
||||
},
|
||||
initList_p: function () {
|
||||
$(".clSelected").removeClass("clSelected");
|
||||
this.rowId_s = '';
|
||||
this.updateButtons_p();
|
||||
},
|
||||
initHandler_p: function () {
|
||||
$("#idPostList").on("click", ".clPostContainer", $.proxy(this.onClickList_p, this));
|
||||
$("#idPostListContent").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
enableButtons_p: function () {
|
||||
|
||||
$("#idPostListContent .clButtonArea button[data-action=back]").prop("disabled", false);
|
||||
|
||||
if (FORUM.user_o.loggedin) {
|
||||
this.enableAddButton_p();
|
||||
}
|
||||
if (this.rowId_s != '') {
|
||||
this.enableViewButton_p();
|
||||
}
|
||||
if (this.rowId_s != '' && FORUM.user_o.loggedin && $("#p" + this.rowId_s + " .clOwner").text() == FORUM.user_o.name_s && $("#p" + this.rowId_s).attr('class') == "newest clSelected") {
|
||||
this.enableEditButtons_p();
|
||||
}
|
||||
},
|
||||
enableViewButton_p: function () {
|
||||
$("#idPostListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "post") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
enableAddButton_p: function () {
|
||||
$("#idPostListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "addPost") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
enableEditButtons_p: function () {
|
||||
$("#idPostListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "deletePost" || $(this).attr("data-action") == "editPost") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
updateButtons_p: function () {
|
||||
$("#idPostListContent .clButtonArea button").each(function () {
|
||||
$(this).prop("disabled", true);
|
||||
});
|
||||
this.enableButtons_p();
|
||||
},
|
||||
canClose_px: function () {
|
||||
return true;
|
||||
},
|
||||
close_px: function () {
|
||||
this.updateButtons_p();
|
||||
$('.clSelected').removeClass("clSelected");
|
||||
$("#idPostList li").remove();
|
||||
$("#idPostListContent").hide();
|
||||
}
|
||||
});
|
||||
// EOF
|
190
Sammlung/Praktikum/4/js/list_topic.js
Normal file
190
Sammlung/Praktikum/4/js/list_topic.js
Normal file
@ -0,0 +1,190 @@
|
||||
// ----------------------------------------------
|
||||
// list_topic.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.TopicListView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
switch (action_s) {
|
||||
|
||||
case 'addTopic':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicEdit', 0]);
|
||||
break;
|
||||
|
||||
|
||||
case 'discussionList':
|
||||
if (this.rowId_s != "") {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussionList', this.rowId_s]);
|
||||
this.updateButtons_p();
|
||||
} else {
|
||||
alert("Wählen Sie bitte einen Eintrag in der Tabelle aus!");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'deleteTopic':
|
||||
if (this.rowId_s != "") {
|
||||
if (confirm("Soll der Datensatz gelöscht werden?")) {
|
||||
var path_s = "/topic/" + this.rowId_s;
|
||||
$.ajax({
|
||||
context: this,
|
||||
// dataType: "json",
|
||||
url: path_s,
|
||||
type: 'DELETE'
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
$('#t' + this.rowId_s + ' .clName').text('>>Gelöscht durch ' + $('#t' + this.rowId_s + ' .clOwner').text() + '<<');
|
||||
$('.clSelected').removeClass('clSelected');
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
this.initList_p();
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[ThemenListe] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
alert("Wählen Sie bitte einen Eintrag in der Tabelle aus!");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'editTopic':
|
||||
if (this.rowId_s != "") {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicEdit', this.rowId_s]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
|
||||
|
||||
getContentFromEditForm_p: function () {
|
||||
return content_o = {
|
||||
'title': $('#idTopicFormEdit #edittitle_s').text(),
|
||||
'username': FORUM.user_o.name_s,
|
||||
'userid': FORUM.user_o.id_s
|
||||
}
|
||||
},
|
||||
storeContentToEditForm_p: function () {
|
||||
content_s = $('#idTopicList .clSelected #idTopicTitle').text();
|
||||
|
||||
$('#idTopicDetailContentHeader #edittitle_s').text(content_s);
|
||||
},
|
||||
onClickList_p: function (event_opl) {
|
||||
this.initList_p();
|
||||
|
||||
if ($(event_opl.target).parent().attr('id') != 'deleted') {
|
||||
this.rowId_s = $(event_opl.target).parent().attr('id').substring(1);
|
||||
$("#t" + this.rowId_s).addClass("clSelected");
|
||||
|
||||
this.updateButtons_p();
|
||||
}
|
||||
},
|
||||
initialize: function () {
|
||||
var that = this;
|
||||
$.get('/html/list_topic.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idTopicListContent").hide();
|
||||
that.initHandler_p();
|
||||
that.initList_p();
|
||||
});
|
||||
},
|
||||
render_px: function (data_opl) {
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/topic',
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Liste] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
doRender_p: function (data_opl) {
|
||||
var unsorted = [];
|
||||
var sorted = [];
|
||||
for (key in data_opl['data']) {
|
||||
if (data_opl['data'][key] != 'nextID') {
|
||||
unsorted.push(data_opl['data'][key]['name']);
|
||||
}
|
||||
}
|
||||
unsorted.sort();
|
||||
for (key in unsorted) {
|
||||
for (key2 in data_opl['data']) {
|
||||
if (key2 != 'nextID' && unsorted[key] == data_opl['data'][key2]['name']) {
|
||||
sorted.push(key2);
|
||||
}
|
||||
}
|
||||
}
|
||||
data_opl['indices'] = sorted;
|
||||
|
||||
var rows_s = FORUM.tm_o.execute_px('list_topic.tpl', data_opl);
|
||||
this.initList_p();
|
||||
|
||||
$("#idTopicList tbody tr[class!='listheader']").remove();
|
||||
$("#idTopicList tbody").append(rows_s);
|
||||
$("#idTopicListContent").show();
|
||||
console.log("[TopicListView_cl] doRender");
|
||||
this.updateButtons_p();
|
||||
},
|
||||
initList_p: function () {
|
||||
$(".clSelected").removeClass("clSelected");
|
||||
this.rowId_s = '';
|
||||
this.updateButtons_p();
|
||||
},
|
||||
initHandler_p: function () {
|
||||
$("#idTopicList").on("click", "td", $.proxy(this.onClickList_p, this));
|
||||
$("#idTopicListContent .clButtonArea").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
enableButtons_p: function () {
|
||||
|
||||
if (FORUM.user_o.loggedin) {
|
||||
this.enableAddButton_p();
|
||||
}
|
||||
if (this.rowId_s != '') {
|
||||
this.enableViewButton_p();
|
||||
}
|
||||
if (this.rowId_s != '' && FORUM.user_o.loggedin && $("#t" + this.rowId_s + " .clOwner").text() == FORUM.user_o.name_s) {
|
||||
this.enableEditButtons_p();
|
||||
}
|
||||
},
|
||||
enableViewButton_p: function () {
|
||||
$("#idTopicListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "discussionList") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
enableAddButton_p: function () {
|
||||
$("#idTopicListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "addTopic") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
enableEditButtons_p: function () {
|
||||
$("#idTopicListContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "deleteTopic" || $(this).attr("data-action") == "editTopic") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
updateButtons_p: function () {
|
||||
$("#idTopicListContent .clButtonArea button").each(function () {
|
||||
$(this).prop("disabled", true);
|
||||
});
|
||||
this.enableButtons_p();
|
||||
},
|
||||
canClose_px: function () {
|
||||
return true;
|
||||
},
|
||||
close_px: function () {
|
||||
this.updateButtons_p();
|
||||
$('.clSelected').removeClass("clSelected");
|
||||
|
||||
$("#idTopicListContent").hide();
|
||||
}
|
||||
});
|
||||
// EOF
|
135
Sammlung/Praktikum/4/js/login.js
Normal file
135
Sammlung/Praktikum/4/js/login.js
Normal file
@ -0,0 +1,135 @@
|
||||
// ----------------------------------------------
|
||||
// login.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.LoginView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
|
||||
var that = this;
|
||||
$.get('/html/login.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idLoginContent").hide();
|
||||
that.initHandler_p();
|
||||
});
|
||||
FORUM.es_o.subscribe_px(this, 'loginform');
|
||||
|
||||
},
|
||||
|
||||
notify_px: function (self_opl, message_spl, data_apl) {
|
||||
switch (message_spl) {
|
||||
case 'loginform':
|
||||
switch (data_apl[0]) {
|
||||
case 'refresh':
|
||||
self_opl.render_px(null);
|
||||
break;
|
||||
default:
|
||||
console.warning('[LoginView_cl] unbekannte list-Notification: ' + data_apl[0]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.warning('[LoginView_cl] unbekannte Notification: ' + message_spl);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
canClose_px: function () {
|
||||
return true;
|
||||
},
|
||||
|
||||
close_px: function () {
|
||||
$("#idLoginContent").hide();
|
||||
},
|
||||
|
||||
render_px: function (data_opl) {
|
||||
this.doRender_p();
|
||||
},
|
||||
|
||||
doRender_p: function () {
|
||||
$("#idLoginContent").show();
|
||||
console.log("[LoginView_cl] doRender");
|
||||
},
|
||||
|
||||
initHandler_p: function () {
|
||||
$("#idLoginContent #idButtonArea").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
|
||||
data_o = {
|
||||
"username": $("#idLoginContent #username").val(),
|
||||
"password": $("#idLoginContent #password").val()
|
||||
}
|
||||
switch (action_s) {
|
||||
case 'login':
|
||||
$.ajax({
|
||||
data: data_o,
|
||||
dataType: "json",
|
||||
url: '/login/',
|
||||
type: 'GET'
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
if (data_opl) {
|
||||
FORUM.user_o.login(data_o);
|
||||
alert("Sie sind eingeloggt als \"" + data_o['username'] + "\"")
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
}
|
||||
else {
|
||||
alert("Die Login-Daten sind nicht korrekt!");
|
||||
}
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert( "Fehler bei Anforderung: " + textStatus_spl );
|
||||
});
|
||||
break;
|
||||
case 'register':
|
||||
$.ajax({
|
||||
data: data_o,
|
||||
dataType: "json",
|
||||
url: '/login/',
|
||||
type: 'PUT'
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
if (data_opl) {
|
||||
FORUM.user_o.login(data_o);
|
||||
alert("Sie sind registriert als \"" + data_o['username'] + "\"")
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
}
|
||||
else {
|
||||
alert("Der Benutzername ist leider schon vergeben!");
|
||||
}
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
break;
|
||||
case 'back':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
break;
|
||||
}
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
|
||||
enableButtons_p: function () {
|
||||
$("#idLoginContent #idButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") != "add") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
disableButtons_p: function () {
|
||||
$("#idLoginContent #idButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") != "add") {
|
||||
$(this).prop("disabled", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// EOF
|
29
Sammlung/Praktikum/4/js/nav.js
Normal file
29
Sammlung/Praktikum/4/js/nav.js
Normal file
@ -0,0 +1,29 @@
|
||||
// ----------------------------------------------
|
||||
// litnav.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.Nav_cl = Class.create({
|
||||
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
this.render_px();
|
||||
this.initHandler_p();
|
||||
},
|
||||
|
||||
render_px: function (data_opl) {
|
||||
$('#idNav .clLinkToLogout').hide();
|
||||
},
|
||||
|
||||
initHandler_p: function () {
|
||||
$("#idNav").on("click", "a", function (event_opl) {
|
||||
var action_s = $(event_opl.target).attr('data-action');
|
||||
FORUM.es_o.publish_px('ContentChanged', [action_s, null]);
|
||||
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// EOF
|
124
Sammlung/Praktikum/4/js/post.js
Normal file
124
Sammlung/Praktikum/4/js/post.js
Normal file
@ -0,0 +1,124 @@
|
||||
// ----------------------------------------------
|
||||
// list_post.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.PostView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
onClickButtons_p: function (event_opl) {
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
switch (action_s) {
|
||||
case 'deletePost':
|
||||
if (confirm("Soll der Datensatz gelöscht werden?")) {
|
||||
var path_s = "/post/" + this.id_s;
|
||||
$.ajax({
|
||||
context: this,
|
||||
// dataType: "json",
|
||||
url: path_s,
|
||||
type: 'DELETE'
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussion', this.tId, this.dId]);
|
||||
this.initList_p();
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[ThemenListe] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case 'editPost':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['postEdit', this.tId, this.dId, this.id_s]);
|
||||
break;
|
||||
|
||||
case 'back':
|
||||
FORUM.es_o.publish_px('ContentChanged', ['discussion', this.tId, this.dId]);
|
||||
break;
|
||||
}
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
storeContentToEditForm_p: function () {
|
||||
content_s = $('#p' + this.rowId_s + ' #idPostTitle').text();
|
||||
|
||||
$('#idPostContentHeader #edittitle_s').text(content_s);
|
||||
},
|
||||
initialize: function () {
|
||||
var that = this;
|
||||
$.get('/html/post.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idPostContent").hide();
|
||||
that.initHandler_p();
|
||||
that.initList_p();
|
||||
});
|
||||
},
|
||||
render_px: function (data_opl) {
|
||||
$("#pEditTitle").val('');
|
||||
$("#pEditText").val('');
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/post/' + data_opl[0] + '/' + data_opl[1] + '/' + data_opl[2],
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Liste] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
doRender_p: function (data_opl) {
|
||||
this.initList_p();
|
||||
|
||||
this.tId = data_opl['tId'];
|
||||
this.dId = data_opl['dId'];
|
||||
this.id_s = data_opl['id'];
|
||||
|
||||
data_o = {};
|
||||
data_o[this.id_s] = data_opl['data'];
|
||||
data_opl['data'] = data_o
|
||||
|
||||
data_opl['indices'] = [this.id_s];
|
||||
var rows_s = FORUM.tm_o.execute_px('list_post.tpl', data_opl);
|
||||
|
||||
$("#idPost li").remove();
|
||||
$("#idPost").append(rows_s);
|
||||
$("#idPostContent").show();
|
||||
console.log("[PostView_cl] doRender");
|
||||
this.updateButtons_p();
|
||||
},
|
||||
initList_p: function () {
|
||||
$(".clSelected").removeClass("clSelected");
|
||||
this.id_s = '';
|
||||
},
|
||||
initHandler_p: function () {
|
||||
$("#idPostContent").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
},
|
||||
enableButtons_p: function () {
|
||||
|
||||
$("#idPostContent .clButtonArea button[data-action=back]").prop("disabled", false);
|
||||
if (FORUM.user_o.loggedin && $("#p" + this.id_s + " .clOwner").text() == FORUM.user_o.name_s) {
|
||||
this.enableEditButtons_p();
|
||||
}
|
||||
},
|
||||
enableEditButtons_p: function () {
|
||||
$("#idPostContent .clButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") == "deletePost" || $(this).attr("data-action") == "editPost") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
updateButtons_p: function () {
|
||||
$("#idPostContent .clButtonArea button").each(function () {
|
||||
$(this).prop("disabled", true);
|
||||
});
|
||||
this.enableButtons_p();
|
||||
},
|
||||
canClose_px: function () {
|
||||
return true;
|
||||
},
|
||||
close_px: function () {
|
||||
this.updateButtons_p();
|
||||
$("#idPost li").remove();
|
||||
$("#idPostContent").hide();
|
||||
}
|
||||
});
|
||||
// EOF
|
111
Sammlung/Praktikum/4/js/register.js
Normal file
111
Sammlung/Praktikum/4/js/register.js
Normal file
@ -0,0 +1,111 @@
|
||||
// ----------------------------------------------
|
||||
// register.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
FORUM.RegisterView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
var that = this;
|
||||
$.get('/html/register.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idRegisterContent").hide();
|
||||
that.initHandler_p();
|
||||
});
|
||||
FORUM.es_o.subscribe_px(this, 'register');
|
||||
},
|
||||
|
||||
notify_px: function (self_opl, message_spl, data_apl) {
|
||||
switch (message_spl) {
|
||||
case 'register':
|
||||
switch (data_apl[0]) {
|
||||
case 'refresh':
|
||||
self_opl.render_px(null);
|
||||
break;
|
||||
default:
|
||||
console.warning('[RegisterView_cl] unbekannte list-Notification: ' + data_apl[0]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.warning('[RegisterView_cl] unbekannte Notification: ' + message_spl);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
canClose_px: function () {
|
||||
return true;
|
||||
},
|
||||
|
||||
close_px: function () {
|
||||
$("#idRegisterContent").hide();
|
||||
},
|
||||
|
||||
render_px: function (data_opl) {
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: '/register',
|
||||
type: 'GET'
|
||||
})
|
||||
.done($.proxy(this.doRender_p, this))
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert("[Register] Fehler bei Anforderung: " + textStatus_spl);
|
||||
});
|
||||
},
|
||||
|
||||
doRender_p: function (data_opl) {
|
||||
$("#idRegisterContent").show();
|
||||
console.log("[RegisterView_cl] doRender");
|
||||
},
|
||||
|
||||
initHandler_p: function () {
|
||||
$("#idRegisterContent #idButtonArea").on("click", "button", $.proxy(this.onClickButtons_p, this));
|
||||
|
||||
},
|
||||
|
||||
onClickButtons_p: function (event_opl) {
|
||||
|
||||
var action_s = $(event_opl.target).attr("data-action");
|
||||
|
||||
switch (action_s) {
|
||||
case 'registerme':
|
||||
var data_s = $("#idForm").serialize();
|
||||
alert(data_s);
|
||||
$.ajax({
|
||||
context: this,
|
||||
data: data_s,
|
||||
url: '/register',
|
||||
type: 'PUT'
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
alert("Speichern ausgeführt!");
|
||||
})
|
||||
.fail(function (jqXHR_opl, textStatus_spl) {
|
||||
alert( "Fehler bei Anforderung: " + textStatus_spl );
|
||||
});
|
||||
FORUM.es_o.publish_px('app', [action_s, null]);
|
||||
break;
|
||||
}
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
|
||||
},
|
||||
|
||||
enableButtons_p: function () {
|
||||
$("#idRegisterContent #idButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") != "add") {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
disableButtons_p: function () {
|
||||
$("#idRegisterContent #idButtonArea button").each(function () {
|
||||
if ($(this).attr("data-action") != "add") {
|
||||
$(this).prop("disabled", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// EOF
|
308
Sammlung/Praktikum/4/js/te.js
Normal file
308
Sammlung/Praktikum/4/js/te.js
Normal file
@ -0,0 +1,308 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Template-Engine
|
||||
//------------------------------------------------------------------------------
|
||||
// depends-on:
|
||||
// inheritance
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// String-Methoden ergänzen
|
||||
|
||||
APPCO = {};
|
||||
|
||||
APPCO.apply = function(o, c, defaults){
|
||||
// no "this" reference for friendly out of scope calls
|
||||
if (defaults) {
|
||||
APPCO.apply(o, defaults);
|
||||
}
|
||||
if (o && c && typeof c == 'object') {
|
||||
for (var p in c) {
|
||||
o[p] = c[p];
|
||||
}
|
||||
}
|
||||
return o;
|
||||
};
|
||||
|
||||
// quick and dirty! Manche Autoren lehnen solche Erweiterungen ab
|
||||
|
||||
APPCO.apply(String.prototype, {
|
||||
include: function (pattern) {
|
||||
return this.indexOf(pattern) > -1;
|
||||
},
|
||||
startsWith: function (pattern) {
|
||||
return this.lastIndexOf(pattern, 0) === 0;
|
||||
},
|
||||
endsWith: function (pattern) {
|
||||
var d = this.length - pattern.length;
|
||||
return d >= 0 && this.indexOf(pattern, d) === d;
|
||||
}
|
||||
});
|
||||
|
||||
APPCO.apply(String, {
|
||||
interpret: function(value) {
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
});
|
||||
|
||||
// Namensraum
|
||||
|
||||
var TELIB = {};
|
||||
|
||||
TELIB.Generator_cl = Class.create({
|
||||
initialize: function () {
|
||||
this.reset_px();
|
||||
},
|
||||
reset_px: function () {
|
||||
this.code_a = ['var result_a = [];\n'];
|
||||
},
|
||||
write_px: function (text_spl) {
|
||||
// Escape-Zeichen bei Strings ergänzen
|
||||
var text_s = text_spl.replace(/"/g, '\\"');
|
||||
text_s = text_s.replace(/'/g, "\\'");
|
||||
this.code_a.push('result_a.push("' + text_s + '");\n');
|
||||
},
|
||||
code_px: function (code_spl) {
|
||||
if (code_spl.startsWith('if')) {
|
||||
this.code_a.push('if (' + code_spl.substr(2) + ') {\n');
|
||||
} else if (code_spl.startsWith('else')) {
|
||||
this.code_a.push('} else {\n');
|
||||
} else if (code_spl.startsWith('endif')) {
|
||||
this.code_a.push('}\n');
|
||||
} else if (code_spl.startsWith('for')) {
|
||||
this.code_a.push('for (' + code_spl.substr(3) + ') {\n');
|
||||
} else if (code_spl.startsWith('endfor')) {
|
||||
this.code_a.push('}\n');
|
||||
} else {
|
||||
this.code_a.push(code_spl + '\n');
|
||||
}
|
||||
},
|
||||
substitute_px: function (subst_spl) {
|
||||
this.code_a.push('result_a.push(' + String.interpret(subst_spl) + ');\n');
|
||||
},
|
||||
generate_px: function () {
|
||||
var result_s = this.code_a.join('') + ' return result_a.join("");';
|
||||
var f_o = new Function ('context', result_s);
|
||||
return f_o;
|
||||
}
|
||||
});
|
||||
|
||||
TELIB.TemplateCompiler_cl = Class.create({
|
||||
initialize: function () {
|
||||
this.gen_o = new TELIB.Generator_cl();
|
||||
this.reset_px();
|
||||
},
|
||||
reset_px: function () {
|
||||
this.gen_o.reset_px();
|
||||
this.preservePreWS_b = false;
|
||||
this.preservePostWS_b = false;
|
||||
},
|
||||
setPreWS_px: function (on_bpl) {
|
||||
if ((on_bpl == undefined) || (on_bpl == false)) {
|
||||
this.preservePreWS_b = false;
|
||||
} else {
|
||||
this.preservePreWS_b = true;
|
||||
}
|
||||
},
|
||||
setPostWS_px: function (on_bpl) {
|
||||
if ((on_bpl == undefined) || (on_bpl == false)) {
|
||||
this.preservePostWS_b = false;
|
||||
} else {
|
||||
this.preservePostWS_b = true;
|
||||
}
|
||||
},
|
||||
compile_px: function (source_spl) {
|
||||
var state_i = 0;
|
||||
var pos_i = 0;
|
||||
var len_i = source_spl.length;
|
||||
var text_s = '';
|
||||
var code_s = '';
|
||||
var subst_s = '';
|
||||
this.gen_o.reset_px();
|
||||
|
||||
var doubletest_f = function (char_spl) {
|
||||
var status_b = false;
|
||||
if ((pos_i + 1) < len_i) {
|
||||
if ((source_spl[pos_i] == char_spl) && (source_spl[pos_i+1] == char_spl)) {
|
||||
status_b = true;
|
||||
}
|
||||
}
|
||||
return status_b;
|
||||
}
|
||||
|
||||
while (pos_i < len_i) {
|
||||
switch (state_i) {
|
||||
case 0:
|
||||
// outside
|
||||
if (source_spl[pos_i] == '@') { // ECMA 5!
|
||||
if (doubletest_f('@') == false) {
|
||||
state_i = 2;
|
||||
code_s = '';
|
||||
} else {
|
||||
// als normales Zeichen verarbeiten, ein Zeichen überlesen
|
||||
state_i = 1;
|
||||
text_s = '@';
|
||||
pos_i++;
|
||||
}
|
||||
} else if (source_spl[pos_i] == '#') {
|
||||
if (doubletest_f('#') == false) {
|
||||
state_i = 3;
|
||||
subst_s = '';
|
||||
} else {
|
||||
// als normales Zeichen verarbeiten, ein Zeichen überlesen
|
||||
state_i = 1;
|
||||
text_s = '#';
|
||||
pos_i++;
|
||||
}
|
||||
} else if ((source_spl[pos_i] == ' ') || (source_spl[pos_i] == '\t')) {
|
||||
state_i = 4;
|
||||
text_s = '';
|
||||
pos_i--; // Zeichen erneut verarbeiten
|
||||
} else {
|
||||
state_i = 1;
|
||||
text_s = '';
|
||||
pos_i--; // Zeichen erneut verarbeiten
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// inText
|
||||
if (source_spl[pos_i] == '@') {
|
||||
if (doubletest_f('@') == false) {
|
||||
// Textende, neuer Code
|
||||
state_i = 0;
|
||||
this.gen_o.write_px(text_s);
|
||||
pos_i--; // Zeichen erneut verarbeiten
|
||||
} else {
|
||||
// als normales Zeichen verarbeiten, ein Zeichen überlesen
|
||||
text_s += '@';
|
||||
pos_i++;
|
||||
}
|
||||
} else if (source_spl[pos_i] == '#') {
|
||||
if (doubletest_f('#') == false) {
|
||||
// Textende, neue Substitution
|
||||
state_i = 0;
|
||||
this.gen_o.write_px(text_s);
|
||||
pos_i--; // Zeichen erneut verarbeiten
|
||||
// Textende, neuer Code
|
||||
} else {
|
||||
// als normales Zeichen verarbeiten, ein Zeichen überlesen
|
||||
text_s += '#';
|
||||
pos_i++;
|
||||
}
|
||||
} else if ((source_spl[pos_i] == ' ') || (source_spl[pos_i] == '\t')) {
|
||||
// Textende
|
||||
state_i = 0;
|
||||
this.gen_o.write_px(text_s);
|
||||
pos_i--; // Zeichen erneut verarbeiten
|
||||
} else {
|
||||
// sammeln
|
||||
if ((source_spl[pos_i] != '\n') && (source_spl[pos_i] != '\r')) {
|
||||
text_s += source_spl[pos_i];
|
||||
} else if (source_spl[pos_i] == '\n') {
|
||||
text_s += '\\n';
|
||||
} else {
|
||||
text_s += '\\r';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// inCode
|
||||
if (source_spl[pos_i] == '@') {
|
||||
if (doubletest_f('@') == false) {
|
||||
// zu Ende, erzeugen
|
||||
this.gen_o.code_px(code_s);
|
||||
state_i = 5; //0
|
||||
} else {
|
||||
// als normales Zeichen verarbeiten, ein Zeichen überlesen
|
||||
code_s += '@';
|
||||
pos_i++;
|
||||
}
|
||||
} else {
|
||||
// sammeln
|
||||
code_s += source_spl[pos_i];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// inSubst
|
||||
// Verdopplung # hier nicht zulässig!
|
||||
if (source_spl[pos_i] == '#') {
|
||||
// zu Ende, erzeugen
|
||||
this.gen_o.substitute_px(subst_s);
|
||||
state_i = 0;
|
||||
} else {
|
||||
// sammeln
|
||||
subst_s += source_spl[pos_i];
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// pre-code-whitespace
|
||||
switch (source_spl[pos_i]) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
// sammeln
|
||||
text_s += source_spl[pos_i];
|
||||
break;
|
||||
default:
|
||||
state_i = 0;
|
||||
if (source_spl[pos_i] != '@') {
|
||||
this.gen_o.write_px(text_s);
|
||||
} else {
|
||||
if (doubletest_f('@') == false) {
|
||||
// Whitespace vor Code-Beginn erkannt
|
||||
if (this.preservePreWS_b == true) {
|
||||
// trotzdem ausgeben
|
||||
this.gen_o.write_px(text_s);
|
||||
}
|
||||
} // ansonsten wie normales Zeichen behandeln
|
||||
}
|
||||
pos_i--; // Zeichen erneut verarbeiten
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
// post-code-whitespace
|
||||
switch (source_spl[pos_i]) {
|
||||
case '\n':
|
||||
text_s += '\\n';
|
||||
state_i = 0;
|
||||
break;
|
||||
case '\r':
|
||||
text_s += '\\r';
|
||||
state_i = 0;
|
||||
break;
|
||||
case ' ':
|
||||
case '\t':
|
||||
// ggf. sammeln
|
||||
text_s += source_spl[pos_i];
|
||||
break;
|
||||
default:
|
||||
// Whitespace nach Code erkannt
|
||||
if (this.preservePostWS_b == true) {
|
||||
// trotzdem ausgeben
|
||||
this.gen_o.write_px(text_s);
|
||||
}
|
||||
state_i = 0;
|
||||
pos_i--; // Zeichen erneut verarbeiten
|
||||
}
|
||||
break;
|
||||
}
|
||||
pos_i++;
|
||||
}
|
||||
// welcher Zustand liegt abschließend vor?
|
||||
if (state_i == 1) {
|
||||
this.gen_o.write_px(text_s);
|
||||
} else if (state_i == 2) {
|
||||
this.gen_o.code_px(code_s);
|
||||
} else if (state_i == 3) {
|
||||
this.gen_o.substitute_px(subst_s);
|
||||
} else if (state_i == 4) {
|
||||
if (this.preservePreWS_b == true) {
|
||||
this.gen_o.write_px(text_s);
|
||||
}
|
||||
} else if (state_i == 5) {
|
||||
if (this.preservePostWS_b == true) {
|
||||
this.gen_o.write_px(text_s);
|
||||
}
|
||||
}
|
||||
|
||||
return this.gen_o.generate_px();
|
||||
}
|
||||
});
|
||||
// EOF
|
61
Sammlung/Praktikum/4/js/tm.js
Normal file
61
Sammlung/Praktikum/4/js/tm.js
Normal file
@ -0,0 +1,61 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Template-Manager
|
||||
// - Laden und Bereitstellen von Template-Quellen oder anderen Textquellen
|
||||
//------------------------------------------------------------------------------
|
||||
// depends-on:
|
||||
// jquery
|
||||
// inheritance
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Namensraum TELIB verwenden
|
||||
|
||||
TELIB.TemplateManager_cl = Class.create({
|
||||
initialize: function () {
|
||||
this.templates_o = {};
|
||||
this.compiled_o = {};
|
||||
this.teCompiler_o = new TELIB.TemplateCompiler_cl();
|
||||
// Templates als Ressource anfordern und speichern
|
||||
var path_s = "/template/";
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: path_s,
|
||||
type: 'GET',
|
||||
context: this
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
this.templates_o = data_opl['templates'];
|
||||
// Benachrichtigung senden
|
||||
//+++ Bezeichnung Namensraum korrigieren
|
||||
FORUM.es_o.publish_px('ContentChanged', ['topicList', null]);
|
||||
})
|
||||
.fail(function(jqXHR_opl, textStatus_spl) {
|
||||
alert( "[TELIB.tm] Fehler bei Anforderung: " + textStatus_spl );
|
||||
});
|
||||
},
|
||||
get_px: function (name_spl) {
|
||||
if (name_spl in this.templates_o) {
|
||||
return this.templates_o[name_spl];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
execute_px: function (name_spl, data_opl) {
|
||||
var compiled_o = null;
|
||||
if (name_spl in this.compiled_o) {
|
||||
compiled_o = this.compiled_o[name_spl];
|
||||
} else {
|
||||
// Übersetzen und ausführen
|
||||
if (name_spl in this.templates_o) {
|
||||
this.teCompiler_o.reset_px();
|
||||
compiled_o = this.teCompiler_o.compile_px(this.templates_o[name_spl]);
|
||||
this.compiled_o[name_spl] = compiled_o;
|
||||
}
|
||||
}
|
||||
if (compiled_o != null) {
|
||||
return compiled_o(data_opl);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
// EOF
|
Reference in New Issue
Block a user