- LSformElement_select_object

-> Création d'un LSformElement_select_object_field pour séparer le traitement
     des champs entre eux.
  -> Utilisation des LSjsConfig[] au lieu de balise HTML pour la configuration.
  -> Ajout de la possibilité d'un attribut mono-valué et réaction à la variable
     de configuration multiple. Attention par défaut multiple vaut 0 et donc
     LSformElement_select_object passe en mono-valué.
- LSselect
  -> Correction d'un bug : Utilisation de la constante NB_LSOBJECT_LIST_SELECT
     plutôt que de NB_LSOBJECT_LIST
  -> Ajout d'une possibilité de sélection multiple ou simple en reaction a la
     variable GET multiple
- LSrelation : Modification pour activer la sélection multiple de LSselect
This commit is contained in:
Benjamin Renard 2008-09-28 11:05:02 +00:00
parent ab7120b589
commit f7f35108eb
9 changed files with 175 additions and 144 deletions

View file

@ -49,19 +49,12 @@ class LSformElement_select_object extends LSformElement {
$params=array(); $params=array();
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
$params['addBtn']=array( $params['attr_name'] = $this -> name;
'href' => "select.php?LSobject=".$this -> selectableObject, $params['object_type'] = $this -> selectableObject;
'id' => "a_LSformElement_select_object_".$this -> name, $params['addBtn'] = _('Modifier');
'label' => _('Modifier') $params['deleteBtns'] = _('Supprimer');
); $params['multiple'] = ($this -> params['multiple'])?1:0;
$params['inputHidden'] = array( $params['noValueLabel'] = _('Aucune valeur definie');
'id' => "LSformElement_select_object_objecttype_".$this -> name,
'name' => 'LSformElement_select_object_objecttype_'.$this -> name,
'value' => $this -> selectableObject
);
$params['deleteBtns'] = array(
'alt' => _('Supprimer')
);
} }
$ul_id="LSformElement_select_object_".$this -> name; $ul_id="LSformElement_select_object_".$this -> name;
@ -79,6 +72,7 @@ class LSformElement_select_object extends LSformElement {
} }
$return['html'].="</ul>\n"; $return['html'].="</ul>\n";
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
$GLOBALS['LSsession'] -> addJSscript('LSformElement_select_object_field.js');
$GLOBALS['LSsession'] -> addJSscript('LSformElement_select_object.js'); $GLOBALS['LSsession'] -> addJSscript('LSformElement_select_object.js');
$GLOBALS['LSsession'] -> addJSscript('LSform.js'); $GLOBALS['LSsession'] -> addJSscript('LSform.js');
$GLOBALS['LSsession'] -> addJSscript('LSselect.js'); $GLOBALS['LSsession'] -> addJSscript('LSselect.js');

View file

