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
|
/*!
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
(function ($, require) {
var exports = require('piwik/UI'),
DataTable = exports.DataTable,
dataTablePrototype = DataTable.prototype;
var UIControl = exports.UIControl;
function getValueFromEvent(event)
{
return event.target.value ? event.target.value : $(event.target).attr('value');
}
/**
* UI control that handles extra functionality for Actions datatables.
*
* @constructor
*/
exports.InsightsDataTable = function (element) {
this.parentAttributeParent = '';
this.parentId = '';
this.disabledRowDom = {}; // to handle double click on '+' row
if ($(element).attr('data-table-onlyinsightsinit')) {
// overview-widget
UIControl.call(this, element);
this._init($(element));
this.workingDivId = this._createDivId();
$(element).attr('id', this.workingDivId);
} else {
DataTable.call(this, element);
}
};
$.extend(exports.InsightsDataTable.prototype, dataTablePrototype, {
handleRowActions: function () {},
_init: function (domElem) {
this.initShowIncreaseOrDecrease(domElem);
this.initOrderBy(domElem);
this.initComparedToXPeriodsAgo(domElem);
this.initFilterBy(domElem);
this.setFixWidthToMakeEllipsisWork(domElem);
},
setFixWidthToMakeEllipsisWork: function (domElem) {
var width = domElem.width();
if (width) {
$('td.label', domElem).width(parseInt(width * 0.50, 10));
}
},
_changeParameter: function (params) {
var widgetParams = {};
for (var index in params) {
if (params.hasOwnProperty(index)) {
this.param[index] = params[index];
widgetParams[index] = params[index];
}
}
this.notifyWidgetParametersChange(this.$element, widgetParams);
},
_changeParameterAndReload: function (params) {
this._changeParameter(params);
this.reloadAjaxDataTable(true);
},
initShowIncreaseOrDecrease: function (domElem) {
var self = this;
$('[name=showIncreaseOrDecrease]', domElem).bind('change', function (event) {
var value = getValueFromEvent(event);
self._changeParameterAndReload({
limit_increaser: (value == 'both' || value == 'increase') ? '5' : '0',
limit_decreaser: (value == 'both' || value == 'decrease') ? '5' : '0'
});
});
},
initOrderBy: function (domElem) {
var self = this;
$('[name=orderBy]', domElem).bind('change', function (event) {
self._changeParameterAndReload({order_by: getValueFromEvent(event)});
});
$('th[name=orderBy]', domElem).bind('click', function (event) {
self._changeParameterAndReload({order_by: getValueFromEvent(event)});
});
},
initComparedToXPeriodsAgo: function (domElem) {
var self = this;
$('[name=comparedToXPeriodsAgo]', domElem).bind('change', function (event) {
self._changeParameterAndReload({compared_to_x_periods_ago: getValueFromEvent(event)});
});
},
initFilterBy: function (domElem) {
var self = this;
$('[name=filterBy]', domElem).bind('change', function (event) {
self._changeParameterAndReload({filter_by: getValueFromEvent(event)});
});
}
});
})(jQuery, require);
|