[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='';
+ $(icon_domid).style='color:green';
+ } else {
+ $(p_value_domid).value=0;
+ $(icon_domid).innerHTML='';
+ $(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
- [Noalyss-commit] [noalyss] 57/107: PDF_Core : code cleaning, (continued)
- [Noalyss-commit] [noalyss] 57/107: PDF_Core : code cleaning, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 71/107: Select_Box add a search, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 77/107: Security : replace direct use of $_GET, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 45/107: Replace PHPCOMPTA by NOALYSS, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 90/107: Cosmetic : add button close in history card & accounting, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 88/107: SQL : correct SQL script to take care of users who delete the profile no 2, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 104/107: 0001728: Aide à l'encodage - Journaux négatifs (note de crédit) Unit test, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 48/107: Doxygen does not allow to document javascript Remove tag for using with jsdoc, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 89/107: Task #1735: Détail opération utilisation icone poubelle, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 103/107: Fix 0001728: Aide à l'encodage - Journaux négatifs (note de crédit) SQL Scripts, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 97/107: New : InputSwitch, display a switch and change the value of a hidden variable,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 102/107: New Task 1728: Aide à l'encodage - Journaux négatifs (note de crédit), Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 42/107: squash! PHPUnit : adapt to new version, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 49/107: translation, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 86/107: Cosmetic : Icon_Trash in Todo_List, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 96/107: traduction, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 70/107: Merge branch 'dev-7109-pluton' into dev7109, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 91/107: Cosmetic : add button close in detail card, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 100/107: CSS : add a class "warning", Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 101/107: Translation, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 41/107: fixup! PHPUnit : adapt to new version, Dany De Bontridder, 2019/08/26