@ -1,5 +1,6 @@
var LSformElement_select_object = new Class({ var LSformElement_select_object = new Class({
initialize: function(){ initialize: function(){
this.fields = [];
this.initialiseLSformElement_select_object(); this.initialiseLSformElement_select_object();
}, },
@ -8,122 +9,8 @@ var LSformElement_select_object = new Class({
el = document; el = document;
} }
el.getElements('ul.LSformElement_select_object').each(function(ul) { el.getElements('ul.LSformElement_select_object').each(function(ul) {
var params = varLSdefault.LSjsConfig[ul.id]; this.fields[ul.id] = new LSformElement_select_object_field(ul);
if ($type(params)) {
if (!params.freeze) {
// Class du UL
ul.addClass('LSformElement_select_object_edit');
// Delete btns
ul.getElements('a.LSformElement_select_object').each(function(a){
var btn = new Element('img');
btn.addClass('btn');
btn.setProperties({
src: 'templates/images/delete.png',
alt: params.deleteBtns.alt
});
btn.addEvent('click',this.LSformElement_select_object_deleteBtn.bind(this,btn));
btn.injectAfter(a);
}, this); }, this);
// li
ul.getElements('li').each(function(li){
li.addClass('LSformElement_select_object');
},this);
// Head
var li = new Element('li');
li.addClass('LSformElement_select_object_addBtn');
var addBtn = new Element('a');
addBtn.addClass('LSformElement_select_object');
addBtn.addClass('LSformElement_select_object_addBtn');
addBtn.setProperties({
href: params.addBtn.href,
id: params.addBtn.id
});
addBtn.set('html',params.addBtn.label);
addBtn.addEvent('click',this.onLSformElement_select_object_addBtnClick.bindWithEvent(this,addBtn));
addBtn.injectInside(li);
var input = new Element('input');
input.setProperties({
type: 'hidden',
name: params.inputHidden.name,
id: params.inputHidden.id,
value: params.inputHidden.value,
});
input.injectInside(li);
li.inject(ul,'top');
}
}
}, this);
},
onLSformElement_select_object_addBtnClick: function(event,a) {
new Event(event).stop();
var getAttrName = /a_LSformElement_select_object_(.*)/
var attrName = getAttrName.exec(a.id)[1];
var fieldId = 'LSformElement_select_object_'+attrName;
values = new Array();
a.getParent().getParent().getElements('input.LSformElement_select_object').each(function(el) {
values.push(el.getProperty('value'));
}, this);
var data = {
template: 'LSselect',
action: 'refreshSession',
objecttype: $('LSformElement_select_object_objecttype_'+attrName).value,
values: JSON.encode(values),
href: a.href
};
data.imgload=varLSdefault.loadingImgDisplay(a,'inside');
this.refreshFields=fieldId;
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSformElement_select_object_addBtnClickComplete.bind(this)}).send();
},
onLSformElement_select_object_addBtnClickComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
varLSsmoothbox.asNew();
varLSsmoothbox.addEvent('valid',this.onLSsmoothboxValid.bind(this));
varLSsmoothbox.displayValidBtn();
varLSsmoothbox.openURL(data.href,{width: 615});
}
},
onLSsmoothboxValid: function() {
var getAttrName = /LSformElement_select_object_(.*)/
var attrName = getAttrName.exec(this.refreshFields)[1];
var data = {
template: 'LSform',
action: 'refreshField',
attribute: attrName,
objecttype: $('LSform_objecttype').value,
objectdn: $('LSform_objectdn').value,
idform: $('LSform_idform').value,
ul: this.refreshFields
};
data.imgload=varLSdefault.loadingImgDisplay($('a_' + this.refreshFields));
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSsmoothboxValidComplete.bind(this)}).send();
},
onLSsmoothboxValidComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
var dd = $(this.refreshFields).getParent();
dd.set('html',data.html);
this.initialiseLSformElement_select_object(dd);
}
},
LSformElement_select_object_deleteBtn: function(img) {
img.getParent().destroy();
} }
}); });
window.addEvent(window.ie ? 'load' : 'domready', function() { window.addEvent(window.ie ? 'load' : 'domready', function() {

View file

@ -0,0 +1,138 @@
var LSformElement_select_object_field = new Class({
initialize: function(ul){
this.ul=ul;
this.dd=ul.getParent();
this.params = varLSdefault.LSjsConfig[ul.id];
if ($type(this.params)) {
if (!this.params.freeze) {
this.initializeLSformElement_select_object();
}
}
},
initializeLSformElement_select_object: function() {
// Class du UL
if (this.params.multiple) {
this.ul.addClass('LSformElement_select_object_edit');
}
// Delete btns
this.ul.getElements('a.LSformElement_select_object').each(function(a){
var btn = new Element('img');
btn.addClass('btn');
btn.setProperties({
src: 'templates/images/delete.png',
alt: this.params.deleteBtns
});
btn.addEvent('click',this.LSformElement_select_object_deleteBtn.bind(this,btn));
btn.injectAfter(a);
},this);
if (this.params.multiple) {
// li
this.ul.getElements('li').each(function(li){
li.addClass('LSformElement_select_object');
},this);
// Head
this.li = new Element('li');
this.li.addClass('LSformElement_select_object_addBtn');
this.addBtn = new Element('span');
this.addBtn.addClass('btn');
this.addBtn.set('html',this.params.addBtn);
this.addBtn.addEvent('click',this.onLSformElement_select_object_addBtnClick.bindWithEvent(this));
this.addBtn.injectInside(this.li);
this.li.inject(this.ul,'top');
}
else {
this.addSingleAddBtn(this.ul.getFirst());
}
},
addSingleAddBtn: function(insideEl) {
this.addBtn = new Element('img');
this.addBtn.setProperty('src','templates/images/modify.png');
this.addBtn.addClass('btn');
this.addBtn.addEvent('click',this.onLSformElement_select_object_addBtnClick.bindWithEvent(this));
this.addBtn.injectInside(insideEl);
},
reinitialize: function() {
this.ul = this.dd.getFirst('ul');
this.initializeLSformElement_select_object();
},
onLSformElement_select_object_addBtnClick: function(event) {
new Event(event).stop();
values = new Array();
this.ul.getElements('input.LSformElement_select_object').each(function(el) {
values.push(el.getProperty('value'));
}, this);
var data = {
template: 'LSselect',
action: 'refreshSession',
objecttype: this.params['object_type'],
values: JSON.encode(values)
};
data.imgload=varLSdefault.loadingImgDisplay(this.addBtn,'inside');
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSformElement_select_object_addBtnClickComplete.bind(this)}).send();
},
onLSformElement_select_object_addBtnClickComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
varLSsmoothbox.asNew();
varLSsmoothbox.addEvent('valid',this.onLSsmoothboxValid.bind(this));
varLSsmoothbox.displayValidBtn();
varLSsmoothbox.openURL('select.php?LSobject='+this.params['object_type']+((this.params['multiple'])?'&multiple=1':''),{width: 615});
}
},
onLSsmoothboxValid: function() {
var data = {
template: 'LSform',
action: 'refreshField',
attribute: this.params['attr_name'],
objecttype: $('LSform_objecttype').value,
objectdn: $('LSform_objectdn').value,
idform: $('LSform_idform').value
};
data.imgload=varLSdefault.loadingImgDisplay(this.addBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSsmoothboxValidComplete.bind(this)}).send();
},
onLSsmoothboxValidComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
this.dd.set('html',data.html);
this.reinitialize();
}
},
LSformElement_select_object_deleteBtn: function(img) {
img.getParent().destroy();
if (!$type(this.ul.getFirst('li.LSformElement_select_object'))) {
this.addNoValueField();
}
},
addNoValueField: function() {
var li = new Element('li');
li.set('html',this.params.noValueLabel);
if (!this.params.multiple) {
this.addSingleAddBtn(li);
}
else {
li.addClass('LSformElement_select_object');
}
li.injectInside(this.ul);
}
});

