LSformElement :: select_object : Add ordered feature

This commit is contained in:
Benjamin Renard 2015-01-21 16:35:23 +01:00
parent 3a6bd1ea06
commit 8313191f54
5 changed files with 58 additions and 1 deletions

View file

@ -13,6 +13,7 @@
'display_name_format' => '[LSformat du nom d'affichage des LSobjects]', 'display_name_format' => '[LSformat du nom d'affichage des LSobjects]',
'value_attribute' => '[Nom de l'attribut clé des LSobjects]' 'value_attribute' => '[Nom de l'attribut clé des LSobjects]'
), ),
'ordered' => [Booléen],
'sort' => [Booléen], 'sort' => [Booléen],
'sortDirection' => '[ASC|DESC]' 'sortDirection' => '[ASC|DESC]'
),]]> ),]]>
@ -66,6 +67,18 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>ordered</term>
<listitem>
<simpara>Booléen définissant si la liste des objets choisis doit être
ordonnable ou non (Faux par défaut). Cela aura pour effet d'activer une
fonctionnalité dynamique de l'interface permettant de remonter ou descendre
dans la liste les objets choisis.</simpara>
<note><simpara>Cette fonctionnalité désactive automatiquement le trie des
objets à l'affichage.</simpara></note>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>sort</term> <term>sort</term>
<listitem> <listitem>

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

View file

@ -67,6 +67,9 @@ class LSformElement_select_object extends LSformElement {
'object_type' => $this -> selectableObject, 'object_type' => $this -> selectableObject,
'addBtn' => _('Modify'), 'addBtn' => _('Modify'),
'deleteBtns' => _('Delete'), 'deleteBtns' => _('Delete'),
'up_label' => _('Move up'),
'down_label' => _('Move down'),
'ordered' => (($this -> params['html_options']['ordered'])?1:0),
'multiple' => (($this -> params['multiple'])?1:0), 'multiple' => (($this -> params['multiple'])?1:0),
'filter64' => (($this -> params['html_options']['selectable_object']['filter'])?base64_encode($this -> params['html_options']['selectable_object']['filter']):''), 'filter64' => (($this -> params['html_options']['selectable_object']['filter'])?base64_encode($this -> params['html_options']['selectable_object']['filter']):''),
'noValueLabel' => _('No set value'), 'noValueLabel' => _('No set value'),
@ -90,7 +93,7 @@ class LSformElement_select_object extends LSformElement {
} }
} }
if (!isset($this -> params['html_options']['sort']) || $this -> params['html_options']['sort']) { if ((!isset($this -> params['html_options']['sort']) || $this -> params['html_options']['sort']) && !$this -> params['html_options']['ordered']) {
uasort($this -> values,array($this,'_sortTwoValues')); uasort($this -> values,array($this,'_sortTwoValues'));
} }

View file

@ -17,6 +17,7 @@ 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){
this.addOrderedBtns(a);
this.addDeleteBtn(a); this.addDeleteBtn(a);
},this); },this);
@ -62,6 +63,45 @@ var LSformElement_select_object_field = new Class({
varLSdefault.addHelpInfo(btn,'LSformElement_select_object','delete'); varLSdefault.addHelpInfo(btn,'LSformElement_select_object','delete');
}, },
addOrderedBtns: function(a) {
if (!this.params.ordered) {
return true;
}
var btn_down = new Element('img');
btn_down.addClass('btn');
btn_down.setProperties({
src: varLSdefault.imagePath('down'),
alt: this.params.down_label
});
btn_down.addEvent('click',this.onDownBtnClick.bind(this,btn_down));
btn_down.injectAfter(a);
var btn_up = new Element('img');
btn_up.addClass('btn');
btn_up.setProperties({
src: varLSdefault.imagePath('up'),
alt: this.params.up_label
});
btn_up.addEvent('click',this.onUpBtnClick.bind(this,btn_up));
btn_up.injectAfter(a);
},
onUpBtnClick: function(btn) {
var li = btn.getParent();
var prev = li.getPrevious('li');
if ($type(prev) && !prev.hasClass('LSformElement_select_object_addBtn')) {
li.inject(prev,'before');
}
},
onDownBtnClick: function(btn) {
var li = btn.getParent();
var next = li.getNext('li');
if ($type(next)) {
li.inject(next,'after');
}
},
addSingleAddBtn: function(insideEl) { addSingleAddBtn: function(insideEl) {
this.addBtn = new Element('img'); this.addBtn = new Element('img');
this.addBtn.setProperty('src',varLSdefault.imagePath('modify')); this.addBtn.setProperty('src',varLSdefault.imagePath('modify'));
@ -190,6 +230,7 @@ var LSformElement_select_object_field = new Class({
input.addClass('LSformElement_select_object'); input.addClass('LSformElement_select_object');
input.injectAfter(a); input.injectAfter(a);
this.addOrderedBtns(a);
this.addDeleteBtn(a); this.addDeleteBtn(a);
li.injectInside(this.ul); li.injectInside(this.ul);