[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 116/151: Manage_Table , the js and php code a
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 116/151: Manage_Table , the js and php code are been splitted in 2 files , the ajax calls are nearly done , doxygen for these files is correct |
Date: |
Sat, 4 Feb 2017 17:14:33 +0000 (UTC) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 1a0e97acefcc5087a100442b5c4a258bf4e350dd
Author: Rachel <address@hidden>
Date: Fri Jan 13 16:56:51 2017 +0100
Manage_Table , the js and php code are been splitted in 2 files , the ajax
calls are nearly done , doxygen for these files is correct
Signed-off-by: Dany De Bontridder <address@hidden>
---
html/js/managetable.js | 211 ++++++++++++++++++++++++++++++++
include/lib/class_manage_table_sql.php | 156 ++++++++---------------
2 files changed, 260 insertions(+), 107 deletions(-)
diff --git a/html/js/managetable.js b/html/js/managetable.js
new file mode 100644
index 0000000..7b766db
--- /dev/null
+++ b/html/js/managetable.js
@@ -0,0 +1,211 @@
+ <script>
+ /*
+ * This file is part of NOALYSS.
+ *
+ * NOALYSS 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.
+ *
+ * NOALYSS 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 NOALYSS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ address@hidden
+ address@hidden Javascript object to manage ajax calls to
+ * save , input or delete data row.
+ address@hidden The callback must
+ respond with a XML file , the tag status for the result
+ and data the HTML code to display
+ address@hidden p_table_name the data table on which we're working
+ in javascript , to create an object to manipulate the table
+ version.
+
+Example of code
+ @code
+ // Version will manage the table "version"
+ var version=new ManageTable("version");
+
+ // the file ajax_my.php will be called
+ version.set_callback("ajax_my.php");
+
+ // Add supplemental parameter to this file
+ version.param_add ({"plugin_code":"OIC"};
+
+ // Set the id of dialog box , table and tr prefix
+ version.set_control("dialbox1");
+
+ @endcode
+
+
+The answer from ajax must be like this template
address@hidden
+<xml>
+<ctl> id of the control to update for diag.box, row </ctl>
+<status> OK , FAIL ...</status>
+<html> Html to display</html>
+</xml>
address@hidden
+
+List of function
+ - set_control(p_ctl_name)
+ - set_callback (p_new_callback)
+ - param_add (json object)
+ - parseXML (private function)
+ - save
+ - delete
+ - input
+
+*/
+
+var ManageTable=function(p_table_name)
+{
+ this.callback="ajax.php"; //!< File to call
+ this.control="dtr"; //<! Prefix Id of dialog box, table, row
+ this.param={"table":p_table_name,"ctl_id":this.control}; //<! default
value to pass
+ var answer={};
+ /**
+ address@hidden ManageTable.set_control
+ address@hidden Set the id of the control name , used as
+ * prefix for dialog box , table id and row
+ address@hidden string p_ctl_name id of dialog box
+ */
+ this.set_control(p_ctl_name) {
+ this.control=p_ctl_name;
+ }
+ /**
+ address@hidden set the name of the callback file to
+ * call by default it is ajax.php
+ */
+ this.set_callback=function(p_new_callback) {
+ this.callback=p_new_callback;
+ };
+ /**
+ address@hidden By default send the json param variable
+ * you can add a json object to it in order to
+ * send it to the callback function
+ */
+ this.param_add= function(p_obj) {
+ var result={};
+ for ( var key in this.param) {
+ result[key]=this.param[key];
+ }
+ for ( var key in p_obj) {
+ result[key]=p_obj[key];
+ }
+ this.param=result;
+ return this.param;
+ };
+ /**
+ @brief receive answer from ajax and fill up the
+ private object "answer"
+ @param req Ajax answer
+ */
+ var 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]);
+
+ };
+ /**
+ address@hidden call the ajax with the action save
+ address@hidden update or append
+ * As a hidden parameter the Manage_Table:object_name must be
+ * set
+ */
+ this.save=function(form_id) {
+ waiting_box();
+ var form=$F(form_id);
+ this.param_add(form);
+ new Ajax.Request(this.callback,{
+ parameters:this.param,
+ method:"post",
+ onSuccess:function(req) {
+ /// Display the result of the update
+ /// or add , the name of the row in the table has the
+ /// if p_ctl_row does not exist it means it is a new
+ /// row , otherwise an update
+ parseXML(req);
+ if (answer ['status'] == 'OK' ) {
+ if ( $(answer['ctl'])) {
+ $(answer['ctl']).update(answer['html']);
+ } else {
+ var new_row=new Element("tr");
+ new_row.id=answer['ctl'];
+ new_row.innerHTML=answer['html'];
+ $("tb"+this.control).appendChild(new_row);
+ }
+ } else {
+ console.error("Error in save");
+ throw Exception "error in save";
+ }
+
+
+ }
+
+
+ };
+ /**
+ address@hidden call the ajax with action delete
+ address@hidden id (pk) of the data row
+ */
+ this.delete=function (p_id,p_ctl_row) {
+ this.param['p_id']=p_id;
+ this.param['action']='delete';
+
+ new Ajax.Request(this.callback,{
+ parameters:this.parm,
+ method:"get",
+ onSuccess:function (req) {
+ parseXML(req);
+ if ( answer['status'] == 'OK') {
+ $(answer['ctl']).hide();}
+ }
+
+ };
+ /**
+ address@hidden display a dialog box with the information
+ * of the data row
+ address@hidden id (pk) of the data row
+ */
+ this.input=function (p_id,p_ctl_row) {
+ waiting_box();
+ this.param['p_id']=p_id;
+ this.param['action']='input';
+ this.param['ctl_row']=p_ctl_row;
+ // display the form to enter data
+ new Ajax.Request(this.callback,{
+ parameters : this.param,
+ method:"get",
+ onSuccess:function (req) {
+ remove_waiting_box();
+ var
obj={"id":this.control,"cssclass":"inner_box","html":loading()};
+ create_div(obj);
+ var pos=calcy(250);
+ $(this.control).setStyle({top:pos+'px'});
+ obj.update(req.responseText);
+
+ }
+ });
+ };
+
+
+}
+</script>
diff --git a/include/lib/class_manage_table_sql.php
b/include/lib/class_manage_table_sql.php
index e7e227d..99af349 100644
--- a/include/lib/class_manage_table_sql.php
+++ b/include/lib/class_manage_table_sql.php
@@ -1,110 +1,46 @@
-<script>
-/**
- address@hidden Javascript object to manage ajax calls to
- * save , input or delete data row. The callback must
-respond with a XML file , the tag status for the result
-and data the HTML code to display
- address@hidden p_table_name the data table on which we're working
-in javascript , to create an object to manipulate the table
-version.
address@hidden
-// Version will manage the table "version"
-var version=new ManageTable("version");
-
-// the file ajax_my.php will be called
-version.set_callback("ajax_my.php");
-
-// Add supplemental parameter to this file
-version.param_add ({"plugin_code":"OIC"};
-
-
-
address@hidden
+<?php
+/*
+ * This file is part of NOALYSS.
+ *
+ * NOALYSS 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.
+ *
+ * NOALYSS 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 NOALYSS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-var ManageTable=function(p_table_name)
-{
- this.callback="ajax.php";
- this.param={"table":p_table_name};
- /**
- address@hidden set the name of the callback file to
- * call by default it is ajax.php
- */
- this.set_callback=function(p_new_callback) {
- this.callback=p_new_callback;
- };
- /**
- address@hidden By default send the json param variable
- * you can add a json object to it in order to
- * send it to the callback function
- */
- this.param_add= function(p_obj) {
- var result={};
- for ( var key in this.param) {
- result[key]=this.param[key];
- }
- for ( var key in p_obj) {
- result[key]=p_obj[key];
- }
- this.param=result;
- return this.param;
- };
- /**
- address@hidden call the ajax with the action save
- */
- this.save=function(form_id) {
- var form=$F(form_id);
- this.param_add(form);
-
- };
- /**
- address@hidden call the ajax with action delete
- address@hidden id (pk) of the data row
- */
- this.delete=function (p_id) {
- this.param['p_id']=p_id;
- this.param['action']='delete';
- };
- /**
- address@hidden display a dialog box with the information
- * of the data row
- address@hidden id (pk) of the data row
- */
- this.input=function (p_table,p_id) {
- this.param['p_id']=p_id;
- this.param['action']='input';
- // display the form to enter data
- new Ajax.Request(this.callback,{
- parameters : this.param,
- method:"get",
- onSuccess:function (req) {
- var a=new Element("div");
- a.id="div_"+p_table+"_"+p_id;
- a.update(req.responseText);
- }
- }
- };
-
-
-}
-</script>
+// Copyright Author Dany De Bontridder address@hidden
+//@file
+//@brief Definition Manage_Table_SQL
-<?php
/**
- address@hidden
+ address@hidden Purpose is to propose a librairy to display a table content
+ * and allow to update and delete row , handle also the ajax call
+ * thanks the script managetable.js
+ address@hidden ManageTable
*/
class Manage_Table_SQL
{
- private $table ;
- private $a_label_displaid;
- private $a_order; //!< order
- private $a_prop ; //!< property
+ private $table ; //!< Object Noalyss_SQL
+ private $a_label_displaid; //!< Label of the col. of the datarow
+ private $a_order; //!< order of the col
+ private $a_prop ; //!< property for each col.
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
- const UPDATABLE=1;
- const VISIBLE=2;
+ const UPDATABLE=1;
+ const VISIBLE=2;
/**
- address@hidden
+ address@hidden Constructor : set the label to the column name,
+ * the order of the column , set the properties and the
+ * permission for updating or deleting row
*/
function __construct(Noalyss_SQL $p_table)
{
@@ -146,8 +82,8 @@ class Manage_Table_SQL
}
/**
address@hidden set a column of the data row updatable or not
- address@hidden $p_key data column
- address@hidden $p_vallue Boolean False or True
+ address@hidden string $p_key data column
+ address@hidden bool $p_value Boolean False or True
*/
function set_property_updatable($p_key,$p_value)
{
@@ -202,8 +138,8 @@ class Manage_Table_SQL
}
/**
address@hidden set a column of the data row visible or not
- address@hidden $p_key data column
- address@hidden $p_vallue Boolean False or True
+ address@hidden string $p_key data column
+ address@hidden bool $p_value Boolean False or True
*/
function set_property_visible($p_key,$p_value)
{
@@ -229,7 +165,8 @@ class Manage_Table_SQL
}
/**
address@hidden set the name to display for a column
- address@hidden $p_key data column
+ address@hidden string $p_key data column
+ address@hidden string $p_display Label to display
*
*/
function set_col_label($p_key,$p_display)
@@ -255,7 +192,8 @@ class Manage_Table_SQL
* With a_order[0,1,2,3]=[x,y,z,a]
* if we move the column x (idx=0) to 2
* we must obtain [y,z,x,a]
- address@hidden $p_key data column
+ address@hidden string $p_key data column
+ address@hidden integer $p_idx new location
*/
function move($p_key,$p_idx)
{
@@ -300,6 +238,7 @@ class Manage_Table_SQL
{
$ret=$this->table->seek();
$nb=Database::num_count($ret);
+ printf ('<table id="tb%s">',$this->object_name);
for ($i=0;$i< $nb ; $i++ )
{
if ( $i == 0 ) {
@@ -370,15 +309,18 @@ class Manage_Table_SQL
}
echo "<td>";
if ( $this->can_update_row() ) {
- $js=printf ("ManageTable.input('%s');",
- $p_row[$this->table->primary_key]
+ $js=printf ("ManageTable.input('%s','%s');",
+ $p_row[$this->table->primary_key],
+ $this->object_name
);
}
echo "</td>";
echo "<td>";
if ( $this->can_delete_row() ) {
- $js=printf ("ManageTable.delete('%s');",
- $p_row[$this->table->primary_key]
+ $js=printf ("ManageTable.delete('%s','%s');",
+ $p_row[$this->table->primary_key],
+ $this->object_name
+
);
}
- [Noalyss-commit] [noalyss] 113/151: Correct doxygen doc, (continued)
- [Noalyss-commit] [noalyss] 113/151: Correct doxygen doc, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 131/151: Doxygen, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 120/151: Add managetable.js to the script to load, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 128/151: Security : add security, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 130/151: #1380 : change the name of the function Acc_Ledger::button_copy_operation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 132/151: Correct Doxygen documentation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 96/151: Documentation and clean code, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 112/151: Improve Doxygen doc, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 73/151: Export en PDF d'operation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 143/151: Fix : when exporting files for creating a PDF in ANC , the filename can be a problem if he contains some char., Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 116/151: Manage_Table , the js and php code are been splitted in 2 files , the ajax calls are nearly done , doxygen for these files is correct,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 101/151: Deprecated HtmlInput::make_object must be replace by json_encode, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 99/151: Improve Sorttable, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 110/151: Add property in Manage_Table VISIBLE UPDATABLE, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 125/151: Test ManageTable ; fix parseXML function, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 144/151: Merge branch 'master' of ns3:/srv/git/noalyss, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 09/151: Experiment less, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 123/151: Test ManageTable ; fix parseXML function, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 126/151: Correct js : this of the object is not callable from a nested function, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 135/151: Fix bug : duplicate doesn't take in account the TVA_ID, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 148/151: Missing col in ANC_TABLE, Dany De Bontridder, 2017/02/04