117 lines
4.5 KiB
JavaScript
117 lines
4.5 KiB
JavaScript
|
// ----------------------------------------------
|
||
|
// 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
|