Sammlung
This commit is contained in:
139
Sammlung/lit-8/js/litform.js
Normal file
139
Sammlung/lit-8/js/litform.js
Normal file
@ -0,0 +1,139 @@
|
||||
// ----------------------------------------------
|
||||
// Beispiel lit-8
|
||||
// litform.js
|
||||
// ----------------------------------------------
|
||||
|
||||
// ----------------------------------------------
|
||||
LITAPP.DetailView_cl = Class.create({
|
||||
// ----------------------------------------------
|
||||
initialize: function () {
|
||||
// Basis-Markup des Formulars anfordern
|
||||
var that = this;
|
||||
$.get('/html/detail.html', function (data_spl) {
|
||||
$("#idContentOuter").append(data_spl);
|
||||
$("#idForm").hide();
|
||||
that.initHandler_p();
|
||||
|
||||
that.storeFormContent_p();
|
||||
});
|
||||
|
||||
},
|
||||
canClose_px: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
var mod_b = this.isModified_p();
|
||||
if (mod_b) {
|
||||
if (confirm("Es gibt nicht gespeicherte Änderungen - verwerfen?")) {
|
||||
mod_b = false;
|
||||
}
|
||||
}
|
||||
return !mod_b;
|
||||
},
|
||||
close_px: function () {
|
||||
$("#idForm").hide();
|
||||
},
|
||||
render_px: function (data_opl) {
|
||||
var path_s;
|
||||
if (data_opl != null) {
|
||||
path_s = '/lit/' + data_opl;
|
||||
} else {
|
||||
path_s = '/lit/0';
|
||||
}
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: path_s,
|
||||
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'];
|
||||
$('#id_s').val(data_o['id']);
|
||||
$('#name_s').val(data_o['name'])
|
||||
$('#typ_s').val(data_o['typ']);
|
||||
$('#referenz_s').val(data_o['referenz']);
|
||||
|
||||
this.storeFormContent_p();
|
||||
|
||||
$("#idForm").show();
|
||||
},
|
||||
initHandler_p: function () {
|
||||
// Ereignisverarbeitung für das Formular einrichten
|
||||
$("#idForm").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
|
||||
LITAPP.es_o.publish_px('app', [action_s, 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 path_s = '/lit';
|
||||
var data_s = $("#idForm").serialize();
|
||||
var type_s = 'POST';
|
||||
var id_s = $('#id_s').val();
|
||||
if (id_s == '') {
|
||||
type_s = 'PUT';
|
||||
} else {
|
||||
path_s += '/' + id_s;
|
||||
}
|
||||
//var that = this;
|
||||
$.ajax({
|
||||
context: this,
|
||||
dataType: "json",
|
||||
data: data_s,
|
||||
url: path_s,
|
||||
type: type_s
|
||||
})
|
||||
.done(function (data_opl) {
|
||||
// Umwandlung der JSON-Daten vom Server bereits erfolgt
|
||||
$('#id_s').val(data_opl['id']);
|
||||
// aktuellen Formularinhalt speichern
|
||||
// (das Formular wird ja nicht mehr neu geladen!)
|
||||
this.storeFormContent_p();
|
||||
alert("Speichern ausgeführt!");
|
||||
})
|
||||
.fail(function(jqXHR_opl, textStatus_spl) {
|
||||
alert( "Fehler bei Anforderung: " + textStatus_spl );
|
||||
});
|
||||
|
||||
} else {
|
||||
alert("Bitte prüfen Sie die Eingaben in den Formularfeldern!")
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Weiterleitung und Standardbearbeitung unterbinden
|
||||
event_opl.stopPropagation();
|
||||
event_opl.preventDefault();
|
||||
},
|
||||
isModified_p: function () {
|
||||
// Prüfen, ob Formularinhalt verändert wurde
|
||||
var mod_b = this.FormContentOrg_s != $("#idForm").serialize();
|
||||
return mod_b;
|
||||
},
|
||||
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;
|
||||
var typ_s = $("#typ_s").val();
|
||||
if ((typ_s != "Typ1") && (typ_s != "Typ2")) {
|
||||
status_b = false;
|
||||
}
|
||||
return status_b;
|
||||
},
|
||||
storeFormContent_p: function () {
|
||||
this.FormContentOrg_s = $("#idForm").serialize();
|
||||
}
|
||||
});
|
||||
// EOF
|
Reference in New Issue
Block a user