Replace index_ajax.php by a LSurl route

This commit is contained in:
Benjamin Renard 2020-05-04 16:12:03 +02:00
parent 86b5e8fece
commit add68ec132
14 changed files with 89 additions and 100 deletions

View file

@ -263,7 +263,7 @@ var LSdefault = new Class({
keepLSsession: function() { keepLSsession: function() {
LSdebug('Keep LSsession'); LSdebug('Keep LSsession');
new Request({url: 'index_ajax.php', data: {}, onSuccess: this.keepLSsessionComplete.bind(this)}).send(); new Request({url: 'ajax/keepLSsession', data: {}, onSuccess: this.keepLSsessionComplete.bind(this)}).send();
}, },
keepLSsessionComplete: function() { keepLSsessionComplete: function() {

View file

@ -23,8 +23,6 @@ var LSformElement = new Class({
onAddFieldBtnClick: function(field){ onAddFieldBtnClick: function(field){
var data = { var data = {
template: 'LSform',
action: 'onAddFieldBtnClick',
attribute: this.name, attribute: this.name,
objecttype: this.LSform.objecttype, objecttype: this.LSform.objecttype,
objectdn: this.LSform.objectdn, objectdn: this.LSform.objectdn,
@ -33,7 +31,7 @@ var LSformElement = new Class({
}; };
LSdebug(data); LSdebug(data);
data.imgload = varLSdefault.loadingImgDisplay(field.li,'inside'); data.imgload = varLSdefault.loadingImgDisplay(field.li,'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onAddFieldBtnClickComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSform/onAddFieldBtnClick', data: data, onSuccess: this.onAddFieldBtnClickComplete.bind(this)}).send();
}, },
onAddFieldBtnClickComplete: function(responseText, responseXML) { onAddFieldBtnClickComplete: function(responseText, responseXML) {

View file

@ -52,15 +52,13 @@ var LSformElement_mail_field = new Class({
this.input.set('disabled', 'disabled'); this.input.set('disabled', 'disabled');
this.lastAutocompletePattern=pattern; this.lastAutocompletePattern=pattern;
var data = { var data = {
template: 'LSformElement_mail',
action: 'autocomplete',
attribute: this.name, attribute: this.name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
idform: varLSform.idform, idform: varLSform.idform,
pattern: pattern pattern: pattern
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.input); data.imgload=varLSdefault.loadingImgDisplay(this.input);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onAutocompleteComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_mail/autocomplete', data: data, onSuccess: this.onAutocompleteComplete.bind(this)}).send();
}, },
onAutocompleteComplete: function(responseText, responseXML) { onAutocompleteComplete: function(responseText, responseXML) {

View file

@ -160,15 +160,13 @@ var LSformElement_password_field = new Class({
onGenerateBtnClick: function() { onGenerateBtnClick: function() {
var data = { var data = {
template: 'LSformElement_password',
action: 'generatePassword',
attribute: this.name, attribute: this.name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
objectdn: varLSform.objectdn, objectdn: varLSform.objectdn,
idform: varLSform.idform idform: varLSform.idform
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.generateBtn); data.imgload=varLSdefault.loadingImgDisplay(this.generateBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onGenerateBtnClickComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_password/generatePassword', data: data, onSuccess: this.onGenerateBtnClickComplete.bind(this)}).send();
}, },
onGenerateBtnClickComplete: function(responseText, responseXML) { onGenerateBtnClickComplete: function(responseText, responseXML) {
@ -207,8 +205,6 @@ var LSformElement_password_field = new Class({
onVerifyBtnClick: function() { onVerifyBtnClick: function() {
var data = { var data = {
template: 'LSformElement_password',
action: 'verifyPassword',
attribute: this.name, attribute: this.name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
idform: varLSform.idform, idform: varLSform.idform,
@ -217,7 +213,7 @@ var LSformElement_password_field = new Class({
}; };
LSdebug(data); LSdebug(data);
data.imgload=varLSdefault.loadingImgDisplay(this.verifyBtn); data.imgload=varLSdefault.loadingImgDisplay(this.verifyBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onVerifyBtnClickComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_password/verifyPassword', data: data, onSuccess: this.onVerifyBtnClickComplete.bind(this)}).send();
}, },
onVerifyBtnClickComplete: function(responseText, responseXML) { onVerifyBtnClickComplete: function(responseText, responseXML) {
@ -237,14 +233,12 @@ var LSformElement_password_field = new Class({
onViewHashBtnClick: function() { onViewHashBtnClick: function() {
var data = { var data = {
template: 'LSformElement_password',
action: 'viewHash',
attribute: this.name, attribute: this.name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
objectdn: varLSform.objectdn objectdn: varLSform.objectdn
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.viewHashBtn); data.imgload=varLSdefault.loadingImgDisplay(this.viewHashBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onViewHashBtnClickComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_password/viewHash', data: data, onSuccess: this.onViewHashBtnClickComplete.bind(this)}).send();
}, },
onViewHashBtnClickComplete: function(responseText, responseXML) { onViewHashBtnClickComplete: function(responseText, responseXML) {

View file

@ -132,14 +132,12 @@ var LSformElement_select_object_field = new Class({
}, this); }, this);
var data = { var data = {
template: 'LSselect',
action: 'refreshSession',
objecttype: this.params['object_type'], objecttype: this.params['object_type'],
values: JSON.encode(values) values: JSON.encode(values)
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.addBtn,'inside'); data.imgload=varLSdefault.loadingImgDisplay(this.addBtn,'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onAddBtnClickComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSselect/refreshSession', data: data, onSuccess: this.onAddBtnClickComplete.bind(this)}).send();
}, },
onAddBtnClickComplete: function(responseText, responseXML) { onAddBtnClickComplete: function(responseText, responseXML) {
@ -165,15 +163,13 @@ var LSformElement_select_object_field = new Class({
onLSsmoothboxValid: function() { onLSsmoothboxValid: function() {
var data = { var data = {
template: 'LSformElement_select_object',
action: 'refresh',
attribute: this.name, attribute: this.name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
objectdn: varLSform.objectdn, objectdn: varLSform.objectdn,
idform: varLSform.idform idform: varLSform.idform
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.addBtn); data.imgload=varLSdefault.loadingImgDisplay(this.addBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSsmoothboxValidComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_select_object/refresh', data: data, onSuccess: this.onLSsmoothboxValidComplete.bind(this)}).send();
}, },
onLSsmoothboxValidComplete: function(responseText, responseXML) { onLSsmoothboxValidComplete: function(responseText, responseXML) {
@ -373,15 +369,13 @@ var LSformElement_select_object_field = new Class({
if (this._lastSearch!=this.searchAddInput.value) { if (this._lastSearch!=this.searchAddInput.value) {
this._lastSearch=this.searchAddInput.value; this._lastSearch=this.searchAddInput.value;
var data = { var data = {
template: 'LSformElement_select_object',
action: 'searchAdd',
attribute: this.name, attribute: this.name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
idform: varLSform.idform, idform: varLSform.idform,
pattern: this.searchAddInput.value pattern: this.searchAddInput.value
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.searchAddInput); data.imgload=varLSdefault.loadingImgDisplay(this.searchAddInput);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onSearchAddComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_select_object/searchAdd', data: data, onSuccess: this.onSearchAddComplete.bind(this)}).send();
} }
}, },

View file

@ -69,8 +69,6 @@ var LSformElement_supannCompositeAttribute_field_value_component = new Class({
this.hidePossibleValues(); this.hidePossibleValues();
this._lastSearch=this.inputSearch.value; this._lastSearch=this.inputSearch.value;
var data = { var data = {
template: 'LSformElement_supannCompositeAttribute',
action: 'searchComponentPossibleValues',
attribute: this.field_name, attribute: this.field_name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
idform: varLSform.idform, idform: varLSform.idform,
@ -78,7 +76,7 @@ var LSformElement_supannCompositeAttribute_field_value_component = new Class({
pattern: this.inputSearch.value pattern: this.inputSearch.value
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch); data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onSearchComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_supannCompositeAttribute/searchComponentPossibleValues', data: data, onSuccess: this.onSearchComplete.bind(this)}).send();
}, },
onSearchComplete: function(responseText, responseXML) { onSearchComplete: function(responseText, responseXML) {

View file

@ -67,15 +67,13 @@ var LSformElement_supannLabeledValue_field_value = new Class({
this.hidePossibleValues(); this.hidePossibleValues();
this._lastSearch=this.inputSearch.value; this._lastSearch=this.inputSearch.value;
var data = { var data = {
template: 'LSformElement_supannLabeledValue',
action: 'searchPossibleValues',
attribute: this.name, attribute: this.name,
objecttype: varLSform.objecttype, objecttype: varLSform.objecttype,
idform: varLSform.idform, idform: varLSform.idform,
pattern: this.inputSearch.value pattern: this.inputSearch.value
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch); data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onSearchComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSformElement_supannLabeledValue/searchPossibleValues', data: data, onSuccess: this.onSearchComplete.bind(this)}).send();
}, },
onSearchComplete: function(responseText, responseXML) { onSearchComplete: function(responseText, responseXML) {

View file

@ -69,8 +69,6 @@ var LSmail = new Class({
open: function(startElement) { open: function(startElement) {
if (this.opened==0) { if (this.opened==0) {
var data = { var data = {
template: 'LSmail',
action: 'display',
object: this.object, object: this.object,
mails: this.mails, mails: this.mails,
msg: this.msg, msg: this.msg,
@ -83,7 +81,7 @@ var LSmail = new Class({
data.imgload=varLSdefault.loadingImgDisplay(startElement); data.imgload=varLSdefault.loadingImgDisplay(startElement);
} }
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onOpenGetHtmlComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSmail/display', data: data, onSuccess: this.onOpenGetHtmlComplete.bind(this)}).send();
} }
}, },
@ -116,12 +114,10 @@ var LSmail = new Class({
send: function() { send: function() {
if ($type(this.sendInfos)) { if ($type(this.sendInfos)) {
var data = { var data = {
template: 'LSmail',
action: 'send',
infos: this.sendInfos infos: this.sendInfos
}; };
data.imgload=varLSdefault.loadingImgDisplay(this.startElement); data.imgload=varLSdefault.loadingImgDisplay(this.startElement);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onSendComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSmail/send', data: data, onSuccess: this.onSendComplete.bind(this)}).send();
} }
}, },

View file

@ -66,13 +66,11 @@ var LSrelation = new Class({
var id = getId.exec(ul.id)[1]; var id = getId.exec(ul.id)[1];
var data = { var data = {
template: 'LSrelation',
action: 'deleteByDn',
id: id, id: id,
dn: this.a2dn(a) dn: this.a2dn(a)
}; };
data.imgload=varLSdefault.loadingImgDisplay(li,'inside'); data.imgload=varLSdefault.loadingImgDisplay(li,'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.deleteFromImgComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSrelation/deleteByDn', data: data, onSuccess: this.deleteFromImgComplete.bind(this)}).send();
}, },
deleteFromImgComplete: function(responseText, responseXML) { deleteFromImgComplete: function(responseText, responseXML) {
@ -102,8 +100,6 @@ var LSrelation = new Class({
new Event(event).stop(); new Event(event).stop();
var data = { var data = {
template: 'LSrelation',
action: 'refreshSession',
id: a.id, id: a.id,
href: a.href href: a.href
}; };
@ -111,7 +107,7 @@ var LSrelation = new Class({
LSdebug(data); LSdebug(data);
this.refreshRelation=a.id; this.refreshRelation=a.id;
data.imgload=varLSdefault.loadingImgDisplay('LSrelation_title_'+a.id,'inside'); data.imgload=varLSdefault.loadingImgDisplay('LSrelation_title_'+a.id,'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSrelationModifyBtnClickComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSrelation/refreshSession', data: data, onSuccess: this.onLSrelationModifyBtnClickComplete.bind(this)}).send();
}, },
onLSrelationModifyBtnClickComplete: function(responseText, responseXML) { onLSrelationModifyBtnClickComplete: function(responseText, responseXML) {
@ -125,14 +121,12 @@ var LSrelation = new Class({
onLSsmoothboxValid: function() { onLSsmoothboxValid: function() {
var data = { var data = {
template: 'LSrelation',
action: 'refreshList',
id: this.refreshRelation id: this.refreshRelation
}; };
LSdebug(data); LSdebug(data);
data.imgload=varLSdefault.loadingImgDisplay('LSrelation_title_'+this.refreshRelation,'inside'); data.imgload=varLSdefault.loadingImgDisplay('LSrelation_title_'+this.refreshRelation,'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSsmoothboxValidComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSrelation/refreshList', data: data, onSuccess: this.onLSsmoothboxValidComplete.bind(this)}).send();
}, },
onLSsmoothboxValidComplete: function(responseText, responseXML) { onLSsmoothboxValidComplete: function(responseText, responseXML) {

View file

@ -50,25 +50,23 @@ var LSselect = new Class({
oncheckboxChange: function(checkbox){ oncheckboxChange: function(checkbox){
if (checkbox.checked) { if (checkbox.checked) {
var url = 'ajax/class/LSselect/addItem';
var data = { var data = {
template: 'LSselect',
action: 'addItem',
objectdn: checkbox.value, objectdn: checkbox.value,
objecttype: $('LSselect-object').getProperties('caption').caption, objecttype: $('LSselect-object').getProperties('caption').caption,
multiple: this.multiple multiple: this.multiple
}; };
} }
else { else {
var url = 'ajax/class/LSselect/dropItem';
var data = { var data = {
template: 'LSselect',
action: 'dropItem',
objectdn: checkbox.value, objectdn: checkbox.value,
objecttype: $('LSselect-object').getProperties('caption').caption, objecttype: $('LSselect-object').getProperties('caption').caption,
multiple: this.multiple multiple: this.multiple
}; };
} }
data.imgload=varLSdefault.loadingImgDisplay(checkbox.getParent().getNext(),'inside'); data.imgload=varLSdefault.loadingImgDisplay(checkbox.getParent().getNext(),'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.oncheckboxChangeComplete.bind(this)}).send(); new Request({url: url, data: data, onSuccess: this.oncheckboxChangeComplete.bind(this)}).send();
}, },
oncheckboxChangeComplete: function(responseText, responseXML) { oncheckboxChangeComplete: function(responseText, responseXML) {

View file

@ -27,12 +27,10 @@ var LSsession_login = new Class({
var server = this.select_ldapserver.value; var server = this.select_ldapserver.value;
var data = { var data = {
noLSsession: 1, noLSsession: 1,
template: 'LSsession',
action: 'onLdapServerChangedLogin',
server: server, server: server,
imgload: imgload imgload: imgload
}; };
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLdapServerChangedComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSsession/onLdapServerChangedLogin', data: data, onSuccess: this.onLdapServerChangedComplete.bind(this)}).send();
}, },
onLdapServerChangedComplete: function(responseText, responseXML){ onLdapServerChangedComplete: function(responseText, responseXML){

View file

@ -26,12 +26,10 @@ var LSsession_recoverPassword = new Class({
var server = this.select_ldapserver.value; var server = this.select_ldapserver.value;
var data = { var data = {
noLSsession: 1, noLSsession: 1,
template: 'LSsession',
action: 'onLdapServerChangedRecoverPassword',
server: server, server: server,
imgload: imgload imgload: imgload
}; };
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLdapServerChangedComplete.bind(this)}).send(); new Request({url: 'ajax/class/LSsession/onLdapServerChangedRecoverPassword', data: data, onSuccess: this.onLdapServerChangedComplete.bind(this)}).send();
}, },
onLdapServerChangedComplete: function(responseText, responseXML){ onLdapServerChangedComplete: function(responseText, responseXML){

View file

@ -46,6 +46,74 @@ function handle_index($request) {
} }
LSurl :: add_handler('#^(index\.php)?$#', 'handle_index', true); LSurl :: add_handler('#^(index\.php)?$#', 'handle_index', true);
/*
* Handle ajax keepLSsession request
*
* @param[in] $request LSurlRequest The request
*
* @retval void
**/
function handle_ajax_keepLSsession($request) {
LSsession :: displayAjaxReturn(null);
}
LSurl :: add_handler('#^ajax/keepLSsession/?$#', 'handle_ajax_keepLSsession', true);
/*
* Handle ajax request
*
* @param[in] $request LSurlRequest The request
*
* @retval void
**/
function handle_ajax($request) {
$data = null;
switch ($request -> type) {
case 'class':
$class = $request -> type_value;
if (LSsession :: loadLSclass($class)) {
$meth = 'ajax_'.$request -> action;
if (method_exists($class, $meth)) {
$class :: $meth($data);
}
}
break;
case 'addon':
$addon = $request -> type_value;
if (LSsession :: loadLSaddon($addon)) {
$func = 'ajax_'.$request -> action;
if (function_exists($func)) {
$func = new ReflectionFunction($func);
if (basename($func->getFileName()) == "LSaddons.$addon.php") {
$func->invokeArgs(array(&$data));
}
else {
LSerror :: addErrorCode('LSsession_21',array('func' => $func -> getName(),'addon' => $addon));
}
}
}
break;
default:
LSlog :: fatal('Unsupported AJAX request type !');
exit();
}
LSsession :: displayAjaxReturn($data);
}
// TODO : find a proper solution for noLSsession URL parameter
LSurl :: add_handler('#^ajax/(?P<type>class|addon)/(?P<type_value>[^/]+)/(?P<action>[^/]+)/?$#', 'handle_ajax', (!isset($_REQUEST['noLSsession'])));
/*
* Handle old index_ajax.php request for retro-compatibility
*
* @param[in] $request LSurlRequest The request
*
* @retval void
**/
function handle_old_index_ajax_php($request) {
LSerror :: addErrorCode('LSsession_26', 'index_ajax.php');
LSsession :: displayAjaxReturn(null);
}
LSurl :: add_handler('#^index_ajax\.php#', 'handle_old_index_ajax_php');
/* /*
* Handle global seearch request * Handle global seearch request
* *

View file

@ -1,43 +0,0 @@
<?php
require_once 'core.php';
if (!isset($_REQUEST['noLSsession'])) {
if ( !LSsession :: startLSsession() ) {
LSerror :: addErrorCode('LSsession_22');
$_ERRORS = true;
}
}
else {
LSsession :: initialize() or die('Error during initialization.');
}
$data=NULL;
if (!isset($_ERRORS)) {
if (isset($_REQUEST['template'])) {
$class = $_REQUEST['template'];
if (LSsession :: loadLSclass($class)) {
$meth = 'ajax_'.$_REQUEST['action'];
if (method_exists($class,$meth)) {
$class :: $meth($data);
}
}
}
elseif (isset($_REQUEST['addon'])) {
$addon = $_REQUEST['addon'];
if (LSsession :: loadLSaddon($addon)) {
$func = 'ajax_'.$_REQUEST['action'];
if (function_exists($func)) {
$func = new ReflectionFunction($func);
if (basename($func->getFileName())=="LSaddons.$addon.php") {
$func->invokeArgs(array(&$data));
}
else {
LSerror :: addErrorCode('LSsession_21',array('func' => $func -> getName(),'addon' => $addon));
}
}
}
}
}
LSsession :: displayAjaxReturn($data);