noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 06/09: CMCARD : template of card, drag'n drop


From: dwm
Subject: [Noalyss-commit] [noalyss] 06/09: CMCARD : template of card, drag'n drop to order the attributes
Date: Fri, 9 Aug 2024 15:18:16 -0400 (EDT)

sparkyx pushed a commit to branch unstable
in repository noalyss.

commit b1896b410f0acb74ef429cbe9c13a1d9be397222
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Fri Aug 9 16:22:03 2024 +0200

    CMCARD : template of card, drag'n drop to order the attributes
---
 html/js/ajax_fiche.js                          | 14 +++++---
 include/ajax/ajax_template_cat_category.php    | 10 ++++--
 include/cfgfiche.inc.php                       |  3 ++
 include/class/fiche_def.class.php              | 41 ++++++++++++++++-------
 include/class/template_card_category.class.php | 46 +++++++++++++++++++++-----
 sql/upgrade.sql                                |  3 ++
 6 files changed, 90 insertions(+), 27 deletions(-)

diff --git a/html/js/ajax_fiche.js b/html/js/ajax_fiche.js
index efecc0e45..03415c18a 100644
--- a/html/js/ajax_fiche.js
+++ b/html/js/ajax_fiche.js
@@ -266,11 +266,17 @@ category_card.add_attribut=function 
(p_dossier,p_fiche_def_ref,p_object_name) {
        onSuccess:function(req) {
            var answer=req.responseText.evalJSON();
            if ( answer.status == 'OK') {
-               var newli=document.createElement("li")
-               newli.setAttribute("id",p_object_name+"_elt"+selected_attr);
-               newli.innerHTML=answer.content
-               $(p_object_name+"_list").append(newli);
+               var newli = document.createElement("li")
+
+               $(p_object_name + "_list").append(newli);
+               newli.replace(answer.content);
+               document.getElementById('attribut_order').value = 
Sortable.serialize(p_object_name + "_list");
                select.remove(select.selectedIndex);
+               Sortable.create(p_object_name + '_list', {
+                   onUpdate: function () {
+                       document.getElementById('attribut_order').value = 
Sortable.serialize(p_object_name + "_list")
+                   }
+               });
            } else {
                smoke.alert(answer.message);
            }
diff --git a/include/ajax/ajax_template_cat_category.php 
b/include/ajax/ajax_template_cat_category.php
index 692a86c95..a94e787a7 100644
--- a/include/ajax/ajax_template_cat_category.php
+++ b/include/ajax/ajax_template_cat_category.php
@@ -68,9 +68,13 @@ switch ($action)
             $answer['message']="";
             $js=sprintf("category_card.remove_attribut('%s','%s','%s',%d)",
                     Dossier::id(), $frd_id, $objname, $ad_id);
-            $answer['content']=$cn->get_value("select ad_text from attr_def 
where ad_id=$1",
-                            [$ad_id]).
-                            Icon_Action::trash(uniqid(), $js);
+            $label=$cn->get_value("select ad_text from attr_def where 
ad_id=$1",
+                [$ad_id]);
+            $content=sprintf('<li id="%s_elt%d" style="cursor:move;border:1px 
solid navy;padding : 0.5rem 0.2rem 0.5rem 0.2rem;margin-top:2px">%s', $objname
+                ,$ad_id,$label);
+            $content.=Icon_Action::trash(uniqid(), $js);
+            $content.='</li>';
+            $answer['content']=$content;
         }
         catch (Exception $exc)
         {
diff --git a/include/cfgfiche.inc.php b/include/cfgfiche.inc.php
index ddbd84f8f..a865d6f8e 100644
--- a/include/cfgfiche.inc.php
+++ b/include/cfgfiche.inc.php
@@ -45,6 +45,9 @@ if ( $action == 'remove_cat' )
                   'Les fiches non utilisées ont cependant été effacées'));
         }
     }
+    $fiche_def=new Fiche_def($cn);
+    $fiche_def->display();
+    return;
 }
 
/*******************************************************************************************/
 // Change some basis info