View file

@ -3,6 +3,8 @@ var LSselect = new Class({
this.main_page = $('LSobject-select-main-div').getParent(); this.main_page = $('LSobject-select-main-div').getParent();
this.content = $('content'); this.content = $('content');
this.multiple = LSselect_multiple;
this.LSselect_search_form = $('LSselect_search_form'); this.LSselect_search_form = $('LSselect_search_form');
var input = new Element('input'); var input = new Element('input');
input.setProperty('name','ajax'); input.setProperty('name','ajax');
@ -52,7 +54,8 @@ var LSselect = new Class({
template: 'LSselect', template: 'LSselect',
action: 'addLSselectobject-item', action: 'addLSselectobject-item',
objectdn: checkbox.value, objectdn: checkbox.value,
objecttype: $('LSselect-object').getProperties('caption').caption objecttype: $('LSselect-object').getProperties('caption').caption,
multiple: this.multiple
}; };
} }
else { else {
@ -60,7 +63,8 @@ var LSselect = new Class({
template: 'LSselect', template: 'LSselect',
action: 'dropLSselectobject-item', action: 'dropLSselectobject-item',
objectdn: checkbox.value, objectdn: checkbox.value,
objecttype: $('LSselect-object').getProperties('caption').caption objecttype: $('LSselect-object').getProperties('caption').caption,
multiple: this.multiple
}; };
} }
data.imgload=varLSdefault.loadingImgDisplay(checkbox.getParent().getNext(),'inside'); data.imgload=varLSdefault.loadingImgDisplay(checkbox.getParent().getNext(),'inside');
@ -102,7 +106,8 @@ var LSselect = new Class({
data: this.LSselect_search_form, data: this.LSselect_search_form,
evalScripts: true, evalScripts: true,
onSuccess: this.onSubmitSearchFormComplete.bind(this), onSuccess: this.onSubmitSearchFormComplete.bind(this),
url: this.LSselect_search_form.get('action') url: this.LSselect_search_form.get('action'),
multiple: this.multiple
}); });
this.LSselect_search_form.send(); this.LSselect_search_form.send();
}, },

