ldapsaisie/trunk/includes/js/LSform.js
Benjamin Renard 7c37c65366 - select.php & view.php : Correction d'un bug concernant le trie lors d'un
rafraichissement.
- base.css : netoyage
- LSform.js :
  -> initializeLSform_AddAndRemoveBtns() : Modularisation des ajouts 
     d'évenements
  -> Ajout du concept de modules permettant l'initialisation JS à l'ajout d'un
     field vide d'un type avancé
- Ajout de types de champs de formulaire : 
  -> LSformElement_url : Un liens web (URL)
  -> LSformElement_rss : Un lien RSS
- class.LSformElement.php :
  -> ajout de la méthode getTitle() : Texte descriptif du champ
- LSdefault.js : Correction de la déclaration de la variable LSdebug_active
- modify.php : Modification du titre des pages
2008-07-15 16:24:35 +00:00

74 lines
2.3 KiB
JavaScript

var LSform = new Class({
initialize: function(){
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));
}, this);
el.getElements('img[class=LSform-remove-field-btn]').each(function(btn) {
btn.addEvent('click',this.onRemoveFieldBtnClick.bind(this,btn));
}, this);
},
addModule: function(name,obj) {
this._modules[name]=obj;
},
onAddFieldBtnClick: function(img){
var getAttrName = /LSform_add_field_btn_(.*)_.*/
var attrName = getAttrName.exec(img.id)[1];
LSdebug(attrName);
var data = {
template: 'LSform',
action: 'onAddFieldBtnClick',
attribute: attrName,
objecttype: $('LSform_objecttype').value,
objectdn: $('LSform_objectdn').value,
idform: $('LSform_idform').value,
img: img.id
};
LSdebug(data);
data.imgload = varLSdefault.loadingImgDisplay(img);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onAddFieldBtnClickComplete.bind(this)}).send();
},
onAddFieldBtnClickComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
LSdebug(data);
if ( varLSdefault.checkAjaxReturn(data) ) {
var li = new Element('li');
var img = $(data.img);
li.set('html',data.html);
li.injectAfter(img.getParent());
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);
}
}
}
},
onRemoveFieldBtnClick: function(img) {
if (img.getParent().getParent().getChildren().length == 1) {
img.getPrevious().getPrevious().value='';
}
else {
img.getParent().destroy();
}
}
});
window.addEvent(window.ie ? 'load' : 'domready', function() {
varLSform = new LSform();
});