noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 14/39: task #0001801: CARD : mise à jour fich


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 14/39: task #0001801: CARD : mise à jour fiche , effacement et modification
Date: Sat, 11 Jul 2020 13:20:39 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 1f7610b8948185b78882344d436a3751a35bfd04
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Tue Jun 2 14:32:04 2020 +0200

    task #0001801: CARD : mise à jour fiche , effacement et modification
---
 html/js/card.js                              | 201 ++++++++++++++++++++++++++-
 include/ajax/ajax_card.php                   | 133 +++++++++++++++---
 include/class/extension.class.php            |   2 +-
 include/class/fiche.class.php                |  39 ++++++
 include/fiche.inc.php                        |  23 ++-
 include/template/result_cat_card_summary.php |  38 ++---
 6 files changed, 375 insertions(+), 61 deletions(-)

diff --git a/html/js/card.js b/html/js/card.js
index 70ede32..1ad8e4e 100644
--- a/html/js/card.js
+++ b/html/js/card.js
@@ -663,13 +663,16 @@ function dis_blank_card(obj)
     } else {
        var dossier=obj.gDossier;
     }
-
     var queryString='gDossier='+dossier;
     queryString+='&ctl='+content;
     queryString+='&fd_id='+fd_id;
     queryString+=ref;
     queryString+='&op2=bc';    // bc for blank card
     queryString+='&op=card';   // bc for blank card
