noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 97/107: New : InputSwitch, display a switch a


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 97/107: New : InputSwitch, display a switch and change the value of a hidden variable
Date: Mon, 26 Aug 2019 10:32:08 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 78155161c189294efafc6959f2d79152efb8c035
Author: Dany De Bontridder <address@hidden>
Date:   Mon Aug 26 11:36:24 2019 +0200

    New : InputSwitch, display a switch and change the value of a hidden 
variable
---
 html/js/scripts.js                 | 34 ++++++++++++++
 include/lib/input_switch.class.php | 81 +++++++++++++++++++++++++++++++++
 scenario/HtmlInput.test.php        | 91 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 206 insertions(+)

diff --git a/html/js/scripts.js b/html/js/scripts.js
index d7207bf..81b0563 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -3605,3 +3605,37 @@ function updatePreference()
     remove_waiting_box();
     
 }
+
+/**
+ * turn on or off ,  set an domElement to 1 or 0 and change the icon
+ * @param string icon_domid : id of the domElement which must be changed
+ * @param string p_value_domid : id of domElement containing 1 or 0
+ * @see param_jrn.php
+ */
+function toggle_onoff(icon_domid,p_value_domid)
+{
+    if ( $(p_value_domid).value==0) {
+        $(p_value_domid).value=1;
+        $(icon_domid).innerHTML='&#xf205;';
+        $(icon_domid).style='color:green';
+    } else {
+        $(p_value_domid).value=0;
+        $(icon_domid).innerHTML='&#xf204;';
+        $(icon_domid).style='color:red';
+    }
+}
+/**
+ * in CFGLED show or hide the row depending if the warning is enable or not
+ * 
+ * @param {type} p_enable
+ * @param {type} p_row
+ * @returns {undefined}
+ */
+function toggle_row_warning_enable(p_enable,p_row)
+{
+    if ($(p_enable).value==1) {
+        $(p_row).show();
+    } else {
+        $(p_row).hide();
+    }
+}
\ No newline at end of file
diff --git a/include/lib/input_switch.class.php 
b/include/lib/input_switch.class.php
new file mode 100644
index 0000000..ba67d7f
--- /dev/null
+++ b/include/lib/input_switch.class.php
@@ -0,0 +1,81 @@
+<?php
+
+/*
+ * * Copyright (C) 2019 Dany De Bontridder <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Aut
+ * 
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show a switch, when you click on it an hidden field is changed, the 
value is 1 or 0 
+ */
+require_once NOALYSS_INCLUDE.'/lib/html_input.class.php';
+
+class InputSwitch extends HtmlInput
+{
+
+    var $icon;
+    var $value_container;
+    var $value;
+
+    function __construct($name='', $value='', $p_id="")
+    {
+        $this->value_container=$name;
+        $this->value=$value;
+        $this->icon=$p_id;
+        $this->javascript="";
+    }
+
+    function input($p_name=NULL, $p_value=NULL)
+    {
+        if ($p_name!=NULL)
+            $this->value_container=$p_name;
+        if ($p_value!==NULL)
+            $this->value=$p_value;
+
+        if ( $this->icon=="") $this->icon=uniqid ("inputSwitch");
+        
+        if  ( trim($this->value_container) ==="" || trim($this->value) === "") 
{
+             throw new Exception(_("Valeur invalide"),1);
+        }
+        if ($this->readOnly == TRUE) {
+            $this->display();
+            return;
+        }
+        echo HtmlInput::hidden($this->value_container, $this->value);
+        
+        
$this->javascript=sprintf('toggle_onoff(\'%s\',\'%s\');%s;',$this->icon,$this->value_container,$this->javascript);
+        
+        if ($this->value=='1') {
+            echo Icon_Action::iconon($this->icon, $this->javascript);
+        } else {
+            echo Icon_Action::iconoff($this->icon, $this->javascript);
+        }
+    }
+    function display()
+    {
+        if ($this->value=='1') {
+            echo Icon_Action::iconon($this->icon, "");
+        } else {
+            echo Icon_Action::iconoff($this->icon, "");
+        }
+    }
+
+}
diff --git a/scenario/HtmlInput.test.php b/scenario/HtmlInput.test.php
new file mode 100644
index 0000000..027f4eb
--- /dev/null
+++ b/scenario/HtmlInput.test.php
@@ -0,0 +1,91 @@
+<?php
+//@description: Test the HtmlInput object it means the Inum, IText , ...
+
+/*
+ * * Copyright (C) 2019 Dany De Bontridder <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+ * 
+ */
+
+
+/**
+ * @file
+ * @brief Test the HtmlInput object it means the Inum, IText , ...
+ */
+
+require_once NOALYSS_INCLUDE.'/lib/html_input.class.php';
+require_once NOALYSS_INCLUDE.'/lib/iaction.class.php';
+require_once NOALYSS_INCLUDE.'/lib/ibutton.class.php';
+require_once NOALYSS_INCLUDE.'/lib/icard.class.php';
+require_once NOALYSS_INCLUDE.'/lib/icheckbox.class.php';
+require_once NOALYSS_INCLUDE.'/lib/iconcerned.class.php';
+require_once NOALYSS_INCLUDE.'/lib/idate.class.php';
+require_once NOALYSS_INCLUDE.'/lib/ifile.class.php';
+require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
+require_once NOALYSS_INCLUDE.'/lib/inum.class.php';
+require_once NOALYSS_INCLUDE.'/lib/iperiod.class.php';
+require_once NOALYSS_INCLUDE.'/lib/iposte.class.php';
+require_once NOALYSS_INCLUDE.'/lib/iradio.class.php';
+require_once NOALYSS_INCLUDE.'/lib/irelated_action.class.php';
+require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
+require_once NOALYSS_INCLUDE.'/lib/ispan.class.php';
+require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
+require_once NOALYSS_INCLUDE.'/lib/itextarea.class.php';
+require_once NOALYSS_INCLUDE.'/lib/itva_popup.class.php';
+require_once NOALYSS_INCLUDE.'/lib/input_switch.class.php';
+
+$http=new HttpInput();
+?>
+<pre>
+    <?php var_dump($_GET);?>
+</pre>
+<form method="GET">
+    <?php echo Dossier::hidden();?>
+    <?php echo HtmlInput::hidden("script",basename(__FILE__));?>
+    <h1>Input_switch.class.php</h1>
+    <h2>Normal</h2>
+    <pre>
+        
+    $input_switch=new InputSwitch('input_switch_value',<?php echo 
$http->get("input_switch_value","string","0")?>);
+    $input_switch->input();
+    </pre>
+    input_switch 
+    <?php
+    
+    $input_switch=new 
InputSwitch('input_switch_value',$http->get("input_switch_value","string","0"));
+    $input_switch->input();
+    ?>
+    <h2>ReadOnly</h2>
+    <pre>
+    $input_switch=new InputSwitch('input_switch_readonly',0);
+    $input_switch->readOnly=TRUE;
+    $input_switch->input();
+    </pre>
+    input_switch
+    <?php
+    $input_switch=new InputSwitch('input_switch_readonly',0);
+    $input_switch->readOnly=TRUE;
+    $input_switch->input();
+    ?>
+    <h1>Submit</h1>
+    <pre>
+        echo HtmlInput::submit("submit", _("Envoi"));
+    </pre>
+    <p>
+    <?php echo HtmlInput::submit("submit", _("Envoi"));?>
+    </p>
+</form>
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]