View file

@ -294,8 +294,11 @@ if (!isset($_ERRORS)) {
case 'LSselect': case 'LSselect':
switch($_REQUEST['action']) { switch($_REQUEST['action']) {
case 'addLSselectobject-item': case 'addLSselectobject-item':
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn']))) { if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['multiple']))) {
if (is_array($_SESSION['LSselect'][$_REQUEST['objecttype']])) { if (!$_REQUEST['multiple']) {
$_SESSION['LSselect'][$_REQUEST['objecttype']]=array($_REQUEST['objectdn']);
}
else if (is_array($_SESSION['LSselect'][$_REQUEST['objecttype']])) {
if (!in_array($_REQUEST['objectdn'],$_SESSION['LSselect'][$_REQUEST['objecttype']])) { if (!in_array($_REQUEST['objectdn'],$_SESSION['LSselect'][$_REQUEST['objecttype']])) {
$_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn']; $_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn'];
} }
@ -319,7 +322,7 @@ if (!isset($_ERRORS)) {
} }
break; break;
case 'refreshSession': case 'refreshSession':
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) && (isset($_REQUEST['href'])) ) { if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) ) {
$_SESSION['LSselect'][$_REQUEST['objecttype']]=array(); $_SESSION['LSselect'][$_REQUEST['objecttype']]=array();
$values=json_decode($_REQUEST['values'],false); $values=json_decode($_REQUEST['values'],false);
if (is_array($values)) { if (is_array($values)) {
@ -328,7 +331,6 @@ if (!isset($_ERRORS)) {
} }
} }
$data=array( $data=array(
'href' => $_REQUEST['href'],
'values' => $values 'values' => $values
); );
} }

View file

