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' ); }