LSform: fix preserving current tab on actions links click

This commit is contained in:
Benjamin Renard 2020-06-03 12:58:05 +02:00
parent 49656cd6f6
commit bfd60b28c6

View file

@ -3,7 +3,6 @@ var LSform = new Class({
this._modules=[]; this._modules=[];
this._fields=[]; this._fields=[];
this._elements=[]; this._elements=[];
this._tabBtns=[];
this.listeners = { this.listeners = {
init: new Array(), init: new Array(),
submit: new Array() submit: new Array()
@ -86,26 +85,28 @@ var LSform = new Class({
} }
} }
} }
li.getFirst('a').addEvent('click',this.onTabBtnClick.bindWithEvent(this,li)); li.getFirst('a').addEvent('click',this.onTabBtnClick.bindWithEvent(this,li));
},this); },this);
$$('li.LSform_layout a').each(function(a) {
this._tabBtns[a.href]=a;
},this);
if (LIs.length != 0) { if (LIs.length != 0) {
if ($type(this._tabBtns[window.location])) { var defaut_on_first = true;
this._currentTab = 'default_value'; this._currentTab = 'default_value';
this._tabBtns[window.location].fireEvent('click'); if (window.location.hash) {
byDefault=0; var li = $('LSform_layout_btn_'+window.location.hash.substr(1));
if (li) {
defaut_on_first = false;
li.getFirst('a').fireEvent('click');
// Scroll on top of the page
window.scroll(0, 0);
}
} }
else { if (defaut_on_first) {
this._currentTab = 'default_value';
document.getElement('li.LSform_layout').getFirst('a').fireEvent('click'); document.getElement('li.LSform_layout').getFirst('a').fireEvent('click');
} }
} }
var checkUrl = new RegExp('^(modify|create|view).php'); var checkUrl = new RegExp('^object/[^/]+/(create|[^/]+(%3D|=)[^/]+(/modify)?)$');
document.getElements('a.LSview-actions').each(function(a) { document.getElements('a.LSview-actions').each(function(a) {
if (checkUrl.exec(a.get('href'))) { if (checkUrl.exec(a.get('href'))) {
a.addEvent('click',this.onActionBtnClick.bindWithEvent(this,a)); a.addEvent('click',this.onActionBtnClick.bindWithEvent(this,a));