Tache #2406: Tableau de bord : tous les widgets doivent pouvoir être rafraîchis

This commit is contained in:
sparkyx 2025-01-13 10:09:07 +01:00
parent 08656bb230
commit 1897ade679
11 changed files with 107 additions and 14 deletions

View file

@ -2796,6 +2796,7 @@ div.menu2 td.mtitle a{
}
.icon:hover {
font-family: "fontello";
background-color: transparent;
}
*.icon {
text-decoration: none;

View file

@ -60,7 +60,7 @@ function errorFid(request,json)
*/
function ajaxFid(p_ctl)
{
debugger
try
{
var gDossier=id$('gDossier').value;

View file

@ -4390,10 +4390,11 @@ Widget = function(dossier_id) {
* Display the widget in the elt box
* @param box DOMID of the target
* @param dossier_id
* @param user_widget_id
* @param widget_code
* @param user_widget_id int
* @param widget_code string
* @param var_name string name of the variable
*/
Widget.prototype.display = function (box,user_widget_id,widget_code) {
Widget.prototype.display = function (box,user_widget_id,widget_code,var_name) {
try {
var queryString = {
@ -4401,6 +4402,7 @@ Widget.prototype.display = function (box,user_widget_id,widget_code) {
'op': 'widget',
'user_widget_id': user_widget_id,
'widget_code': widget_code,
'var_name':var_name,
'action': 'widget.display'
}
var action = new Ajax.Request(

View file

@ -872,7 +872,7 @@ class HtmlInput
* @return type
*/
static function title_box($p_name, $p_div, $p_mod="close", $p_js="",
$p_draggable="n",$p_enlarge='n',$raw="")
$p_draggable="n",$p_enlarge='n',$raw="",$refresh='')
{
$p_div=strip_tags($p_div);
$r='<div class="bxbutton">';
@ -885,6 +885,9 @@ class HtmlInput
if ( $p_enlarge=='y') {
$r.=Icon_Action::full_size($p_div);
}
if ( $refresh != '') {
$r.=Icon_Action::refresh(uniqid(), $refresh);
}
if ($p_mod=='close')
{
$r.=Icon_Action::close($p_div, $p_js);

View file

@ -509,5 +509,15 @@ class Icon_Action
);
return $r;
}
static function refresh($p_id,$javascript)
{
$javascript=str_replace('"', '&quot;',$javascript);
//icon-arrows-cw
$r=sprintf('<i id="%s" onclick="%s" class="smallicon icon icon-arrows-cw" style="margin-left:5px"></i>',
$p_id,$javascript
);
return $r;
}
}

View file

@ -21,7 +21,7 @@
* \file
* \brief main display for situation
*/
$http=new \HttpInput();
$Operation=new Follow_Up($cn);
$last_operation=$Operation->get_today();
$late_operation=$Operation->get_late();
@ -38,8 +38,10 @@ $customer_late=$Ledger->get_customer_late();
$gDossier_id=Dossier::id();
// var refresh : string javascript code to refresh this widget
$refresh=sprintf("event_display_main('%s')",Dossier::id());
?>
<?php echo HtmlInput::title_box(_("Résumé"),"situation_div",'none','','n')?>
<?php echo HtmlInput::title_box(_("Résumé"),"situation_div",'none','','n','','',$refresh)?>
<table class='result'>
<tr>
<th>

View file

@ -39,13 +39,25 @@ class Agenda extends Widget
global $g_user;
/* others report */
$cal=new \Calendar();
$cal->default_periode=$g_user->get_periode();
$box= sprintf( '%s_%s',$this->get_widget_code(),$this->get_user_widget_id());
$obj=sprintf("{gDossier:%d,invalue:'%s',outdiv:'%s','distype':'%s'}",
\Dossier::id(),'per','calendar_zoom_div','cal');
$this->open_div();
echo \HtmlInput::title_box(_('Calendrier'),'cal_div','zoom',"calendar_zoom($obj)",'n',raw:'&#x1F4C5;');
// var $refresh string javascript to refresh the widget
$refresh='';
if ( $this->get_var_name() !="") {
$refresh=Widget::build_refresh_js( $this->get_widget_code(),
$this->get_user_widget_id(),
$this->get_var_name());
}
echo \HtmlInput::title_box(_('Calendrier'),'cal_div','zoom',"calendar_zoom($obj)",'n',raw:'&#x1F4C5;',refresh: $refresh);
echo $cal->display('short',0);
$this->close_div();
}

View file

@ -44,20 +44,27 @@ try {
} catch (\Exception $e) {
echo $e->getMessage();
}
/**************************************************************************
// action = display,
*
*************************************************************************/
if ($action == 'widget.display') {
try {
$widget=\Noalyss\Widget\Widget::build_user_widget($http->request('user_widget_id'),$http->request("widget_code"));
$widget?->set_var_name($http->request("var_name"),'string','');
$widget?->display();
} catch (\Exception $e) {
record_log($e);
echo $e->getMessage();
}
return;
}
/**************************************************************************
// call from a widget
*
*************************************************************************/
if ( $w != "widget") {
// security
// widget exists ? Protect against attack when w is a relative path to something else

View file

@ -40,8 +40,11 @@ class Last_Operation extends Widget
{
global $cn;
$this->open_div();
echo \HtmlInput::title_box(_('Dernières opérations'),"last_operation_box_div",'zoom','popup_recherche('.\Dossier::id().')','n');
$refresh="";
if ( $this->get_var_name() != "") {
$refresh = Widget::build_refresh_js($this->widget_code, $this->user_widget_id,$this->var_name);
}
echo \HtmlInput::title_box(_('Dernières opérations'),"last_operation_box_div",'zoom','popup_recherche('.\Dossier::id().')','n','','',$refresh);
require_once "last_operation-display.php";
$this->close_div();
}

View file

@ -30,12 +30,34 @@ namespace Noalyss\Widget;
*/
abstract class Widget
{
//!< $var_name string name of the variable in javascript
protected $var_name;
public function __construct(protected int $user_widget_id=0,protected string $widget_code="",protected $db=null)
{
if ($db == null) {
$this->db=\Dossier::connect();
}
$this->var_name='';
}
/**
* @return mixed
*/
public function get_var_name()
{
return $this->var_name;
}
/**
* @param mixed $var_name
*/
public function set_var_name($var_name):Widget
{
$this->var_name = $var_name;
return $this;
}
public function get_user_widget_id(): int
@ -197,7 +219,7 @@ where use_login=$1 order by uw.uw_order
echo <<<EOF
<script>
var {$widgetjs}= new Widget('{$dossier_id}')
{$widgetjs}.display('{$box}',{$widget->get_user_widget_id()},'{$widget->get_widget_code()}')
{$widgetjs}.display('{$box}',{$widget->get_user_widget_id()},'{$widget->get_widget_code()}','{$widgetjs}')
</script>
@ -359,15 +381,43 @@ EOF;
return $bt;
}
/**
* @brief display the title and the icon for zooming
* @brief display the title and the icon for zooming + refresh if possible
* @param $title string title of the widget
*/
function title( $title) {
// var $refresh string javascript to refresh the widget
$refresh='';
if ( $this->get_var_name() !="") {
$refresh=Widget::build_refresh_js( $this->get_widget_code(),
$this->get_user_widget_id(),
$this->get_var_name());
}
$r='<div class="bxbutton">';
$r.=\Icon_Action::refresh(uniqid(), $refresh);
$r.='<span id="span_'.uniqid().'" style="float:right;margin-right:5px">'.$this->button_zoom()."</span>";
$r.='</div>';
$r.=sprintf('<h2 class="title">%s</h2>',$title);
echo $r;
}
/**
* @brief build refresh javascript
* @param $widget_id int id from DB
* @param $widget_code string code of the widget
* @param $var_name string name of the js variable
*/
static function build_refresh_js($widget_code,$widget_id,$var_name)
{
// var $box string DOM ID of the DIV containing the widget
$box= sprintf( '%s_%s',$widget_code,$widget_id);
$refresh=sprintf("%s.display('%s','%s','%s','%s')",
$var_name,
$box,
$widget_id,
$widget_code,
$var_name
);
return $refresh;
}
}

View file

@ -117,4 +117,7 @@ include_once NOALYSS_INCLUDE."/lib/icon_action.class.php";
<div id="example_div" style="display:none">
Ceci est caché
</div>
</div>
</p>
<p>
<?=\Icon_Action::refresh(uniqid(),'alert("1")')?>
</p>