Skip to content
Extraits de code Groupes Projets
Valider d95a2280 rédigé par robocoder's avatar robocoder
Parcourir les fichiers

refs #2979 - set svn:eol-style on new file

git-svn-id: http://dev.piwik.org/svn/trunk@6030 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent 61b9dda1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
/*! /*!
* Piwik - Web Analytics * Piwik - Web Analytics
* *
* @link http://piwik.org * @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/ */
(function( $ ){ (function( $ ){
$.widget('piwik.dashboardWidget', { $.widget('piwik.dashboardWidget', {
isMaximised: false, isMaximised: false,
uniqueId: null, uniqueId: null,
widgetParameters: {}, widgetParameters: {},
options: { options: {
uniqueId: null, uniqueId: null,
isHidden: false, isHidden: false,
onChange: null, onChange: null,
widgetParameters: {} widgetParameters: {}
}, },
/** /**
* creates a widget object * creates a widget object
*/ */
_create: function() { _create: function() {
if(!this.options.uniqueId) { if(!this.options.uniqueId) {
console.error('widgets can\'t be created without an uniqueId'); console.error('widgets can\'t be created without an uniqueId');
return; return;
} else { } else {
this.uniqueId = this.options.uniqueId; this.uniqueId = this.options.uniqueId;
} }
if(this.options.widgetParameters) { if(this.options.widgetParameters) {
this.widgetParameters = this.options.widgetParameters; this.widgetParameters = this.options.widgetParameters;
} }
this._createDashboardWidget(this.uniqueId); this._createDashboardWidget(this.uniqueId);
var self = this; var self = this;
this.element.on('setParameters.dashboardWidget', function(e, params) { self.setParameters(params); }); this.element.on('setParameters.dashboardWidget', function(e, params) { self.setParameters(params); });
this.reload(); this.reload();
}, },
/** /**
* Cleanup some events and dialog * Cleanup some events and dialog
* Called automaticly upon removing the widgets dom * Called automaticly upon removing the widgets dom
*/ */
destroy: function() { destroy: function() {
if(this.isMaximised) { if(this.isMaximised) {
$('[widgetId='+this.uniqueId+']').dialog('destroy'); $('[widgetId='+this.uniqueId+']').dialog('destroy');
} }
$('*', this.element).off('.dashboardWidget'); // unbind all events $('*', this.element).off('.dashboardWidget'); // unbind all events
return this; return this;
}, },
/** /**
* Returns the data currently set for the widget * Returns the data currently set for the widget
*/ */
getWidgetObject: function() { getWidgetObject: function() {
return { return {
uniqueId: this.uniqueId, uniqueId: this.uniqueId,
parameters: this.widgetParameters, parameters: this.widgetParameters,
isHidden: this.options.isHidden isHidden: this.options.isHidden
}; };
}, },
/** /**
* Show the current widget in an ui.dialog * Show the current widget in an ui.dialog
*/ */
maximise: function() { maximise: function() {
this.isMaximised = true; this.isMaximised = true;
var minWidth = this.element.width() < 500 ? 500 : this.element.width(); var minWidth = this.element.width() < 500 ? 500 : this.element.width();
var maxWidth = minWidth > 1000 ? minWidth+100 : 1000; var maxWidth = minWidth > 1000 ? minWidth+100 : 1000;
this.element.css({'minWidth': minWidth+'px', 'maxWidth': maxWidth+'px'}); this.element.css({'minWidth': minWidth+'px', 'maxWidth': maxWidth+'px'});
$('.button#close, .button#maximise', this.element).hide(); $('.button#close, .button#maximise', this.element).hide();
this.element.before('<div id="'+this.uniqueId+'-placeholder" class="widgetPlaceholder widget"> </div>'); this.element.before('<div id="'+this.uniqueId+'-placeholder" class="widgetPlaceholder widget"> </div>');
$('#'+this.uniqueId+'-placeholder').height(this.element.height()); $('#'+this.uniqueId+'-placeholder').height(this.element.height());
$('#'+this.uniqueId+'-placeholder').width(this.element.width()-16); $('#'+this.uniqueId+'-placeholder').width(this.element.width()-16);
var self = this; var self = this;
this.element.dialog({ this.element.dialog({
title: '', title: '',
modal: true, modal: true,
width: 'auto', width: 'auto',
position: ['center', 'center'], position: ['center', 'center'],
resizable: true, resizable: true,
autoOpen: true, autoOpen: true,
close: function(event, ui) { close: function(event, ui) {
self.isMaximised = false; self.isMaximised = false;
$('.button#minimise', $(this)).hide() $('.button#minimise', $(this)).hide()
$('body').off('.dashboardWidget'); $('body').off('.dashboardWidget');
$(this).dialog("destroy"); $(this).dialog("destroy");
$('#'+self.uniqueId+'-placeholder').replaceWith(this); $('#'+self.uniqueId+'-placeholder').replaceWith(this);
$(this).removeAttr('style'); $(this).removeAttr('style');
self.options.onChange(); self.options.onChange();
$(this).find('div.piwik-graph').trigger('resizeGraph'); $(this).find('div.piwik-graph').trigger('resizeGraph');
} }
}); });
this.element.find('div.piwik-graph').trigger('resizeGraph'); this.element.find('div.piwik-graph').trigger('resizeGraph');
var currentWidget = this.element; var currentWidget = this.element;
$('body').on('click.dashboardWidget', function(ev) { $('body').on('click.dashboardWidget', function(ev) {
if(ev.target.className == "ui-widget-overlay") { if(ev.target.className == "ui-widget-overlay") {
$(currentWidget).dialog("close"); $(currentWidget).dialog("close");
} }
}); });
return this; return this;
}, },
/** /**
* Reloads the widgets content with the currently set parameters * Reloads the widgets content with the currently set parameters
*/ */
reload: function() { reload: function() {
var currentWidget = this.element; var currentWidget = this.element;
function onWidgetLoadedReplaceElementWithContent(loadedContent) function onWidgetLoadedReplaceElementWithContent(loadedContent)
{ {
$('.widgetContent', currentWidget).html(loadedContent); $('.widgetContent', currentWidget).html(loadedContent);
} }
var segment = broadcast.getValueFromHash('segment'); var segment = broadcast.getValueFromHash('segment');
if(segment.length) { if(segment.length) {
this.widgetParameters.segment = segment; this.widgetParameters.segment = segment;
} }
if(!this.widgetParameters.filter_limit) { if(!this.widgetParameters.filter_limit) {
this.widgetParameters.filter_limit = 10; this.widgetParameters.filter_limit = 10;
} }
piwikHelper.queueAjaxRequest( $.ajax(widgetsHelper.getLoadWidgetAjaxRequest(this.uniqueId, this.widgetParameters, onWidgetLoadedReplaceElementWithContent)) ); piwikHelper.queueAjaxRequest( $.ajax(widgetsHelper.getLoadWidgetAjaxRequest(this.uniqueId, this.widgetParameters, onWidgetLoadedReplaceElementWithContent)) );
return this; return this;
}, },
/** /**
* Update widget parameters * Update widget parameters
* @param parameters * @param parameters
*/ */
setParameters: function(parameters) { setParameters: function(parameters) {
if (!this.isMaximised && (parameters.viewDataTable == 'tableAllColumns' || parameters.viewDataTable == 'tableGoals')) { if (!this.isMaximised && (parameters.viewDataTable == 'tableAllColumns' || parameters.viewDataTable == 'tableGoals')) {
this.maximise(); this.maximise();
} }
for (var name in parameters) { for (var name in parameters) {
this.widgetParameters[name] = parameters[name]; this.widgetParameters[name] = parameters[name];
} }
if (!this.isMaximised) { if (!this.isMaximised) {
this.options.onChange(); this.options.onChange();
} }
return this; return this;
}, },
/** /**
* Creaates the widget markup for the given uniqueId * Creaates the widget markup for the given uniqueId
* @param uniqueId * @param uniqueId
*/ */
_createDashboardWidget: function(uniqueId) { _createDashboardWidget: function(uniqueId) {
var widgetName = widgetsHelper.getWidgetNameFromUniqueId(uniqueId); var widgetName = widgetsHelper.getWidgetNameFromUniqueId(uniqueId);
if(widgetName == false) { if(widgetName == false) {
widgetName = _pk_translate('Dashboard_WidgetNotFound_js'); widgetName = _pk_translate('Dashboard_WidgetNotFound_js');
} }
var emptyWidgetContent = widgetsHelper.getEmptyWidgetHtml(uniqueId, widgetName); var emptyWidgetContent = widgetsHelper.getEmptyWidgetHtml(uniqueId, widgetName);
this.element.html(emptyWidgetContent); this.element.html(emptyWidgetContent);
var widgetElement = $('#'+ uniqueId, this.element); var widgetElement = $('#'+ uniqueId, this.element);
var self = this; var self = this;
widgetElement widgetElement
.on( 'mouseenter.dashboardWidget', function() { .on( 'mouseenter.dashboardWidget', function() {
if(!self.isMaximised) { if(!self.isMaximised) {
$(this).addClass('widgetHover'); $(this).addClass('widgetHover');
$('.widgetTop', this).addClass('widgetTopHover'); $('.widgetTop', this).addClass('widgetTopHover');
$('.button#close, .button#maximise', this).show(); $('.button#close, .button#maximise', this).show();
if(!$('.widgetContent', this).hasClass('hidden')) { if(!$('.widgetContent', this).hasClass('hidden')) {
$('.button#minimise', this).show(); $('.button#minimise', this).show();
} }
} }
}) })
.on( 'mouseleave.dashboardWidget', function() { .on( 'mouseleave.dashboardWidget', function() {
if(!self.isMaximised) { if(!self.isMaximised) {
$(this).removeClass('widgetHover'); $(this).removeClass('widgetHover');
$('.widgetTop', this).removeClass('widgetTopHover'); $('.widgetTop', this).removeClass('widgetTopHover');
$('.button#close, .button#maximise, .button#minimise', this).hide(); $('.button#close, .button#maximise, .button#minimise', this).hide();
} }
}); });
if(this.options.isHidden) { if(this.options.isHidden) {
$('.widgetContent', widgetElement).toggleClass('hidden'); $('.widgetContent', widgetElement).toggleClass('hidden');
} }
var self = this; var self = this;
$('.button#close', widgetElement) $('.button#close', widgetElement)
.on( 'click.dashboardWidget', function(ev){ .on( 'click.dashboardWidget', function(ev){
piwikHelper.windowModal('#confirm', function(){ piwikHelper.windowModal('#confirm', function(){
self.element.remove(); self.element.remove();
self.options.onChange(); self.options.onChange();
}); });
}); });
$('.button#maximise', widgetElement) $('.button#maximise', widgetElement)
.on( 'click.dashboardWidget', function(ev){ .on( 'click.dashboardWidget', function(ev){
if($('.widgetContent', $(this).parents('.widget')).hasClass('hidden')) { if($('.widgetContent', $(this).parents('.widget')).hasClass('hidden')) {
self.isMaximised = false; self.isMaximised = false;
self.options.isHidden = false; self.options.isHidden = false;
$('.widgetContent', $(this).parents('.widget')).removeClass('hidden'); $('.widgetContent', $(this).parents('.widget')).removeClass('hidden');
$('.button#minimise', $(this).parents('.widget')).show(); $('.button#minimise', $(this).parents('.widget')).show();
$(this).parents('.widget').find('div.piwik-graph').trigger('resizeGraph'); $(this).parents('.widget').find('div.piwik-graph').trigger('resizeGraph');
self.options.onChange(); self.options.onChange();
} else { } else {
self.maximise(); self.maximise();
} }
}); });
$('.button#minimise', widgetElement) $('.button#minimise', widgetElement)
.on( 'click.dashboardWidget', function(ev){ .on( 'click.dashboardWidget', function(ev){
if(!self.isMaximised) { if(!self.isMaximised) {
$('.widgetContent', $(this).parents('.widget')).addClass('hidden'); $('.widgetContent', $(this).parents('.widget')).addClass('hidden');
$('.button#minimise', $(this).parents('.widget')).hide(); $('.button#minimise', $(this).parents('.widget')).hide();
self.options.isHidden = true; self.options.isHidden = true;
self.options.onChange(); self.options.onChange();
} else { } else {
self.element.dialog("close"); self.element.dialog("close");
} }
}); });
widgetElement.show(); widgetElement.show();
} }
}); });
})( jQuery ); })( jQuery );
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter