2008-02-26 18:40:05 +01:00
|
|
|
var LSrelation = new Class({
|
|
|
|
initialize: function(){
|
2009-02-20 15:05:22 +01:00
|
|
|
this.labels = varLSdefault.LSjsConfig['LSrelation_labels'];
|
|
|
|
if (!$type(this.labels)) {
|
|
|
|
this.labels = {
|
|
|
|
close_confirm_text: 'Do you really want to delete',
|
|
|
|
close_confirm_title: 'Warning',
|
|
|
|
close_confirm_validate: 'Delete'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
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;
|
2009-11-11 21:00:59 +01:00
|
|
|
$$('a.LSrelation_editable').each(function(a) {
|
2008-02-26 18:40:05 +01:00
|
|
|
this.deleteBtn[this.deleteBtnId] = new Element('img');
|
2013-06-19 02:17:39 +02:00
|
|
|
this.deleteBtn[this.deleteBtnId].src = varLSdefault.imagePath('delete');
|
2008-02-26 18:40:05 +01:00
|
|
|
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]));
|
2008-10-08 17:34:36 +02:00
|
|
|
this.deleteBtn[this.deleteBtnId].injectAfter(a);
|
|
|
|
a.getParent().id=this.deleteBtnId;
|
2008-02-26 18:40:05 +01:00
|
|
|
this.deleteBtnId++;
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteBtnClick: function(img) {
|
2008-07-05 22:28:49 +02:00
|
|
|
if (this._confirmDelete) {
|
2008-10-08 17:34:36 +02:00
|
|
|
var a = img.getPrevious('a');
|
2008-07-05 22:28:49 +02:00
|
|
|
this.confirmBox = new LSconfirmBox({
|
2009-02-20 15:05:22 +01:00
|
|
|
text: this.labels.close_confirm_text + ' "'+a.innerHTML+'" ?',
|
|
|
|
title: this.labels.close_confirm_title,
|
|
|
|
validate_label: this.labels.close_confirm_validate,
|
2009-02-17 14:16:48 +01:00
|
|
|
startElement: img,
|
|
|
|
onConfirm: this.deleteFromImg.bind(this,img)
|
2008-07-05 22:28:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.deleteFromImg(img);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteFromImg: function(img) {
|
2008-10-27 16:37:45 +01:00
|
|
|
var li = img.getParent('li');
|
2008-10-08 17:34:36 +02:00
|
|
|
var a = img.getPrevious('a');
|
2008-10-27 16:37:45 +01:00
|
|
|
var ul = li.getParent('ul');
|
2008-07-05 22:28:49 +02:00
|
|
|
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,
|
2013-11-28 20:51:43 +01:00
|
|
|
dn: this.a2dn(a)
|
2008-02-26 18:40:05 +01:00
|
|
|
};
|
2008-10-08 17:34:36 +02:00
|
|
|
data.imgload=varLSdefault.loadingImgDisplay(li,'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 {
|
2013-11-28 20:51:43 +01:00
|
|
|
var ul=$('LSrelation_ul_'+data.id);
|
|
|
|
var li = $('LSrelation_'+data.id+'_'+data.dn).getParent();
|
2008-10-08 17:34:36 +02:00
|
|
|
li.destroy();
|
|
|
|
if (!$type(ul.getFirst())) {
|
|
|
|
var getId = /LSrelation_ul_([0-9]*)/
|
|
|
|
var id = getId.exec(ul.id)[1];
|
|
|
|
|
|
|
|
var newli = new Element('li');
|
|
|
|
newli.addClass('LSrelation');
|
|
|
|
newli.set('html',varLSdefault.LSjsConfig['LSrelations'][id]['emptyText']);
|
|
|
|
newli.injectInside(ul);
|
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
}
|
|
|
|
catch(e) {
|
2009-02-17 14:46:41 +01:00
|
|
|
LSdebug('Error while deleting the li of DN : '+data.dn);
|
2008-07-05 22:28:49 +02:00
|
|
|
}
|
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) ) {
|
2008-09-25 17:15:33 +02:00
|
|
|
varLSsmoothbox.asNew();
|
|
|
|
varLSsmoothbox.addEvent('valid',this.onLSsmoothboxValid.bind(this));
|
2009-03-20 01:28:36 +01:00
|
|
|
varLSsmoothbox.openURL(data.href,{startElement: $(data.id), width: 635});
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-25 17:15:33 +02:00
|
|
|
onLSsmoothboxValid: function() {
|
2008-02-26 18:40:05 +01:00
|
|
|
var data = {
|
|
|
|
template: 'LSrelation',
|
|
|
|
action: 'refreshList',
|
|
|
|
id: this.refreshRelation
|
|
|
|
};
|
|
|
|
|
|
|
|
LSdebug(data);
|
|
|
|
data.imgload=varLSdefault.loadingImgDisplay('LSrelation_title_'+this.refreshRelation,'inside');
|
2008-09-25 17:15:33 +02:00
|
|
|
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSsmoothboxValidComplete.bind(this)}).send();
|
2008-02-26 18:40:05 +01:00
|
|
|
},
|
|
|
|
|
2008-09-25 17:15:33 +02:00
|
|
|
onLSsmoothboxValidComplete: 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
|
|
|
}
|
2013-11-28 20:51:43 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
a2dn: function(a) {
|
|
|
|
var getId = /LSrelation_[0-9]*_(.*)$/
|
|
|
|
return getId.exec(a.id)[1];
|
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();
|
|
|
|
});
|