[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 19/32: Improve ManageTable : add a ctl_pk_id
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 19/32: Improve ManageTable : add a ctl_pk_id as attribute in the row + doc |
Date: |
Thu, 5 Jan 2023 14:18:31 -0500 (EST) |
sparkyx pushed a commit to branch devel
in repository noalyss.
commit fc4d0d98188641f6dbbe31a5929a6cfbf72a4937
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Mon Dec 26 20:34:34 2022 +0100
Improve ManageTable : add a ctl_pk_id as attribute in the row + doc
---
html/js/managetable.js | 13 ++++++++++---
include/lib/manage_table_sql.class.php | 35 +++++++++++++++++++++++++++++-----
2 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/html/js/managetable.js b/html/js/managetable.js
index 5b8a63238..a9c4d4113 100644
--- a/html/js/managetable.js
+++ b/html/js/managetable.js
@@ -67,10 +67,12 @@
Example :
@code
- // the object_name is tbl6030ee4ee519e
+ // the object_name is tbl6030ee4ee519e , in the table each row (TR) has an
attribute ctl_pk_id which is the id (primary key)
+ // <tr ctl_pk_id="" ...> </tr>
tbl6030ee4ee519e.afterSaveFct=function(p_param) {
console.log(p_param);
console.log(this)
+ console.log(p_param.getAttribute(ctl_pk_id))
}
@endcode
@@ -191,6 +193,7 @@ var ManageTable = function (p_table_name)
var ctl = xml.getElementsByTagName("ctl");
var html = xml.getElementsByTagName("html");
var ctl_row = xml.getElementsByTagName("ctl_row");
+ var ctl_pk_id=xml.getElementsByTagName("ctl_pk_id");
if (status.length == 0 || ctl.length == 0 || html.length == 0)
{
throw content[53] + req.responseText;
@@ -201,6 +204,7 @@ var ManageTable = function (p_table_name)
answer['ctl'] = getNodeText(ctl[0]);
answer['ctl_row'] = getNodeText(ctl_row[0]);
answer['html'] = getNodeText(html[0]);
+ answer['ctl_pk_id'] = getNodeText(ctl_pk_id[0]);
return answer;
} catch (e) {
console.error("managetable:parseXML")
@@ -253,14 +257,17 @@ var ManageTable = function (p_table_name)
/// row , otherwise an update
var answer=here.parseXML(req);
var new_row;
+
if (answer ['status'] == 'OK') {
- if ($(answer['ctl_row'])) {
+ if ($(answer['ctl_row']) ) {
new_row=$(answer['ctl_row']);
$(answer['ctl_row']).update(answer['html']);
+ new_row.setAttribute("ctl_pk_id",answer['ctl_pk_id']);
} else {
new_row = new Element("tr");
new_row.id = answer['ctl_row'];
new_row.innerHTML = answer['html'];
+ new_row.setAttribute("ctl_pk_id",answer['ctl_pk_id']);
/**
* put the element at the right place
*/
@@ -273,7 +280,7 @@ var ManageTable = function (p_table_name)
// if there is an afterSaveFct then call it
if (here.afterSaveFct != undefined && typeof
here.afterSaveFct == "function") {
try {
- here.afterSaveFct.call(here,new_row);
+ here.afterSaveFct.call(here,new_row,req);
} catch (e) {
console.error("FAIL253 afterSaveFct ");
console.error(e.message);
diff --git a/include/lib/manage_table_sql.class.php
b/include/lib/manage_table_sql.class.php
index ccaec8118..37c9f98f0 100644
--- a/include/lib/manage_table_sql.class.php
+++ b/include/lib/manage_table_sql.class.php
@@ -59,7 +59,21 @@
* @see ManageTable.js
* @see ajax_accounting.php
* @see sorttable.js
- *
+ *
+ * If you need to add extra XML fields to manage them in the afterSaveFct then
you can do like this
+ * in your php code answering the ajax call
+ *
+ * @code
+ header('Content-type: text/xml; charset=UTF-8');
+ $xml=$manage_table->ajax_save();
+ $s1=$xml->createElement("previous_id",$previous);
+ $data=$xml->getElementsByTagName("data");
+ $data[0]->append($s1);
+ echo $xml->saveXML();
+
+
+ * @endcode
+ *
*/
class Manage_Table_SQL
@@ -969,19 +983,21 @@ function check()
/**
* @brief display a data row in the table, with the order defined
- * in a_order and depending of the visibility of the column
+ * in a_order and depending of the visibility of the column, all the rows
contains the attribute ctl_pk_id , to retrieve
+ * in javascript , ie with the function afterSaveFct (see managetable.js)
* @param array $p_row contains a row from the database
* @see set_col_type
* @see input_custom
* @see display_table
* @see display_row_custom
+ * @see managetable.js
*/
function display_row($p_row)
{
$pk_id=$p_row[$this->table->primary_key];
- printf('<tr id="%s_%s">', $this->object_name,
- $pk_id)
+ printf('<tr id="%s_%s" ctl_pk_id="%s">', $this->object_name,
+ $pk_id,$pk_id)
;
if ($this->icon_mod=="left")
@@ -1261,6 +1277,7 @@ function check()
$ctl=$this->object_name."_".$this->table->get_pk_value();
$s2=$xml->createElement("ctl_row", $ctl);
$s4=$xml->createElement("ctl", $this->object_name);
+ $s5=$xml->createElement("ctl_pk_id",
$this->table->get_pk_value());
ob_start();
$this->table->load();
$array=$this->table->to_array();
@@ -1277,6 +1294,7 @@ function check()
$root->appendChild($s2);
$root->appendChild($s3);
$root->appendChild($s4);
+ $root->appendChild($s5);
$xml->appendChild($root);
}
catch (Exception $ex)
@@ -1291,6 +1309,7 @@ function check()
$root->appendChild($s2);
$root->appendChild($s3);
$root->appendChild($s4);
+ $root->appendChild($s5);
$xml->appendChild($root);
}
return $xml;
@@ -1354,6 +1373,7 @@ function check()
$s2=$xml->createElement("ctl_row", $ctl);
$s4=$xml->createElement("ctl", $this->object_name);
$s3=$xml->createElement("html");
+ $s5=$xml->createElement("ctl_pk_id", $this->table->get_pk_value());
$t1=$xml->createTextNode($html);
$s3->appendChild($t1);
@@ -1362,6 +1382,8 @@ function check()
$root->appendChild($s2);
$root->appendChild($s3);
$root->appendChild($s4);
+ $root->appendChild($s5);
+
}
catch (Exception $ex)
{
@@ -1370,12 +1392,15 @@ function check()
$s2=$xml->createElement("ctl_row",
$this->object_name."_".$this->table->get_pk_value());
$s4=$xml->createElement("html", $ex->getTraceAsString());
-
+ $s5=$xml->createElement("ctl_pk_id", $this->table->get_pk_value());
$root=$xml->createElement("data");
$root->appendChild($s1);
$root->appendChild($s2);
$root->appendChild($s3);
$root->appendChild($s4);
+ $root->appendChild($s5);
+
+
}
$xml->appendChild($root);
return $xml;
- [Noalyss-commit] [noalyss] 32/32: Merge branch '9035-followup-description-mod-rtf', (continued)
- [Noalyss-commit] [noalyss] 32/32: Merge branch '9035-followup-description-mod-rtf', Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 22/32: PHP 8.1 , option ASSERT_QUIET_EVAL is removed, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 27/32: Fix Bug TVA : cannot save VAT, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 20/32: New #0001327: Code TVA : utilisation des symboles plutôt que des codes, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 02/32: Bug : incorrect name, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 12/32: PHPUNIT improve test, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 28/32: Cosmetic, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 24/32: New : Follow Up , the description modifiable is using NicEdit, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 21/32: Merge branch 'dev-9035-tva-code', Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 31/32: Merge branch 'devel-venus2', Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 19/32: Improve ManageTable : add a ctl_pk_id as attribute in the row + doc,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 18/32: Improve install config.inc.php file, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 15/32: Cosmetic add alert box, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 03/32: Cosmetic, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 06/32: Ergonomy : add button Close Cosmetic : color, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 08/32: Follow Up small bug with the #document_id, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 09/32: remove comment, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 29/32: Bug : ledger doesn't exist in 7.4 because the return value, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 26/32: Fix bug : for new TVA id not taken into account but auto-computed, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 25/32: Forgotten files, Dany De Bontridder, 2023/01/05
- [Noalyss-commit] [noalyss] 16/32: 0Task #002219: Compatibilit PHP 8.2 : Deprecated: Creation of dynamic property ..., Dany De Bontridder, 2023/01/05