noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 38/323: Task #1518 : ajout de modèle de caté


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 38/323: Task #1518 : ajout de modèle de catégorie de fiche Modification des attributs minimums
Date: Wed, 14 Mar 2018 17:38:14 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 0ee94566f8038c3b23cffc9d02c4a3296fceba32
Author: Dany De Bontridder <address@hidden>
Date:   Tue Jan 9 19:06:40 2018 +0100

    Task #1518 : ajout de modèle de catégorie de fiche
    Modification des attributs minimums
---
 html/ajax_misc.php                             |   4 +-
 html/js/ajax_fiche.js                          |  68 ++++++++++++++
 include/ajax/ajax_template_cat_category.php    | 120 ++++++++++++++++++++++++
 include/class/template_card_category.class.php | 124 ++++++++++++++++++++++---
 4 files changed, 302 insertions(+), 14 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index a2a4362..984ebb9 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -211,7 +211,9 @@ $path = array(
     // delete operation
        'delete_search_operation'=>'ajax_search_filter',
     // template category of card
-    'template_cat_card'=>'ajax_template_cat_card'
+    'template_cat_card'=>'ajax_template_cat_card',
+    // Attribute for category of card
+    'template_cat_category'=>'ajax_template_cat_category'
 )    ;
 
 if (array_key_exists($op, $path)) {
diff --git a/html/js/ajax_fiche.js b/html/js/ajax_fiche.js
index 28e7afb..ac6033c 100644
--- a/html/js/ajax_fiche.js
+++ b/html/js/ajax_fiche.js
@@ -250,4 +250,72 @@ function ajax_get_failure(request,json)
 
 }
 
+var category_card={};
+
+/**
+ * Add an attribute selected in "sel"+p_object_name into the list 
(id:p_object_name+"_list")
+ * this attribut will have the ID:p_object_name+"_elt"+ad_id (ad_id = 
attr_def.ad_id)
+ * @param int p_dossier dossier nb
+ * @param int p_fiche_def_ref is the frd_id
+ * @param string p_object_name , name of the prefix for id 
+ */
+category_card.add_attribut=function (p_dossier,p_fiche_def_ref,p_object_name) {
+    var select=$("sel"+p_object_name);
+    var selected_attr=select.value;
+    new Ajax.Request("ajax_misc.php",{
+       method:"post",
+       parameters:{"gDossier":p_dossier,
+           "objname":p_object_name,
+           "op":"template_cat_category",
+           "action":"add_attribute",
+           "frd_id":p_fiche_def_ref,
+           "ad_id":selected_attr
+       },
+       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);
+               select.remove(select.selectedIndex);
+           } else {
+               smoke.alert(answer.message);
+           }
+       }
+    });
+};
+/**
+ * Remove an attribute (id:p_object_name+"_elt"+ad_id (ad_id = attr_def.ad_id))
+ * from the list (id:p_object_name+"list")
+ * @param int p_dossier dossier nb
+ * @param string p_object_name , name of the prefix for id 
+ * @param int p_fiche_def_ref is the frd_id
+ * @param {type} p_attribute_id
+ */
+category_card.remove_attribut=function 
(p_dossier,p_fiche_def_ref,p_object_name,p_attribute_id) {
+    new Ajax.Request("ajax_misc.php",{
+       method:"post",
+       parameters:{"gDossier":p_dossier,
+           "objname":p_object_name,
+           "op":"template_cat_category",
+           "action":"remove_attribute",
+           "frd_id":p_fiche_def_ref,
+           "ad_id":p_attribute_id
+       },
+       onSuccess:function(req) {
+           var answer=req.responseText.evalJSON();
+           if ( answer.status == 'OK') {
+               $(p_object_name+"_elt"+p_attribute_id).remove();
+               var option=document.createElement("option");
+               option.text=answer['content'];
+               option.value=p_attribute_id;
+               $('sel'+p_object_name).add(option);
+           } else {
+               smoke.alert(answer.message);
+           }
+       }
+    });
+};
+
 //-->
