~dhis2-devs-core/dhis2/dhis2-ccei-2.18

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroupEditorView.js

  • Committer: Tran Chau
  • Date: 2015-04-10 09:14:23 UTC
  • Revision ID: tran.hispvietnam@gmail.com-20150410091423-3te5dqij63s37c4n
Fixed bug - Exception thrown when to update Data Element Group Member in Data Element Group Editor form, View 1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
        {
29
29
                        if( !checkSelectedDataElement( id ) )
30
30
                        {
31
 
                                list_1.append( '<option value="' + id + '">' + text + '</option>' );
 
31
                                list_1.append( '<option value="' + id + '" title="' + text + '">' + text + '</option>' );
32
32
                        }
33
33
                }
34
34
                
35
35
                if ( text.toLowerCase().indexOf( filter_2.toLowerCase() ) != -1 )
36
36
        {
37
 
                        list_2.append( '<option value="' + id + '">' + text + '</option>' );
 
37
                        list_2.append( '<option value="' + id + '" title="' + text + '">' + text + '</option>' );
38
38
                }
39
39
    }
40
40
 
83
83
 
84
84
        if ( text.toLowerCase().indexOf( filter_1.toLowerCase() ) != -1 )
85
85
        {
86
 
            list_1.append( '<option value="' + id + '">' + text + '</option>' );
87
 
            list_2.append( '<option value="' + id + '">' + text + '</option>' );
 
86
            list_1.append( '<option value="' + id + '" title="' + text + '">' + text + '</option>' );
 
87
            list_2.append( '<option value="' + id + '" title="' + text + '">' + text + '</option>' );
88
88
        }
89
89
    }
90
90
 
124
124
            var text = item.name;
125
125
            if ( text.toLowerCase().indexOf( filter_1.toLowerCase() ) != -1 )
126
126
            {
127
 
                list_1.append( '<option value="' + item.id + '">' + text + '</option>' );
 
127
                list_1.append( '<option value="' + item.uid + '" title="' + text + '">' + text + '</option>' );
128
128
            }
129
129
            jQuery( "#view_1 #availableDataElements" ).children().each( function( k, it )
130
130
            {
131
 
                if ( item.id == it.value )
 
131
                if ( item.uid == it.value )
132
132
                {
133
133
                    jQuery( it ).remove();
134
134
                }
140
140
function showAddGroup()
141
141
{
142
142
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'title', i18n_new );
 
143
        jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'width', '350px' );
 
144
        jQuery( '#addDataElementGroupForm #shortName' ).closest('tr').show();
 
145
        jQuery( '#addDataElementGroupForm #code' ).closest('tr').show();
 
146
                        
143
147
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'buttons', [ {
144
148
        text : i18n_save,
145
149
        click : function()
146
150
        {
147
 
            jQuery.postJSON( "validateDataElementGroup.action", {
148
 
                name : function()
149
 
                {
150
 
                    return jQuery( '#addDataElementGroupForm #name' ).val();
151
 
                }
152
 
            }, function( json )
153
 
            {
154
 
                if ( json.response == 'success' )
155
 
                {
156
 
                    jQuery.postJSON( "addDataElementGroupEditor.action", {
157
 
                        name : function()
158
 
                        {
159
 
                            return jQuery( '#addDataElementGroupForm #name' ).val();
160
 
                        }
161
 
                    }, function( json )
162
 
                    {
163
 
                        dataElementGroups[json.dataElementGroup.id] = json.dataElementGroup.name;
164
 
                        loadAvailableGroups();
165
 
                        loadAvailableDataElements();
166
 
                        jQuery( "#view_1 #selectedDataElements" ).empty();
167
 
                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
168
 
                    } );
169
 
                } else
170
 
                {
171
 
                    markInvalid( "addDataElementGroupForm #name", json.message );
172
 
                }
173
 
            } );
 
151
                        if( jQuery( '#addDataElementGroupForm #name' ).val() == "" ){
 
152
                                markValid( "addDataElementGroupForm #shortName" );
 
153
                                markInvalid( "addDataElementGroupForm #name", i18n_this_field_is_required );
 
154
                        }
 
155
                        else if( jQuery( '#addDataElementGroupForm #shortName' ).val() == "" ){
 
156
                                markValid( "addDataElementGroupForm #name" );
 
157
                                markInvalid( "addDataElementGroupForm #shortName", i18n_this_field_is_required );
 
158
                        }
 
159
                        else
 
160
                        {
 
161
                                jQuery.postJSON( "validateDataElementGroup.action", {
 
162
                                        name : jQuery( '#addDataElementGroupForm #name' ).val()
 
163
                                        ,shortName : jQuery( '#addDataElementGroupForm #shortName' ).val()
 
164
                                        ,code : jQuery( '#addDataElementGroupForm #code' ).val()
 
165
                                }, function( json )
 
166
                                {
 
167
                                        if ( json.response == 'success' )
 
168
                                        {
 
169
                                                markValid( "addDataElementGroupForm #name" );                           
 
170
                                                markValid( "addDataElementGroupForm #shortName" );
 
171
                                
 
172
                                                jQuery.postJSON( "addDataElementGroupEditor.action", {
 
173
                                                        name : jQuery( '#addDataElementGroupForm #name' ).val(),
 
174
                                                        shortName : jQuery( '#addDataElementGroupForm #shortName' ).val(),
 
175
                                                        code : jQuery( '#addDataElementGroupForm #code' ).val()
 
176
                                                }, function( json )
 
177
                                                {
 
178
                                                        var id = json.dataElementGroup.id;
 
179
                                                        dataElementGroups[id] = json.dataElementGroup.name;
 
180
                                                        dataElementGroupShortNames[id] = json.dataElementGroup.name;
 
181
                                                        dataElementGroupCodes[id] = json.dataElementGroup.shortName;
 
182
                                                        loadAvailableGroups();
 
183
                                                        jQuery( "#view_1 #selectedDataElements" ).empty();
 
184
                                                        $("#dataElementGroups option:contains('" + jQuery( '#addDataElementGroupForm #name' ).val() + "')").attr("selected",true);
 
185
                                                        loadAvailableDataElements();
 
186
                                                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
 
187
                                                } );
 
188
                                        } else
 
189
                                        {
 
190
                                                markInvalid( "addDataElementGroupForm #name", json.message );
 
191
                                        }
 
192
                                } );
 
193
                        }
174
194
        }
175
195
    } ] );
