2
// -----------------------------------------------------------------------------
3
// Data retrieval methods
4
// -----------------------------------------------------------------------------
6
function getDataElements()
8
var dataElementGroupList = document.getElementById( "dataElementGroupId" );
9
var dataElementGroupId = dataElementGroupList.options[ dataElementGroupList.selectedIndex ].value;
11
if ( dataElementGroupId != null )
13
var url = "../dhis-web-commons-ajax/getDataElements.action?id=" + dataElementGroupId + "&aggregate=true";
15
var request = new Request();
16
request.setResponseTypeXML( 'dataElement' );
17
request.setCallbackSuccess( getDataElementsReceived );
22
function getIndicators()
24
var indicatorGroupList = document.getElementById( "indicatorGroupId" );
25
var indicatorGroupId = indicatorGroupList.options[ indicatorGroupList.selectedIndex ].value;
27
if ( indicatorGroupId != null )
29
var url = "../dhis-web-commons-ajax/getIndicators.action?id=" + indicatorGroupId;
31
var request = new Request();
32
request.setResponseTypeXML( 'indicator' );
33
request.setCallbackSuccess( getIndicatorsReceived );
38
function getOrganisationUnits()
40
var organisationUnitLevelList = document.getElementById( "organisationUnitLevel" );
41
var organisationUnitLevel = organisationUnitLevelList.options[ organisationUnitLevelList.selectedIndex ].value;
43
if ( organisationUnitLevel != null )
45
var url = "../dhis-web-commons-ajax/getOrganisationUnits.action?level=" + organisationUnitLevel;
47
var request = new Request();
48
request.setResponseTypeXML( 'organisationUnit' );
49
request.setCallbackSuccess( getOrganisationUnitsReceived );
54
function getOrganisationUnitChildren()
56
var organisationUnitList = document.getElementById( "availableOrganisationUnits" );
57
var organisationUnitId = organisationUnitList.options[ organisationUnitList.selectedIndex ].value;
59
if ( organisationUnitId != null )
61
var url = "../dhis-web-commons-ajax/getOrganisationUnitChildren.action?id=" + organisationUnitId;
63
var request = new Request();
64
request.setResponseTypeXML( 'organisationUnit' );
65
request.setCallbackSuccess( getOrganisationUnitChildrenReceived );
72
var periodTypeList = document.getElementById( "periodTypeId" );
73
var periodTypeId = periodTypeList.options[ periodTypeList.selectedIndex ].value;
75
if ( periodTypeId != null )
77
var url = "../dhis-web-commons-ajax/getPeriods.action?name=" + periodTypeId;
79
var request = new Request();
80
request.setResponseTypeXML( 'period' );
81
request.setCallbackSuccess( getPeriodsReceived );
86
function getDataElementsReceived( xmlObject )
88
var availableDataElements = document.getElementById( "availableDataElements" );
89
var selectedDataElements = document.getElementById( "selectedDataElements" );
91
clearList( availableDataElements );
93
var dataElements = xmlObject.getElementsByTagName( "dataElement" );
95
for ( var i = 0; i < dataElements.length; i++ )
97
var id = dataElements[ i ].getElementsByTagName( "id" )[0].firstChild.nodeValue;
98
var dataElementName = dataElements[ i ].getElementsByTagName( "name" )[0].firstChild.nodeValue;
100
if ( listContains( selectedDataElements, id ) == false )
102
var option = document.createElement( "option" );
104
option.text = dataElementName;
105
availableDataElements.add( option, null );
110
function getIndicatorsReceived( xmlObject )
112
var availableIndicators = document.getElementById( "availableIndicators" );
113
var selectedIndicators = document.getElementById( "selectedIndicators" );
115
clearList( availableIndicators );
117
var indicators = xmlObject.getElementsByTagName( "indicator" );
119
for ( var i = 0; i < indicators.length; i++ )
121
var id = indicators[ i ].getElementsByTagName( "id" )[0].firstChild.nodeValue;
122
var indicatorName = indicators[ i ].getElementsByTagName( "name" )[0].firstChild.nodeValue;
124
if ( listContains( selectedIndicators, id ) == false )
126
var option = document.createElement( "option" );
128
option.text = indicatorName;
129
availableIndicators.add( option, null );
134
function getOrganisationUnitsReceived( xmlObject )
136
var availableOrganisationUnits = document.getElementById( "availableOrganisationUnits" );
137
var selectedOrganisationUnits = document.getElementById( "selectedOrganisationUnits" );
139
clearList( availableOrganisationUnits );
141
var organisationUnits = xmlObject.getElementsByTagName( "organisationUnit" );
143
for ( var i = 0; i < organisationUnits.length; i++ )
145
var id = organisationUnits[ i ].getElementsByTagName( "id" )[0].firstChild.nodeValue;
146
var organisationUnitName = organisationUnits[ i ].getElementsByTagName( "name" )[0].firstChild.nodeValue;
148
if ( listContains( selectedOrganisationUnits, id ) == false )
150
var option = document.createElement( "option" );
152
option.text = organisationUnitName;
153
availableOrganisationUnits.add( option, null );
158
function getOrganisationUnitChildrenReceived( xmlObject )
160
var selectedOrganisationUnits = document.getElementById( "selectedOrganisationUnits" );
162
var organisationUnits = xmlObject.getElementsByTagName( "organisationUnit" );
164
for ( var i = 0; i < organisationUnits.length; i++ )
166
var id = organisationUnits[ i ].getElementsByTagName( "id" )[0].firstChild.nodeValue;
168
var organisationUnitName = organisationUnits[ i ].getElementsByTagName( "name" )[0].firstChild.nodeValue;
170
if ( listContains( selectedOrganisationUnits, id ) == false )
172
var option = document.createElement( "option" );
174
option.text = organisationUnitName;
175
selectedOrganisationUnits.add( option, null );
180
function getPeriodsReceived( xmlObject )
182
var availablePeriods = document.getElementById( "availablePeriods" );
183
var selectedPeriods = document.getElementById( "selectedPeriods" );
185
clearList( availablePeriods );
187
var periods = xmlObject.getElementsByTagName( "period" );
189
for ( var i = 0; i < periods.length; i++ )
191
var id = periods[ i ].getElementsByTagName( "id" )[0].firstChild.nodeValue;
192
var periodName = periods[ i ].getElementsByTagName( "name" )[0].firstChild.nodeValue;
194
if ( listContains( selectedPeriods, id ) == false )
196
var option = document.createElement( "option" );
198
option.text = periodName;
199
availablePeriods.add( option, null );
204
// -----------------------------------------------------------------------------
205
// DataMartExport details
206
// -----------------------------------------------------------------------------
208
function showDataMartExportDetails( id )
210
var request = new Request();
211
request.setResponseTypeXML( 'dataMartExport' );
212
request.setCallbackSuccess( dataMartExportReceived );
213
request.send( 'getDataMartExport.action?id=' + id );
216
function dataMartExportReceived( xmlObject )
218
setFieldValue( "nameField", getElementValue( xmlObject, "name" ) );
219
setFieldValue( "dataElementField", getElementValue( xmlObject, "dataElements" ) );
220
setFieldValue( "indicatorField", getElementValue( xmlObject, "indicators" ) );
221
setFieldValue( "organisationUnitField", getElementValue( xmlObject, "organisationUnits" ) );
222
setFieldValue( "periodField", getElementValue( xmlObject, "periods" ) );
227
// -----------------------------------------------------------------------------
229
// -----------------------------------------------------------------------------
231
function saveExport()
233
if ( validateCollections() )
235
var exportId = document.getElementById( "exportId" ).value;
236
var exportName = document.getElementById( "exportName" ).value;
238
var url = "validateDataMartExport.action?id=" + exportId + "&name=" + exportName;
240
var request = new Request();
241
request.setResponseTypeXML( 'message' );
242
request.setCallbackSuccess( saveExportReceived );
247
function saveExportReceived( messageElement )
249
var type = messageElement.getAttribute( 'type' );
250
var message = messageElement.firstChild.nodeValue;
252
if ( type == "input" )
254
setMessage( message );
256
else if ( type == "success" )
258
var params = getExportParams();
260
var url = "saveDataMartExport.action";
262
var request = new Request();
263
request.sendAsPost( params );
264
request.setCallbackSuccess( saveReceived );
269
function saveReceived( messageElement )
271
setMessage( i18n_export_saved );
274
// -----------------------------------------------------------------------------
276
// -----------------------------------------------------------------------------
278
function exportValues()
280
if ( validateCollections() )
282
var params = getExportParams();
284
var url = "export.action";
286
var request = new Request();
287
request.sendAsPost( params );
288
request.setCallbackSuccess( exportReceived );
293
function exportReceived( messageElement )
295
waitAndGetExportStatus( 500 );
298
function getExportStatus()
300
var url = "getExportStatus.action";
302
var request = new Request();
303
request.setResponseTypeXML( 'status' );
304
request.setCallbackSuccess( exportStatusReceived );
308
function exportStatusReceived( xmlObject )
310
var message = getElementValue( xmlObject, "message" );
311
var running = getElementValue( xmlObject, "running" );
313
setMessage( message );
315
if ( running == "true" )
317
waitAndGetExportStatus( 2000 );
321
function waitAndGetExportStatus( millis )
323
setTimeout( "getExportStatus();", millis );
326
function cancelExport()
328
var url = "cancelExport.action";
330
var request = new Request();
334
function removeDatamartExport( exportId, exportName )
336
var result = window.confirm( i18n_confirm_delete + '\n\n' + exportName );
340
window.location.href = 'removeDataMartExport.action?id=' + exportId;
344
function getExportParams()
346
var exportId = document.getElementById( "exportId" ).value;
347
var exportName = document.getElementById( "exportName" ).value;
348
var dataElements = document.getElementById( "selectedDataElements" );
349
var indicators = document.getElementById( "selectedIndicators" );
350
var organisationUnits = document.getElementById( "selectedOrganisationUnits" );
351
var periods = document.getElementById( "selectedPeriods" );
353
var params = "id=" + exportId + "&name=" + exportName;
355
for ( var i = 0; i < dataElements.options.length; i++ )
357
params += "&selectedDataElements=" + dataElements.options[i].value;
360
for ( var i = 0; i < indicators.options.length; i++ )
362
params += "&selectedIndicators=" + indicators.options[i].value;
365
for ( var i = 0; i < organisationUnits.options.length; i++ )
367
params += "&selectedOrganisationUnits=" + organisationUnits.options[i].value;
370
for ( var i = 0; i < periods.options.length; i++ )
372
params += "&selectedPeriods=" + periods.options[i].value;
378
// -----------------------------------------------------------------------------
380
// -----------------------------------------------------------------------------
382
function validateCollections()
384
if ( !hasElements( "selectedDataElements" ) && !hasElements( "selectedIndicators" ) )
386
setMessage( i18n_must_select_at_least_one_dataelement_or_indicator );
391
if ( !hasElements( "selectedOrganisationUnits" ) )
393
setMessage( i18n_must_select_at_least_one_organisation_unit );
398
if ( !hasElements( "selectedPeriods" ) )
400
setMessage( i18n_must_select_at_least_one_period );
408
// -----------------------------------------------------------------------------
410
// -----------------------------------------------------------------------------
412
function addToDashboard( id )
414
var dialog = window.confirm( i18n_confirm_add_to_dashboard );
418
var request = new Request();
419
request.send( "addDataMartExportToDashboard.action?id=" + id );