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
|
Reference in New Issue
Block a user