176
196
 
180
200
function showAddGroupView2()
181
201
{
182
202
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'title', i18n_new );
 
203
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'width', '350px' );
183
204
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'buttons', [ {
184
205
        text : i18n_save,
185
206
        click : function()
186
207
        {
187
 
            jQuery.postJSON( "validateDataElementGroup.action", {
188
 
                name : function()
189
 
                {
190
 
                    return jQuery( '#addDataElementGroupForm #name' ).val();
191
 
                }
192
 
            }, function( json )
193
 
            {
194
 
                if ( json.response == 'success' )
195
 
                {
196
 
                    jQuery.postJSON( "addDataElementGroupEditor.action", {
197
 
                        name : function()
198
 
                        {
199
 
                            return jQuery( '#addDataElementGroupForm #name' ).val();
200
 
                        }
201
 
                    }, function( json )
202
 
                    {
203
 
                        dataElementGroups[json.dataElementGroup.id] = json.dataElementGroup.name;
204
 
                        loadAvailableGroups();
205
 
                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
206
 
                    } );
207
 
                } else
208
 
                {
209
 
                    markInvalid( "addDataElementGroupForm #name", json.message );
210
 
                }
211
 
            } );
 
208
                        if( jQuery( '#addDataElementGroupForm #name' ).val() == "" ){
 
209
                                markValid( "addDataElementGroupForm #shortName" );
 
210
                                markInvalid( "addDataElementGroupForm #name", i18n_this_field_is_required );
 
211
                        }
 
212
                        else if( jQuery( '#addDataElementGroupForm #shortName' ).val() == "" ){
 
213
                                markValid( "addDataElementGroupForm #name" );
 
214
                                markInvalid( "addDataElementGroupForm #shortName", i18n_this_field_is_required );
 
215
                        }
 
216
                        else
 
217
                        {
 
218
                                jQuery.postJSON( "validateDataElementGroup.action", {
 
219
                                        name : jQuery( '#addDataElementGroupForm #name' ).val(),
 
220
                                        shortName : jQuery( '#addDataElementGroupForm #shortName' ).val(),
 
221
                                        code : jQuery( '#addDataElementGroupForm #code' ).val()
 
222
                                }, function( json )
 
223
                                {
 
224
                                        if ( json.response == 'success' )
 
225
                                        {
 
226
                                                jQuery.postJSON( "addDataElementGroupEditor.action", {
 
227
                                                        name : jQuery( '#addDataElementGroupForm #name' ).val(),
 
228
                                                        shortName : jQuery( '#addDataElementGroupForm #shortName' ).val(),
 
229
                                                        code : jQuery( '#addDataElementGroupForm #code' ).val()
 
230
                                                }, function( json )
 
231
                                                {
 
232
                                                        dataElementGroups[json.dataElementGroup.id] = json.dataElementGroup.name;
 
233
                                                        loadAvailableGroups();
 
234
                                                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
 
235
                                                } );
 
236
                                        } else
 
237
                                        {
 
238
                                                markInvalid( "addDataElementGroupForm #name", json.message );
 
239
                                        }
 
240
                                } );
 
241
                        }
212
242
        }
213
243
    } ] );
