From fb1ade420a7c962e318e2bb3c2534103e46675c1 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 10 Nov 2020 10:54:25 +0100 Subject: [PATCH] Follow_Up : other card, change presentation, use a button instead of displaying a lot of cells , one per card, the button calls a dialog box with the list of other cards --- html/js/card.js | 64 ++++- include/ajax/ajax_action_concerned_list.php | 66 +++++ include/ajax/ajax_action_remove_concerned.php | 18 +- include/ajax/ajax_action_save_concerned.php | 8 +- include/ajax/ajax_card.php | 7 + include/ajax/ajax_save_card_option.php | 7 +- include/class/follow_up.class.php | 60 +---- .../class/follow_up_other_concerned.class.php | 237 ++++++++++++++++++ include/lib/html_input.class.php | 13 +- include/template/detail-action.php | 6 +- ...ollow_up_other_concerned_display_table.php | 71 ++++++ unit-test/create-dossier-test.sh | 3 +- 12 files changed, 474 insertions(+), 86 deletions(-) create mode 100644 include/ajax/ajax_action_concerned_list.php create mode 100644 include/class/follow_up_other_concerned.class.php create mode 100644 include/template/follow_up_other_concerned_display_table.php diff --git a/html/js/card.js b/html/js/card.js index 0bf2e8260..428c38426 100644 --- a/html/js/card.js +++ b/html/js/card.js @@ -161,7 +161,10 @@ function action_concerned_save_card(obj) code_html = unescape_xml(code_html); $(namectl).update(code_html); removeDiv('search_card'); - + /* if dialog box exist with list other card, then refresh it */ + if ( document.getElementById("action_concerned_list_dv") ) { + action_concerned_list({ag_id:obj.ag_id.value,dossier:obj.gDossier.value}); + } } }); @@ -173,6 +176,58 @@ function action_concerned_save_card(obj) } return false; } +/** + * Display the list of other card from a followup action + * @returns {undefined} + */ +function action_concerned_list(p_obj) { + try { + var action = new Ajax.Request('ajax_misc.php', + { + method: 'get', + parameters: {gDossier: p_obj.dossier, op: 'card', 'op2': "action_concerned_list", "ag_id": p_obj.ag_id + ,"ctl":'action_concerned_list_dv'}, + onFailure: errorFid, + onSuccess: function (req, txt) + { + try { + var sx = 0; + if (window.scrollY) + { + sx = window.scrollY + 40; + } else + { + sx = document.body.scrollTop + 60; + } + var div_style = "top:" + sx + "px;"; + add_div({id: 'action_concerned_list_dv', cssclass: 'inner_box', html: "", + style: div_style, drag: true}); + remove_waiting_box(); + 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); + + + $('action_concerned_list_dv').innerHTML = code_html; + } catch (e) { + alert_box(e.message); + } + } + } + ); + } catch (e) { + alert_box("action_concerned_list" + e.message); + } +} /** * Display form for searching cards to add to action-follow-up *@see ajax_add_concerned_card.php @@ -1089,8 +1144,11 @@ function action_remove_concerned(p_dossier,p_fiche_id,p_action_id) var nodeXml=html[0]; var code_html = getNodeText(nodeXml); code_html = unescape_xml(code_html); - removeDiv('search_card'); $('concerned_card_td').innerHTML = code_html; + removeDiv('search_card'); + + $(namectl).remove(); + } catch (e) { if ( console) { console.log('Erreur ') + e.message;} alert_box('action_remove_concerned '+e.message); @@ -1346,6 +1404,8 @@ function save_linked_card_option(obj) onSuccess:function(req) { remove_waiting_box(); removeDiv("d_linked_card_option"); + $("other_"+obj.action_person_id.value).update(req.responseText); + new Effect.Highlight("other_"+obj.action_person_id.value,{startcolor: '#FAD4D4',endcolor: '#F78082' }); } }); return false; diff --git a/include/ajax/ajax_action_concerned_list.php b/include/ajax/ajax_action_concerned_list.php new file mode 100644 index 000000000..55548a1a2 --- /dev/null +++ b/include/ajax/ajax_action_concerned_list.php @@ -0,0 +1,66 @@ + + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); +$http=new HttpInput(); +try { + // follow_up id + $ag_id=$http->request("ag_id","number"); +} catch (Exception $ex) { + record_log(__FILE__.$ex->getMessage().$ex->getTraceAsString()); + return; +} +/* + * security Who can do it ? + */ +if ( ! $g_user->can_write_action($ag_id) ) { + record_log(__FILE__."security : access refused"); + return; +} +require_once 'class/follow_up_other_concerned.class.php'; +ob_start(); +echo HtmlInput::title_box(_("Liste Autres Fiches"), "action_concerned_list_dv"); + +$follow=new Follow_Up_Other_Concerned($cn,$ag_id); +$follow->display_table(); + +echo $follow->button_action_add_concerned_card( ); +$csv="export.php?". + http_build_query(["gDossier"=>Dossier::id(), + "act"=>"CSV:FollowUpContactOption", + "ag_id"=>$ag_id]); +echo HtmlInput::button_anchor(_("Export CSV"), $csv,"",' title="Export Contacts options"','smallbutton'); + +echo HtmlInput::button_close("action_concerned_list_dv"); +$response = ob_get_clean(); + +if ( headers_sent() && DEBUG) { + echo $response; +} +$html = escape_xml($response); +header('Content-type: text/xml; charset=UTF-8'); +echo << + +$ctl +$html + +EOF; +?> \ No newline at end of file diff --git a/include/ajax/ajax_action_remove_concerned.php b/include/ajax/ajax_action_remove_concerned.php index 00d389490..08251710e 100644 --- a/include/ajax/ajax_action_remove_concerned.php +++ b/include/ajax/ajax_action_remove_concerned.php @@ -45,22 +45,30 @@ if ( ! $g_user->can_read_action($ag_id) ) { return; } -require_once 'class/follow_up.class.php'; -$follow=new Follow_Up($cn,$ag_id); +require_once 'class/follow_up_other_concerned.class.php'; +$follow=new Follow_Up_Other_Concerned($cn,$ag_id); ob_start(); +$action_person_id=$cn->get_value(" select ap_id from action_person where ag_id =$1 and f_id =$2 ",[$ag_id,$f_id]); + +// row id to update +$ctl= "other_".$action_person_id; + $follow->remove_linked_card($f_id); -echo $follow->display_linked(); -echo HtmlInput::button_action_add_concerned_card( $follow->ag_id); +$follow->display_linked_count(); +echo $follow->button_action_add_concerned_card( ); $response = ob_get_clean(); +if (headers_sent() && DEBUG) { + echo $response; +} $html = escape_xml($response); header('Content-type: text/xml; charset=UTF-8'); echo << -unused +$ctl $html EOF; diff --git a/include/ajax/ajax_action_save_concerned.php b/include/ajax/ajax_action_save_concerned.php index 25baf3008..4500c5b59 100644 --- a/include/ajax/ajax_action_save_concerned.php +++ b/include/ajax/ajax_action_save_concerned.php @@ -46,8 +46,8 @@ if ( ! $g_user->can_write_action($ag_id) ) { return; } -require_once 'class/follow_up.class.php'; -$follow=new Follow_Up($cn,$ag_id); +require_once 'class/follow_up_other_concerned.class.php'; +$follow=new Follow_Up_Other_Concerned($cn,$ag_id); $nb_card=count($selected_card); for ($i=0;$i< $nb_card;$i++) { @@ -61,8 +61,8 @@ for ($i=0;$i< $nb_card;$i++) */ ob_start(); -$follow->display_linked(); -echo HtmlInput::button_action_add_concerned_card( $ag_id); +$follow->display_linked_count(); +echo $follow->button_action_add_concerned_card( ); $response = ob_get_clean(); $html = escape_xml($response); header('Content-type: text/xml; charset=UTF-8'); diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php index 7b065898b..62e88de20 100644 --- a/include/ajax/ajax_card.php +++ b/include/ajax/ajax_card.php @@ -776,6 +776,13 @@ case 'upr': return; break; + // ---------------------------------------------------------------------------------------------------------------- + // Display a list of other card linked to the event / followup + // ---------------------------------------------------------------------------------------------------------------- + case 'action_concerned_list': + require_once NOALYSS_INCLUDE.'/ajax/ajax_action_concerned_list.php'; + return ; + break; } // switch $xml=escape_xml($html); diff --git a/include/ajax/ajax_save_card_option.php b/include/ajax/ajax_save_card_option.php index 931f07ed3..58457d431 100644 --- a/include/ajax/ajax_save_card_option.php +++ b/include/ajax/ajax_save_card_option.php @@ -21,7 +21,7 @@ if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); - +require_once NOALYSS_INCLUDE."/class/follow_up_other_concerned.class.php"; /** * @file * @brief save option of card into action_person_option @@ -52,4 +52,7 @@ for ($i=0;$i<$nb; $i++) { $cn->exec_sql("UPDATE public.action_person_option SET ap_value=$1 WHERE ap_id=$2", [$ap_value[$i],$ap_id[$i]]); -} \ No newline at end of file +} +$follow=new Follow_Up_Other_Concerned($cn,$ag_id); +$aColumn = $follow->get_option(); +echo $follow->display_row($fiche_id, 0, $aColumn); \ No newline at end of file diff --git a/include/class/follow_up.class.php b/include/class/follow_up.class.php index 03a748536..380743a15 100644 --- a/include/class/follow_up.class.php +++ b/include/class/follow_up.class.php @@ -1670,65 +1670,7 @@ class Follow_Up $this->f_id_dest=null; } - /** - * Add another concerned (tiers, supplier...) - * @remark type $g_user - * @param type $p_fiche_id - */ - function insert_linked_card($p_fiche_id) - { - global $g_user; - if ($g_user->can_write_action($this->ag_id)) - { - /** - * insert into action_person - */ - $count=$this->db->get_value('select count(*) from action_person where f_id=$1 and ag_id=$2', array($p_fiche_id, $this->ag_id)); - if ($count==0) - { - $this->db->exec_sql('insert into action_person (ag_id,f_id) values ($1,$2)', array($this->ag_id, $p_fiche_id)); - } - } - } - - /** - * Remove another concerned (tiers, supplier...) - * @remark type $g_user - * @param type $p_fiche_id - */ - function remove_linked_card($p_fiche_id) - { - global $g_user; - if ($g_user->can_write_action($this->ag_id)) - { - $this->db->exec_sql('delete from action_person where ag_id = $1 and f_id = $2', array($this->ag_id, $p_fiche_id)); - } - } - - /** - * Display the other concerned (tiers, supplier...) - * @return string - */ - function display_linked() - { - $a_linked=$this->db->get_array('select ap_id,f_id from action_person where ag_id=$1', array($this->ag_id)); - if (count($a_linked)==0) - return ""; - $dossier_id=Dossier::id(); - for ($i=0; $idb, $a_linked[$i]['f_id']); - $qc=$fiche->get_quick_code(); - $js_remove=sprintf("action_remove_concerned('%s','%s','%s')", dossier::id(), $a_linked[$i]['f_id'], $this->ag_id); - echo ''; - echo HtmlInput::anchor($qc,"", sprintf("onclick=\"linked_card_option('%s','%s')\"", - $a_linked[$i]['ap_id'],$dossier_id)); - echo Icon_Action::trash(uniqid(), $js_remove); - echo ''; - echo ' '; - echo ' '; - } - } + /** * @brief display a small form to enter a new event * diff --git a/include/class/follow_up_other_concerned.class.php b/include/class/follow_up_other_concerned.class.php new file mode 100644 index 000000000..56cec39ef --- /dev/null +++ b/include/class/follow_up_other_concerned.class.php @@ -0,0 +1,237 @@ + + + +/** + * @file + * @brief Others concerned card in an action + * @see Follow_Up + */ + +/** + * @class + * @brief Others concerned card in an action + * @see Follow_Up + */ + +class Follow_Up_Other_Concerned +{ + private $ag_id; /*!< action_gestion.ag_id*/ + private $db; /*!< Database handle */ + + function __construct($p_database,$p_action_gestion_id) + { + $this->db=$p_database; + $this->ag_id=$p_action_gestion_id; + } + public function get_ag_id() + { + return $this->ag_id; + } + + public function set_ag_id($ag_id) + { + $this->ag_id=$ag_id; + return $this; + } + public function get_db() + { + return $this->db; + } + + public function set_db($cn) + { + $this->db=$cn; + return $this; + } + + + /** + * Remove another concerned (tiers, supplier...) + * @remark type $g_user + * @param type $p_fiche_id + */ + function remove_linked_card($p_fiche_id) + { + global $g_user; + if ($g_user->can_write_action($this->ag_id)) + { + $this->db->exec_sql('delete from action_person where ag_id = $1 and f_id = $2', array($this->ag_id, $p_fiche_id)); + return true; + } + return false; + } + +// /** +// * Display the other concerned (tiers, supplier...) in a small cell +// * @return string +// */ +// function display_linked() +// { +// $a_linked=$this->db->get_array('select ap_id,f_id from action_person where ag_id=$1', array($this->ag_id)); +// if (count($a_linked)==0) +// return ""; +// $dossier_id=Dossier::id(); +// for ($i=0; $idb, $a_linked[$i]['f_id']); +// $qc=$fiche->get_quick_code(); +// $js_remove=sprintf("action_remove_concerned('%s','%s','%s')", dossier::id(), $a_linked[$i]['f_id'], +// $this->ag_id); +// echo ''; +// echo HtmlInput::anchor($qc,"", sprintf("onclick=\"linked_card_option('%s','%s')\"", +// $a_linked[$i]['ap_id'],$dossier_id)); +// echo Icon_Action::trash(uniqid(), $js_remove); +// echo ''; +// echo ' '; +// echo ' '; +// } +// } + /** + * Display the count of other concerned card (tiers, supplier...) in button which call + * @return string + */ + function display_linked_count() + { + $a_linked=$this->db->get_array('select ap_id,f_id from action_person where ag_id=$1', array($this->ag_id)); + if (count($a_linked)==0) + return "0"; + $dossier_id=Dossier::id(); + $javascript=<<ag_id};action_concerned_list(obj); +EOF; + echo HtmlInput::anchor_action(count($a_linked), $javascript, null, "button"); + } + + /** + * Add another concerned (tiers, supplier...) + * @remark type $g_user + * @param type $p_fiche_id + */ + function insert_linked_card($p_fiche_id) + { + global $g_user; + if ($g_user->can_write_action($this->ag_id)) + { + /** + * insert into action_person + */ + $count=$this->db->get_value('select count(*) from action_person where f_id=$1 and ag_id=$2', array($p_fiche_id, $this->ag_id)); + if ($count==0) + { + $this->db->exec_sql('insert into action_person (ag_id,f_id) values ($1,$2)', array($this->ag_id, $p_fiche_id)); + } + } + } + /** + * Return a HTML string with a button for adding other cards + * @return type + */ + function button_action_add_concerned_card() + { + $dossier=Dossier::id(); + $javascript=<<ag_id};action_concerned_search_card(obj); +EOF; + $js=HtmlInput::button_action(_('Ajout autres'), $javascript, 'xx', + 'smallbutton'); + return $js; + } + + /** + * Display one row for all the option of a card + * @param int $p_fid card if (fiche.f_id) + * @param int $p_row index of the row used for alternate the color of the rows + * @param array $aOther Column of the options + */ + function display_row($p_fid,$p_row,$pa_Column){ + static $dossier_id; + $dossier_id=Dossier::id(); + + $action_person_id=$this->db->get_value("select ap_id from action_person where f_id=$1 and ag_id=$2", + [$p_fid,$this->ag_id]); + + // Name , first & quick code from fiche + $row= $this->db->get_row("select + (select ad_value from fiche_detail fd2 where fd2.f_id=ap.f_id and fd2.ad_id = 1) as xname, + (select ad_value from fiche_detail fd2 where fd2.f_id=ap.f_id and fd2.ad_id = 32) as xfirst_name, + (select ad_value from fiche_detail fd2 where fd2.f_id=ap.f_id and fd2.ad_id = 23) as xqcode + from fiche ap + where ap.f_id=$1 + ",[$p_fid]); + + + // Detail for this one + $detail = HtmlInput::anchor($row['xqcode'],"", sprintf("onclick=\"linked_card_option('%s','%s')\"", + $action_person_id,$dossier_id),'class="line"',_("Options")); + // remove card + $js_remove=sprintf("action_remove_concerned('%s','%s','%s')", dossier::id(), $p_fid, + $this->ag_id); + $remove = Icon_Action::trash(uniqid(), $js_remove); + $r=<< + + + {$detail} + + + {$row['xname']} + + + {$row['xfirst_name']} + +EOF; + $nb_other=count($pa_Column); + for ($i=0;$i<$nb_other;$i++) { + $value=$this->db->get_value(" + select apo2.ap_value + from action_person_option apo2 + join action_person ap on (apo2.action_person_id=ap.ap_id) + where + apo2.contact_option_ref_id =$1 + and ap.f_id=$2 + ",array($pa_Column[$i]['cor_id'] , $p_fid)); + $r.= td($value); + } + $r.=''.$remove.''; + $r.=''; + return $r; + } + /** + * Display all the person with option in a html table + */ + function display_table(){ + require_once NOALYSS_TEMPLATE."/follow_up_other_concerned_display_table.php"; + } + /** + * Get Available options + */ + function get_option() + { + $aColumn = $this->db->get_array("select cor_id,cor_label,jdoc.jdoc_enable + from contact_option_ref cor + join jnt_document_option_contact jdoc on (cor.cor_id=jdoc.contact_option_ref_id ) + join action_gestion ag on (ag.ag_type=jdoc.document_type_id ) + where ag_id=$1 + order by upper(cor_label)",[$this->ag_id]); + return $aColumn; + } +} \ No newline at end of file diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php index cf3978cc6..e43c0ff53 100755 --- a/include/lib/html_input.class.php +++ b/include/lib/html_input.class.php @@ -480,7 +480,7 @@ class HtmlInput $id=uniqid("xx"); } $r=""; - $r.=''.$p_symbole.h($action).''; + $r.=''.$p_symbole.h($action).''; return $r; } @@ -1137,16 +1137,7 @@ class HtmlInput return $js; } - static function button_action_add_concerned_card($p_agid) - { - $dossier=Dossier::id(); - $javascript=<< display_linked(); + $followup_other_concerned=new Follow_Up_Other_Concerned($this->db,$this->ag_id); + echo $followup_other_concerned->display_linked_count(); if ($p_view != 'READ' && $g_user->can_write_action($this->ag_id) == true ): - echo HtmlInput::button_action_add_concerned_card( $this->ag_id); + echo $followup_other_concerned->button_action_add_concerned_card(); endif; ?> diff --git a/include/template/follow_up_other_concerned_display_table.php b/include/template/follow_up_other_concerned_display_table.php new file mode 100644 index 000000000..275d711e8 --- /dev/null +++ b/include/template/follow_up_other_concerned_display_table.php @@ -0,0 +1,71 @@ + + +if (!defined('ALLOWED')) + die('Appel direct ne sont pas permis'); + +/** + * @file + * @brief display a table + */ +$aColumn = $this->get_option(); +$r='0,1,2'; + $nb_column=count($aColumn); +for ( $e=0;$e<$nb_column;$e++) { + $r.=','.($e+3); + +} +?> + + + + + + + + + db->get_array(" + select (select ad_value from fiche_detail fd1 where fd1.f_id=ap.f_id and ad_id=23) as qcode , + f_id + ,ap.ap_id + from action_person ap + join action_gestion on (ap.ag_id=action_gestion.ag_id) + where ap.ag_id=$1 order by 1",[$this->ag_id]); + $nb_other=count($aOther); + for ($x=0;$x<$nb_other;$x++) { + + echo $this->display_row($aOther[$x]['f_id'],$x,$aColumn); + } + ?> + +
+ + + + + +
\ No newline at end of file diff --git a/unit-test/create-dossier-test.sh b/unit-test/create-dossier-test.sh index 372e87440..144f47113 100755 --- a/unit-test/create-dossier-test.sh +++ b/unit-test/create-dossier-test.sh @@ -1,7 +1,8 @@ #!/bin/bash +export PGCLUSTER=10/main DOSSIER_TEST=rel70dossier25 -FILE_TEST=dossiertest200318-1402.sql +FILE_TEST=dossiertest201107-1806.sql dropdb $DOSSIER_TEST createdb $DOSSIER_TEST