dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25334
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12540: more small js fixes, replaced a couple of for-loops with $.each and take advantage of having item...
------------------------------------------------------------
revno: 12540
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-10-09 22:17:14 +0200
message:
more small js fixes, replaced a couple of for-loops with $.each and take advantage of having item scoped to this
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-10-09 20:04:17 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-10-09 20:17:14 +0000
@@ -461,7 +461,7 @@
hideById( 'listDiv' );
$( '#searchingAttributeIdTD [id=searchObjectId] option' ).remove();
$( '#advancedSearchTB [id=searchObjectId] option' ).remove();
- programStageId = $( '#programId option:selected' ).attr( 'psid' );
+ var programStageId = $( '#programId option:selected' ).attr( 'psid' );
setFieldValue( 'programStageId', programStageId );
setInnerHTML( 'reportDateDescriptionField', $( '#programId option:selected' ).attr( 'reportDateDes' ) );
setInnerHTML( 'reportDateDescriptionField2', $( '#programId option:selected' ).attr( 'reportDateDes' ) );
@@ -477,61 +477,59 @@
return;
}
- $.getJSON( "getProgramStageDataElementList.action",
- {
- programStageId: getFieldValue( 'programStageId' )
- },
- function ( json ) {
- $( '#advancedSearchTB [name=searchText]' ).val( '' );
- $( '.stage-object-selected' ).attr( 'psid', $( '#programId option:selected' ).attr( "psid" ) );
-
- clearListById( 'searchObjectId' );
- clearListById( 'displayInReports' );
-
- $('[name=searchObjectId]').append('<option value="" >[' + i18n_please_select + ']</option>');
- for( i in json.programStageDataElements ) {
- $('[name=searchObjectId]').append('<option value="' + json.programStageDataElements[i].id + '" uid="' + json.programStageDataElements[i].uid + '" type="' + json.programStageDataElements[i].type + '">' + json.programStageDataElements[i].name + '</option>');
-
- if( json.programStageDataElements[i].displayInReports == 'true' ) {
- $('#displayInReports').append('<option value="' + json.programStageDataElements[i].id + '" uid="' + json.programStageDataElements[i].uid + '" ></option>');
- }
+ $.getJSON( "getProgramStageDataElementList.action", {
+ programStageId: getFieldValue( 'programStageId' )
+ }, function ( json ) {
+ $( '#advancedSearchTB [name=searchText]' ).val( '' );
+ $( '.stage-object-selected' ).attr( 'psid', $( '#programId option:selected' ).attr( "psid" ) );
+
+ clearListById( 'searchObjectId' );
+ clearListById( 'displayInReports' );
+
+ $('[name=searchObjectId]').append('<option value="" >[' + i18n_please_select + ']</option>');
+
+ $.each(json.programStageDataElements, function() {
+ $('[name=searchObjectId]').append('<option value="' + this.id + '" uid="' + this.uid + '" type="' + this.type + '">' + this.name + '</option>');
+
+ if( this.displayInReports == 'true' ) {
+ $('#displayInReports').append('<option value="' + this.id + '" uid="' + this.uid + '" ></option>');
}
-
- enableCriteriaDiv();
- validateSearchEvents( true );
- } ).fail(function() {
- enable( 'addBtn' );
});
+ enableCriteriaDiv();
+ validateSearchEvents( true );
+ } ).fail(function() {
+ enable( 'addBtn' );
+ });
+
updateOfflineEvents();
}
function dataElementOnChange( this_ ) {
- var container = $( this_ ).parent().parent().attr( 'id' );
- var element = $( '#' + container + ' [id=searchText]' );
- var valueType = $( '#' + container + ' [id=searchObjectId] option:selected' ).attr( 'type' );
+ var container = $(this_).parent().parent().attr('id');
+ var element = $('#' + container + ' [id=searchText]');
+ var valueType = $('#' + container + ' [id=searchObjectId] option:selected').attr('type');
- if ( valueType == 'date' ) {
- element.replaceWith( getDateField( container ) );
- datePickerValid( 'searchText_' + container );
- return;
+ if( valueType == 'date' ) {
+ element.replaceWith(getDateField(container));
+ datePickerValid('searchText_' + container);
}
else {
- $( '#searchText_' + container ).datepicker( "destroy" );
- $( '#' + container + ' [id=dateOperator]' ).replaceWith( "" );
+ $('#searchText_' + container).datepicker("destroy");
+ $('#' + container + ' [id=dateOperator]').replaceWith("");
- if ( valueType == 'bool' ) {
- element.replaceWith( getTrueFalseBox() );
- }
- else if ( valueType == 'optionset' ) {
- element.replaceWith( searchTextBox );
- autocompletedFilterField( container + " [id=searchText]", $(this_).find("option:selected").attr('uid') );
- }
- else if ( valueType == 'username' ) {
- autocompletedUsernameField( $( this_ ).attr( 'id' ) );
+ if( valueType == 'bool' ) {
+ element.replaceWith(getTrueFalseBox());
+ }
+ else if( valueType == 'optionset' ) {
+ element.replaceWith(searchTextBox);
+ autocompletedFilterField(container + " [id=searchText]", $(this_).find("option:selected").attr('uid'));
+ }
+ else if( valueType == 'username' ) {
+ autocompletedUsernameField($(this_).attr('id'));
}
else {
- element.replaceWith( searchTextBox );
+ element.replaceWith(searchTextBox);
}
}
}
@@ -620,7 +618,6 @@
}
} );
},
- minLength: 0,
select: function ( event, ui ) {
var fieldValue = ui.item.value;
@@ -826,24 +823,20 @@
if ( value.indexOf( '"' ) != value.lastIndexOf( '"' ) ) {
value = value.replace( /"/g, "'" );
}
- // if key is [xyz] && [=xyz]
- if ( value.indexOf( "'" ) == -1 ) {
- var flag = value.match( /[>|>=|<|<=|=|!=]+[ ]*/ );
-
- if ( flag == null ) {
+
+ var flag = value.match( /[>|>=|<|<=|=|!=]+[ ]*/ );
+
+ if( value.indexOf("'") == -1 ) {
+ if( flag == null ) {
value = "='" + value + "'";
}
else {
- value = value.replace( flag, flag + "'" );
+ value = value.replace(flag, flag + "'");
value += "'";
}
}
- // if key is ['xyz'] && [='xyz']
- // if( value.indexOf("'") != value.lastIndexOf("'") )
else {
- var flag = value.match( /[>|>=|<|<=|=|!=]+[ ]*/ );
-
- if ( flag == null ) {
+ if( flag == null ) {
value = "=" + value;
}
}
@@ -975,19 +968,21 @@
function removeAllOption() {
enable( 'filterBtn' );
- $( '#advancedSearchTB tr' ).each( function ( i, row ) {
- if ( i > 2 ) {
- $( this ).remove();
+
+ $( '#advancedSearchTB tr' ).each( function ( idx ) {
+ if( idx > 2 ) {
+ $(this).remove();
}
- else if ( i == 2 ) {
- $( this ).find( ':input' ).each( function ( idx, item ) {
- var input = $( item );
- if ( input.attr( 'type' ) != 'button' ) {
- input.val( '' );
+ else if( idx == 2 ) {
+ $(this).find(':input').each(function( idx, item ) {
+ var input = $(item);
+ if( input.attr('type') != 'button' ) {
+ input.val('');
}
- } );
+ });
}
} );
+
$( '#searchObjectId' ).val( "" );
$( '#searchText' ).val( "" );
searchEvents( eval( getFieldValue( "listAll" ) ) );