- LSldapObject : Agrémentation des paramètres de la méthode getSelectArray()

- LSformElement_select_object :
  - Ajout d'un bouton d'ajout/recherche rapide (Feature Requests #1731)
  - JS correction d'un bug lors du refresh (bouton Modifier)
This commit is contained in:
Benjamin Renard 2008-11-05 14:57:19 +00:00
parent 6db3e82759
commit 1e64358b08
7 changed files with 327 additions and 13 deletions

View file

@ -32,3 +32,34 @@ li.LSformElement_select_object_addBtn {
img.LSformElement_select_object_deleteBtn { img.LSformElement_select_object_deleteBtn {
cursor: pointer; cursor: pointer;
} }
/* LSformElement_select_object_searchAdd */
input.LSformElement_select_object_searchAdd {
border: 1px solid #ccc;
width: 200px;
margin-left: 20px;
}
ul.LSformElement_select_object_searchAdd {
border: 1px solid #ccc;
width: 200px;
margin: 0;
margin-top: 0.1em;
height: 10em;
overflow: auto;
padding: 0;
list-style-type: none;
}
li.LSformElement_select_object_searchAdd {
cursor: pointer;
}
li.LSformElement_select_object_searchAdd_over {
background-color: #ccc;
}
li.LSformElement_select_object_searchAdd_current {
font-style: italic;
color: #777;
}

View file

@ -33,3 +33,33 @@ img.LSformElement_select_object_deleteBtn {
cursor: pointer; cursor: pointer;
} }
/* LSformElement_select_object_searchAdd */
input.LSformElement_select_object_searchAdd {
border: 1px solid #ccc;
width: 200px;
margin-left: 20px;
}
ul.LSformElement_select_object_searchAdd {
border: 1px solid #ccc;
width: 200px;
margin: 0;
margin-top: 0.1em;
height: 10em;
overflow: auto;
padding: 0;
list-style-type: none;
}
li.LSformElement_select_object_searchAdd {
cursor: pointer;
}
li.LSformElement_select_object_searchAdd_over {
background-color: #ccc;
}
li.LSformElement_select_object_searchAdd_current {
font-style: italic;
color: #777;
}

View file

@ -115,6 +115,28 @@ class LSformElement_select_object extends LSformElement {
return true; return true;
} }
/**
* Recherche les objets sélectionnables à partir du pattern fournis
*
* @param[in] $pattern Pattern de recherche
*
* @retval array(dn -> displayValue) Les objets trouvés
*/
function searchAdd ($pattern) {
if (is_array($this -> params['selectable_object'])) {
if ($GLOBALS['LSsession'] -> loadLSobject($this -> params['selectable_object']['object_type'])) {
$obj = new $this -> params['selectable_object']['object_type']();
$ret = $obj -> getSelectArray($pattern,NULL,$this -> params['selectable_object']['display_attribute']);
if (is_array($ret)) {
return $ret;
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$this -> params['selectable_object']['object_type']);
}
}
return array();
}
} }
?> ?>

View file