+    if (obj.after_save) {
+        queryString+='&after_save='+obj.after_save;
+    }
+
     if ( obj.elementId) queryString+="&eltid="+obj.elementId;
     var action=new Ajax.Request ( 'ajax_misc.php',
                                   {
@@ -748,16 +751,42 @@ function save_card(obj)
                                   parameters:queryString,
                                   onFailure:errorFid,
                                   onSuccess:function (req,json) {
-                                     
                                       var 
elt=req.responseXML.getElementsByTagName("eltid");
                                       var 
status=req.responseXML.getElementsByTagName("status");
                                       var status_value='OK';
+                                      var 
after_savetag=req.responseXML.getElementsByTagName("after_save");
+                                      var after_save=0;
                                       if ( status.length !=0) {
                                         status_value=getNodeText(status[0]);
                                       }
-                                      if ( status_value == 'OK') {
+                                      if ( after_savetag.length !=0 ) {
+                                          
after_save=getNodeText(after_savetag[0]);
+                                      }
+                                      // if status == OK and after_save == 0 
+                                      // then update the box
+                                      if ( status_value == 'OK' && after_save 
== 0) {
                                              fill_box(req,json);
                                       }
+                                      
+                                      // if status == OK and after_save == 1
+                                      // then add a row to the table
+                                      if ( status_value == 'OK' && after_save 
== 1) {
+                                            var table_card=$('fiche_tb_id');
+                                            
f_id=getNodeText(req.responseXML.getElementsByTagName("f_id")[0]);
+                                             var row=new Element('tr');
+                                             row.id="row_card"+f_id;
+                                             
row.innerHTML=getNodeText(req.responseXML.getElementsByTagName("code")[0]);
+                                             
table_card.tBodies[0].appendChild(row);
+                                              new Effect.Highlight(row.id 
,{startcolor: '#FAD4D4',endcolor: '#F78082' });
+                                             //
+                                             if ( 
table_card.tBodies[0].rows.length % 2 == 0 ) {
+                                                 row.addClassName("odd");
+                                             } else {
+                                                 row.addClassName("even");
+                                                 
+                                             }
+                                      }
+                                      
                                       remove_waiting_box();
                                       if ( elt.length != 0) {
                                          var eltid=getNodeText(elt[0]);
@@ -1024,3 +1053,169 @@ function delete_card(obj) {
         }
     });
 }
+/**
+ * Display a card , modify it , redraw the row
+ * before calling this function , it it neeed to have in the web page a hidden 
card_gdossier with the dossier id
+ * @param {type} p_fiche_id
+ * @returns {undefined}
+ */
+function modify_card(p_fiche_id)
+{
+    /* window with result */
+    card_layer++;
+
+    var content = 'card_' + card_layer;
+    var nTop = 170 + card_layer;
+    if (nTop > 300) {
+        nTop = 170;
+    }
+    var str_top = fixed_position(250, nTop)
+    var str_style = str_top + ";width:45em;height:auto;position:absolute";
+
+    var popup = {'id': content, 'cssclass': 'inner_box', 'style': str_style, 
'html': loading(), 'drag': false};
+
+    add_div(popup);
+    
+    /* dossier id */
+    if ( ! document.getElementById("card_gdossier")) {
+        
+        console.error("card_gdossier error");
+        throw ("card_gdossier not set");
+    }
+    var dossier = $('card_gdossier').value;
+
+    
+    var action = new Ajax.Request('ajax_misc.php',
+            {
+                method: 'get',
+                parameters: 
{'gDossier':dossier,"op":'card',"op2":"dc","f_id":p_fiche_id,'ctl':content,after_save:2}
 ,
+                onFailure: errorFid,
+                onSuccess: function (respTxt) {
+                    fill_box(respTxt);
+                }
+            }
+    );
+}
+/**
+ * Delete a card and remove the row
+ * before calling this function , it it neeed to have in the web page a hidden 
card_gdossier with the dossier id
+ * @param {type} p_fiche_id
+ * @returns {undefined}
+ */
+function delete_card_id(p_fiche_id)
+{
+    var row="row_card"+p_fiche_id;
+    if ( ! document.getElementById("card_gdossier")) {
+        
+        console.error("card_gdossier error");
+        throw ("card_gdossier not set");
+    }
+    $(row).addClassName("background-selected");
+    var dossier = $('card_gdossier').value;
+    smoke.confirm(content[47], function (e) {
+        if (e) {
+            waiting_box();
+            new Ajax.Request("ajax_misc.php", {
+                "method": "get",
+                parameters: 
{'gDossier':dossier,"op":'card',"op2":"rm_card","f_id":p_fiche_id,'ctl':row} ,
+                onSuccess: function (req) {
+                    remove_waiting_box();
+                    var table_card=$('fiche_tb_id');
+                    var answer = req.responseXML;
+                    var a = answer.getElementsByTagName('ctl');
+                    if (a.length == 0)
+                    {
+                        var rec = req.responseText;
+                        alert_box('erreur :' + rec);
+                    }
+                    var html = answer.getElementsByTagName('code');
+                    var namectl = a[0].firstChild.nodeValue;
+                    var nodeXml = html[0];
+                    var code_html = getNodeText(nodeXml);
+                    code_html = unescape_xml(code_html);
+                   
+                    if ((code_html) == "OK") {
+                        Effect.Fade(row, {duration: 0.1});
+                        table_card.tBodies[0].removeChild($(row));
+                        alternate_row_color("fiche_tb_id");
+                    } else {
+                        smoke.alert(code_html);
+                        
+                    }
+                }
+                    
+            });
+        } else{ 
+                   $(row).removeClassName("background-selected");
+            
+        }
+    });
+  
+}
+
+/**
+* update a card in ajax , and update a row
+* 
+*/
+function update_row(obj)
+{
+    try {
+        var name = obj.id;
+
+        var qs = Form.serialize(name) + '&op2=upr&op=card';
+        var action = new Ajax.Request('ajax_misc.php',
+                {
+                    method: 'get',
+                    parameters: qs,
+                    onFailure: errorFid,
+                    onSuccess: function (req) {
+                        try {
+
+                            remove_waiting_box();
+
+                            var answer = req.responseXML;
+                            var a = answer.getElementsByTagName('ctl');
+                            var html = answer.getElementsByTagName('code');
+                            if (a.length === 0) {
+                                var rec = req.responseText;
+                                alert_box('erreur :' + rec);
+                            }
+                            var name_ctl = "row_card" + obj.f_id.value;
+                            var code_html = getNodeText(html[0]); // Firefox 
ne prend que les 4096 car.
+                            code_html = unescape_xml(code_html);
+                            
+                            if ( document.getElementById(name_ctl)) {
+                                // update the row
+                                $(name_ctl).innerHTML = code_html;
+                                new Effect.Highlight(name_ctl ,{startcolor: 
'#FAD4D4',endcolor: '#F78082' });
+                                
+                            }
+                            $(a[0].firstChild.nodeValue).remove();
+                            
+                            
+                        } catch (e) {
+                            alert_box(e.message);
+                            if (console) {
+                                console.error(e);
+                                console.error("log answer = " + 
req.responseText);
+                            }
+                        }
+                        try {
+                            code_html.evalScripts();
+                        } catch (e) {
+                            if (console) {
+                                console.error(e);
+                                console.error("log answer = " + 
req.responseText);
+                            }
+                            alert_box(content[53] + "\n" + e.message);
+                        }
+                       
+                 
+                    }
+                }
+        );
+    } catch (e) {
+        alert_box(e.message);
+        return false;
+    }
+}
\ No newline at end of file
diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php
index 9802158..2053f1a 100644
--- a/include/ajax/ajax_card.php
+++ b/include/ajax/ajax_card.php
@@ -77,7 +77,7 @@ foreach ($var as $v)
         $cont=1;
     }
 }