214
244
    jQuery( '#addDataElementGroupForm' ).dialog( 'open' );
218
248
{
219
249
    var id = jQuery( "#view_1 #dataElementGroups" ).val();
220
250
    var text = jQuery( "#view_1 #dataElementGroups option[value=" + id + "]" ).text();
 
251
        
221
252
    jQuery( '#addDataElementGroupForm #name' ).val( text );
 
253
    jQuery( '#addDataElementGroupForm #shortName' ).closest('tr').hide();
 
254
    jQuery( '#addDataElementGroupForm #code' ).closest('tr').hide();
222
255
 
223
256
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'buttons', [ {
224
257
        text : i18n_save,
225
258
        click : function()
226
259
        {
227
 
            jQuery.postJSON( "validateDataElementGroup.action", {
228
 
                id : id,
229
 
                name : function()
230
 
                {
231
 
                    return jQuery( '#addDataElementGroupForm #name' ).val();
232
 
                }
233
 
            }, function( json )
234
 
            {
235
 
                if ( json.response == 'success' )
236
 
                {
237
 
                    jQuery.postJSON( "renameDataElementGroupEditor.action", {
238
 
                        name : function()
239
 
                        {
240
 
                            return jQuery( '#addDataElementGroupForm #name' ).val();
241
 
                        },
242
 
                        id : id
243
 
                    }, function( json )
244
 
                    {
245
 
                        dataElementGroups[json.dataElementGroup.id] = json.dataElementGroup.name;
246
 
                        loadAvailableGroups();
247
 
                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
248
 
                        setHeaderDelayMessage( i18n_update_success );
249
 
                    } );
250
 
                } else
251
 
                {
252
 
                    markInvalid( "addDataElementGroupForm #name", json.message );
253
 
                }
254
 
            } );
 
260
                        if( jQuery( '#addDataElementGroupForm #name' ).val() == "" ){
 
261
                                markInvalid( "addDataElementGroupForm #name", i18n_this_field_is_required );
 
262
                        }
 
263
                        else
 
264
                        {
 
265
                                jQuery.postJSON( "validateDataElementGroup.action", {
 
266
                                        id : id,
 
267
                                        name :jQuery( '#addDataElementGroupForm #name' ).val()
 
268
                                }, function( json )
 
269
                                {
 
270
                                        if ( json.response == 'success' )
 
271
                                        {
 
272
                                                markValid( "addDataElementGroupForm #name" );
 
273
                                
 
274
                                                jQuery.postJSON( "renameDataElementGroupEditor.action", {
 
275
                                                        name : function()
 
276
                                                        {
 
277
                                                                return jQuery( '#addDataElementGroupForm #name' ).val();
 
278
                                                        },
 
279
                                                        id : id
 
280
                                                }, function( json )
 
281
                                                {
 
282
                                                        dataElementGroups[json.dataElementGroup.id] = json.dataElementGroup.name;
 
283
                                                        loadAvailableGroups();
 
284
                                                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
 
285
                                                        setHeaderDelayMessage( i18n_update_success );
 
286
                                                } );
 
287
                                        } else
 
288
                                        {
 
289
                                                markInvalid( "addDataElementGroupForm #name", json.message );
 
290
                                        }
 
291
                                } );
 
292
                        }
255
293
        }
256
294
    } ] );
257
295
 
258
296
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'title', i18n_rename );
 
297
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'width', '350px' );
259
298
    jQuery( '#addDataElementGroupForm' ).dialog( 'open' );
260
299
}
261
300
 
262
301
function showUpdateGroup2()
263
302
{
264
 
    var id = jQuery( "#view_2 #availableGroups" ).val();
 
303
    var id = jQuery( "#view_2 #availableGroups option:selected" ).val();
265
304
    var text = jQuery( "#view_2 #availableGroups option[value=" + id + "]" ).text();
266
305
    jQuery( '#addDataElementGroupForm #name' ).val( text );
267
306
 
 
307
    jQuery( '#addDataElementGroupForm #shortName' ).closest('tr').hide();
 
308
    jQuery( '#addDataElementGroupForm #code' ).closest('tr').hide();
 
309
        
268
310
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'buttons', [ {
269
311
        text : i18n_save,
270
312
        click : function()
271
313
        {
272
 
 
273
 
            jQuery.postJSON( "validateDataElementGroup.action", {
274
 
                id : id,
275
 
                name : function()
276
 
                {
277
 
                    return jQuery( '#addDataElementGroupForm #name' ).val();
278
 
                }
279
 
            }, function( json )
280
 
            {
281
 
                if ( json.response == 'success' )
282
 
                {
283
 
                    jQuery.postJSON( "renameDataElementGroupEditor.action", {
284
 
                        name : function()
285
 
                        {
286
 
                            return jQuery( '#addDataElementGroupForm #name' ).val();
287
 
                        },
288
 
                        id : id
289
 
                    }, function( json )
290
 
                    {
291
 
                        dataElementGroups[json.dataElementGroup.id] = json.dataElementGroup.name;
292
 
                        loadAvailableGroups();
293
 
                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
294
 
                        setHeaderDelayMessage( i18n_update_success );
295
 
                    } );
296
 
                } else
297
 
                {
298
 
                    markInvalid( "addDataElementGroupForm #name", json.message );
299
 
                }
300
 
            } );
 
314
                        if( jQuery( '#addDataElementGroupForm #name' ).val() == "" ){
 
315
                                markInvalid( "addDataElementGroupForm #name", i18n_this_field_is_required );
 
316
                        }
 
317
                        else
 
318
                        {
 
319
                                jQuery.postJSON( "validateDataElementGroup.action", {
 
320
                                        id : id,
 
321
                                        name : jQuery( '#addDataElementGroupForm #name' ).val()
 
322
                                }, function( json )
 
323
                                {
 
324
                                        if ( json.response == 'success' )
 
325
                                        {
 
326
                                                markValid( "addDataElementGroupForm #name" );
 
327
                                
 
328
                                                jQuery.postJSON( "renameDataElementGroupEditor.action", {
 
329
                                                        name :jQuery( '#addDataElementGroupForm #name' ).val(),
 
330
                                                        id : id
 
331
                                                }, function( json )
 
332
                                                {
 
333
                                                        dataElementGroups[json.dataElementGroup.id] = json.dataElementGroup.name;
 
334
                                                        loadAvailableGroups();
 
335
                                                        jQuery( '#addDataElementGroupForm' ).dialog( 'close' );
 
336
                                                        setHeaderDelayMessage( i18n_update_success );
 
337
                                                } );
 
338
                                        } else
 
339
                                        {
 
340
                                                markInvalid( "addDataElementGroupForm #name", json.message );
 
341
                                        }
 
342
                                } );
 
343
                        }
301
344
        }
302
345
    } ] );
303
346
 
304
347
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'title', i18n_rename );
 
348
    jQuery( '#addDataElementGroupForm' ).dialog( 'option', 'width', '350px' );
305
349
    jQuery( '#addDataElementGroupForm' ).dialog( 'open' );
306
350
}
307
351
 
318
362
            if ( json.response == 'success' )
319
363
            {
320
364
                dataElementGroups.splice( id, 1 );
 
365
                                clearListById('view_1 #selectedDataElements');
321
366
                loadAvailableGroups();
322
367
                setHeaderDelayMessage( json.message );
323
368
            } else
354
399
function updateGroupMembers()
355
400
{
356
401
    var id = jQuery( "#view_1 #dataElementGroups" ).val();
 
402
        var name = dataElementGroups[id];
 
403
        var shortName = dataElementGroupShortNames[id];
 
404
        var code = dataElementGroupCodes[id];
357
405
 
358
 
    jQuery.getJSON( "updateDataElementGroupEditor.action?id=" + id + "&"
359
 
            + toQueryString( '#view_1 #selectedDataElements', 'groupMembers' ), function( json )
 
406
    jQuery.getJSON( "updateDataElementGroupEditor.action?id=" + id
 
407
                        + "&name=" + name + "&shortName=" + shortName + "&code=" + code + "&"
 
408
            + toQueryString( '#view_1 #selectedDataElements', 'deSelected' ), function( json )
360
409
    {
361
410
        setHeaderDelayMessage( i18n_update_success );
362
411
    } );
390
439
        
391
440
        jQuery.each( json.dataElementGroups, function( i, item )
392
441
        {
393
 
            list_2.append( '<option value="' + item.id + '">' + item.name + '</option>' );
 
442
            list_2.append( '<option value="' + item.id + '" title="' + item.name + '">' + item.name + '</option>' );
394
443
 
395
444
            jQuery( "#view_2 #availableGroups" ).children().each( function( k, it )
396
445
            {