2008-02-05 17:11:21 +01:00
|
|
|
var LSform = new Class({
|
|
|
|
initialize: function(){
|
2008-07-15 18:24:35 +02:00
|
|
|
this._modules=[];
|
2014-11-20 00:18:35 +01:00
|
|
|
this._fields=[];
|
2008-10-15 19:40:04 +02:00
|
|
|
this._elements=[];
|
2020-06-11 20:05:28 +02:00
|
|
|
this.listeners = new Hash({
|
|
|
|
init: new Hash(),
|
|
|
|
submit: new Hash()
|
|
|
|
});
|
|
|
|
this.listeners_answers = new Hash();
|
|
|
|
|
|
|
|
// On non-ajax submit form, store confirmation status;
|
|
|
|
this.submit_confirmed = false;
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-03 20:25:22 +01:00
|
|
|
if ($type($('LSform_idform'))) {
|
|
|
|
this.objecttype = $('LSform_objecttype').value;
|
|
|
|
this.objectdn = $('LSform_objectdn').value;
|
|
|
|
this.idform = $('LSform_idform').value;
|
|
|
|
}
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2020-06-11 20:05:28 +02:00
|
|
|
this.submiting = false;
|
|
|
|
|
2008-10-15 19:40:04 +02:00
|
|
|
this.initializeLSform();
|
2008-11-03 20:25:22 +01:00
|
|
|
this.initializeLSformLayout();
|
2008-07-15 18:24:35 +02:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-10-15 19:40:04 +02:00
|
|
|
initializeLSform: function(el) {
|
2009-02-12 11:04:50 +01:00
|
|
|
this.params={};
|
2008-11-03 20:25:22 +01:00
|
|
|
if (this.idform) {
|
|
|
|
if (typeof(el) == 'undefined') {
|
|
|
|
el = document;
|
|
|
|
}
|
|
|
|
el.getElements('ul.LSform').each(function(ul) {
|
|
|
|
this._elements[ul.id] = new LSformElement(this,ul.id,ul);
|
|
|
|
}, this);
|
2009-02-12 11:04:50 +01:00
|
|
|
this.params=varLSdefault.LSjsConfig['LSform_'+this.idform];
|
|
|
|
if (!$type(this.params)) {
|
|
|
|
this.params={};
|
|
|
|
}
|
|
|
|
this._ajaxSubmit=this.params.ajaxSubmit;
|
2010-11-17 15:52:37 +01:00
|
|
|
|
|
|
|
this.warnBox = new LSinfosBox({
|
|
|
|
name: 'LSformWarnBox',
|
|
|
|
fxDuration: 600,
|
|
|
|
closeBtn: 1,
|
|
|
|
autoClose: 0
|
|
|
|
});
|
|
|
|
|
2010-11-17 15:15:56 +01:00
|
|
|
if ($type(this.params.warnings)) {
|
|
|
|
this.warnTxt = '<ul>';
|
|
|
|
this.params.warnings.each(function(w) {
|
|
|
|
this.warnTxt +='<li>'+w+'</li>';
|
|
|
|
},this);
|
|
|
|
this.warnTxt += '</ul>';
|
|
|
|
this.warnBox.display(this.warnTxt);
|
|
|
|
}
|
2009-02-12 11:04:50 +01:00
|
|
|
LSdebug(this.params);
|
2010-11-17 19:00:09 +01:00
|
|
|
|
|
|
|
this.listAvailableDataEntryForm=$('LSform_listAvailableDataEntryForm');
|
|
|
|
if ($type(this.listAvailableDataEntryForm)) {
|
|
|
|
this.listAvailableDataEntryForm.addEvent('change',this.onListAvailableDataEntryFormChange.bind(this));
|
|
|
|
}
|
2008-11-03 20:25:22 +01:00
|
|
|
}
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 00:24:46 +01:00
|
|
|
LSforms = $$('form.LSform');
|
|
|
|
if ($type(LSforms[0])) {
|
|
|
|
this.LSform = LSforms[0];
|
2020-06-11 20:05:28 +02:00
|
|
|
this.LSform.addEvent('submit',this.onSubmit.bindWithEvent(this));
|
2008-11-10 00:24:46 +01:00
|
|
|
}
|
2018-06-15 16:10:55 +02:00
|
|
|
|
|
|
|
this.fireEvent.bind(this)('init');
|
2008-11-03 20:25:22 +01:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-03 20:25:22 +01:00
|
|
|
initializeLSformLayout: function(el) {
|
|
|
|
$$('.LSform_layout').each(function(el) {
|
|
|
|
el.addClass('LSform_layout_active');
|
|
|
|
},this);
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-03 20:25:22 +01:00
|
|
|
var LIs = $$('li.LSform_layout');
|
|
|
|
LIs.each(function(li) {
|
2009-02-12 11:04:50 +01:00
|
|
|
var Layout = this.getLayout(li);
|
|
|
|
if ($type(Layout)) {
|
|
|
|
if ($type(Layout.getElement('dt.LSform-errors'))) {
|
|
|
|
LSdebug('add');
|
|
|
|
li.addClass('LSform_layout_errors');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!$type(Layout.getElement('dt'))) {
|
2019-02-26 18:02:51 +01:00
|
|
|
li.destroy();
|
|
|
|
Layout.destroy();
|
2009-02-12 11:04:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-11 13:51:24 +02:00
|
|
|
|
2020-06-03 12:58:37 +02:00
|
|
|
// Remove corresponding anchor to avoid scrolling on tab change
|
|
|
|
$$('a[name='+this.getLayoutNameFromBtn(li)+']').dispose();
|
|
|
|
|
2020-06-03 12:58:05 +02:00
|
|
|
li.getFirst('a').addEvent('click',this.onTabBtnClick.bindWithEvent(this,li));
|
2011-04-11 13:51:24 +02:00
|
|
|
},this);
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-03 20:25:22 +01:00
|
|
|
if (LIs.length != 0) {
|
2020-06-03 12:58:05 +02:00
|
|
|
var defaut_on_first = true;
|
|
|
|
this._currentTab = 'default_value';
|
|
|
|
if (window.location.hash) {
|
|
|
|
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);
|
|
|
|
}
|
2011-04-11 13:51:24 +02:00
|
|
|
}
|
2020-06-03 12:58:05 +02:00
|
|
|
if (defaut_on_first) {
|
2011-04-11 13:51:24 +02:00
|
|
|
document.getElement('li.LSform_layout').getFirst('a').fireEvent('click');
|
|
|
|
}
|
2008-11-03 20:25:22 +01:00
|
|
|
}
|
2014-11-24 23:07:30 +01:00
|
|
|
|
2020-06-03 12:58:05 +02:00
|
|
|
var checkUrl = new RegExp('^object/[^/]+/(create|[^/]+(%3D|=)[^/]+(/modify)?)$');
|
2014-11-24 23:07:30 +01:00
|
|
|
document.getElements('a.LSview-actions').each(function(a) {
|
|
|
|
if (checkUrl.exec(a.get('href'))) {
|
|
|
|
a.addEvent('click',this.onActionBtnClick.bindWithEvent(this,a));
|
|
|
|
}
|
|
|
|
},this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onActionBtnClick: function(event,a) {
|
|
|
|
if (!location.hash) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ($type(event)) {
|
|
|
|
event = new Event(event);
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
var href=a.href;
|
|
|
|
var checkExistingHash=new RegExp('^([^#]+)#[^#]+$');
|
|
|
|
var cur = checkExistingHash.exec(href);
|
|
|
|
if (cur) {
|
|
|
|
href=cur[1]+location.hash;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
href=href+location.hash;
|
|
|
|
}
|
|
|
|
window.location=href;
|
2008-11-03 20:25:22 +01:00
|
|
|
},
|
2008-11-10 03:03:44 +01:00
|
|
|
|
|
|
|
getLayoutBtn: function(div) {
|
|
|
|
var getName = new RegExp('LSform_layout_div_(.*)');
|
|
|
|
var name = getName.exec(div.id);
|
|
|
|
if (!name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $('LSform_layout_btn_'+name[1]);
|
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2014-11-24 23:07:30 +01:00
|
|
|
getLayoutNameFromBtn: function(btn) {
|
2008-11-10 03:03:44 +01:00
|
|
|
var getName = new RegExp('LSform_layout_btn_(.*)');
|
|
|
|
var name = getName.exec(btn.id);
|
|
|
|
if (!name) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-24 23:07:30 +01:00
|
|
|
return name[1];
|
|
|
|
},
|
|
|
|
|
|
|
|
getLayout: function(btn) {
|
|
|
|
var name = this.getLayoutNameFromBtn(btn);
|
|
|
|
if (!name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $('LSform_layout_div_'+name);
|
2008-11-10 03:03:44 +01:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-03 20:25:22 +01:00
|
|
|
onTabBtnClick: function(event,li) {
|
|
|
|
if ($type(event)) {
|
2008-11-04 14:30:17 +01:00
|
|
|
event = new Event(event);
|
|
|
|
event.stop();
|
2008-11-13 20:05:06 +01:00
|
|
|
if ($type(event.target.blur)) {
|
|
|
|
event.target.blur();
|
|
|
|
}
|
2008-11-03 20:25:22 +01:00
|
|
|
}
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 03:03:44 +01:00
|
|
|
if (this._currentTab!=li) {
|
|
|
|
if (this._currentTab!='default_value') {
|
|
|
|
this._currentTab.removeClass('LSform_layout_current');
|
|
|
|
var oldDiv = this.getLayout(this._currentTab);
|
|
|
|
if ($type(oldDiv)) {
|
|
|
|
oldDiv.removeClass('LSform_layout_current');
|
|
|
|
}
|
2008-11-03 20:25:22 +01:00
|
|
|
}
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 03:03:44 +01:00
|
|
|
this._currentTab = li;
|
|
|
|
li.addClass('LSform_layout_current');
|
2014-11-24 23:07:30 +01:00
|
|
|
var a=li.getElement('a');
|
|
|
|
if ($type(a)) {
|
2020-06-03 12:58:37 +02:00
|
|
|
var layout_name = this.getLayoutNameFromBtn(li);
|
|
|
|
if (layout_name) {
|
|
|
|
location.hash='#'+layout_name;
|
|
|
|
}
|
2014-11-24 23:07:30 +01:00
|
|
|
}
|
2008-11-10 03:03:44 +01:00
|
|
|
var div = this.getLayout(li);
|
|
|
|
if ($type(div)) {
|
|
|
|
div.addClass('LSform_layout_current');
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 03:03:44 +01:00
|
|
|
// Focus
|
|
|
|
var ul = div.getElement('ul.LSform');
|
|
|
|
if ($type(ul)) {
|
|
|
|
var el = ul.getElement('input');
|
|
|
|
if (!$type(el)) {
|
|
|
|
el = ul.getElement('textarea');
|
|
|
|
}
|
|
|
|
if (!$type(el)) {
|
|
|
|
el = ul.getElement('select');
|
|
|
|
}
|
|
|
|
if ($type(el)) {
|
|
|
|
if(el.type!='hidden') {
|
|
|
|
el.focus();
|
|
|
|
}
|
2008-11-04 14:30:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-03 20:25:22 +01:00
|
|
|
}
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-07-15 18:24:35 +02:00
|
|
|
addModule: function(name,obj) {
|
|
|
|
this._modules[name]=obj;
|
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-10-15 19:40:04 +02:00
|
|
|
initializeModule: function(fieldType,li) {
|
|
|
|
if ($type(this._modules[fieldType])) {
|
|
|
|
try {
|
|
|
|
this._modules[fieldType].reinitialize(li);
|
|
|
|
}
|
|
|
|
catch(e) {
|
2009-02-17 14:46:41 +01:00
|
|
|
LSdebug('No reinitialize for ' + fieldType);
|
2008-07-15 18:24:35 +02:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-10-31 13:12:31 +01:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
|
|
|
addField: function(name,obj) {
|
|
|
|
this._fields[name]=obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
clearFieldValue: function(name) {
|
|
|
|
if ($type(this._fields[name]) && $type(this._fields[name].clearValue)) {
|
|
|
|
this._fields[name].clearValue();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-10-31 13:12:31 +01:00
|
|
|
getValue: function(fieldName) {
|
2014-06-17 17:31:40 +02:00
|
|
|
var retVal = Array();
|
|
|
|
var inputs = this.getInput(fieldName);
|
|
|
|
inputs.each(function(el){
|
|
|
|
if (el.value!="") {
|
|
|
|
retVal.include(el.value);
|
|
|
|
}
|
|
|
|
},this);
|
|
|
|
return retVal;
|
|
|
|
},
|
|
|
|
|
|
|
|
getInput: function(fieldName) {
|
2008-10-31 13:12:31 +01:00
|
|
|
var retVal = Array();
|
|
|
|
var ul = $(fieldName);
|
|
|
|
if ($type(ul)) {
|
|
|
|
var elements = ul.getElements('input');
|
|
|
|
elements.combine(ul.getElements('textarea'));
|
|
|
|
elements.combine(ul.getElements('select'));
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-10-31 13:12:31 +01:00
|
|
|
var getName = new RegExp('([a-zA-Z0-9]*)(\[.*\])?');
|
|
|
|
elements.each(function(el){
|
|
|
|
var name = getName.exec(el.name);
|
|
|
|
LSdebug(name);
|
|
|
|
if (name) {
|
|
|
|
if (name[1]==fieldName) {
|
2014-06-17 17:31:40 +02:00
|
|
|
retVal.include(el);
|
2008-10-31 13:12:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},this);
|
|
|
|
}
|
|
|
|
return retVal;
|
2008-11-10 00:24:46 +01:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2020-06-11 20:05:28 +02:00
|
|
|
onSubmit: function(event) {
|
|
|
|
if (this.submit_confirmed) {
|
|
|
|
// On non-ajax form, leave form submiting if already confirmed
|
|
|
|
LSdebug('onSubmit(): form submission already confirmed');
|
|
|
|
return;
|
|
|
|
}
|
2009-02-12 11:04:50 +01:00
|
|
|
|
2020-06-11 20:05:28 +02:00
|
|
|
// Stop form submiting event
|
|
|
|
event = new Event(event);
|
|
|
|
event.stop();
|
|
|
|
|
|
|
|
// Check if form is already submitting
|
|
|
|
if (this.submiting) {
|
|
|
|
// Form is already submitting: stop
|
|
|
|
LSdebug('onSubmit(): form already submiting...');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.submiting = true;
|
|
|
|
|
|
|
|
// Fire
|
|
|
|
LSdebug('onSubmit(): fire submit event');
|
|
|
|
this.fireEvent.bind(this)('submit', this.onSubmitConfirm.bind(this));
|
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2020-06-11 20:05:28 +02:00
|
|
|
onSubmitConfirm: function (confirmed, event) {
|
|
|
|
if (!confirmed) {
|
|
|
|
this.submiting = false;
|
|
|
|
return;
|
|
|
|
}
|
2018-06-15 16:10:55 +02:00
|
|
|
|
2020-06-11 20:05:28 +02:00
|
|
|
// Check file upload to disable ajax submission in this case
|
|
|
|
this.checkUploadFileDefined();
|
|
|
|
|
|
|
|
if (this._ajaxSubmit) {
|
2009-02-12 11:04:50 +01:00
|
|
|
this.LSformAjaxInput = new Element('input');
|
|
|
|
this.LSformAjaxInput.setProperties ({
|
|
|
|
type: 'hidden',
|
|
|
|
name: 'ajax',
|
|
|
|
value: '1'
|
|
|
|
});
|
|
|
|
this.LSformAjaxInput.injectInside(this.LSform);
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2009-02-12 11:04:50 +01:00
|
|
|
this.LSform.set('send',{
|
|
|
|
data: this.LSform,
|
|
|
|
onSuccess: this.onAjaxSubmitComplete.bind(this),
|
|
|
|
url: this.LSform.get('action'),
|
|
|
|
imgload: varLSdefault.loadingImgDisplay($('LSform_title'),'inside')
|
|
|
|
});
|
|
|
|
this.LSform.send();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if($type(this.LSformAjaxInput)) {
|
|
|
|
this.LSformAjaxInput.dispose();
|
|
|
|
}
|
2020-06-11 20:05:28 +02:00
|
|
|
this.submit_confirmed = true;
|
|
|
|
this.LSform.fireEvent('submit');
|
2009-02-12 11:04:50 +01:00
|
|
|
}
|
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2009-02-12 11:04:50 +01:00
|
|
|
checkUploadFileDefined: function() {
|
|
|
|
this.LSform.getElements('input[type=file]').each(function(ipt) {
|
|
|
|
if (ipt.files.length!=0) {
|
|
|
|
this._ajaxSubmit=0;
|
|
|
|
}
|
|
|
|
}, this);
|
2008-11-10 00:24:46 +01:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 00:24:46 +01:00
|
|
|
onAjaxSubmitComplete: function(responseText, responseXML) {
|
2020-06-11 20:05:28 +02:00
|
|
|
this.submiting = false;
|
2008-11-10 00:24:46 +01:00
|
|
|
var data = JSON.decode(responseText);
|
|
|
|
if ( varLSdefault.checkAjaxReturn(data) ) {
|
2014-06-19 17:09:57 +02:00
|
|
|
this.resetErrors();
|
2009-01-21 18:08:09 +01:00
|
|
|
if ($type(data.LSformErrors) == 'object') {
|
2008-11-10 00:24:46 +01:00
|
|
|
data.LSformErrors = new Hash(data.LSformErrors);
|
|
|
|
data.LSformErrors.each(this.addError,this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 00:24:46 +01:00
|
|
|
resetErrors: function() {
|
|
|
|
$$('dd.LSform-errors').each(function(dd) {
|
|
|
|
dd.destroy();
|
|
|
|
});
|
|
|
|
$$('dt.LSform-errors').each(function(dt) {
|
|
|
|
dt.removeClass('LSform-errors');
|
|
|
|
});
|
|
|
|
$$('li.LSform_layout_errors').each(function(li) {
|
|
|
|
li.removeClass('LSform_layout_errors');
|
|
|
|
});
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 00:24:46 +01:00
|
|
|
},
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 00:24:46 +01:00
|
|
|
addError: function(errors,name) {
|
|
|
|
var ul = $(name);
|
|
|
|
if ($type(ul)) {
|
|
|
|
errors = new Array(errors);
|
|
|
|
errors.each(function(txt){
|
|
|
|
var dd = new Element('dd');
|
|
|
|
dd.addClass('LSform');
|
|
|
|
dd.addClass('LSform-errors');
|
|
|
|
dd.set('html',txt);
|
|
|
|
dd.injectAfter(this.getParent());
|
|
|
|
},ul);
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2010-04-15 18:21:18 +02:00
|
|
|
var dt = ul.getParent('dd.LSform').getPrevious('dt');
|
|
|
|
if ($type(dt)) {
|
|
|
|
dt.addClass('LSform-errors');
|
|
|
|
}
|
2014-11-20 00:18:35 +01:00
|
|
|
|
2008-11-10 00:24:46 +01:00
|
|
|
var layout = ul.getParent('div.LSform_layout_active');
|
|
|
|
if ($type(layout)) {
|
2008-11-10 15:07:59 +01:00
|
|
|
var li = this.getLayoutBtn(layout);
|
2008-11-10 00:24:46 +01:00
|
|
|
if($type(li)) {
|
|
|
|
li.addClass('LSform_layout_errors');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-17 15:52:37 +01:00
|
|
|
else {
|
|
|
|
this.tmp=name+" :</br><ul>";
|
|
|
|
errors = new Array(errors);
|
|
|
|
errors.each(function(error){
|
|
|
|
this.tmp += "<li>"+error+"</li>";
|
|
|
|
},this);
|
|
|
|
this.tmp +="</ul>";
|
|
|
|
this.warnBox.display(this.tmp);
|
|
|
|
}
|
2010-11-17 19:00:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onListAvailableDataEntryFormChange: function() {
|
|
|
|
var url=window.location.pathname+"?LSobject="+this.objecttype
|
|
|
|
if (this.listAvailableDataEntryForm.value!="") {
|
|
|
|
url+="&LSform_dataEntryForm="+this.listAvailableDataEntryForm.value;
|
|
|
|
}
|
|
|
|
document.location=url;
|
2018-06-15 16:10:55 +02:00
|
|
|
},
|
|
|
|
|
2020-06-11 20:05:28 +02:00
|
|
|
addEvent: function(event,fnct,fnct_name) {
|
2018-06-15 16:10:55 +02:00
|
|
|
if ($type(this.listeners[event])) {
|
|
|
|
if ($type(fnct)=="function") {
|
2020-06-11 20:05:28 +02:00
|
|
|
if ($type(fnct_name)!="string") {
|
|
|
|
fnct_name = generate_uuid();
|
|
|
|
}
|
|
|
|
else if (this.listeners[event].has(fnct_name)) {
|
|
|
|
fnct_name = fnct_name+"_"+generate_uuid();
|
|
|
|
}
|
|
|
|
this.listeners[event].set(fnct_name, fnct);
|
2018-06-15 16:10:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-06-11 20:05:28 +02:00
|
|
|
fireEvent: function(event, callback) {
|
2018-06-15 16:10:55 +02:00
|
|
|
LSdebug('LSform :: fireEvent('+event+')');
|
2020-06-11 20:05:28 +02:00
|
|
|
if (this.listeners.has(event)) {
|
|
|
|
// If no listener configured, considered as confirmed and run callback
|
|
|
|
if ($type(callback) == "function" && this.listeners[event].getLength() == 0) {
|
|
|
|
callback(true, event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset listeners answers state
|
|
|
|
this.listeners_answers[event] = new Hash();
|
|
|
|
|
|
|
|
// Run listeners callback
|
|
|
|
this.listeners[event].each(function(fnct, listener_uuid) {
|
|
|
|
var result;
|
2018-06-15 16:10:55 +02:00
|
|
|
try {
|
2020-06-11 20:05:28 +02:00
|
|
|
fnct(
|
|
|
|
this,
|
|
|
|
function() {
|
|
|
|
LSdebug('Listener '+listener_uuid+' confirmed');
|
|
|
|
this.eventListenerCallback.bind(this)(event, listener_uuid, true, callback);
|
|
|
|
}.bind(this),
|
|
|
|
function() {
|
|
|
|
LSdebug('Listener '+listener_uuid+' cancel');
|
|
|
|
this.eventListenerCallback.bind(this)(event, listener_uuid, false, callback);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2018-06-15 16:10:55 +02:00
|
|
|
}
|
|
|
|
catch(e) {
|
2020-06-11 20:05:28 +02:00
|
|
|
LSdebug('LSform :: fireEvent('+event+') :: exception occured running listener '+listener_uuid+' => considered as not-confirmed.');
|
|
|
|
LSdebug(e);
|
|
|
|
result = false;
|
2018-06-15 16:10:55 +02:00
|
|
|
}
|
|
|
|
},this);
|
|
|
|
}
|
2020-06-11 20:05:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
eventListenerCallback: function(event, listener_uuid, listener_answer, final_callback) {
|
|
|
|
// Check event & listener_uuid
|
|
|
|
if (!this.listeners.has(event) || !this.listeners[event].has(listener_uuid))
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set listener answers
|
|
|
|
this.listeners_answers[event].set(listener_uuid, listener_answer);
|
|
|
|
LSdebug('LSform :: eventListenerCallback('+event+', '+listener_uuid+', '+listener_answer+')');
|
|
|
|
|
|
|
|
// Check all listeners have answered
|
|
|
|
if (this.listeners_answers[event].getLength() != this.listeners[event].getLength())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Run final callback
|
|
|
|
this.onFinalEventListenerCallback.bind(this)(event, final_callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
onFinalEventListenerCallback: function(event, final_callback) {
|
|
|
|
LSdebug('LSform :: onFinalEventListenerCallback('+event+')');
|
|
|
|
if ($type(final_callback) != "function") {
|
|
|
|
LSdebug('LSform :: onFinalEventListenerCallback('+event+') : final_callback is not a function, stop.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine all listeners answers
|
|
|
|
var final_result = true;
|
|
|
|
this.listeners[event].each(function(fnct, listener_uuid) {
|
|
|
|
if (!this.listeners_answers[event].has(listener_uuid) || !this.listeners_answers[event][listener_uuid]) {
|
|
|
|
final_result = false;
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
LSdebug('LSform :: onFinalEventListenerCallback('+event+'): final result = '+final_result);
|
|
|
|
|
|
|
|
// Run final callback
|
|
|
|
final_callback(final_result, event);
|
|
|
|
},
|
2018-06-15 16:10:55 +02:00
|
|
|
|
2008-02-05 17:11:21 +01:00
|
|
|
});
|
|
|
|
window.addEvent(window.ie ? 'load' : 'domready', function() {
|
2008-02-08 18:39:24 +01:00
|
|
|
varLSform = new LSform();
|
2008-02-05 17:11:21 +01:00
|
|
|
});
|