135 lines
4.4 KiB
JavaScript
135 lines
4.4 KiB
JavaScript
// ----------------------------------------------
|
|
// 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
|