1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
var SegmentedVisitorLog = function() {
function getDataTableFromApiMethod(apiMethod)
{
var div = $(require('piwik/UI').DataTable.getDataTableByReport(apiMethod));
if (div.length && div.data('uiControlObject')) {
return div.data('uiControlObject');
}
}
function getLabelFromTr ($tr, apiMethod) {
var label;
if (apiMethod && 0 === apiMethod.indexOf('Actions.')) {
// for now only use this for Actions... I know a hack :( Otherwise in Search Engines
// it would show "http://www.searchenginename.org" instead of "SearchEngineName"
label = $tr.attr('data-url-label');
}
if (!label) {
label = $tr.find('.label .value').text();
}
if (label) {
label = $.trim(label);
}
return label;
}
function getDimensionFromApiMethod(apiMethod)
{
if (!apiMethod) {
return;
}
var dataTable = getDataTableFromApiMethod(apiMethod);
var metadata = getMetadataFromDataTable(dataTable);
if (metadata && metadata.dimension) {
return metadata.dimension;
}
}
function getMetadataFromDataTable(dataTable)
{
if (dataTable) {
return dataTable.getReportMetadata();
}
}
function findTitleOfRowHavingRawSegmentValue(apiMethod, rawSegmentValue)
{
var $tr = $('[data-report="' + apiMethod + '"] tr[data-segment-filter="' + rawSegmentValue + '"]').first();
return getLabelFromTr($tr, apiMethod);
}
function setPopoverTitle(apiMethod, segment, index) {
var dataTable = getDataTableFromApiMethod(apiMethod);
if (!dataTable) {
if (index < 15) {
// this is needed when the popover is opened before the dataTable is there which can often
// happen when opening the popover directly via URL (broadcast.popoverHandler)
setTimeout(function () {
setPopoverTitle(apiMethod, segment, index + 1);
}, 150);
}
return;
}
var segmentName = getDimensionFromApiMethod(apiMethod);
var segmentValue = findTitleOfRowHavingRawSegmentValue(apiMethod, segment);
if (!segmentName || (segment && segment.indexOf(';') > 0)) {
segmentName = _pk_translate('General_Segment');
var segmentParts = segment.split(';');
segmentValue = segmentParts.join(' ' + _pk_translate('General_And') + ' ');
}
segmentName = piwikHelper.escape(segmentName);
segmentName = piwikHelper.htmlEntities(segmentName);
segmentValue = piwikHelper.escape(segmentValue);
segmentValue = piwikHelper.htmlEntities(segmentValue);
segmentName = segmentName.replace(/(&)(#[0-9]{2,5};)/g, '&$2');
segmentValue = segmentValue.replace(/(&)(#[0-9]{2,5};)/g, '&$2');
var title = _pk_translate('Live_SegmentedVisitorLogTitle', [segmentName, segmentValue]);
Piwik_Popover.setTitle(title);
}
function show(apiMethod, segment, extraParams) {
// open the popover
var box = Piwik_Popover.showLoading('Segmented Visitor Log');
box.addClass('segmentedVisitorLogPopover');
var callback = function (html) {
Piwik_Popover.setContent(html);
// remove title returned from the server
var title = box.find('h2[piwik-enriched-headline]');
var defaultTitle = title.text();
if (title.length) {
title.remove();
}
Piwik_Popover.setTitle(defaultTitle);
setPopoverTitle(apiMethod, segment, 0);
};
// prepare loading the popover contents
var requestParams = {
module: 'Live',
action: 'indexVisitorLog',
segment: segment,
disableLink: 1,
small: 1
};
$.extend(requestParams, extraParams);
var ajaxRequest = new ajaxHelper();
ajaxRequest.addParams(requestParams, 'get');
ajaxRequest.setCallback(callback);
ajaxRequest.setFormat('html');
ajaxRequest.send();
}
return {
show: show
}
}();
|