~dhis2-devs-india/dhis2/2.0.6-in

« back to all changes in this revision

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

  • Committer: Tran Chau
  • Date: 2010-09-06 09:12:16 UTC
  • Revision ID: tran.hispvietnam@gmail.com-20100906091216-7ndguxwqzka0gpq5
Fix bugs into Excel-reporting module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// EXCEL ITEM GROUP
3
3
// ========================================================================================================================
4
4
 
5
 
// ========================================================================================================================
6
 
// Open Add Excel item form
7
 
// ========================================================================================================================
8
 
 
9
 
function openAddExcelItem() 
10
 
{       
11
 
        byId( "okButton" ).onclick = validateAddExcelItem;
12
 
        enable( "name" );
13
 
        $( "#divExcelitem" ).showAtCenter( true );
14
 
}
15
 
 
16
 
// ========================================================================================================================
17
 
// Open Update Excel item form
18
 
// ========================================================================================================================
19
 
 
20
 
function openUpdateExcelItem( id ) 
21
 
{       
22
 
        var request = new Request();
23
 
        request.setResponseTypeXML( 'excelItem' );
24
 
        request.setCallbackSuccess( openUpdateExcelItemReceived );      
25
 
        request.send( "getExcelItem.action?id=" + id );         
26
 
}
27
 
 
28
 
function openUpdateExcelItemReceived( xmlObject ) 
29
 
{
30
 
        
31
 
        byId("id").value = xmlObject.getElementsByTagName('id')[0].firstChild.nodeValue;
32
 
        byId("name").value = xmlObject.getElementsByTagName('name')[0].firstChild.nodeValue;
33
 
        byId("expression").value = xmlObject.getElementsByTagName('expression')[0].firstChild.nodeValue;
34
 
        byId("row").value = xmlObject.getElementsByTagName('row')[0].firstChild.nodeValue;
35
 
        byId("column").value = xmlObject.getElementsByTagName('column')[0].firstChild.nodeValue;
36
 
        byId("sheetNo").value = xmlObject.getElementsByTagName('sheetNo')[0].firstChild.nodeValue;      
37
 
        byId( "okButton" ).onclick = validateUpdateExcelItem;
38
 
        enable("name");
39
 
        $("#divExcelitem").showAtCenter( true );
40
 
        
41
 
}
42
 
 
43
 
// ========================================================================================================================
44
 
// Validate Add Excel item 
45
 
// ========================================================================================================================
46
 
 
47
 
function validateAddExcelItem() 
48
 
{
49
 
        
50
 
        var request = new Request();
51
 
        request.setResponseTypeXML( 'message' );
52
 
        request.setCallbackSuccess( validateAddExcelItemReceived );     
53
 
        
54
 
        var params = "name=" + byId("name").value;
55
 
        params += "&expression=" + byId("expression").value;
56
 
        params += "&row=" + byId("row").value;
57
 
        params += "&column=" + byId("column").value;
58
 
        params += "&sheetNo=" + byId("sheetNo").value;
59
 
        params += "&excelItemGroupId=" + byId( "excelItemGroupId" ).value; 
60
 
        
61
 
        request.sendAsPost( params );
62
 
        request.send( "validateExcelItem.action" );     
63
 
        
64
 
}
65
 
 
66
 
function validateAddExcelItemReceived( message )
67
 
{
68
 
        var type = message.getAttribute( 'type' );
69
 
        
70
 
        if ( type == 'error' )
71
 
        {
72
 
                setMessage(message.firstChild.nodeValue);               
73
 
        }
74
 
        else if ( type == 'success' )
75
 
        {                               
76
 
                addExcelItem();         
77
 
        }
78
 
}
79
 
// ========================================================================================================================
80
 
// Validate Update Excel item 
81
 
// ========================================================================================================================
82
 
 
83
 
function validateUpdateExcelItem() 
84
 
{       
85
 
        var request = new Request();
86
 
        request.setResponseTypeXML( 'message' );
87
 
        request.setCallbackSuccess( validateUpdateExcelItemReceived );
88
 
        
89
 
        var params = "name=" + byId("name").value;
90
 
        params += "&expression=" + byId("expression").value;
91
 
        params += "&row=" + byId("row").value;
92
 
        params += "&column=" + byId("column").value;
93
 
        params += "&sheetNo=" + byId("sheetNo").value;
94
 
        params += "&excelItemGroupId=" + byId( "excelItemGroupId" ).value; 
95
 
        params += "&id=" + byId( "id" ).value; 
96
 
        
97
 
        request.sendAsPost( params );
98
 
        
99
 
        request.send( "validateExcelItem.action" );     
100
 
        
101
 
}
102
 
 
103
 
function validateUpdateExcelItemReceived( xmlObject ) 
104
 
{
105
 
        
106
 
        var type = xmlObject.getAttribute( 'type' );
107
 
        
108
 
        if ( type == 'error' )
109
 
        {
110
 
                setMessage(xmlObject.firstChild.nodeValue);
111
 
        }
112
 
        else if ( type == 'success' )
113
 
        {               
114
 
                updateExcelItem();              
115
 
        }
116
 
}
117
 
// ========================================================================================================================
118
 
// Add Excel item
119
 
// ========================================================================================================================
120
 
 
121
 
function addExcelItem() {
122
 
        
123
 
        /* var request = new Request();
124
 
        request.setResponseTypeXML( 'datalement' );
125
 
        request.setCallbackSuccess( Completed );
126
 
        var params = "name=" + byId("name").value;      
127
 
        params += "&expression=" + byId("expression").value; 
128
 
        params += "&row=" + byId("row").value; 
129
 
        params += "&column=" + byId("column").value; 
130
 
        params += "&sheetNo=" + byId("sheetNo").value; 
131
 
        params += "&excelItemGroupId=" + byId( "excelItemGroupId" ).value; 
132
 
        request.sendAsPost( params );
133
 
        request.send( "addExcelItem.action" ); */
134
 
        
135
 
        $.post("addExcelItem.action",{
136
 
                name:$("#name").val(),          
137
 
                expression:$("#expression").val(),
138
 
                row:$("#row").val(),    
139
 
                column:$("#column").val(),              
140
 
                sheetNo:byId("sheetNo").value,
141
 
                excelItemGroupId:byId("excelItemGroupId").value
142
 
                
143
 
        }, function (data){
144
 
                window.location.reload();
145
 
        },'xml');
146
 
}
147
 
 
148
 
function Completed( xmlObject ) {
149
 
 
150
 
        window.location.reload();
151
 
}
152
 
 
153
 
// ========================================================================================================================
154
 
// Update Excel Item
155
 
// ========================================================================================================================
156
 
 
157
 
function updateExcelItem() {
158
 
 
159
 
        $.post("updateExcelItem.action",{
160
 
                id:$("#id").val(),      
161
 
                name:$("#name").val(),          
162
 
                expression:$("#expression").val(),
163
 
                row:$("#row").val(),    
164
 
                column:$("#column").val(),              
165
 
                sheetNo:byId("sheetNo").value,
166
 
                excelItemGroupId:byId("excelItemGroupId").value
167
 
                
168
 
        }, function (data){
169
 
                window.location.reload();
170
 
        },'xml');
171
 
        
172
 
}
173
 
// ===============================================================================
 
5
function changeItemType()
 
6
{
 
7
        var type = getFieldValue( 'excelItemGroupType' );
 
8
        
 
9
        if( type == 'NORMAL' ){
 
10
                byId('expression-button' ).onclick = openExpressionBuild;
 
11
        }else {
 
12
                byId('expression-button' ).onclick =  caExpressionBuilderForm;
 
13
        }       
 
14
}
 
15
 
 
16
// -----------------------------------------------------------------------
 
17
// Open Expression Form for Normal Excel-Item group
 
18
// -----------------------------------------------------------------------
 
19
 
174
20
// Open Expression Form
175
 
