128 lines
5.1 KiB
JavaScript
128 lines
5.1 KiB
JavaScript
|
// ----------------------------------------------
|
||
|
// 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
|