~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// -----------------------------------------------------------------------------
 
3
// View chart
 
4
// -----------------------------------------------------------------------------
 
5
 
 
6
var tempChartId;
 
7
 
 
8
function runAndViewChart( chartId )
 
9
{
 
10
    tempChartId = chartId;
 
11
    
 
12
    var request = new Request();
 
13
    request.setCallbackSuccess( runAndViewChartReceived );    
 
14
    request.send( "createChart.action?id=" + chartId );
 
15
}
 
16
 
 
17
function runAndViewChartReceived( messageElement )
 
18
{
 
19
    getChartStatus();
 
20
}
 
21
 
 
22
function getChartStatus()
 
23
{   
 
24
    var url = "getStatus.action";
 
25
    
 
26
    var request = new Request();
 
27
    request.setResponseTypeXML( "status" );
 
28
    request.setCallbackSuccess( chartStatusReceived );    
 
29
    request.send( url );
 
30
}
 
31
 
 
32
function chartStatusReceived( xmlObject )
 
33
{
 
34
    var statusMessage = getElementValue( xmlObject, "statusMessage" );
 
35
    var finished = getElementValue( xmlObject, "finished" );
 
36
    
 
37
    if ( finished == "true" )
 
38
    {
 
39
        var url = "viewChart.action?id=" + tempChartId;
 
40
        
 
41
        viewChart( url );
 
42
    }
 
43
    else
 
44
    {
 
45
        setTimeout( "getChartStatus();", 2000 );
 
46
    }
 
47
}
 
48
 
 
49
function viewChart( url )
 
50
{
 
51
    window.open( url, "_blank", "directories=no, height=560, width=760, location=no, menubar=no, status=no, toolbar=no, resizable=no, scrollbars=no" );
 
52
}
 
53
 
 
54
// -----------------------------------------------------------------------------
 
55
// Remove chart
 
56
// -----------------------------------------------------------------------------
 
57
 
 
58
function removeChart( chartId, chartTitle )
 
59
{
 
60
    var result = window.confirm( i18n_confirm_delete + '\n\n' + chartTitle );
 
61
    
 
62
    if ( result )
 
63
    {
 
64
        window.location.href = "removeChart.action?id=" + chartId;
 
65
    }
 
66
}
 
67
 
 
68
// -----------------------------------------------------------------------------
 
69
// Show chart details
 
70
// -----------------------------------------------------------------------------
 
71
 
 
72
function showChartDetails( chartId )
 
73
{
 
74
    var request = new Request();
 
75
    request.setResponseTypeXML( 'chart' );
 
76
    request.setCallbackSuccess( chartReceived );
 
77
    request.send( 'getChart.action?id=' + chartId );
 
78
}
 
79
 
 
80
function chartReceived( xmlObject )
 
81
{
 
82
    setFieldValue( 'titleField', getElementValue( xmlObject, 'title' ) );
 
83
    setFieldValue( 'dimensionField', getElementValue( xmlObject, 'dimension' ) );
 
84
    setFieldValue( 'indicatorsField', getElementValue( xmlObject, 'indicators' ) );
 
85
    setFieldValue( 'periodsField', getElementValue( xmlObject, 'periods' ) );
 
86
    setFieldValue( 'organisationUnitsField', getElementValue( xmlObject, 'organisationUnits' ) );
 
87
    
 
88
    showDetails();
 
89
}
 
90
 
 
91
// -----------------------------------------------------------------------------
 
92
// Validate and save
 
93
// -----------------------------------------------------------------------------
 
94
 
 
95
function saveChart()
 
96
{
 
97
    if ( validateCollections() )
 
98
    {
 
99
        var id = document.getElementById( "id" ).value;
 
100
        var title = document.getElementById( "title" ).value;
 
101
        
 
102
        var url = "validateChart.action?id=" + id + "&title=" + htmlEncode( title );
 
103
 
 
104
        var request = new Request();
 
105
        request.setResponseTypeXML( 'message' );
 
106
        request.setCallbackSuccess( saveChartReceived );
 
107
        request.send( url );
 
108
    }
 
109
}
 
110
 
 
111
function saveChartReceived( messageElement )
 
112
{
 
113
    var type = messageElement.getAttribute( 'type' );
 
114
    var message = messageElement.firstChild.nodeValue;
 
115
    var dimension = document.getElementById( "dimension" ).value;
 
116
 
 
117
    if ( type == "input" )
 
118
    {
 
119
        setMessage( message );
 
120
        
 
121
        return false;
 
122
    }
 
123
    else if ( type == "success" )
 
124
    {
 
125
        selectAllById( "selectedIndicators" );
 
126
        
 
127
        if ( dimension == "period" )
 
128
        {
 
129
            selectAllById( "selectedPeriods" );
 
130
        }
 
131
        else if ( dimension == "organisationUnit" )
 
132
        {        
 
133
            selectAllById( "selectedOrganisationUnits" );
 
134
        }
 
135
        
 
136
        document.getElementById( "chartForm" ).submit();
 
137
    }
 
138
}
 
139
 
 
140
function validateCollections()
 
141
{
 
142
    if ( !hasElements( "selectedIndicators" ) )
 
143
    {
 
144
        setMessage( i18n_must_select_at_least_one_indicator );
 
145
        
 
146
        return false;
 
147
    }
 
148
    
 
149
    if ( !hasElements( "selectedOrganisationUnits" ) )
 
150
    {
 
151
        setMessage( i18n_must_select_at_least_one_unit );
 
152
        
 
153
        return false;
 
154
    }
 
155
    
 
156
    if ( !hasElements( "selectedPeriods" ) ) //&& !relativePeriodsChecked() )
 
157
    {
 
158
        setMessage( i18n_must_select_at_least_one_period );
 
159
        
 
160
        return false;
 
161
    }
 
162
    
 
163
    return true;
 
164
}
 
165
 
 
166
function relativePeriodsChecked()
 
167
{
 
168
    if ( isChecked( "reportingMonth" ) == true ||
 
169
         isChecked( "last3Months" ) == true ||
 
170
         isChecked( "last6Months" ) == true ||
 
171
         isChecked( "last9Months" ) == true ||
 
172
         isChecked( "last12Months" ) == true ||
 
173
         isChecked( "last3To6Months" ) == true ||
 
174
         isChecked( "last6To9Months" ) == true ||
 
175
         isChecked( "last9To12Months" ) == true ||
 
176
         isChecked( "last12IndividualMonths" ) == true ||
 
177
         isChecked( "soFarThisYear" ) == true ||
 
178
         isChecked( "soFarThisFinancialYear" ) == true ||
 
179
         isChecked( "individualMonthsThisYear" ) == true ||
 
180
         isChecked( "individualQuartersThisYear" ) == true )
 
181
    {
 
182
        return true;
 
183
    }
 
184
    
 
185
    return false;
 
186
}