// ===============================================================================
176
 
 
177
21
function openExpressionBuild() {
178
22
        
179
23
        byId("formula").value = byId("expression").value;
180
 
        
181
 
        getALLDataElementGroup();
182
 
        getDataElementsByGroup();
183
 
        enable("dataElementGroup");
184
 
        enable("availableDataElements");
185
 
        
 
24
        loadDataElementGroups( "#divExpression select[id=dataElementGroup]" );
 
25
        loadAllDataElements( "#divExpression select[id=availableDataElements]" );
186
26
        $( "#availableDataElements" ).change(getOptionCombos);          
187
 
        $( "#divExpression" ).showAtCenter( true );
188
 
        
189
 
}
190
 
 
191
 
// ===============================================================================
192
 
// Get all Dataelement Group
193
 
// ===============================================================================
194
 
 
195
 
function getALLDataElementGroup() {
196
 
 
197
 
        var list = byId( 'dataElementGroup' );
198
 
        
199
 
        list.options.length = 0;
200
 
        list.add( new Option( "ALL", "ALL" ), null );
201
 
        
202
 
        for ( id in dataElementGroups )
203
 
        {
204
 
                list.add( new Option( dataElementGroups[id], id ), null );
205
 
        }
206
 
}
207
 
 
208
 
// ===============================================================================
209
 
// Get DataElements by Group
210
 
// ===============================================================================
211
 
 
212
 
function getDataElementsByGroup()
213
 
{               
214
 
        var request = new Request();
215
 
    request.setResponseTypeXML( 'xmlObject' );
216
 
    request.setCallbackSuccess( getDataElementsByGroupCompleted );
217
 
    var url = "../dhis-web-commons-ajax/getDataElements.action?id=" + byId("dataElementGroup").value;
218
 
        request.send( url );    
219
 
}
220
 
 
221
 
function getDataElementsByGroupCompleted( xmlObject ) {
222
 
 
223
 
        var dataElementList = byId( "availableDataElements" );
224
 
                
225
 
        dataElementList.options.length = 0;
226
 
        
227
 
        var dataelements = xmlObject.getElementsByTagName( "dataElement" );
228
 
        
229
 
        for ( var i = 0; i < dataelements.length; i++)
230
 
        {
231
 
                var id = dataelements[ i ].getElementsByTagName( "id" )[0].firstChild.nodeValue;
232
 
                var elementName = dataelements[ i ].getElementsByTagName( "name" )[0].firstChild.nodeValue;
233
 
                var option = new Option( elementName, id );
234
 
                option.onmousemove  = function(e){
235
 
                        showToolTip( e, this.text);
236
 
                }
237
 
                dataElementList.add( option, null );            
238
 
        }
239
 
}
240
 
 
241
 
// ===============================================================================
242
 
// Get OptionCombos by DataElement
243
 
// ===============================================================================
244
 
 
 
27
        
 
28
        showPopupWindowById( 'divExpression', 600, 300 );
 
29
}
 
30
 
 
31
// Get option combos for selected dataelement
245
32
function getOptionCombos() {
246
 
        
247
 
        var request = new Request();
248
 
    request.setResponseTypeXML( 'xmlObject' );
249
 
    request.setCallbackSuccess( getOptionCombosReceived);
250
 
        request.send( "getOptionCombos.action?dataElementId=" + byId("availableDataElements").value );  
251
 
}
252
 
 
253
 
function getOptionCombosReceived( xmlObject ) {
254
 
        
255
 
        xmlObject = xmlObject.getElementsByTagName('categoryOptions')[0];
256
 
        
257
 
        var optionComboList = byId( "optionCombos" );                   
258
 
        optionComboList.options.length = 0;
259
 
        var optionCombos = xmlObject.getElementsByTagName( "categoryOption" );
260
 
        
261
 
        for ( var i = 0; i < optionCombos.length; i++ )
262
 
        {
263
 
                var id = optionCombos[ i ].getAttribute('id');
264
 
                var name = optionCombos[ i ].firstChild.nodeValue;                      
265
 
                var option = document.createElement( "option" );
266
 
                option.value = id ;
267
 
                option.text = name;
268
 
                optionComboList.add( option, null );    
269
 
        }
270
 
}
271
 
 
272
 