@ -894,11 +894,28 @@ class LSldapObject {
* *
* @retval array('dn' => 'display') * @retval array('dn' => 'display')
*/ */
function getSelectArray($topDn=NULL) { function getSelectArray($pattern=NULL,$topDn=NULL,$displayFormat=NULL,$approx=false) {
$list = $this -> listObjects(NULL,$topDn); if ($pattern!=NULL) {
$filter='(|';
if ($approx) {
foreach ($this -> attrs as $attr_name => $attr_val) {
$filter.='('.$attr_name.'~='.$pattern.')';
}
}
else {
foreach ($this -> attrs as $attr_name => $attr_val) {
$filter.='('.$attr_name.'=*'.$pattern.'*)';
}
}
$filter.=')';
}
else {
$filter=NULL;
}
$list = $this -> listObjects($filter,$topDn);
$return=array(); $return=array();
foreach($list as $object) { foreach($list as $object) {
$return[$object -> getDn()] = $object -> getDisplayValue(); $return[$object -> getDn()] = $object -> getDisplayValue($displayFormat);
} }
return $return; return $return;
} }

View file

@ -596,7 +596,7 @@ class LSsession {
} }
if( $this -> loadLSobject($LSobject_name) ) { if( $this -> loadLSobject($LSobject_name) ) {
if ($subdnobject = new $LSobject_name()) { if ($subdnobject = new $LSobject_name()) {
$tbl_return = $subdnobject -> getSelectArray($topDn); $tbl_return = $subdnobject -> getSelectArray(NULL,$topDn);
if (is_array($tbl_return)) { if (is_array($tbl_return)) {
$return=array_merge($return,$tbl_return); $return=array_merge($return,$tbl_return);
} }

View file

@ -17,16 +17,11 @@ var LSformElement_select_object_field = new Class({
// Delete btns // Delete btns
this.ul.getElements('a.LSformElement_select_object').each(function(a){ this.ul.getElements('a.LSformElement_select_object').each(function(a){
var btn = new Element('img'); this.addDeleteBtn(a);
btn.addClass('btn');
btn.setProperties({
src: varLSdefault.imagePath('delete.png'),
alt: this.params.deleteBtns
});
btn.addEvent('click',this.LSformElement_select_object_deleteBtn.bind(this,btn));
btn.injectAfter(a);
},this); },this);
if (this.params.multiple) { if (this.params.multiple) {
// li // li
this.ul.getElements('li').each(function(li){ this.ul.getElements('li').each(function(li){
@ -48,6 +43,25 @@ var LSformElement_select_object_field = new Class({
else { else {
this.addSingleAddBtn(this.ul.getFirst()); this.addSingleAddBtn(this.ul.getFirst());
} }
this._searchAddOpen = 0;
document.addEvent('click',this.closeIfOpenSearchAdd.bind(this));
this.searchAddBtn = new Element('img');
this.searchAddBtn.setProperty('src',varLSdefault.imagePath('add.png'));
this.searchAddBtn.addClass('btn');
this.searchAddBtn.addEvent('click',this.onSearchAddBtnClick.bind(this));
this.searchAddBtn.injectAfter(this.addBtn);
},
addDeleteBtn: function(a) {
var btn = new Element('img');
btn.addClass('btn');
btn.setProperties({
src: varLSdefault.imagePath('delete.png'),
alt: this.params.deleteBtns
});
btn.addEvent('click',this.LSformElement_select_object_deleteBtn.bind(this,btn));
btn.injectAfter(a);
}, },
addSingleAddBtn: function(insideEl) { addSingleAddBtn: function(insideEl) {
@ -61,14 +75,23 @@ var LSformElement_select_object_field = new Class({
reinitialize: function() { reinitialize: function() {
this.ul = this.dd.getFirst('ul'); this.ul = this.dd.getFirst('ul');
this.initializeLSformElement_select_object(); this.initializeLSformElement_select_object();
if($type(this.searchAddInput)) {
this.searchAddInput.injectInside(this.dd);
if($type(this.searchAddUl)) {
this.searchAddUl.injectAfter(this.searchAddInput);
}
}
}, },
onLSformElement_select_object_addBtnClick: function(event) { onLSformElement_select_object_addBtnClick: function(event) {
new Event(event).stop(); new Event(event).stop();
values = new Array(); values = new Array();
var inputname=this.name+'[]';
this.ul.getElements('input.LSformElement_select_object').each(function(el) { this.ul.getElements('input.LSformElement_select_object').each(function(el) {
values.push(el.getProperty('value')); if (el.name==inputname) {
values.push(el.getProperty('value'));
}
}, this); }, this);
var data = { var data = {
@ -113,6 +136,53 @@ var LSformElement_select_object_field = new Class({
} }
}, },
clearUlIfNoValue: function() {
if (!$type(this.ul.getElement('a.LSformElement_select_object'))) {
this.ul.getElements('li.LSformElement_select_object').each(function(li){
li.destroy();
});
}
},
addLi: function(name,dn) {
if (this.params.multiple) {
this.clearUlIfNoValue();
var li = new Element('li');
li.addClass('LSformElement_select_object');
var a = new Element('a');
a.addClass('LSformElement_select_object');
a.href="view.php?LSobject="+this.params['object_type']+"&dn="+dn;
a.set('html',name);
a.injectInside(li);
var input = new Element('input');
input.setProperties({
type: 'hidden',
value: dn,
name: this.name+'[]'
});
input.addClass('LSformElement_select_object');
input.injectAfter(a);
this.addDeleteBtn(a);
li.injectInside(this.ul);
}
else {
var a = this.ul.getElement('a');
a.href="view.php?LSobject="+this.params['object_type']+"&dn="+dn;
a.set('html',name);
var input = this.ul.getElement('input');
input.setProperties({
value: dn,
name: this.name+'[]'
});
}
},
LSformElement_select_object_deleteBtn: function(img) { LSformElement_select_object_deleteBtn: function(img) {
var li = img.getParent(); var li = img.getParent();
var a = li.getFirst('a'); var a = li.getFirst('a');
@ -127,5 +197,136 @@ var LSformElement_select_object_field = new Class({
a.addClass('LSformElement_select_object_deleted'); a.addClass('LSformElement_select_object_deleted');
a.removeClass('LSformElement_select_object'); a.removeClass('LSformElement_select_object');
} }
},
onSearchAddBtnClick: function() {
if (this._searchAddOpen==0) {
this._searchAddOpen = 1;
if (!$type(this.searchAddInput)) {
this.searchAddInput = new Element('input');
this.searchAddInput.addClass('LSformElement_select_object_searchAdd');
this.searchAddInput.addEvent('keydown',this.onKeyUpSearchAddInput.bindWithEvent(this));
this.searchAddInput.injectAfter(this.ul);
}
else {
this.searchAddInput.value = "";
}
if (this.params.multiple) {
this.searchAddInput.setStyles({
top: this.li.getCoordinates().top + 'px',
left: this.li.getCoordinates().right + 'px',
position: 'absolute'
});
}
else {
this.searchAddInput.setStyles({
top: this.searchAddBtn.getCoordinates().top + 'px',
left: this.searchAddBtn.getCoordinates().right + 'px',
position: 'absolute'
});
}
this._lastSearch = "";
this.searchAddInput.setStyle('display','block');
this.searchAddInput.focus();
}
},
onKeyUpSearchAddInput: function(event) {
event = new Event(event);
if ((event.key=='enter')||(event.key=='tab')) {
event.stop();
if (this.searchAddInput.value!="") {
this.launchSearchAdd();
}
}
},
launchSearchAdd: function() {
if (this._lastSearch!=this.searchAddInput.value) {
this._lastSearch=this.searchAddInput.value;
var data = {
template: 'LSform',
action: 'LSformElement_select_object_searchAdd',
attribute: this.name,
objecttype: varLSform.objecttype,
idform: varLSform.idform,
pattern: this.searchAddInput.value
};
data.imgload=varLSdefault.loadingImgDisplay(this.searchAddBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onSearchAddComplete.bind(this)}).send();
}
},
onSearchAddComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
if (!$type(this.searchAddUl)) {
this.searchAddUl = new Element('ul');
this.searchAddUl.addClass('LSformElement_select_object_searchAdd');
this.searchAddUl.injectAfter(this.searchAddInput);
}
this.searchAddUl.setStyles({
top: this.searchAddInput.getCoordinates().bottom + 'px',
left: this.searchAddInput.getCoordinates().left + 'px',
position: 'absolute'
});
this.searchAddUl.empty();
if (data.objects) {
var objs = new Hash(data.objects);
objs.each(this.addSearchAddLi,this);
}
this.searchAddUl.setStyle('display','block');
}
},
addSearchAddLi: function(name,dn) {
var current = 0;
this.ul.getElements("input[type=hidden]").each(function(input){
if (input.value==dn) {
current=1;
}
},this);
var li = new Element('li');
li.addClass('LSformElement_select_object_searchAdd');
li.id = dn;
li.set('html',name);
li.addEvent('mouseenter',this.onSearchAddLiMouseEnter.bind(this,li));
li.addEvent('mouseleave',this.onSearchAddLiMouseLeave.bind(this,li));
if (current) {
li.addClass('LSformElement_select_object_searchAdd_current');
}
else {
li.addEvent('click',this.onSearchAddLiClick.bind(this,li));
}
li.injectInside(this.searchAddUl);
},
onSearchAddLiMouseEnter: function(li) {
li.addClass('LSformElement_select_object_searchAdd_over');
},
onSearchAddLiMouseLeave: function(li) {
li.removeClass('LSformElement_select_object_searchAdd_over');
},
onSearchAddLiClick: function(li) {
var name = li.innerHTML;
var dn = li.id;
this.addLi(name,dn);
},
closeIfOpenSearchAdd: function(event) {
event = new Event(event);
if (this._searchAddOpen == 1 && event.target!=this.searchAddBtn && event.target!=this.searchAddInput && event.target!=this.searchAddUl) {
this.searchAddInput.setStyle('display','none');
if ($type(this.searchAddUl)) {
this.searchAddUl.setStyle('display','none');
}
this._searchAddOpen = 0;
}
} }
}); });

View file

@ -82,6 +82,19 @@ if (!isset($_ERRORS)) {
} }
} }
break; break;
case 'LSformElement_select_object_searchAdd':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['pattern'])) && (isset($_REQUEST['idform'])) ) {
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {
$object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']);
$field=$form -> getElement($_REQUEST['attribute']);
$data['objects'] = $field -> searchAdd($_REQUEST['pattern']);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$_REQUEST['objecttype']);
}
}
break;
case 'generatePassword': case 'generatePassword':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['idform'])) ) { if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['idform'])) ) {
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) { if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {