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
|
'use strict';
/* eslint-disable no-implicit-globals */
/*!
* Display translation stats via a form.
* @author Amir E. Aharoni
* @author Siebrand Mazeland
* @author Niklas Laxström
* @copyright Copyright © 2012-2013 Amir E. Aharoni, Siebrand Mazeland
* @license GPL-2.0-or-later
*/
var FormHandler = function () {
var $form = $( '#translationStatsConfig' ),
onFilter = null;
function getHeight() {
return parseInt( $form.find( 'input[name="height"]' ).val(), 10 );
}
function getWidth() {
return parseInt( $form.find( 'input[name="width"]' ).val(), 10 );
}
function getLanguages() {
var languages = $form.find( 'input[name="language"]' ).val().trim();
if ( languages.length > 0 ) {
return getSplitValues( languages );
}
return [];
}
function getGroups() {
var groups = $form.find( 'input[name="group"]' ).val().trim();
if ( groups.length > 0 ) {
return getSplitValues( groups );
}
return [];
}
function getGranularity() {
return $form.find( 'input[name="scale"]:checked' ).val().trim();
}
function getMeasure() {
return $form.find( 'input[name="count"]:checked' ).val().trim();
}
function getDays() {
return parseInt( $form.find( 'input[name="days"]' ).val(), 10 );
}
function getStart() {
return $form.find( '#start' ).val();
}
function getAllOptions() {
return {
measure: getMeasure(),
days: getDays(),
start: getStart(),
granularity: getGranularity(),
group: getGroups(),
language: getLanguages(),
height: getHeight(),
width: getWidth()
};
}
function getSplitValues( values ) {
return values.split( ',' ).map( function ( value ) {
return value.trim();
} );
}
function filter() {
if ( !this.onFilter ) {
return;
}
this.onFilter( this.getAllOptions() );
}
return {
onFilter: onFilter,
filter: filter,
getAllOptions: getAllOptions
};
};
$( function () {
var widget, defaultValue, defaultDate,
$input = $( '#start' ),
formHandler = new FormHandler(),
$graphContainer = $( '#translationStatsGraphContainer' ),
graphBuilder;
defaultDate = new Date();
defaultDate.setDate( 1 );
if ( $input.val() ) {
defaultValue = new Date( $input.val() );
}
widget = new mw.widgets.datetime.DateTimeInputWidget( {
formatter: {
format: '${year|0}-${month|0}-${day|0}',
defaultDate: defaultDate
},
type: 'date',
value: defaultValue,
max: new Date()
} );
$input.after( widget.$element ).addClass( 'mw-translate-translationstats-hide' );
widget.on( 'change', function ( data ) {
$input.val( data + 'T00:00:00' );
} );
// Check if the graph container has been loaded
if ( $graphContainer.length !== 0 ) {
graphBuilder = new mw.translate.TranslationStatsGraphBuilder( $graphContainer );
graphBuilder.display( formHandler.getAllOptions() );
}
} );
|