diff --git a/include/class/fiche_def.class.php 
b/include/class/fiche_def.class.php
index 965f9159d..586a752a3 100644
--- a/include/class/fiche_def.class.php
+++ b/include/class/fiche_def.class.php
@@ -253,7 +253,7 @@ $order
             $p_create='true';
         else
             $p_create='false';
-
+        $add_accounting=false;
         // Class is valid ?
         if ( sql_string($p_class_base) != null || ( $p_class_base !='' && 
strpos(',',$p_class_base) != 0 ))
         {
@@ -272,10 +272,11 @@ $order
                        // Get the fd_id
                        $fd_id=$this->cn->get_current_seq('s_fdef');
 
-                       // update jnt_fic_attr
-                       $sql=sprintf("insert into 
jnt_fic_attr(fd_id,ad_id,jnt_order)
-                                        values 
(%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
-                       $Res=$this->cn->exec_sql($sql);
+//                     // update jnt_fic_attr
+//                     $sql=sprintf("insert into 
jnt_fic_attr(fd_id,ad_id,jnt_order)
+//                                      values 
(%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
+//                     $Res=$this->cn->exec_sql($sql);
+            $add_accounting=true;
         }
         else
         {
@@ -295,24 +296,39 @@ $order
 
         //if defaut attr not null
         // build the sql insert for the table attr_def
+        $add_qcode=true;
         if (sizeof($def_attr) != 0 )
         {
             // insert all the mandatory fields into jnt_fiche_attr
             foreach ( $def_attr as $row)
             {
-                               $order=$row['ad_default_order'];
-                if ( $row['ad_id'] == ATTR_DEF_NAME )
-                    $order=0;
+
                                $count=$this->cn->get_value("select count(*) 
from jnt_fic_attr where fd_id=$1 and ad_id=$2",array($fd_id,$row['ad_id']));
                                if ($count == 0)
                                {
                                        $sql=sprintf("insert into 
jnt_fic_Attr(fd_id,ad_id,jnt_order)
                              values (%d,%s,%d)",
-                             $fd_id,$row['ad_id'],$order);
+                             $fd_id,$row['ad_id'],$row['ad_default_order']);
                                        $this->cn->exec_sql($sql);
                                }
+                // if there is an accounting , then not needed to add one
+                if ( $row['ad_id']==ATTR_DEF_ACCOUNT) $add_accounting=FALSE;
+                if ( $row['ad_id']==ATTR_DEF_QUICKCODE) $add_qcode=FALSE;
             }
         }
+        // if there is an base accounting, and the accounting is not in 
ATTR_MIN,
+        // then it is needed to add it
+        if ( $add_accounting) {
+            $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
+                                        values 
(%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
+                       $Res=$this->cn->exec_sql($sql);
+        }
+        // if there is no quick code in attr_min, it is added
+        if ( $add_qcode) {
+            $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
+                                        values 
(%d,%d,10000)",$fd_id,ATTR_DEF_QUICKCODE);
+            $Res=$this->cn->exec_sql($sql);
+        }
         $this->id=$fd_id;
         return 0;
 
@@ -710,9 +726,10 @@ $order
     {
 
         // find the min attr for the fiche_def_ref
-        $Sql="select ad_id,ad_text ,ad_default_order 
-                from attr_min natural join attr_def
-             natural join fiche_def_ref
+        $Sql="select ad_id,ad_text ,attr_min.ad_default_order 
+             from attr_min 
+                join attr_def using(ad_id)
+              join fiche_def_ref using(frd_id)
              where
              frd_id= $1 order by ad_default_order";
         $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
diff --git a/include/class/template_card_category.class.php 
b/include/class/template_card_category.class.php
index 2fae8bb75..7afa86637 100644
--- a/include/class/template_card_category.class.php
+++ b/include/class/template_card_category.class.php
@@ -148,19 +148,20 @@ EOF;
             $cn=Dossier::connect();
             $dossier_id=Dossier::id();
             $objname=$this->get_object_name();
-            $a_attribut=$cn->get_array("select ad_id,ad_text,ad_type from 
attr_min join attr_def using (ad_id) where frd_id=$1 order by 2",
+            $a_attribut=$cn->get_array("select 
ad_id,ad_text,ad_type,a1.ad_default_order from attr_min a1 join attr_def using 
(ad_id) where frd_id=$1 order by a1.ad_default_order",
                     [$this->table->frd_id]);
             $nb_attribut=count($a_attribut);
-            printf('<ul id="%s_list"> ', $objname);
+            printf('<ul class="list-unstyled" style="width: 60%%;margin-left: 
21%%" id="%s_list"> ', $objname);
             $used=$cn->get_value("select count(*) from jnt_fic_attr join 
fiche_def using (fd_id) where frd_id=$1",
                     [$this->table->frd_id]);
             if ($used!=0)
             {
-                echo _("Catégorie utilisée, les attributs ne peuvent pas être 
modifiés");
+                echo_warning( _("Catégorie utilisée, les attributs de base ne 
peuvent pas être modifiés"));
             }
+            echo _("Vous pouvez modifier l'ordre des attributs avec la 
souris");
             for ($i=0; $i<$nb_attribut; $i++)
             {
-                printf('<li id="%s_elt%d">', $objname
+                printf('<li id="%s_elt%d" style="cursor:move;border:1px solid 
navy;padding : 0.5rem 0.2rem 0.5rem 0.2rem;margin-top:2px">', $objname
                         , $a_attribut[$i]['ad_id']);
                 echo $a_attribut[$i]['ad_text'];
                 // cannot delete NAME and QUICKCODE + attribute used in a
@@ -193,22 +194,51 @@ EOF;
                         $dossier_id, $this->table->frd_id, $objname);
                 echo Icon_Action::icon_add(uniqid(), $js_script);
             }
+            echo \HtmlInput::hidden("attribut_order", "");
+            echo create_script("Sortable.create('{$objname}_list',{
+            
onUpdate:function(){document.getElementById('attribut_order').value=Sortable.serialize('{$objname}_list')}})");
         }
      
     }
 
     /**
-     * When adding a template of category  of card, the minimum is the name 
+     * @brief When adding a template of category  of card, the minimum is the 
name
      * and the quickcode, which must be added into attr_min
      */
     function add_mandatory_attr()
     {
         $cn=Dossier::connect();
         $frd_id=$this->get_table()->getp("frd_id");
+        $cn->exec_sql("insert into attr_min (frd_id,ad_id,ad_default_order) 
values ($1,$2)",
+                [$frd_id, ATTR_DEF_NAME],1);
         $cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
-                [$frd_id, ATTR_DEF_NAME]);
-        $cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
-                [$frd_id, ATTR_DEF_QUICKCODE]);
+                [$frd_id, ATTR_DEF_QUICKCODE,10000]);
+    }
+
+    /**
+     * @brief save also the order
+     * @return void
+     */
+    function save()
+    {
+        parent::save();
+        $cn=$this->get_table()->get_cn();
+        $table_sql=$this->get_table();
+        $http=new HttpInput();
+        $ctl=$http->request("ctl")."_list";
+        $attribut_order=$http->post('attribut_order','string','');
+        if ($attribut_order=='') return;
+        parse_str($attribut_order,$aOrder);
+        if ( isset($aOrder[$ctl])) {
+            $order = 10;
+            foreach( $aOrder[$ctl] as $item) {
+                $ad_id = str_replace('elt','',$item);
+                $cn->exec_sql("update attr_min set ad_default_order = $1 where 
ad_id=$2 and frd_id=$3",
+                [$order,$ad_id,$table_sql->get('frd_id')]);
+                $order+=10;
+            }
+        }
+
     }
 
 }
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index e69de29bb..3778e96ff 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -0,0 +1,3 @@
+alter table attr_min add ad_default_order int;
+
+update attr_min set ad_default_order = a1.ad_default_order from attr_def a1 
where a1.ad_id = attr_min.ad_id;
\ No newline at end of file



reply via email to

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