[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 104/119: Select_Box Add new position : absolu
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 104/119: Select_Box Add new position : absolute |
Date: |
Mon, 26 Oct 2020 18:27:37 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 94bba9cf625c0df98ba6601aec1a2aff0405bd23
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Oct 14 15:53:21 2020 +0200
Select_Box Add new position : absolute
---
include/lib/select_box.class.php | 177 ++++++++++++++++++++++++++++-----------
1 file changed, 126 insertions(+), 51 deletions(-)
diff --git a/include/lib/select_box.class.php b/include/lib/select_box.class.php
index 8d3ccea..85b768b 100644
--- a/include/lib/select_box.class.php
+++ b/include/lib/select_box.class.php
@@ -26,7 +26,6 @@
* Display a kind of select
* @include select-box-test.php
*/
-
// Copyright Author Dany De Bontridder danydb@aevalys.eu
class Select_Box
{
@@ -36,8 +35,8 @@ class Select_Box
private $cnt;
private $filter; //!< allow a dynamic not case sensitive search
var $default_value;
- private $position ; //!< change depending if we are in an absolute block
or not
-
+ private $position; //!< change depending if we are in an absolute block or
not
+
/**
* Default constructor
* @param type $p_id javascript DOMid
@@ -52,9 +51,43 @@ class Select_Box
$this->cnt=0;
$this->default_value=-1;
$this->style_box="";
- $this->filter="";
+ $this->filter="";
$this->position="normal";
}
+
+ public function get_id()
+ {
+ return $this->id;
+ }
+
+ public function set_id($id)
+ {
+ $this->id=$id;
+ return $this;
+ }
+
+ public function get_item()
+ {
+ return $this->item;
+ }
+
+ public function get_default_value()
+ {
+ return $this->default_value;
+ }
+
+ public function set_item($item)
+ {
+ $this->item=$item;
+ return $this;
+ }
+
+ public function set_default_value($default_value)
+ {
+ $this->default_value=$default_value;
+ return $this;
+ }
+
public function get_position()
{
return $this->position;
@@ -62,18 +95,59 @@ class Select_Box
public function set_position($position)
{
- if ( ! in_array($position,array("normal","in-absolute") ) ) {
- throw new Exception("SB0005",EXC_PARAM_VALUE);
+ if (!in_array($position, array("normal", "in-absolute", "absolute")))
+ {
+ throw new Exception("SB0005", EXC_PARAM_VALUE);
}
$this->position=$position;
return $this;
}
- private function compute_position()
+ protected function compute_position()
{
$list_id=sprintf('%s_list', $this->id);
switch ($this->position)
{
+ case 'absolute':
+ // Show when click
+ $javascript=sprintf('
+ $("%s_bt").onclick=function() {
+ try {
+
+
+ if (! document.getElementById("select_box%s") ) {
+
+ var newDiv=new Element("div");
+ newDiv.id="select_box%s";
+ document.body.appendChild(newDiv);
+ newDiv.addClassName("select_box");
+ $("select_box%s").onmouseleave=function() {
+ try {
+ var newDiv=$("select_box%s");
+ newDiv.setStyle({display:"none"});
+ } catch(e) {
+ alert(e.message);
+ }
+ }
+ } else {
+ var
newDiv=document.getElementById("select_box%s");
+ }
+ newDiv.innerHTML=$("select_box%s").innerHTML;
+ var pos=$("%s_bt").cumulativeOffset();
+ var nTop=pos.top;
+ var viewport = document.viewport.getDimensions();
+ if ( nTop> viewport.height-newDiv.getHeight()-20)
{ nTop-=newDiv.getHeight()-5}
+
+
newDiv.setStyle({display:"block",position:"absolute",top:nTop+"px",left:pos.left+5+"px","z-index":999});
+
+ if ( $("search_%s") ) { $("search_%s").focus();}
+ } catch(e) {
+ alert(e.message);
+ }
+ }
+ ', $this->id, $this->id, $this->id,$this->id,
$this->id, $this->id, $this->id, $this->id, $list_id, $list_id);
+
+ break;
case "normal":
// Show when click
@@ -98,7 +172,7 @@ class Select_Box
} catch(e) {
alert(e.message);
}
- }',$this->id,$this->id);
+ }', $this->id, $this->id);
break;
case "in-absolute":
// Show when click
@@ -107,22 +181,22 @@ class Select_Box
try {
- if (! document.getElementById("select_box%s") ) {
+ if (!
document.getElementById("select_box_content") ) {
var newDiv=new Element("div");
- newDiv.id="select%s";
+ newDiv.id="select_box_content";
document.body.appendChild(newDiv);
newDiv.addClassName("select_box");
- $("select_box%s").onmouseleave=function() {
+
$("select_box_content").onmouseleave=function() {
try {
- var newDiv=$("select_box%s");
+ var newDiv=$("select_box_content");
newDiv.setStyle({display:"none"});
} catch(e) {
alert(e.message);
}
}
} else {
- var
newDiv=document.getElementById("select_box%s");
+ var
newDiv=document.getElementById("select_box_content");
}
newDiv.innerHTML=$("select_box%s").innerHTML;
var pos=$("%s_bt").cumulativeOffset();
@@ -137,10 +211,10 @@ class Select_Box
alert(e.message);
}
}
- ', $this->id,$this->id,$this->id,$this->id,$this->id,
$this->id, $this->id, $this->id,$list_id, $list_id);
-
- break;
-
+ ', $this->id, $this->id, $this->id, $list_id,
$list_id);
+
+ break;
+
default:
break;
}
@@ -149,55 +223,51 @@ class Select_Box
function input()
{
- $list_id=sprintf('%s_list',$this->id);
-
+ $list_id=sprintf('%s_list', $this->id);
+
// Show when click
$javascript=$this->compute_position();
-
-
+
+
// display the button
- printf('<input type="button" class="smallbutton " id="%s_bt" value="%s
▾" >',
- $this->id, $this->value);
- printf('<input type="hidden" id="%s" name="%s" value="%s">', $this->id,
- $this->id, $this->default_value);
- printf('<div class="select_box " id="select_box%s" style="%s">',
- $this->id, $this->style_box);
-
- // Show the filter if there is one,
- if ( $this->filter != "" ) {
-
+ printf('<input type="button" class="smallbutton " id="%s_bt" value="%s
▾" >', $this->id, $this->value);
+ printf('<input type="hidden" id="%s" name="%s" value="%s">',
$this->id, $this->id, $this->default_value);
+ printf('<div class="select_box " id="select_box%s" style="%s">',
$this->id, $this->style_box);
+
+ // Show the filter if there is one,
+ if ($this->filter!="")
+ {
+
echo HtmlInput::filter_list($list_id);
- }
-
+ }
+
// Print the list of possible options
- printf('<ul id="%s">',$list_id);
+ printf('<ul id="%s">', $list_id);
for ($i=0; $i<count($this->item); $i++)
{
if ($this->item[$i]['type']=="url")
{
- printf('<li><a href="%s">%s</a></li>', $this->item[$i]['url'],
- $this->item[$i]['label']);
+ printf('<li><a href="%s">%s</a></li>', $this->item[$i]['url'],
$this->item[$i]['label']);
}
else // For javascript
if ($this->item[$i]['type']=="javascript")
{
- printf('<li><a href="javascript:void(0)"
onclick="%s">%s</a></li>',
- $this->item[$i]['javascript'],
$this->item[$i]['label']);
+ printf('<li><a href="javascript:void(0)"
onclick="%s">%s</a></li>', $this->item[$i]['javascript'],
+ $this->item[$i]['label']);
}
else if ($this->item[$i]['type']=="value")
{
- printf('<li><a href="javascript:void(0)"
onclick="%s">%s</a></li>',
- $this->item[$i]['javascript'],
$this->item[$i]['label']);
+ printf('<li><a href="javascript:void(0)"
onclick="%s">%s</a></li>', $this->item[$i]['javascript'],
+ $this->item[$i]['label']);
}
- else if ($this->item[$i]['type']=="input") {
+ else if ($this->item[$i]['type']=="input")
+ {
$ok=new IButton("ok");
$ok->value=$this->item[$i]['label'];
$ok->javascript=$this->item[$i]['input']->javascript;
- printf('<li> %s %s</li>',
- $this->item[$i]['input']->input(),
- $ok->input()
- );
+ printf('<li> %s %s</li>', $this->item[$i]['input']->input(),
$ok->input()
+ );
}
}
@@ -235,10 +305,12 @@ class Select_Box
$this->item[$this->cnt]['type']='value';
$this->cnt++;
}
- function add_input($p_label,HtmlInput $p_element) {
+
+ function add_input($p_label, HtmlInput $p_element)
+ {
/* $this->item[$this->cnt]['label']=$p_element->label;
- $this->item[$this->cnt]['value']=$p_element->value;
- $this->item[$this->cnt]['javascript']=$p_element->javascript;
+ $this->item[$this->cnt]['value']=$p_element->value;
+ $this->item[$this->cnt]['javascript']=$p_element->javascript;
*
*/
$this->item[$this->cnt]['label']=$p_label;
@@ -246,12 +318,15 @@ class Select_Box
$this->item[$this->cnt]['type']='input';
$this->cnt++;
}
+
function set_filter($p_filter)
{
- $this->filter=$p_filter;
+ $this->filter=$p_filter;
}
- function get_filter() {
- return $this->filter;
+
+ function get_filter()
+ {
+ return $this->filter;
}
}
- [Noalyss-commit] [noalyss] 112/119: Cosmetic Follow Up add waiting box for search, (continued)
- [Noalyss-commit] [noalyss] 112/119: Cosmetic Follow Up add waiting box for search, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 114/119: Cosmetic & version, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 115/119: Analytic accountancy protect against divide by zero, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 82/119: Follow up search card, add a button to select all , cosmetic add qcode in dialog box for contact option, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 83/119: Bug : from VEN , cannot get the price, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 85/119: Follow-up fix order, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 88/119: Fix bug : follow up option contact are not remove when document type changed, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 99/119: Upgrade DB 147, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 102/119: remove dead code, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 106/119: Filter_Multiselect : make a search on select (multi-row), Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 104/119: Select_Box Add new position : absolute,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 111/119: Follow-Up improve search, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 110/119: Follow Up : an action can have several parents, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 119/119: Tache #0001859: PARAM/CFGDOC : icone fermer + bouton, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 116/119: Modern CheckBox, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 118/119: Fontello : fix icon-edit, Dany De Bontridder, 2020/10/26