-extract($_REQUEST, EXTR_SKIP );
+extract($_REQUEST, EXTR_SKIP ); 
 
 if ( $cont != 0 ) exit();
 
@@ -132,6 +132,29 @@ case 'dc':
     $f=new Fiche($cn);
     /* add title + close */
     $html=HtmlInput::title_box(_("Détail fiche"), $ctl,"close","","y");
+    
+    // if there is no qcode then try to find it thanks the card id
+    if ( ! isset ($qcode) ){
+        $f->id=$http->get("f_id","number");
+        $qcode=$f->get_quick_code();
+    }
+    
+    // after save , we can either show a card in readonly or update a row
+    $safter_save=$http->request("after_save","string","1");
+    switch ($safter_save)
+    {
+        case "1":
+            // show a card it readonly and fade it
+            $after_save="update_card(this)";
+            break;
+        case "2":
+            // update a row in the table X
+            $after_save="update_row(this)";
+            break;
+        default:
+            break;
+    }
+
     if ( $qcode != '')
     {
         $f->get_by_qcode($qcode);
@@ -153,7 +176,7 @@ case 'dc':
 
            if ($can_modify==1)
              {
-               $html.='<form id="form_'.$ctl.'" method="get" 
onsubmit="update_card(this);return false;">';
+               $html.='<form id="form_'.$ctl.'" method="get" 
onsubmit="'.$after_save.';return false;">';
                $html.=dossier::hidden();
                $html.=HtmlInput::hidden('f_id',$f->id);
                $html.=HtmlInput::hidden('ctl',$ctl);
@@ -207,6 +230,9 @@ case 'bc':
         if ( isset ($eltid)) {
             $r.=HtmlInput::hidden("eltid", $eltid);
         }
+        // Action after save = 0, the card is display one second and fade out
+        $after_save=$http->get("after_save","number",0);
+        $r.=HtmlInput::hidden("after_save",$after_save);
         $r.='</form>';
         $html=$r;
     }
@@ -336,7 +362,7 @@ return;
      *
      ----------------------------------------------------------------------*/
 case 'sc':
-    $html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
+    
     if ( $g_user->check_action(FICADD)==1 )
     {
         $f=new Fiche($cn);
@@ -344,19 +370,46 @@ case 'sc':
         try {
             $f->insert($fd_id,$_POST);
             $f->Get();
-            $html.='<h2 class="notice">'._('Fiche sauvée').'</h2>';
-            $html.=$f->Display(true);
-            $js="";
-            if ( isset( $_POST['ref'])) $js=create_script(' 
window.location.reload()');
-            $html.=$js;
-            if ( isset ($eltid)) {
-                // after adding a new card, we update some field
-                $extra="<eltid>$eltid</eltid>".
-                        "<elt_value>{$f->get_quick_code ()}</elt_value>";
+            $after_save=$http->post("after_save","number",0);
 
+            // Action after save = 0, the card is display one second and fade 
out
+            //
+            if ( $after_save == 0 ) {
+                $html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
+                $html.='<h2 class="notice">'._('Fiche sauvée').'</h2>';
+                $html.=$f->Display(true);
+                $js="";
+                if ( isset( $_POST['ref'])) $js=create_script(' 
window.location.reload()');
+                $html.=$js;
+                if ( isset ($eltid)) {
+                    // after adding a new card, we update some field
+                    $extra="<eltid>$eltid</eltid>".
+                            "<elt_value>{$f->get_quick_code ()}</elt_value>";
+                            
+
+                }
+                $extra.=$status;
+                $extra.="<after_save>0</after_save>";
+            
+            }
+            // Action after save = 1 ;  after adding a card the table must be 
updated
+            // see fiche.inc.php
+            //
+            if ( $after_save == 1 ){
+                $f_id=$f->id;
+                ob_start();
+                $detail=Icon_Action::modify("mod".$f_id, 
sprintf("modify_card('%s')",$f_id)).
+                "&nbsp;".
+                Icon_Action::trash("del".$f_id,  
sprintf("delete_card_id('%s')",$f_id));
+                $html = td($detail);
+                $html .= $f->display_row();
+                $html.=ob_get_contents();
+                ob_clean();
+                $extra="<f_id>".$f_id."</f_id>";
+                $ctl="row_card".$f_id;
+                $extra.="<after_save>1</after_save>";
+                
             }
-            $extra.=$status;
-            $html.=HtmlInput::button_close($ctl);
         } catch (Exception $exc) {
             $html="<h2 class=\"error\">"._("Erreur sauvegarde")."</h2>";
             $html.=$exc->getMessage();
@@ -592,6 +645,9 @@ case 'scc':
         $ctl="info_div";
     }
     break;
+    
+// Update a card and then display the result
+// in a readonly box
 case 'upc':
     $html=HtmlInput::title_box("Détail fiche", $ctl);
 
@@ -619,17 +675,52 @@ case 'upc':
        }
       }
       break;
-      //------------------------------------------------------------------
-      // Unlink a card
-      //------------------------------------------------------------------
-        case 'rm_card':
-             $html=HtmlInput::title_box("Détail fiche", $ctl);
+// Update a card and then display the result
+// in the table
+case 'upr':
+    $f_id=$http->get("f_id","number");
+    $html="";
+    if ( $g_user->check_action(FICADD)==0 )
+    {
+        $html.=alert(_('Action interdite'),true);
+    }
+  else
+    {
+      if ($cn->get_value('select count(*) from fiche where 
f_id=$1',array($f_id)) == '0' )
+       {
+         $html.=alert(_('Fiche non valide'),true);
+         }
 
-  if ( $g_user->check_action(FIC)==0 )
+      else
+       {
+
+         $f=new Fiche($cn,$f_id );
+         ob_start();
+         $f->update($_GET);
+          $detail=Icon_Action::modify("mod".$f_id, 
sprintf("modify_card('%s')",$f_id)).
+                "&nbsp;".
+                Icon_Action::trash("del".$f_id,  
sprintf("delete_card_id('%s')",$f_id));
+          $html.=td($detail);
+         $html.=$f->display_row();
+         $html.=ob_get_contents();
+         ob_end_clean();
+       }
+      }
+      break;
+      
+      
+      
+//------------------------------------------------------------------
+// Unlink a card
+//------------------------------------------------------------------
+ case 'rm_card':
+    $html=HtmlInput::title_box("Détail fiche", $ctl);
+     
+    if ( $g_user->check_action(FIC)==0 )
     {
       $html.=alert(_('Action interdite'),true);
     }
-  else
+    else
     {
       if ($cn->get_value('select count(*) from fiche where 
f_id=$1',array($_GET['f_id'])) == '0' )
        {
diff --git a/include/class/extension.class.php 
b/include/class/extension.class.php
index 64e4d33..5fad200 100644
--- a/include/class/extension.class.php
+++ b/include/class/extension.class.php
@@ -353,7 +353,7 @@ class Extension extends Menu_Ref_sql
             $extension->me_type='PL';
             $extension->me_menu=trim($xml->plugin[$i]->name);
             
$extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code);
-            
$extension->depend=(isset($xml->plugin[$i]->depend))?trim($xml->plugin[$i]->depend):"";
+            
$extension->depend=(isset($xml->plugin[$i]->depend))?trim($xml->plugin[$i]->depend):"EXT";
             
$extension->order=(isset($xml->plugin[$i]->order))?trim($xml->plugin[$i]->order):9000;
             $a_extension[]=clone $extension;
         }
diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php
index 9a300b4..73d5bec 100644
--- a/include/class/fiche.class.php
+++ b/include/class/fiche.class.php
@@ -2257,6 +2257,45 @@ class Fiche
     function filter_history($p_table_id) {
         return _('Cherche').' '.HtmlInput::filter_table($p_table_id, 
'0,1,2,3,4,5,6,7,8,9,10', 1);
     }
+    /**
+     * @brief display card as a table row , the tag TR must be added
+     * 
+     * @return HTMLT string starting
+     * 
+     */
+    function display_row()
+    {
+        $this->getAttribut();
+        foreach($this->attribut as $attr) {
+            $sort="";
+
+            if ($attr->ad_type!='select') 
+            {
+
+                if ($attr->ad_type=="date") {
+                // format YYYYMMDD
+                $sort='sorttable_customkey="'.format_date($attr->av_text, 
"DD.MM.YYYY", "YYYYMMDD").'"';
+                }
+                elseif ($attr->ad_type=="poste"){
+                $sort='sorttable_customkey="TEXT'.$attr->av_text.'"';
+                }
+                echo td($attr->av_text, 'style="padding: 0 10 1 
10;white-space:nowrap;" '.$sort);
+             }
+             else {
+                $value=$cn->make_array($attr->ad_extra);
+                $row_content="";
+                for ($e=0; $e<count($value); $e++) {
+                    if ( $value[$e]['value']==$attr->av_text) {
+                        $row_content=h($value[$e]['label']);
+                        break;
+                    }
+                }
+                echo td($row_content, 'style="padding: 0 10 1 
10;white-space:nowrap;"');
+
+            }
+        }
+
+    }
 }
 
 ?>
diff --git a/include/fiche.inc.php b/include/fiche.inc.php
index 8b05b53..50eaf6f 100644
--- a/include/fiche.inc.php
+++ b/include/fiche.inc.php
@@ -234,16 +234,25 @@ if ($histo->selected  == 3)
        $cat_card = new Fiche_Def($cn);
        $cat_card->id =$http->get('cat','number');
        $aHeading = $cat_card->getAttribut();
-       if ( $allcard == 0) echo $str_add_card;
+        $str_add_card="";
+        if ( $allcard == 0 ) {
+            $h_add_card_b = new IButton('add_card');
+            $h_add_card_b->label = _('Créer une nouvelle fiche');
+            $h_add_card_b->javascript = 
"dis_blank_card({gDossier:$gDossier,fd_id:$fd_id,after_save:1,ref:2})";
+            $str_add_card=$h_add_card_b->input();
+        }
+        echo $str_add_card;
        require_once NOALYSS_TEMPLATE.'/result_cat_card_summary.php';
 
        $hid = new IHidden();
-       echo '<form method="GET" ACTION="export.php">' . dossier::hidden() .
-       HtmlInput::submit('bt_csv', _("Export CSV")) .
-       HtmlInput::hidden('act', "CSV:fiche") .
-       $hid->input("type", "fiche") .
-       $hid->input("ac", $http->request('ac')) .
-       $hid->input("fd_id", $http->request('cat',"number"));
+       echo '<form method="GET" ACTION="export.php">' . dossier::hidden() ;
+        echo $str_add_card;
+        echo 
+            HtmlInput::submit('bt_csv', _("Export CSV")) .
+            HtmlInput::hidden('act', "CSV:fiche") .
+            $hid->input("type", "fiche") .
+            $hid->input("ac", $http->request('ac')) .
+            $hid->input("fd_id", $http->request('cat',"number"));
        echo "</form>";
 
        return;
diff --git a/include/template/result_cat_card_summary.php 
b/include/template/result_cat_card_summary.php
index 3b1c406..86aea8e 100644
--- a/include/template/result_cat_card_summary.php
+++ b/include/template/result_cat_card_summary.php
@@ -24,42 +24,22 @@ for ($i=0;$i<count($aHeading);$i++) :
 </tr>
 <?php 
 $e=0;
+ $fiche=new Fiche($cn);
+ echo HtmlInput::hidden("card_gdossier",Dossier::id());
 foreach ($array as $row ) :
  $e++;
    if ($e%2==0)
-   printf('<tr id="card%s" class="odd">',$row['f_id']);
+   printf('<tr id="row_card%s" class="odd">',$row['f_id']);
    else 
-   printf('<tr id="card%s" class="even">',$row['f_id']);
+   printf('<tr id="row_card%s" class="even">',$row['f_id']);
    
-   $fiche=new Fiche($cn);
-   $fiche->id=$row['f_id'];
- $fiche->getAttribut();
-$detail=HtmlInput::card_detail($fiche->strAttribut(ATTR_DEF_QUICKCODE));
+  $fiche->id=$row['f_id'];
+  $detail=Icon_Action::modify("mod".$fiche->id, 
sprintf("modify_card('%s')",$fiche->id)).
+          "&nbsp;".
+          Icon_Action::trash("del".$fiche->id,  
sprintf("delete_card_id('%s')",$fiche->id));
 echo td($detail);
- foreach($fiche->attribut as $attr) :
-         $sort="";
+$fiche->display_row();
 
-        if ( $attr->ad_type != 'select'):
-                if ($attr->ad_type=="date") :
-                    // format YYYYMMDD
-                    $sort='sorttable_customkey="'.format_date($attr->av_text, 
"DD.MM.YYYY", "YYYYMMDD").'"'; 
-                elseif ($attr->ad_type=="poste"):
-                    $sort='sorttable_customkey="TEXT'.$attr->av_text.'"'; 
-                endif;
-               echo td($attr->av_text,'style="padding: 0 10 1 
10;white-space:nowrap;" '.$sort);
-        else:
-               $value=$cn->make_array($attr->ad_extra);
-                $row_content="";
-                for ($e=0;$e<count($value);$e++):
-                        if ( $value[$e]['value']==$attr->av_text):
-                                $row_content=h($value[$e]['label']);
-                                break;
-                        endif;
-                endfor;
-                echo td($row_content,'style="padding: 0 10 1 
10;white-space:nowrap;"');
-
-        endif;
- endforeach;
  echo '</tr>';
 endforeach;
 



reply via email to

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