[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 122/151: Test ManageTable ; fix several bugs
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 122/151: Test ManageTable ; fix several bugs and add the ajax answer , it not yet finished |
Date: |
Sat, 4 Feb 2017 17:14:33 +0000 (UTC) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit c0f046889c1ec0dfa11b31a7a899a922bfee9332
Author: Dany De Bontridder <address@hidden>
Date: Sat Jan 14 14:30:27 2017 +0100
Test ManageTable ; fix several bugs and add the ajax answer , it not yet
finished
---
html/js/managetable.js | 72 +++++++++++++++----------
include/database/class_menu_ref_sql.php | 55 ++++++++++---------
include/lib/class_manage_table_sql.php | 64 ++++++++++++++++-------
scenario/test_manage_table_sql.php | 87 +++++++++++++++++++++++++++++++
4 files changed, 206 insertions(+), 72 deletions(-)
diff --git a/html/js/managetable.js b/html/js/managetable.js
index 75299d9..deac84f 100644
--- a/html/js/managetable.js
+++ b/html/js/managetable.js
@@ -65,10 +65,38 @@
*/
/**
+ @brief receive answer from ajax and fill up the
+ private object "answer"
+ @param req Ajax answer
+ */
+var parseXML = function (req) {
+ console.log(" start parsing");
+ console.log(req.responseText);
+ try {
+ var xml = req.responseXML;
+ var status = getElementsByTagName("status");
+ var ctl = xml.getElementsByTagName("ctl");
+ var html = xml.getElementsByTagName("html");
+ if (status.length == 0 || ctl.length == 0 || html.length == 0)
+ {
+ throw "Invalid answer " + req.responseText;
+
+ }
+ answer['status'] = getNodeText(status[0]);
+ answer['ctl'] = getNodeText(ctl[0]);
+ answer['html'] = getNodeText(html[0]);
+ return answer;
+ } catch (e) {
+ console.log("erreur parsing");
+ throw e;
+ }
+};
+/**
* @class ManageTable
* @param string p_table_name name of the table and schema
*/
+
var ManageTable = function (p_table_name)
{
this.callback = "ajax.php"; //!< File to call
@@ -107,26 +135,7 @@ var ManageTable = function (p_table_name)
this.param = result;
return this.param;
};
- /**
- @brief receive answer from ajax and fill up the
- private object "answer"
- @param req Ajax answer
- */
- this.parseXML = function (req) {
- var xml = req.responseXML;
- var status = getElementsByTagName("status");
- var ctl = xml.getElementsByTagName("ctl");
- var html = xml.getElementsByTagName("html");
- if (status.length == 0 || ctl.length == 0 || html.length == 0)
- {
- throw "Invalid answer " + req.responseText;
- }
- answer['status'] = getNodeText(status[0]);
- answer['ctl'] = getNodeText(ctl[0]);
- answer['html'] = getNodeText(html[0]);
- return answer;
- };
/**
address@hidden call the ajax with the action save
address@hidden update or append
@@ -197,21 +206,28 @@ var ManageTable = function (p_table_name)
this.param['action'] = 'input';
this.param['ctl_row'] = p_ctl_row;
var control = this.control;
- var parsexml=this.parseXML;
// display the form to enter data
new Ajax.Request(this.callback, {
parameters: this.param,
method: "get",
onSuccess: function (req) {
remove_waiting_box();
- var x=parsexml(req);
- console.log("x");
- console.log(x);
- var obj = {id:control, "cssclass": "inner_box", "html":
loading()};
- add_div(obj);
- var pos = calcy(250);
- $(obj.id).setStyle({position:"absolute",top: pos +
'px',width:"auto","margin-left":"10%"});
- $(obj.id).update(req.responseText);
+ try {
+ console.log("parse xml");
+ var x = parseXML(req);
+ console.log("x");
+ console.log(x);
+ console.log("create div");
+ var obj = {id: control, "cssclass": "inner_box", "html":
loading()};
+ add_div(obj);
+ var pos = calcy(250);
+ $(obj.id).setStyle({position: "absolute", top: pos + 'px',
width: "auto", "margin-left": "10%"});
+ console.log("set dgb content")
+ $(obj.id).update(req.responseText);
+ } catch (e) {
+ console.log(e.getMessage());
+ smoke.alert("ERREUR " + e.getMessage());
+ }
}
});
diff --git a/include/database/class_menu_ref_sql.php
b/include/database/class_menu_ref_sql.php
index 9bd6b19..35c00b0 100644
--- a/include/database/class_menu_ref_sql.php
+++ b/include/database/class_menu_ref_sql.php
@@ -1,4 +1,5 @@
<?php
+
/*
* This file is part of NOALYSS.
*
@@ -33,34 +34,36 @@ require_once
NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
*/
class Menu_Ref_SQL extends Noalyss_SQL
{
- protected $table="public.menu_ref";
- protected $primary_key="me_code";
- protected $name = array(
- "me_code" => "me_code"
- , "me_menu" => "me_menu"
- , "me_file" => "me_file"
- , "me_url" => "me_url"
- , "me_description" => "me_description"
- , "me_parameter" => "me_parameter"
- , "me_javascript" => "me_javascript"
- , "me_type" => "me_type"
- , 'me_description_etendue'=>'me_description_etendue'
- );
- protected $type=array(
- "me_code" => "text"
- , "me_menu" => "text"
- , "me_file" => "text"
- , "me_url" => "text"
- , "me_description" => "text"
- , "me_parameter" => "text"
- , "me_javascript" => "text"
- , "me_type" => "text"
- ,"me_description_etendue"=>"text"
- );
- function __construct(Database &$p_cn,$p_id=-1)
+
+ function __construct(Database &$p_cn, $p_id=-1)
{
- parent::__construct($p_cn,$p_id);
+ $this->table="public.menu_ref";
+ $this->primary_key="me_code";
+ $this->name=array(
+ "me_code"=>"me_code"
+ , "me_menu"=>"me_menu"
+ , "me_file"=>"me_file"
+ , "me_url"=>"me_url"
+ , "me_description"=>"me_description"
+ , "me_parameter"=>"me_parameter"
+ , "me_javascript"=>"me_javascript"
+ , "me_type"=>"me_type"
+ , 'me_description_etendue'=>'me_description_etendue'
+ );
+ $this->type=array(
+ "me_code"=>"text"
+ , "me_menu"=>"text"
+ , "me_file"=>"text"
+ , "me_url"=>"text"
+ , "me_description"=>"text"
+ , "me_parameter"=>"text"
+ , "me_javascript"=>"text"
+ , "me_type"=>"text"
+ , "me_description_etendue"=>"text"
+ );
+ parent::__construct($p_cn, $p_id);
}
}
+
?>
diff --git a/include/lib/class_manage_table_sql.php
b/include/lib/class_manage_table_sql.php
index a71bdad..b46a10f 100644
--- a/include/lib/class_manage_table_sql.php
+++ b/include/lib/class_manage_table_sql.php
@@ -18,8 +18,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright Author Dany De Bontridder address@hidden
-//@file
-//@brief Definition Manage_Table_SQL
+///@file
+///@brief Definition Manage_Table_SQL
/**
* @brief Purpose is to propose a librairy to display a table content
@@ -37,7 +37,7 @@ class Manage_Table_SQL
private $object_name; //!< Object_name is used for the javascript
private $row_delete; //!< Flag to indicate if rows can be deleted
private $row_update; //!< Flag to indicate if rows can be updated
-
+ private $json_parameter; //!< Default parameter to add (gDossier...)
const UPDATABLE=1;
const VISIBLE=2;
@@ -61,8 +61,30 @@ class Manage_Table_SQL
$this->object_name=uniqid("tbl");
$this->row_delete=TRUE;
$this->row_update=TRUE;
+ $this->callback="ajax.php";
+ $this->json=json_encode(array("gDossier"=>Dossier::id(),
+ "op"=>"managetable"));
+ }
+
+ /**
+ * Get the object name
+ * @details : return the object name , it is useful it
+ * the javascript will return coded without the create_js_script function
+ * @see create_js_script
+ */
+ function get_js_variable () {
+ return $this->object_name;
+ }
+ /**
+ * Set the parameter of the object (gDossier, ac, plugin_code...)
+ * @detail By default , only gDossier will be set . The default value
+ * is given in the constructor
+ * @param string with json format $p_json
+ *
+ */
+ function param_set($p_json) {
+ $this->json=$p_json;
}
-
/**
* @brief set the callback function that is passed to javascript
* @param $p_file : callback file by default ajax.php
@@ -77,11 +99,12 @@ class Manage_Table_SQL
* row. It is the default script .
*/
function create_js_script()
- {
+ {
echo "
<script>
- var {$this->object_name}=new
ManageTable(\"{$this->table->tablename}\");
+ var {$this->object_name}=new
ManageTable(\"{$this->table->table}\");
{$this->object_name}.set_callback(\"{$this->callback}\");
+ {$this->object_name}.param_add({$this->json});
</script>
";
@@ -97,7 +120,7 @@ class Manage_Table_SQL
if (!$this->a_prop[$p_key])
throw new Exception(__FILE__.":".__LINE__."$p_key invalid index");
if ($p_value==False)
- $this->a_prop[$p_key]=$this->a_prop[$p_key]-self::UPDATABLE;
+ $this->a_prop[$p_key]=$this->a_prop[$p_key] - self::UPDATABLE;
elseif ($p_value==True)
$this->a_prop[$p_key]=$this->a_prop[$p_key]|self::UPDATABLE;
else
@@ -149,7 +172,8 @@ class Manage_Table_SQL
*/
function get_property_updatable($p_key)
{
- if ( $this->a_prop[$p_key] & self::UPDATABLE == 1) return true;
+ $val= $this->a_prop[$p_key] & self::UPDATABLE ;
+ if ( $val == self::UPDATABLE) return true;
return false;
}
@@ -163,7 +187,7 @@ class Manage_Table_SQL
if (!$this->a_prop[$p_key])
throw new Exception(__FILE__.":".__LINE__."$p_key invalid index");
if ($p_value==False)
- $this->a_prop[$p_key]=$this->a_prop[$p_key]-self::VISIBLE;
+ $this->a_prop[$p_key]=$this->a_prop[$p_key] -self::VISIBLE;
elseif ($p_value==True)
$this->a_prop[$p_key]=$this->a_prop[$p_key]|self::VISIBLE;
else
@@ -176,7 +200,8 @@ class Manage_Table_SQL
*/
function get_property_visible($p_key)
{
- if ( $this->a_prop[$p_key] & self::VISIBLE == 1) return true;
+ $val = $this->a_prop[$p_key] & self::VISIBLE ;
+ if ( $val === self::VISIBLE) return true;
return false;
}
@@ -262,8 +287,8 @@ class Manage_Table_SQL
function display_table()
{
$ret=$this->table->seek();
- $nb=Database::num_count($ret);
- printf('<table id="tb%s">', $this->object_name);
+ $nb=Database::num_row($ret);
+ printf('<table class="result" id="tb%s">', $this->object_name);
for ($i=0; $i<$nb; $i++)
{
if ($i==0)
@@ -288,7 +313,8 @@ class Manage_Table_SQL
{
$key=$this->a_order[$i];
- if ($this->get_property_visible($key))
+
+ if ($this->get_property_visible($key)==true)
echo th($this->a_label_displaid[$key]);
}
echo "</tr>";
@@ -331,24 +357,26 @@ class Manage_Table_SQL
$nb_order=count($this->a_order);
for ($i=0; $i<$nb_order; $i++)
{
- $v=$this->a_order($i);
+ $v=$this->a_order[$i];
if ($this->get_property_visible($v))
echo td($p_row[$v]);
}
echo "<td>";
if ($this->can_update_row())
{
- $js=printf("ManageTable.input('%s','%s');",
- $p_row[$this->table->primary_key], $this->object_name
+ $js=sprintf("onclick=\"%s.input('%s','%s');\"",
+
$this->object_name,$p_row[$this->table->primary_key],$this->object_name
);
+ echo HtmlInput::anchor(_("Modifier"), "", $js);
}
echo "</td>";
echo "<td>";
if ($this->can_delete_row())
{
- $js=printf("ManageTable.delete('%s','%s');",
- $p_row[$this->table->primary_key], $this->object_name
+ $js=sprintf("onclick=\"%s.delete('%s','%s');\"",
+ $this->object_name,$p_row[$this->table->primary_key],
$this->object_name
);
+ echo HtmlInput::anchor(_("Effacer"), "", $js);
}
echo "</td>";
echo '</tr>';
diff --git a/scenario/test_manage_table_sql.php
b/scenario/test_manage_table_sql.php
new file mode 100644
index 0000000..ec7601f
--- /dev/null
+++ b/scenario/test_manage_table_sql.php
@@ -0,0 +1,87 @@
+<?php
+
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta 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.
+ *
+ * PhpCompta 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 PhpCompta; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+// Copyright (2016) Author Dany De Bontridder <address@hidden>
+ ini_set('disable_functions', 'exit,die,header');
+ //@description:Test the class manage_table_sql and javascript
+
+ $_GET=array (
+ 'gDossier' => '10079',
+);
+$_POST=array (
+);
+$_POST['gDossier']=$gDossierLogInput;
+$_GET['gDossier']=$gDossierLogInput;
+$_REQUEST=array_merge($_GET,$_POST);
+require_once NOALYSS_INCLUDE."/database/class_menu_ref_sql.php";
+require_once NOALYSS_INCLUDE."/lib/class_manage_table_sql.php";
+
+$jrn=new Menu_Ref_SQL($cn);
+
+$manage_table=new Manage_Table_SQL($jrn);
+$manage_table->set_callback("ajax_misc.php");
+$manage_table->create_js_script();
+?>
+<script>
+ <?php echo $manage_table->get_js_variable()?>.param_add({gDossier:"<?php
echo Dossier::id()?>"})
+ </script>
+<?php
+
+// Test the column header
+$manage_table->set_col_label('me_code', "Code");
+$manage_table->set_col_label('me_menu', "Menu");
+$manage_table->set_col_label('me_file', "Fichier");
+$manage_table->set_col_label('me_description', "Description");
+$manage_table->set_col_label('me_description_etendue', "Detail");
+
+// Change visible property
+$manage_table->set_property_visible("me_javascript", false);
+$manage_table->set_property_visible("me_url", false);
+
+
+
+
+// Change update property
+$manage_table->set_property_updatable("me_type", false);
+$manage_table->set_property_updatable("me_parameter", false);
+
+// Check
+
+echo "me_javascript Visible (false)"
.$manage_table->get_property_visible("me_javascript");
+if ( ! $manage_table->get_property_visible("me_javascript")) echo "OK"; else
echo "FAIL";echo "<br>";
+echo "me_javascript updatable (true)"
.$manage_table->get_property_updatable("me_javascript");
+if ( $manage_table->get_property_updatable("me_javascript")) echo "OK"; else
echo "FAIL";echo "<br>";
+echo "me_url Visible (false)" .$manage_table->get_property_visible("me_url");
+if ( ! $manage_table->get_property_visible("me_url")) echo "OK"; else echo
"FAIL";echo "<br>";
+echo "me_url updatable (true)"
.$manage_table->get_property_updatable("me_url");
+if ( $manage_table->get_property_updatable("me_url")) echo "OK"; else echo
"FAIL";echo "<br>";
+
+echo "me_type Visible (true)" ;
+if ( $manage_table->get_property_visible("me_type")) echo "OK"; else echo
"FAIL";echo "<br>";
+echo "me_type updatable (false)" ;
+if ( ! $manage_table->get_property_updatable("me_type")) echo "OK"; else echo
"FAIL";echo "<br>";
+
+echo "me_parameter Visible (true)" ;
+if ( $manage_table->get_property_visible("me_parameter")) echo "OK"; else
echo "FAIL";echo "<br>";
+echo "me_parameter updatable (false)" ;
+if ( ! $manage_table->get_property_updatable("me_parameter")) echo "OK"; else
echo "FAIL";echo "<br>";
+
+$manage_table->display_table();
+
+ ?>
- [Noalyss-commit] [noalyss] 114/151: Move class_table_sql to lib , since it is usable without Noalyss, (continued)
- [Noalyss-commit] [noalyss] 114/151: Move class_table_sql to lib , since it is usable without Noalyss, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 127/151: Add the noalyss version in the info page, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 121/151: Fix several issue in JS, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 98/151: Correct simul.py remove old file, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 146/151: Merge branch 'master' of ns3:/srv/git/noalyss, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 142/151: Doc : complete documentation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 119/151: correct syntax, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 151/151: Improve description, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 145/151: change name alternate_row_color, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 137/151: Remove console.log from JS Safer function for XML (problem with escaping), Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 122/151: Test ManageTable ; fix several bugs and add the ajax answer , it not yet finished,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 62/151: Experiment less, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 149/151: Correct doxygen, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 49/151: Remove unused documentation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 100/151: Remove unused documentation, Dany De Bontridder, 2017/02/04