2008-02-26 18:40:05 +01:00
|
|
|
var LSrelation = new Class({
|
|
|
|
initialize: function(){
|
|
|
|
this.edit = 0;
|
|
|
|
this.deleteBtn = [];
|
|
|
|
this.deleteBtnId = 0;
|
|
|
|
this.refreshRelation=0;
|
2008-07-05 22:28:49 +02:00
|
|
|
this._confirmDelete=1;
|
2008-02-26 18:40:05 +01:00
|
|
|
$$('a.LSrelation_modify').each(function(el) {
|
|
|
|
this.edit=1;
|
|
|
|
el.addEvent('click',this.onLSrelationModifyBtnClick.bindWithEvent(this,el));
|
|
|
|
}, this);
|
|
|
|
if (this.edit) {
|
|
|
|
this.initializeBtn();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
initializeBtn: function() {
|
|
|
|
$$('img.LSrelation-btn').each(function(el) {
|
2008-07-05 22:28:49 +02:00
|
|
|
el.destroy();
|
2008-02-26 18:40:05 +01:00
|
|
|
}, this);
|
|
|
|
this.deleteBtnId = 0;
|
|
|
|
$$('li.LSrelation').each(function(li) {
|
|
|
|
this.deleteBtn[this.deleteBtnId] = new Element('img');
|
|
|
|
this.deleteBtn[this.deleteBtnId].src = 'templates/images/delete.png';
|
|
|
|
this.deleteBtn[this.deleteBtnId].setStyle('cursor','pointer');
|
|
|
|
this.deleteBtn[this.deleteBtnId].addClass('LSrelation-btn');
|
|
|
|
this.deleteBtn[this.deleteBtnId].addEvent('click',this.onDeleteBtnClick.bind(this,this.deleteBtn[this.deleteBtnId]));
|
|
|
|
this.deleteBtn[this.deleteBtnId].injectInside(li);
|
|
|
|
li.id=this.deleteBtnId;
|
|
|
|
this.deleteBtnId++;
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteBtnClick: function(img) {
|
2008-07-05 22:28:49 +02:00
|
|
|
if (this._confirmDelete) {
|
|
|
|
var li = img.getParent();
|
|
|
|
var span = li.getFirst('span');
|
|
|
|
this.confirmBox = new LSconfirmBox({
|
|
|
|
text: 'Etês-vous sur de vouloir supprimer "'+span.innerHTML+'" ?',
|
|
|
|
startElement: img,
|
|
|
|
onConfirm: this.deleteFromImg.bind(this,img)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.deleteFromImg(img);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteFromImg: function(img) {
|
|
|
|
var li = img.getParent();
|
|
|
|
var span = li.getFirst('span');
|
|
|
|
var ul = li.getParent();
|
|
|
|
img.destroy();
|
2008-02-26 18:40:05 +01:00
|
|
|
LSdebug(ul.id);
|
|
|
|
var getId = /LSrelation_ul_([0-9]*)/
|
|
|
|
var id = getId.exec(ul.id)[1];
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
template: 'LSrelation',
|
2008-07-05 22:28:49 +02:00
|
|
|
action: 'deleteByDn',
|
2008-02-26 18:40:05 +01:00
|
|
|
id: id,
|
2008-07-05 22:28:49 +02:00
|
|
|
dn: span.id
|
2008-02-26 18:40:05 +01:00
|
|
|
};
|
|
|
|
data.imgload=varLSdefault.loadingImgDisplay(li.id,'inside');
|
2008-07-05 22:28:49 +02:00
|
|
|
new Request({url: 'index_ajax.php', data: data, onSuccess: this.deleteFromImgComplete.bind(this)}).send();
|
2008-02-26 18:40:05 +01:00
|
|
|
},
|
|
|
|
|
2008-07-05 22:28:49 +02:00
|
|
|
deleteFromImgComplete: function(responseText, responseXML) {
|
|
|
|
var data = JSON.decode(responseText);
|
|
|
|
if ( varLSdefault.checkAjaxReturn(data) ) {
|
|
|
|
try {
|
|
|
|
$(data.dn).getParent().destroy();
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
LSdebug('Erreur durant la suppression du li du DN : '+data.dn);
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onLSrelationModifyBtnClick: function(event,a) {
|
|
|
|
new Event(event).stop();
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
template: 'LSrelation',
|
|
|
|
action: 'refreshSession',
|
|
|
|
id: a.id,
|
|
|
|
href: a.href
|
|
|
|
};
|
|
|
|
|
|
|
|
LSdebug(data);
|
|
|
|
this.refreshRelation=a.id;
|
|
|
|
data.imgload=varLSdefault.loadingImgDisplay('LSrelation_title_'+a.id,'inside');
|
2008-07-05 22:28:49 +02:00
|
|
|
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSrelationModifyBtnClickComplete.bind(this)}).send();
|
2008-02-26 18:40:05 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onLSrelationModifyBtnClickComplete: function(responseText, responseXML) {
|
2008-07-05 22:28:49 +02:00
|
|
|
var data = JSON.decode(responseText);
|
|
|
|
if ( varLSdefault.checkAjaxReturn(data) ) {
|
|
|
|
varLSsmoothbox.setRefreshElement(this);
|
|
|
|
varLSsmoothbox.openURL(data.href,{startElement: $(data.id), width: 615});
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
refresh: function() {
|
|
|
|
var data = {
|
|
|
|
template: 'LSrelation',
|
|
|
|
action: 'refreshList',
|
|
|
|
id: this.refreshRelation
|
|
|
|
};
|
|
|
|
|
|
|
|
LSdebug(data);
|
|
|
|
data.imgload=varLSdefault.loadingImgDisplay('LSrelation_title_'+this.refreshRelation,'inside');
|
2008-07-05 22:28:49 +02:00
|
|
|
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onRrefreshComplete.bind(this)}).send();
|
2008-02-26 18:40:05 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onRrefreshComplete: function(responseText, responseXML) {
|
2008-07-05 22:28:49 +02:00
|
|
|
var data = JSON.decode(responseText);
|
|
|
|
if ( varLSdefault.checkAjaxReturn(data) ) {
|
|
|
|
$('LSrelation_ul_'+this.refreshRelation).set('html',data.html);
|
|
|
|
this.initializeBtn();
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
2008-05-05 14:28:16 +02:00
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
window.addEvent(window.ie ? 'load' : 'domready', function() {
|
|
|
|
varLSrelation = new LSrelation();
|
|
|
|
});
|