// ===============================================================================
273
 
// Insert dataelement's id into the Formular textbox
274
 
// ===============================================================================
275
 
 
 
33
        loadCategoryOptionComboByDE( byId("availableDataElements").value, "#divExpression select[id=optionCombos]" );
 
34
}
 
35
 
 
36
// Insert operand into the Formular textbox
276
37
function insertDataElementId() {
277
38
 
278
39
        var dataElementComboId = "[" + byId("availableDataElements").value + "." + byId("optionCombos").value + "]";
279
40
        byId("formula").value += dataElementComboId;
280
41
}
281
42
 
282
 
// ===============================================================================
283
43
// Insert operators into the Formular textbox
284
 
// ===============================================================================
285
 
 
286
44
function insertOperation( target, value ) {
287
45
 
288
46
        byId( target ).value += value;
289
47
}
290
48
 
 
49
// Update expression for item
 
50
function updateNormalExpression()
 
51
{
 
52
        expression = jQuery( '#divExpression textarea[id=formula]' ).val();
 
53
        setFieldValue( 'expression', getFieldValue('formula' ) );
 
54
        hideById('divExpression'); 
 
55
        unLockScreen();
 
56
}
 
57
 
 
58
// -----------------------------------------------------------------------
 
59
// Open Expression Form for Catagory Excel-Item group
 
60
// -----------------------------------------------------------------------
 
61
 
 
62
// Open Expression Form
 
63
function caExpressionBuilderForm()
 
64
{
 
65
        loadDataElementGroups( "#divCategory select[id=dataElementGroup]" );
 
66
        loadAllDataElements( "#divCategory select[id=availableDataElements]" );
 
67
        
 
68
        setFieldValue( 'divCategory textarea[id=formula]', getFieldValue('expression') );
 
69
        showPopupWindowById( 'divCategory', 600, 320 );                         
 
70
}
 
71
 
 
72
// Insert operand into the Formular textbox
 
73
function insertExpression() 
 
74
{
 
75
        var expression = "[*." + getFieldValue("divCategory select[id=optionCombos]") + "]";
 
76
        setFieldValue( 'divCategory textarea[id=formula]', getFieldValue( 'divCategory textarea[id=formula]') + expression );   
 
77
}
 
78
 
 
79
// Update expression for item
 
80
function updateCaExpression()
 
81
{
 
82
        expression = jQuery( '#divCategory textarea[id=formula]' ).val();
 
83
        setFieldValue( 'expression', expression );
 
84
        hideById('divCategory'); 
 
85
        unLockScreen();
 
86
}
 
87
 
 
88
// Get option combos for selected dataelement
 
89
function getOptionCombos(id, target) {
 
90
        loadCategoryOptionComboByDE( id, target);
 
91
}
 
92
 
 
93
// -----------------------------------------------------------------------
 
94
// Get Dataelement by Group
 
95
// -----------------------------------------------------------------------
 
96
 
 
97
function getDataElements( id, target )
 
98
{
 
99
        loadDataElementsByGroup( id, target );
 
100
}
 
101
 
291
102
// -----------------------------------------------------------------------
292
103
// SAVE COPY EXCEL ITEM(s) TO EXCEL_ITEM_GROUP
293
104
// -----------------------------------------------------------------------
322
133
                options.add(new Option(name,id), null);
323
134
        }
324
135
        
325
 
        $("#copyTo").showAtCenter( true );
 
136
        showPopupWindowById( 'copyTo', 450, 110 );
326
137
}
327
138
 
328
139
function validateCopyExcelItemsToExcelItemGroup() {
463
274
                setMessage( warningMessages );
464
275
        }
465
276
                
466
 
        hideById("copyTo");
467
 
        deleteDivEffect();
 
277
        hideById('copyTo'); 
 
278
        unLockScreen();
468
279
}
469
280
 
470
281
function saveCopiedExcelItemsToExcelItemGroupReceived( data ) {