diff --git a/include/ajax/ajax_template_cat_category.php 
b/include/ajax/ajax_template_cat_category.php
new file mode 100644
index 0000000..32f22d9
--- /dev/null
+++ b/include/ajax/ajax_template_cat_category.php
@@ -0,0 +1,120 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   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>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+/**
+ * @file
+ * @brief manage attribut of a Template of Category of card. The answer must 
be 
+ * in json
+ */
+$answer=[];
+$answer['status']="NOK";
+$answer['content']="";
+$answer['message']=_("Commande inconnue");
+
+
+/**
+ * security 
+ */
+try
+{
+    if ($g_user->check_module("CFGCARDCAT")==0)
+        throw new Exception(_("Accès non autorisé"));
+    $http=new HttpInput();
+    $action=$http->request("action");
+    $ad_id=$http->request("ad_id", "number");
+    $frd_id=$http->request("frd_id", "number");
+    $objname=$http->request("objname");
+}
+catch (Exception $ex)
+{
+    $answer['message']=_("Accès non autorisé");
+    header("Content-type: text/json; charset: utf8", true);
+    echo json_encode($answer,
+            JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
+    return;
+}
+switch ($action)
+{
+    case "add_attribute":
+        try
+        {
+            if ($cn->get_value("select count(*) from attr_min where frd_id=$1 
and ad_id=$2",
+                            [$frd_id, $ad_id])>0)
+                throw new Exception(_("Attribut déjà ajouté"));
+            $cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
+                    [$frd_id, $ad_id]);
+            $answer['status']="OK";
+            $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]).
+                    HtmlInput::anchor(SMALLX, "javascript:void(0)", $js,
+                            ' class="smallbutton" 
style="padding:0px;display:inline" ');
+        }
+        catch (Exception $exc)
+        {
+            echo $exc->getMessage();
+            error_log($exc->getTraceAsString());
+            $answer['message']=$exc->getMessage();
+        }
+
+
+        break;
+    case "remove_attribute":
+        try
+        {
+            if ($cn->get_value("select count(*) from jnt_fic_attr 
+                    join fiche_def using (fd_id)
+                    where frd_id=$1 and ad_id=$2",
+                            [$frd_id, $ad_id])>0)
+                throw new Exception(_("Attribut déjà utilisé"));
+            if (in_array($ad_id, [ATTR_DEF_NAME,ATTR_DEF_QUICKCODE]) )
+            {
+                throw new Exception(_("Attribut obligatoire"));
+            }
+            $answer['content']=$cn->get_value("select ad_text from attr_def 
where ad_id=$1",
+                    [$ad_id]);
+            $answer['status']="OK";
+            $answer['message']="";
+            $cn->exec_sql("delete from attr_min where frd_id=$1 and ad_id=$2",
+                    [$frd_id,$ad_id]);
+        }
+        catch (Exception $exc)
+        {
+            echo $exc->getMessage();
+            error_log($exc->getTraceAsString());
+            $answer['message']=$exc->getMessage();
+        }
+        break;
+
+    default:
+        break;
+}
+
+
+header("Content-type: text/json; charset: utf8", true);
+echo json_encode($answer,
+        JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
+return;
diff --git a/include/class/template_card_category.class.php 
b/include/class/template_card_category.class.php
index 81b6f6f..afaaf49 100644
--- a/include/class/template_card_category.class.php
+++ b/include/class/template_card_category.class.php
@@ -33,6 +33,7 @@ require_once 
NOALYSS_INCLUDE.'/database/fiche_def_ref_sql.class.php';
  */
 class Template_Card_Category extends Manage_Table_SQL
 {
+
     function __construct(Fiche_def_ref_SQL $p_table)
     {
         $this->table=$p_table;
@@ -43,17 +44,21 @@ class Template_Card_Category extends Manage_Table_SQL
         $this->set_col_label("frd_id", _("ID"));
         // Cannot update frd_id
         $this->set_property_updatable("frd_id", FALSE);
-        $this->a_order=["frd_id","frd_text","frd_class_base"];
+        $this->a_order=["frd_id", "frd_text", "frd_class_base"];
     }
+
     function delete()
     {
         $cn=Dossier::connect();
-        
-        if ( $cn->get_value("select count(*) from fiche_def where 
frd_id=$1",[$this->table->frd_id])>0)
+
+        if ($cn->get_value("select count(*) from fiche_def where frd_id=$1",
+                        [$this->table->frd_id])>0)
         {
             throw new Exception(_("Effacement impossible : catégorie 
utilisée"));
         }
+        $this->table->delete();
     }
+
     /**
      * Check before inserting or updating, return TRUE if ok otherwise FALSE.
      * @return boolean
@@ -62,23 +67,116 @@ class Template_Card_Category extends Manage_Table_SQL
     {
         $cn=Dossier::connect();
         $error=0;
-        if ( trim($this->table->frd_text) == "" ) {
-            $this->set_error("frd_text",_("Le nom ne peut pas être vide"));
+        if (trim($this->table->frd_text)=="")
+        {
+            $this->set_error("frd_text", _("Le nom ne peut pas être vide"));
             $error++;
         }
-        if ( trim($this->table->frd_class_base) != "" ) {
+        if (trim($this->table->frd_class_base)!="")
+        {
             $cnt=$cn->get_value("select count(*) from tmp_pcmn where 
pcm_val=$1"
-                    ,[$this->table->frd_class_base]);
-            if ($cnt == 0) {
-                $this->set_error("frd_class_base",_("Poste comptable n'existe 
pas"));
+                    , [$this->table->frd_class_base]);
+            if ($cnt==0)
+            {
+                $this->set_error("frd_class_base",
+                        _("Poste comptable n'existe pas"));
                 $error++;
             }
         }
-        
-        if ( $error != 0) {
+
+        if ($error!=0)
+        {
             return false;
         }
         return true;
-        
     }
-}
\ No newline at end of file
+
+    /**
+     * @brief display into a dialog box the datarow in order 
+     * to be appended or modified. Can be override if you need
+     * a more complex form
+     */
+    function input()
+    {
+        echo "<br><font color=\"red\"> ";
+        echo _("Attention, ne pas changer la signification de ce poste.");
+        echo hi(_("par exemple ne pas changer Client par fournisseur"))."<br>";
+        echo _("sinon le programme fonctionnera mal, ".
+                "utiliser uniquement des chiffres pour la classe de base ou 
rien")."</font>";
+        parent::input();
+
+        /**
+         * Add / Remove attribut Minimum
+         */
+        if ($this->table->frd_id!=-1)
+        {
+            echo h2(_("Attribut minimum pour les catégories de fiches"));
+            $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",
+                    [$this->table->frd_id]);
+            $nb_attribut=count($a_attribut);
+            printf('<ul 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");
+            }
+            for ($i=0; $i<$nb_attribut; $i++)
+            {
+                printf('<li id="%s_elt%d">', $objname
+                        , $a_attribut[$i]['ad_id']);
+                echo $a_attribut[$i]['ad_text'];
+                // cannot delete NAME and QUICKCODE + attribute used in a
+                if (!in_array($a_attribut[$i]['ad_id'], [ATTR_DEF_NAME, 
ATTR_DEF_QUICKCODE])&&$used==0)
+                {
+                    // allow to remove attribute
+                    
$js=sprintf("onclick=\"category_card.remove_attribut('%s','%s','%s',%d)\"",
+                            Dossier::id(), $this->table->frd_id, $objname, 
$a_attribut[$i]['ad_id']);
+                    echo HtmlInput::anchor(SMALLX, "", $js,
+                            ' class="smallbutton" 
style="padding:0px;display:inline" ');
+                }
+                echo '</li>';
+            }
+            echo '</ul>';
+            // Add some attribute if not used
+            if ($used==0)
+            {
+                $sel_attribut=new ISelect("sel".$this->get_object_name());
+                $sel_attribut->value=$cn->make_array("select ad_id,ad_text 
+                        from attr_def 
+                        where 
+                        not exists (select 1 
+                                    from 
+                                    attr_min
+                                    where 
+                                    frd_id=$1 and ad_id=attr_def.ad_id)", NULL,
+                        [$this->table->frd_id]);
+                echo _("Attribut à ajouter");
+                echo $sel_attribut->input();
+                
$js_script=sprintf("category_card.add_attribut('%s','%s','%s')",
+                        $dossier_id, $this->table->frd_id, $objname);
+                echo HtmlInput::button_image($js_script, uniqid(),
+                        'class="smallbutton image_search"',
+                        "image/bouton-plus.png");
+            }
+        }
+    }
+
+    /**
+     * 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->table->frd_id;
+        $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]);
+    }
+
+}



reply via email to

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