LSrelation :

-> Revue de la mise en forme
	-> Revue de la structure de <li> (supression des <span>)
	-> Mise en place d'un texte quand plus aucun objet est en relation
This commit is contained in:
Benjamin Renard 2008-10-08 15:34:36 +00:00
parent 9ad151312e
commit 95b3854e46
5 changed files with 52 additions and 18 deletions

View file

@ -19,24 +19,23 @@ var LSrelation = new Class({
el.destroy(); el.destroy();
}, this); }, this);
this.deleteBtnId = 0; this.deleteBtnId = 0;
$$('li.LSrelation').each(function(li) { $$('a.LSrelation').each(function(a) {
this.deleteBtn[this.deleteBtnId] = new Element('img'); this.deleteBtn[this.deleteBtnId] = new Element('img');
this.deleteBtn[this.deleteBtnId].src = 'templates/images/delete.png'; this.deleteBtn[this.deleteBtnId].src = 'templates/images/delete.png';
this.deleteBtn[this.deleteBtnId].setStyle('cursor','pointer'); this.deleteBtn[this.deleteBtnId].setStyle('cursor','pointer');
this.deleteBtn[this.deleteBtnId].addClass('LSrelation-btn'); 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].addEvent('click',this.onDeleteBtnClick.bind(this,this.deleteBtn[this.deleteBtnId]));
this.deleteBtn[this.deleteBtnId].injectInside(li); this.deleteBtn[this.deleteBtnId].injectAfter(a);
li.id=this.deleteBtnId; a.getParent().id=this.deleteBtnId;
this.deleteBtnId++; this.deleteBtnId++;
}, this); }, this);
}, },
onDeleteBtnClick: function(img) { onDeleteBtnClick: function(img) {
if (this._confirmDelete) { if (this._confirmDelete) {
var li = img.getParent(); var a = img.getPrevious('a');
var span = li.getFirst().getFirst('span');
this.confirmBox = new LSconfirmBox({ this.confirmBox = new LSconfirmBox({
text: 'Etês-vous sur de vouloir supprimer "'+span.innerHTML+'" ?', text: 'Etês-vous sur de vouloir supprimer "'+a.innerHTML+'" ?',
startElement: img, startElement: img,
onConfirm: this.deleteFromImg.bind(this,img) onConfirm: this.deleteFromImg.bind(this,img)
}); });
@ -48,7 +47,7 @@ var LSrelation = new Class({
deleteFromImg: function(img) { deleteFromImg: function(img) {
var li = img.getParent(); var li = img.getParent();
var span = li.getFirst().getFirst('span'); var a = img.getPrevious('a');
var ul = li.getParent(); var ul = li.getParent();
img.destroy(); img.destroy();
LSdebug(ul.id); LSdebug(ul.id);
@ -59,9 +58,9 @@ var LSrelation = new Class({
template: 'LSrelation', template: 'LSrelation',
action: 'deleteByDn', action: 'deleteByDn',
id: id, id: id,
dn: span.id dn: a.id
}; };
data.imgload=varLSdefault.loadingImgDisplay(li.id,'inside'); data.imgload=varLSdefault.loadingImgDisplay(li,'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.deleteFromImgComplete.bind(this)}).send(); new Request({url: 'index_ajax.php', data: data, onSuccess: this.deleteFromImgComplete.bind(this)}).send();
}, },
@ -69,7 +68,18 @@ var LSrelation = new Class({
var data = JSON.decode(responseText); var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) { if ( varLSdefault.checkAjaxReturn(data) ) {
try { try {
$(data.dn).getParent().getParent().destroy(); var li = $(data.dn).getParent();
var ul=$(data.dn).getParent().getParent();
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);
}
} }
catch(e) { catch(e) {
LSdebug('Erreur durant la suppression du li du DN : '+data.dn); LSdebug('Erreur durant la suppression du li du DN : '+data.dn);

View file

@ -180,13 +180,18 @@ if (!isset($_ERRORS)) {
if($objRel -> $relationConf['update_function']($object,$_SESSION['LSselect'][$relationConf['LSobject']])) { if($objRel -> $relationConf['update_function']($object,$_SESSION['LSselect'][$relationConf['LSobject']])) {
if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) { if (method_exists($relationConf['LSobject'],$relationConf['list_function'])) {
$list = $objRel -> $relationConf['list_function']($object); $list = $objRel -> $relationConf['list_function']($object);
if (is_array($list)) { if (is_array($list)&&(!empty($list))) {
foreach($list as $o) { foreach($list as $o) {
$data['html'].= "<li class='LSrelation'><a href='view.php?LSobject=".$relationConf['LSobject']."&amp;dn=".$o -> getDn()."' class='LSrelation'><span id='".$o -> getDn()."'>".$o -> getDisplayValue(NULL,true)."</span></li>\n"; $data['html'].= "<li class='LSrelation'><a href='view.php?LSobject=".$relationConf['LSobject']."&amp;dn=".$o -> getDn()."' class='LSrelation' id='".$o -> getDn()."'>".$o -> getDisplayValue(NULL,true)."</a></li>\n";
} }
} }
else { else {
$data['html'] = "<li>"._('Liste vide.')."</li>\n"; if (isset($relationConf['emptyText'])) {
$data['html'] = "<li>".$relationConf['emptyText']."</li>\n";
}
else {
$data['html'] = "<li>"._('Aucun objet en relation.')."</li>\n";
}
} }
$data['id'] = $_REQUEST['id']; $data['id'] = $_REQUEST['id'];
} }

View file

@ -1,4 +1,4 @@
<h1 id='LSrelation_title_{$item.id}'>{$item.label}</h1> <h1 id='LSrelation_title_{$item.id}' class='LSrelation'>{$item.label}</h1>
{if $item.actions!=''} {if $item.actions!=''}
<ul class='LSview-actions'> <ul class='LSview-actions'>
{foreach from=$item.actions item=action} {foreach from=$item.actions item=action}
@ -8,6 +8,8 @@
{/if} {/if}
<ul id='LSrelation_ul_{$item.id}' class='LSrelation'> <ul id='LSrelation_ul_{$item.id}' class='LSrelation'>
{foreach from=$item.objectList item=object} {foreach from=$item.objectList item=object}
<li class='LSrelation'><a href='view.php?LSobject={$item.LSobject}&amp;dn={$object.dn}' class='LSrelation'><span id='{$object.dn}'>{$object.text}</span></a></li> <li class='LSrelation'><a href='view.php?LSobject={$item.LSobject}&amp;dn={$object.dn}' class='LSrelation' id='{$object.dn}'>{$object.text}</a></li>
{foreachelse}
<li class='LSrelation'>{$item.emptyText}</li>
{/foreach} {/foreach}
</ul> </ul>

View file

@ -3,6 +3,10 @@
* LSrelation * LSrelation
*********************** ***********************
*/ */
h1.LSrelation {
font-size: 1.4em;
}
img.LSrelation-btn { img.LSrelation-btn {
margin-left: 0.5em; margin-left: 0.5em;
} }

View file

@ -81,6 +81,7 @@ if($LSsession -> startLSsession()) {
// Relations // Relations
if (is_array($object -> config['relations'])) { if (is_array($object -> config['relations'])) {
$LSrelations=array(); $LSrelations=array();
$LSrelations_JSparams=array();
foreach($object -> config['relations'] as $relationName => $relationConf) { foreach($object -> config['relations'] as $relationName => $relationConf) {
if ($GLOBALS['LSsession'] -> relationCanAccess($object -> getValue('dn'),$LSobject,$relationName)) { if ($GLOBALS['LSsession'] -> relationCanAccess($object -> getValue('dn'),$LSobject,$relationName)) {
$return=array( $return=array(
@ -88,8 +89,18 @@ if($LSsession -> startLSsession()) {
'LSobject' => $relationConf['LSobject'] 'LSobject' => $relationConf['LSobject']
); );
if (isset($relationConf['emptyText'])) {
$return['emptyText'] = $relationConf['emptyText'];
}
else {
$return['emptyText'] = _('Aucun objet en relation.');
}
$id=rand(); $id=rand();
$return['id']=$id; $return['id']=$id;
$LSrelations_JSparams[$id]=array(
'emptyText' => $return['emptyText']
);
$_SESSION['LSrelation'][$id] = array( $_SESSION['LSrelation'][$id] = array(
'relationName' => $relationName, 'relationName' => $relationName,
'objectType' => $object -> getType(), 'objectType' => $object -> getType(),
@ -137,9 +148,11 @@ if($LSsession -> startLSsession()) {
} }
} }
} }
$GLOBALS['LSsession'] -> addJSscript('LSconfirmBox.js'); $GLOBALS['LSsession'] -> addJSscript('LSconfirmBox.js');
$GLOBALS['LSsession'] -> addCssFile('LSconfirmBox.css'); $GLOBALS['LSsession'] -> addCssFile('LSconfirmBox.css');
$GLOBALS['Smarty'] -> assign('LSrelations',$LSrelations); $GLOBALS['Smarty'] -> assign('LSrelations',$LSrelations);
$GLOBALS['LSsession'] -> addJSconfigParam('LSrelations',$LSrelations_JSparams);
} }
$GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions); $GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions);