//handle target var target = false; var refreshInterval = null; //CHARGEMENT DE LA PAGE $(function(){ if($.page()!='index' || $.urlParam('module')!=null) return; dashboard_dashboardwidget_search(); $('#dashboardView li').click(function(){ $('#dashboardView li').removeAttr('data-selected'); $(this).attr('data-selected',1); dashboard_dashboardwidget_search(); }); $('#widgetList').change(function(){ var option = $('#widgetList option:selected').data(); option.text = $('#widgetList option:selected').text(); $('.widgetDescription').removeClass('hidden'); $('.widgetDescription h1 span').text(option.text); $('.widgetDescription h1 i').attr('class',option.icon); $('.widgetDescription p').text(option.description); $('.widgetDescription .widgetColor small').css('background-color',option.background); $('.widgetDescription .widgetColor span').text(option.background); }); $('#dashboard').sortable({ update:function(event,ui){ var data = dashboard_dashboardwidget_save_position(); } }); $( ".widget" ).disableSelection(); }); function init_setting_dashboard(){ dashboard_dashboard_search(); } //Enregistrement des configurations function dashboard_setting_save(){ $.action({ action : 'dashboard_setting_save', fields : $('#dashboard-setting-form').toJson() },function(){ $.message('info','Configuration enregistrée'); }); } /** DASHBOARD **/ //Récuperation d'une liste de dashboard dans le tableau #dashboards function dashboard_dashboard_search(callback){ $('#dashboards').fill({ action:'dashboard_dashboard_search' },function(){ if(callback!=null) callback(); }); } //Ajout ou modification d'élément dashboard function dashboard_dashboard_save(){ var data = $('#dashboard-form').toJson(); $.action(data,function(r){ $.message('success','Enregistré'); dashboard_dashboard_search(); $('#dashboard-form').attr('data-id',''); }); } //Récuperation ou edition d'élément dashboard function dashboard_dashboard_edit(element){ var line = $(element).closest('tr'); $.action({action:'dashboard_dashboard_edit',id:line.attr('data-id')},function(r){ $.setForm('#dashboard-form',r); $('#dashboard-form').attr('data-id',r.id); }); } //Suppression d'élement dashboard function dashboard_dashboard_delete(element){ if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return; var line = $(element).closest('tr'); $.action({ action : 'dashboard_dashboard_delete', id : line.attr('data-id') },function(r){ line.remove(); $.message('info','Élement supprimé'); }); } /** DASHBOARDWIDGET **/ //Récuperation d'une liste de dashboardwidget dans le tableau #dashboardwidgets function dashboard_dashboardwidget_search(callback){ var dashboard = $('#dashboardView li[data-selected]').attr('data-id'); if(!dashboard || dashboard=='') return; $.action({ action : 'dashboard_dashboardwidget_search', dashboard : dashboard },function(r){ $('#dashboard .widget:visible').remove(); for(var i in r.rows){ var widget = r.rows[i]; dashboard_dashboardwidget_append(widget); dashboard_dashboardwidget_load(widget); } clearInterval(refreshInterval); refreshInterval = setInterval(function(){ $.action({ action : 'dashboard_dashboardwidget_refresh', dashboard : $('#dashboardView li[data-selected]').attr('data-id') },function(r){ for(var id in r.rows){ var widget = r.rows[id]; if(widget.widget){ var header = $('.widget[data-id="'+id+'"]').find('.widget_header'); if(widget.widget.title) header.find('span').text(widget.widget.title); if(widget.widget.icon) header.find('i').attr('class','fa '+widget.widget.icon); if(widget.widget.background) header.css('backgroundColor',widget.widget.background); } if(widget.callback){ if(window[widget.callback]!=null) window[widget.callback]($('.widget[data-id="'+id+'"]'),widget.data); } } }); },3000); }); } //Mise à jour des infos d'un élement widget à partir d'un object data function dashboard_dashboardwidget_render(widget,data){ widget.attr('data-id',data.id); widget.removeClass (function (index, css) { return (css.match (/(^|\s)col-md-\S+/g) || []).join(' '); }); widget.attr('data-id',data.id) .attr('data-load',data.load) .attr('data-configure',data.configure) .attr('data-delete',data.delete) .addClass('col-md-'+data.width) .find('.widget_header') .css('background',data.background) .find('i:eq(0)').attr('class','fa '+data.icon); widget.find('.widget_header span:eq(0)').html(data.title); widget.find('.widget_content').html(data.content); var options = ''; for(var k in data.options){ var option = data.options[k]; options+='