2008-02-05 17:11:21 +01:00
|
|
|
var LSform = new Class({
|
|
|
|
initialize: function(){
|
2008-07-15 18:24:35 +02:00
|
|
|
this._modules=[];
|
|
|
|
this.initializeLSform_AddAndRemoveBtns();
|
|
|
|
},
|
|
|
|
|
|
|
|
initializeLSform_AddAndRemoveBtns: function(el) {
|
|
|
|
if (typeof(el) == 'undefined') {
|
|
|
|
el = document;
|
|
|
|
}
|
|
|
|
el.getElements('img[class=LSform-add-field-btn]').each(function(btn) {
|
|
|
|
btn.addEvent('click',this.onAddFieldBtnClick.bind(this,btn));
|
2008-02-08 18:39:24 +01:00
|
|
|
}, this);
|
2008-07-15 18:24:35 +02:00
|
|
|
el.getElements('img[class=LSform-remove-field-btn]').each(function(btn) {
|
|
|
|
btn.addEvent('click',this.onRemoveFieldBtnClick.bind(this,btn));
|
2008-02-08 18:39:24 +01:00
|
|
|
}, this);
|
2008-02-26 18:40:05 +01:00
|
|
|
},
|
|
|
|
|
2008-07-15 18:24:35 +02:00
|
|
|
addModule: function(name,obj) {
|
|
|
|
this._modules[name]=obj;
|
|
|
|
},
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
onAddFieldBtnClick: function(img){
|
|
|
|
var getAttrName = /LSform_add_field_btn_(.*)_.*/
|
|
|
|
var attrName = getAttrName.exec(img.id)[1];
|
|
|
|
LSdebug(attrName);
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
var data = {
|
|
|
|
template: 'LSform',
|
|
|
|
action: 'onAddFieldBtnClick',
|
|
|
|
attribute: attrName,
|
|
|
|
objecttype: $('LSform_objecttype').value,
|
2008-02-26 18:40:05 +01:00
|
|
|
objectdn: $('LSform_objectdn').value,
|
2008-02-08 18:39:24 +01:00
|
|
|
idform: $('LSform_idform').value,
|
|
|
|
img: img.id
|
|
|
|
};
|
|
|
|
LSdebug(data);
|
2008-05-07 16:09:47 +02:00
|
|
|
data.imgload = varLSdefault.loadingImgDisplay(img);
|
2008-07-05 22:28:49 +02:00
|
|
|
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onAddFieldBtnClickComplete.bind(this)}).send();
|
2008-02-08 18:39:24 +01:00
|
|
|
},
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
onAddFieldBtnClickComplete: function(responseText, responseXML) {
|
2008-07-05 22:28:49 +02:00
|
|
|
var data = JSON.decode(responseText);
|
2008-02-08 18:39:24 +01:00
|
|
|
LSdebug(data);
|
2008-07-05 22:28:49 +02:00
|
|
|
if ( varLSdefault.checkAjaxReturn(data) ) {
|
|
|
|
var li = new Element('li');
|
|
|
|
var img = $(data.img);
|
|
|
|
li.set('html',data.html);
|
|
|
|
li.injectAfter(img.getParent());
|
2008-07-15 18:24:35 +02:00
|
|
|
this.initializeLSform_AddAndRemoveBtns(li);
|
|
|
|
if (typeof(this._modules[data.fieldtype]) != "undefined") {
|
|
|
|
try {
|
|
|
|
this._modules[data.fieldtype].reinitialize(li);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
LSdebug('Pas de reinitialise pour ' + data.fieldtype);
|
|
|
|
}
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
},
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
onRemoveFieldBtnClick: function(img) {
|
|
|
|
if (img.getParent().getParent().getChildren().length == 1) {
|
|
|
|
img.getPrevious().getPrevious().value='';
|
|
|
|
}
|
|
|
|
else {
|
2008-07-05 22:28:49 +02:00
|
|
|
img.getParent().destroy();
|
2008-02-08 18:39:24 +01: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
|
|
|
});
|