@ -165,11 +165,14 @@ if($LSsession -> startLSsession()) {
} }
$GLOBALS['Smarty']->assign('LSselect_topDn',$selectedTopDn); $GLOBALS['Smarty']->assign('LSselect_topDn',$selectedTopDn);
$multiple = (isset($_REQUEST['multiple']))?1:0;
// Hidden fields // Hidden fields
$GLOBALS['Smarty']->assign('LSview_search_hidden_fields',array( $GLOBALS['Smarty']->assign('LSview_search_hidden_fields',array(
'LSobject' => $LSobject, 'LSobject' => $LSobject,
'LSview_search_submit' => 1, 'LSview_search_submit' => 1,
'ajax' => 1 'ajax' => 1,
'multiple' => $multiple
)); ));
// Hash de la recherche déterminer à partir des paramètres de la recherche // Hash de la recherche déterminer à partir des paramètres de la recherche
@ -265,17 +268,17 @@ if($LSsession -> startLSsession()) {
$GLOBALS['Smarty']->assign('LSobject_list_ordersense',$ordersense); $GLOBALS['Smarty']->assign('LSobject_list_ordersense',$ordersense);
// Pagination // Pagination
if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST) { if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST_SELECT) {
if (isset($_REQUEST['page'])) { if (isset($_REQUEST['page'])) {
$searchData['objectList'] = array_slice($searchData['objectList'], ($_REQUEST['page']) * NB_LSOBJECT_LIST, NB_LSOBJECT_LIST); $searchData['objectList'] = array_slice($searchData['objectList'], ($_REQUEST['page']) * NB_LSOBJECT_LIST_SELECT, NB_LSOBJECT_LIST_SELECT);
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',$_REQUEST['page']); $GLOBALS['Smarty']->assign('LSobject_list_currentpage',$_REQUEST['page']);
} }
else { else {
$searchData['objectList'] = array_slice($searchData['objectList'], 0, NB_LSOBJECT_LIST); $searchData['objectList'] = array_slice($searchData['objectList'], 0, NB_LSOBJECT_LIST_SELECT);
$GLOBALS['Smarty']->assign('LSobject_list_currentpage',0); $GLOBALS['Smarty']->assign('LSobject_list_currentpage',0);
} }
$searchData['LSobject_list_nbpage']=ceil($searchData['LSobject_list_nbresult'] / NB_LSOBJECT_LIST); $searchData['LSobject_list_nbpage']=ceil($searchData['LSobject_list_nbresult'] / NB_LSOBJECT_LIST_SELECT);
$GLOBALS['Smarty']->assign('LSobject_list_nbpage',$searchData['LSobject_list_nbpage']); $GLOBALS['Smarty']->assign('LSobject_list_nbpage',$searchData['LSobject_list_nbpage']);
} }
@ -310,6 +313,7 @@ if($LSsession -> startLSsession()) {
$GLOBALS['Smarty']->assign('LSobject_list',$searchData['objectList']); $GLOBALS['Smarty']->assign('LSobject_list',$searchData['objectList']);
$GLOBALS['Smarty']->assign('LSobject_list_objecttype',$LSobject); $GLOBALS['Smarty']->assign('LSobject_list_objecttype',$LSobject);
$GLOBALS['Smarty'] -> assign('LSview_actions',$searchData['LSview_actions']); $GLOBALS['Smarty'] -> assign('LSview_actions',$searchData['LSview_actions']);
$GLOBALS['Smarty'] -> assign('LSselect_multiple',$multiple);
if (isset($_REQUEST['ajax'])) { if (isset($_REQUEST['ajax'])) {
$GLOBALS['LSsession'] -> setTemplate('select_table.tpl'); $GLOBALS['LSsession'] -> setTemplate('select_table.tpl');
} }

View file

@ -30,5 +30,6 @@
</div> </div>
</div> </div>
<script type='text/javascript'> <script type='text/javascript'>
LSselect_multiple = {$LSselect_multiple};
varLSselect = new LSselect(); varLSselect = new LSselect();
</script> </script>

View file

@ -7,7 +7,7 @@
{assign var='bis' value=false} {assign var='bis' value=false}
{foreach from=$LSobject_list item=object} {foreach from=$LSobject_list item=object}
<tr class='LSobject-list{if $bis} LSobject-list-bis{assign var='bis' value=false}{else}{assign var='bis' value=true}{/if}'> <tr class='LSobject-list{if $bis} LSobject-list-bis{assign var='bis' value=false}{else}{assign var='bis' value=true}{/if}'>
<td class='LSobject-list LSobject-select-check'><input type='checkbox' name='LSobjects_selected[]' value='{$object.dn}' {if $object.select}checked{/if} class='LSobject-select' /></td> <td class='LSobject-list LSobject-select-check'><input type='{if $LSselect_multiple}checkbox{else}radio{/if}' name='LSobjects_selected[]' value='{$object.dn}' {if $object.select}checked{/if} class='LSobject-select' /></td>
<td class='LSobject-list LSobject-select-names'>{$object.displayValue}</td> <td class='LSobject-list LSobject-select-names'>{$object.displayValue}</td>
{if $LSobject_list_subDn}<td class='LSobject-list LSobject-select-level'>{$object.subDn}</td>{/if} {if $LSobject_list_subDn}<td class='LSobject-list LSobject-select-level'>{$object.subDn}</td>{/if}
</tr> </tr>
@ -23,7 +23,7 @@
{if $LSobject_list_currentpage == $smarty.section.listpage.index} {if $LSobject_list_currentpage == $smarty.section.listpage.index}
<strong class='LSobject-list-page'>{$LSobject_list_currentpage+1}</strong> <strong class='LSobject-list-page'>{$LSobject_list_currentpage+1}</strong>
{else} {else}
<a href='select.php?LSobject={$LSobject_list_objecttype}&amp;page={$smarty.section.listpage.index}&amp;{$LSobject_list_filter}' class='LSobject-list-page'>{$smarty.section.listpage.index+1}</a> <a href='select.php?LSobject={$LSobject_list_objecttype}&amp;multiple={$LSselect_multiple}&amp;page={$smarty.section.listpage.index}&amp;{$LSobject_list_filter}' class='LSobject-list-page'>{$smarty.section.listpage.index+1}</a>
{/if} {/if}
{/section} {/section}
</p> </p>

View file

@ -98,7 +98,7 @@ if($LSsession -> startLSsession()) {
if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$relationName)) { if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$relationName)) {
$return['actions'][] = array( $return['actions'][] = array(
'label' => _('Modifier'), 'label' => _('Modifier'),
'url' => 'select.php?LSobject='.$relationConf['LSobject'], 'url' => 'select.php?LSobject='.$relationConf['LSobject'].'&amp;multiple=1',
'action' => 'modify' 'action' => 'modify'
); );
} }