From f7f35108eb8a5c6b5380ec86d30aefd61179b50a Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 28 Sep 2008 11:05:02 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSformElement=5Fselect=5Fobject=20=20=20->?= =?UTF-8?q?=20Cr=C3=A9ation=20d'un=20LSformElement=5Fselect=5Fobject=5Ffie?= =?UTF-8?q?ld=20pour=20s=C3=A9parer=20le=20traitement=20=20=20=20=20=20des?= =?UTF-8?q?=20champs=20entre=20eux.=20=20=20->=20Utilisation=20des=20LSjsC?= =?UTF-8?q?onfig[]=20au=20lieu=20de=20balise=20HTML=20pour=20la=20configur?= =?UTF-8?q?ation.=20=20=20->=20Ajout=20de=20la=20possibilit=C3=A9=20d'un?= =?UTF-8?q?=20attribut=20mono-valu=C3=A9=20et=20r=C3=A9action=20=C3=A0=20l?= =?UTF-8?q?a=20variable=20=20=20=20=20=20de=20configuration=20multiple.=20?= =?UTF-8?q?Attention=20par=20d=C3=A9faut=20multiple=20vaut=200=20et=20donc?= =?UTF-8?q?=20=20=20=20=20=20LSformElement=5Fselect=5Fobject=20passe=20en?= =?UTF-8?q?=20mono-valu=C3=A9.=20-=20LSselect=20=20=20->=20Correction=20d'?= =?UTF-8?q?un=20bug=20:=20Utilisation=20de=20la=20constante=20NB=5FLSOBJEC?= =?UTF-8?q?T=5FLIST=5FSELECT=20=20=20=20=20=20plut=C3=B4t=20que=20de=20NB?= =?UTF-8?q?=5FLSOBJECT=5FLIST=20=20=20->=20Ajout=20d'une=20possibilit?= =?UTF-8?q?=C3=A9=20de=20s=C3=A9lection=20multiple=20ou=20simple=20en=20re?= =?UTF-8?q?action=20a=20la=20=20=20=20=20=20variable=20GET=20multiple=20-?= =?UTF-8?q?=20LSrelation=20:=20Modification=20pour=20activer=20la=20s?= =?UTF-8?q?=C3=A9lection=20multiple=20de=20LSselect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class.LSformElement_select_object.php | 20 +-- .../js/LSformElement_select_object.js | 117 +-------------- .../js/LSformElement_select_object_field.js | 138 ++++++++++++++++++ trunk/includes/js/LSselect.js | 13 +- trunk/index_ajax.php | 10 +- trunk/select.php | 14 +- trunk/templates/select.tpl | 1 + trunk/templates/select_table.tpl | 4 +- trunk/view.php | 2 +- 9 files changed, 175 insertions(+), 144 deletions(-) create mode 100644 trunk/includes/js/LSformElement_select_object_field.js diff --git a/trunk/includes/class/class.LSformElement_select_object.php b/trunk/includes/class/class.LSformElement_select_object.php index 4d128114..75b0ae1f 100644 --- a/trunk/includes/class/class.LSformElement_select_object.php +++ b/trunk/includes/class/class.LSformElement_select_object.php @@ -49,19 +49,12 @@ class LSformElement_select_object extends LSformElement { $params=array(); if (!$this -> isFreeze()) { - $params['addBtn']=array( - 'href' => "select.php?LSobject=".$this -> selectableObject, - 'id' => "a_LSformElement_select_object_".$this -> name, - 'label' => _('Modifier') - ); - $params['inputHidden'] = array( - 'id' => "LSformElement_select_object_objecttype_".$this -> name, - 'name' => 'LSformElement_select_object_objecttype_'.$this -> name, - 'value' => $this -> selectableObject - ); - $params['deleteBtns'] = array( - 'alt' => _('Supprimer') - ); + $params['attr_name'] = $this -> name; + $params['object_type'] = $this -> selectableObject; + $params['addBtn'] = _('Modifier'); + $params['deleteBtns'] = _('Supprimer'); + $params['multiple'] = ($this -> params['multiple'])?1:0; + $params['noValueLabel'] = _('Aucune valeur definie'); } $ul_id="LSformElement_select_object_".$this -> name; @@ -79,6 +72,7 @@ class LSformElement_select_object extends LSformElement { } $return['html'].="\n"; if (!$this -> isFreeze()) { + $GLOBALS['LSsession'] -> addJSscript('LSformElement_select_object_field.js'); $GLOBALS['LSsession'] -> addJSscript('LSformElement_select_object.js'); $GLOBALS['LSsession'] -> addJSscript('LSform.js'); $GLOBALS['LSsession'] -> addJSscript('LSselect.js'); diff --git a/trunk/includes/js/LSformElement_select_object.js b/trunk/includes/js/LSformElement_select_object.js index 51fabe32..4157f442 100644 --- a/trunk/includes/js/LSformElement_select_object.js +++ b/trunk/includes/js/LSformElement_select_object.js @@ -1,5 +1,6 @@ var LSformElement_select_object = new Class({ initialize: function(){ + this.fields = []; this.initialiseLSformElement_select_object(); }, @@ -8,122 +9,8 @@ var LSformElement_select_object = new Class({ el = document; } el.getElements('ul.LSformElement_select_object').each(function(ul) { - var params = varLSdefault.LSjsConfig[ul.id]; - 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); - - // 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.fields[ul.id] = new LSformElement_select_object_field(ul); }, 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() { diff --git a/trunk/includes/js/LSformElement_select_object_field.js b/trunk/includes/js/LSformElement_select_object_field.js new file mode 100644 index 00000000..835f054c --- /dev/null +++ b/trunk/includes/js/LSformElement_select_object_field.js @@ -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); + } +}); diff --git a/trunk/includes/js/LSselect.js b/trunk/includes/js/LSselect.js index 71f04c93..872c5ad7 100644 --- a/trunk/includes/js/LSselect.js +++ b/trunk/includes/js/LSselect.js @@ -3,6 +3,8 @@ var LSselect = new Class({ this.main_page = $('LSobject-select-main-div').getParent(); this.content = $('content'); + this.multiple = LSselect_multiple; + this.LSselect_search_form = $('LSselect_search_form'); var input = new Element('input'); input.setProperty('name','ajax'); @@ -52,7 +54,8 @@ var LSselect = new Class({ template: 'LSselect', action: 'addLSselectobject-item', objectdn: checkbox.value, - objecttype: $('LSselect-object').getProperties('caption').caption + objecttype: $('LSselect-object').getProperties('caption').caption, + multiple: this.multiple }; } else { @@ -60,8 +63,9 @@ var LSselect = new Class({ template: 'LSselect', action: 'dropLSselectobject-item', 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'); new Request({url: 'index_ajax.php', data: data, onSuccess: this.oncheckboxChangeComplete.bind(this)}).send(); @@ -102,7 +106,8 @@ var LSselect = new Class({ data: this.LSselect_search_form, evalScripts: true, 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(); }, diff --git a/trunk/index_ajax.php b/trunk/index_ajax.php index 7937f80f..6342b669 100644 --- a/trunk/index_ajax.php +++ b/trunk/index_ajax.php @@ -294,8 +294,11 @@ if (!isset($_ERRORS)) { case 'LSselect': switch($_REQUEST['action']) { case 'addLSselectobject-item': - if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn']))) { - if (is_array($_SESSION['LSselect'][$_REQUEST['objecttype']])) { + if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['multiple']))) { + 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']])) { $_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn']; } @@ -319,7 +322,7 @@ if (!isset($_ERRORS)) { } break; case 'refreshSession': - if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) && (isset($_REQUEST['href'])) ) { + if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) ) { $_SESSION['LSselect'][$_REQUEST['objecttype']]=array(); $values=json_decode($_REQUEST['values'],false); if (is_array($values)) { @@ -328,7 +331,6 @@ if (!isset($_ERRORS)) { } } $data=array( - 'href' => $_REQUEST['href'], 'values' => $values ); } diff --git a/trunk/select.php b/trunk/select.php index b825a026..392a75e4 100644 --- a/trunk/select.php +++ b/trunk/select.php @@ -165,11 +165,14 @@ if($LSsession -> startLSsession()) { } $GLOBALS['Smarty']->assign('LSselect_topDn',$selectedTopDn); + $multiple = (isset($_REQUEST['multiple']))?1:0; + // Hidden fields $GLOBALS['Smarty']->assign('LSview_search_hidden_fields',array( 'LSobject' => $LSobject, 'LSview_search_submit' => 1, - 'ajax' => 1 + 'ajax' => 1, + 'multiple' => $multiple )); // 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); // Pagination - if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST) { + if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST_SELECT) { 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']); } 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); } - $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']); } @@ -310,6 +313,7 @@ if($LSsession -> startLSsession()) { $GLOBALS['Smarty']->assign('LSobject_list',$searchData['objectList']); $GLOBALS['Smarty']->assign('LSobject_list_objecttype',$LSobject); $GLOBALS['Smarty'] -> assign('LSview_actions',$searchData['LSview_actions']); + $GLOBALS['Smarty'] -> assign('LSselect_multiple',$multiple); if (isset($_REQUEST['ajax'])) { $GLOBALS['LSsession'] -> setTemplate('select_table.tpl'); } diff --git a/trunk/templates/select.tpl b/trunk/templates/select.tpl index 335edfcd..089b7ec2 100644 --- a/trunk/templates/select.tpl +++ b/trunk/templates/select.tpl @@ -30,5 +30,6 @@ diff --git a/trunk/templates/select_table.tpl b/trunk/templates/select_table.tpl index 3649630f..5c4e607a 100644 --- a/trunk/templates/select_table.tpl +++ b/trunk/templates/select_table.tpl @@ -7,7 +7,7 @@ {assign var='bis' value=false} {foreach from=$LSobject_list item=object} - + {$object.displayValue} {if $LSobject_list_subDn}{$object.subDn}{/if} @@ -23,7 +23,7 @@ {if $LSobject_list_currentpage == $smarty.section.listpage.index} {$LSobject_list_currentpage+1} {else} - {$smarty.section.listpage.index+1} + {$smarty.section.listpage.index+1} {/if} {/section}

diff --git a/trunk/view.php b/trunk/view.php index 7c6c14b4..1a7d8f7d 100644 --- a/trunk/view.php +++ b/trunk/view.php @@ -98,7 +98,7 @@ if($LSsession -> startLSsession()) { if ($GLOBALS['LSsession'] -> relationCanEdit($object -> getValue('dn'),$relationName)) { $return['actions'][] = array( 'label' => _('Modifier'), - 'url' => 'select.php?LSobject='.$relationConf['LSobject'], + 'url' => 'select.php?LSobject='.$relationConf['LSobject'].'&multiple=1', 'action' => 'modify' ); }