← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3130: Fix bug: Many program stages into a program can use one data-entry-form.

 

------------------------------------------------------------
revno: 3130
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-03-23 09:10:08 +0700
message:
  Fix bug: Many program stages into a program can use one data-entry-form.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SaveDataEntryFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStageList.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm


--
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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java	2010-11-21 15:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java	2011-03-23 02:10:08 +0000
@@ -126,7 +126,7 @@
         Session session = sessionFactory.getCurrentSession();
 
         Criteria criteria = session.createCriteria( ProgramStage.class );
-        criteria.add( Restrictions.in( "id", programStageIds ) );
+        criteria.add( Restrictions.in( "id", programStageIds ) ).add( Restrictions.isNotNull( "dataEntryForm" ) );
         criteria.setProjection( Projections.groupProperty( "dataEntryForm" ) );
 
         return criteria.list();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SaveDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SaveDataEntryFormAction.java	2010-11-21 15:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SaveDataEntryFormAction.java	2011-03-23 02:10:08 +0000
@@ -71,13 +71,6 @@
     // Getters & Setters
     // -------------------------------------------------------------------------
 
-    private int associationIdField;
-
-    public void setAssociationIdField( int associationIdField )
-    {
-        this.associationIdField = associationIdField;
-    }
-
     private String name;
 
     public void setName( String name )
@@ -92,18 +85,27 @@
         this.designTextarea = designTextarea;
     }
 
+    private Integer programId;
+    
+    public Integer getProgramId()
+    {
+        return programId;
+    }
+
     private Integer programStageId;
 
-    public Integer getProgramStageId()
-    {
-        return programStageId;
-    }
-
     public void setProgramStageId( Integer programStageId )
     {
         this.programStageId = programStageId;
     }
 
+    private Integer dataEntryFormId;
+
+    public void setDataEntryFormId( Integer dataEntryFormId )
+    {
+        this.dataEntryFormId = dataEntryFormId;
+    }
+
     // -------------------------------------------------------------------------
     // Execute
     // -------------------------------------------------------------------------
@@ -111,26 +113,52 @@
     public String execute()
         throws Exception
     {
-        ProgramStage association = programStageService.getProgramStage( associationIdField );
-        
-        DataEntryForm dataEntryForm = association.getDataEntryForm();
+        ProgramStage programStage = programStageService.getProgramStage( programStageId );
+        
+        programId = programStage.getProgram().getId();
+        
+        DataEntryForm dataEntryForm = null;
+
+        // ---------------------------------------------------------------------
+        // Get data-entry-form
+        // ---------------------------------------------------------------------
+
+        if ( dataEntryFormId == null )
+        {
+            dataEntryForm = programStage.getDataEntryForm();
+        }
+        else
+        {
+            dataEntryForm = dataEntryFormService.getDataEntryForm( dataEntryFormId );
+        }
+
+        // ---------------------------------------------------------------------
+        // Save data-entry-form
+        // ---------------------------------------------------------------------
 
         if ( dataEntryForm == null )
         {
             dataEntryForm = new DataEntryForm( name, prepareDataEntryFormCode( designTextarea ) );
-            association.setDataEntryForm( dataEntryForm );
-            programStageService.updateProgramStage( association );
+            programStage.setDataEntryForm( dataEntryForm );
+            programStageService.updateProgramStage( programStage );
         }
         else
         {
             dataEntryForm.setName( name );
             dataEntryForm.setHtmlCode( prepareDataEntryFormCode( designTextarea ) );
-            dataEntryFormService.updateDataEntryForm( dataEntryForm );
+            //dataEntryFormService.updateDataEntryForm( dataEntryForm );
+            
+            programStage.setDataEntryForm( dataEntryForm );
+            programStageService.updateProgramStage( programStage );
         }
 
         return SUCCESS;
     }
-
+    
+    // -------------------------------------------------------------------------
+    // Support methods
+    // -------------------------------------------------------------------------
+    
     private String prepareDataEntryFormCode( String dataEntryFormCode )
     {
         String preparedCode = dataEntryFormCode;
@@ -206,9 +234,9 @@
             result = matDataElement.find();
         }
 
-        // -----------------------------------------------------------------
+        // ---------------------------------------------------------------------
         // Add remaining code (after the last match), and return formatted code.
-        // -----------------------------------------------------------------
+        // ---------------------------------------------------------------------
 
         matDataElement.appendTail( sb );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java	2010-10-14 08:14:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java	2011-03-23 02:10:08 +0000
@@ -101,20 +101,8 @@
     // Getters & Setters
     // -------------------------------------------------------------------------
 
-    private int associationId;
-
-    public void setAssociationId( int associationId )
-    {
-        this.associationId = associationId;
-    }
-
     private Integer programStageId;
 
-    public Integer getProgramStageId()
-    {
-        return programStageId;
-    }
-
     public void setProgramStageId( Integer programStageId )
     {
         this.programStageId = programStageId;
@@ -127,11 +115,11 @@
         return dataEntryForm;
     }
 
-    private ProgramStage association;
+    private ProgramStage programStage;
 
-    public ProgramStage getAssociation()
+    public ProgramStage getProgramStage()
     {
-        return association;
+        return programStage;
     }
 
     private List<DataEntryForm> existingDataEntryForms;
@@ -162,13 +150,24 @@
     public String execute()
         throws Exception
     {
-        association = programStageService.getProgramStage( associationId );
-
-        dataEntryForm = association.getDataEntryForm();
+        programStage = programStageService.getProgramStage( programStageId );
+
+        // ---------------------------------------------------------------------
+        // Get dataEntryForm of selected program-stage
+        // ---------------------------------------------------------------------
+
+        dataEntryForm = programStage.getDataEntryForm();
+        
+        editorManager.setValue( dataEntryForm == null ? "" : dataEntryManager.prepareDataEntryFormCode( dataEntryForm
+            .getHtmlCode() ) );
+        
+        // ---------------------------------------------------------------------
+        // Get existing Data Entry Forms
+        // ---------------------------------------------------------------------
 
         List<Integer> listAssociationIds = new ArrayList<Integer>();
 
-        for ( ProgramStage ps : association.getProgram().getProgramStages() )
+        for ( ProgramStage ps : programStage.getProgram().getProgramStages() )
         {
             listAssociationIds.add( ps.getId() );
         }
@@ -176,19 +175,24 @@
         existingDataEntryForms = new ArrayList<DataEntryForm>( dataEntryFormService
             .listDisctinctDataEntryFormByProgramStageIds( listAssociationIds ) );
 
-        editorManager.setValue( dataEntryForm == null ? "" : dataEntryManager.prepareDataEntryFormCode( dataEntryForm
-            .getHtmlCode() ) );
-
-        existingDataEntryForms.remove( dataEntryForm );
-
-        dataElements = new ArrayList<DataElement>( programStageDataElementService.getListDataElement( association ) );
+        existingDataEntryForms.remove( dataEntryForm );     
+        
+        // ---------------------------------------------------------------------
+        // Get data-elements into selected program-stage
+        // ---------------------------------------------------------------------
+
+        dataElements = new ArrayList<DataElement>( programStageDataElementService.getListDataElement( programStage ) );
 
         Collections.sort( dataElements, new DataElementNameComparator() );
-        
-        programStages = new ArrayList<ProgramStage>( association.getProgram().getProgramStages() );
-        
-        programStages.remove( association );
-        
+
+        // ---------------------------------------------------------------------
+        // Get other program-stages into the program
+        // ---------------------------------------------------------------------
+
+        programStages = new ArrayList<ProgramStage>( programStage.getProgram().getProgramStages() );
+
+        programStages.remove( programStage );
+
         Collections.sort( programStages, new ProgramStageNameComparator() );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2011-02-16 02:55:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2011-03-23 02:10:08 +0000
@@ -855,17 +855,18 @@
 		<action name="viewDataEntryForm"
 			class="org.hisp.dhis.patient.action.dataentryform.ViewDataEntryFormAction">
 			<result name="success" type="velocity">/main.vm</result>
-			<param name="page">/dhis-web-maintenance-patient/viewDataEntryForm.vm</param>			
+			<param name="page">/dhis-web-maintenance-patient/viewDataEntryForm.vm</param>	
+			<param name="javascripts">javascript/viewDataEntryForm.js</param>		
 		</action>
 
 		<action name="saveDataEntryForm"
 			class="org.hisp.dhis.patient.action.dataentryform.SaveDataEntryFormAction">
-			<result name="success" type="redirect">programStage.action?id=${programStageId}</result>
+			<result name="success" type="redirect">programStage.action?id=${programId}</result>
 		</action>
 
 		<action name="delDataEntryForm"
 			class="org.hisp.dhis.patient.action.dataentryform.DelDataEntryFormAction">
-			<result name="success" type="redirect">programStage.action?id=${programStageId}</result>			
+			<result name="success" type="redirect">programStage.action?id=${programId}</result>			
 		</action>
 
 		<action name="validateDataEntryForm"

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	2011-03-23 02:10:08 +0000
@@ -0,0 +1,273 @@
+
+var dataElementSelector;
+var otherProgramStageDataElements;
+var existedDataEntry;
+
+jQuery(function(){
+	dataElementSelector = jQuery("#dataElementSelection").dialog({
+		title: "$i18n.getString( 'dataelement' )",
+		minWidth: 650,
+		minHeight: 250,
+		width:650,
+		autoOpen: false,
+		zIndex:99999
+	});
+	
+	otherProgramStageDataElements = jQuery("#otherProgramStageDataElements").dialog({
+		title: "$i18n.getString( 'dataelement_of_orther_program_stage' )",
+		minWidth: 650,
+		minHeight: 250,
+		width:650,
+		autoOpen: false,
+		zIndex:99999
+	});
+	
+	existedDataEntry = jQuery("#existedDataEntry").dialog({
+		title: i18n_choose_existing_dataentry,
+		minWidth: 400,
+		minHeight: 80,
+		width:400,
+		autoOpen: false,
+		zIndex:99999
+	});	
+});
+
+function openOtherProgramStageDataElements()
+{
+	otherProgramStageDataElements.dialog("open");
+}
+	
+function openDataElementSelector()
+{
+	dataElementSelector.dialog("open");
+}	
+
+function openloadExistedForm()
+{
+	existedDataEntry.dialog("open");
+}
+
+function loadExistedForm()
+{
+	jQuery.post("showDataEntryForm.action",{
+		dataEntryFormId: getFieldValue( 'existedDataEntryId' )
+	}, function( html ){
+		FCKeditorAPI.GetInstance('designTextarea').SetHTML( html );
+		
+		var dataEntryFormField = byId('existedDataEntryId');
+		var optionField = dataEntryFormField.options[dataEntryFormField.selectedIndex];
+		setFieldValue('dataEntryFormId', optionField.value );
+		setFieldValue('name', optionField.text );
+		
+		checkValueIsExist('name', 'validateDataEntryForm.action', {dataEntryFormId:getFieldValue('dataEntryFormId')});
+	});
+}
+
+function deleteDataEntryForm( associationId )
+{
+	if( window.confirm( i18n_delete_confirm ) )
+	{
+		window.location = 'delDataEntryForm.action?associationId=' + associationId;
+	}
+}
+
+function getProgramStageDataElements( id )
+{
+	var dataElements = jQuery( "#otherProgramStageDataElements #dataElementIds" );
+	dataElements.empty();
+	var dataElementIdsStore = jQuery( "#otherProgramStageDataElements #dataElementIdsStore" );
+	dataElementIdsStore.empty();
+	
+	jQuery( "#otherProgramStageDataElements #optionComboIds" ).empty();
+	if( id != '' ){
+		jQuery.post("getSelectedDataElements.action",{
+			associationId: id
+		}, function( xml ){			
+			jQuery( xml ).find( 'dataElement' ).each( function(i, item ){			
+				dataElements.append("<option value='" + jQuery( item ).find( "json" ).text() + "'>" + jQuery( item ).find( "name" ).text() + "</option>");
+				dataElementIdsStore.append("<option value='" + jQuery( item ).find( "json" ).text() + "'>" + jQuery( item ).find( "name" ).text() + "</option>");
+			});
+		});
+	}
+}
+
+
+function getOptionCombos( dataElement, target )
+{
+	var dataElement = JSON.parse( dataElement );
+	
+	var optionCombo = jQuery( target );
+	
+	if( dataElement.type=='string' ){
+		optionCombo.attr("multiple", "multiple" );
+	}else{
+		optionCombo.removeAttr( "multiple" );
+	}
+	
+	jQuery.postJSON("../dhis-web-commons-ajax-json/getCategoryOptionCombos.action", {
+		id: dataElement.id
+	}, function( json ){		
+		optionCombo.empty();
+		jQuery.each( json.categoryOptionCombos, function(i, item ){
+			optionCombo.append( "<option value='{\"id\":\"" + item.id + "\",\"name\":\"" + item.name + "\",\"default\":\"" + item.default + "\"}' selected='true'>" + item.name + "</option>" );
+		});
+	});
+}
+
+function insertDataElement( source )
+{
+	var oEditor = FCKeditorAPI.GetInstance('designTextarea') ;
+	
+	var dataElement = JSON.parse( jQuery( source + ' #dataElementIds').val() );
+	if( dataElement == null )
+	{
+		jQuery( source + " #message_").html( "<b>" + i18n_specify_dataelememt + "</b>" );
+		return;
+	}else{
+		jQuery( source + " #message_").html( "" );
+	}
+	var categoryOptionCombos = getSelectedValues( source + ' #optionComboIds' );
+	
+	var associationId = $association.id;
+	
+	var dataElementId = dataElement.id;	
+	var dataElementName = dataElement.name;	
+	var dataElementType = dataElement.type;
+	var viewByValue = jQuery( source + ' #viewBySelector' ).val();	
+	
+	var strPSDataEntryId   = "value["+ associationId +"].value:value["+ dataElementId +"].value";
+    var comboPSDataEntryId = "value["+ associationId +"].combo:value["+ dataElementId +"].combo";
+    var boolPSDataEntryId  = "value["+ associationId +"].boolean:value["+ dataElementId +"].boolean";
+    var datePSDataEntryId  = "value["+ associationId +"].date:value["+ dataElementId +"].date";
+	
+	if(viewByValue == "deid") dispName = "[ " + dataElementId;
+	else if (viewByValue == "deshortname") dispName = "[ " + dataElement.shortName;
+	else dispName = "[ " + dataElementName;
+	
+	viewByValue = "@@" + viewByValue + "@@";
+	
+	var id = "";
+	
+	var selectString = "";
+	
+	if( dataElementType == "string" )
+	{
+		if( categoryOptionCombos[0].default == 'true' )
+		{			
+			strPSDataEntryId  = strPSDataEntryId + ":value["+ categoryOptionCombos[0].id +"].value";
+			selectString += "<input name=\"entryfield\" id=\""+strPSDataEntryId+"\" type=\"text\" value=\"\" onkeypress=\"return keyPress(event, this)\" >";			
+			id = strPSDataEntryId;
+		}else{			
+			selectString = "<select name=\"entryselect\" id=\"" + comboPSDataEntryId + "\" > <option value=\"\">i18n_select_value</option>";
+		
+			jQuery.each( categoryOptionCombos, function(i, item ){
+				selectString += "<option value=\""+ item.id +"\" id=\"combo[" + item.id + "].combo\" >(" + item.name + ")</option>";
+			});
+			
+			selectString += "</select>";
+			
+			id = comboPSDataEntryId;
+		}		
+		
+	}else if (dataElementType == "bool")
+	{
+		selectString = "<select name=\"entryselect\" id=\"" + boolPSDataEntryId + "\" > <option value=\"\">i18n_select_value</option>";
+		selectString += "<option value=\"true\" >i18n_yes</option>";
+		selectString += "<option value=\"false\" >i18n_no</option>";
+		selectString += "</select>";
+		
+		id = boolPSDataEntryId;
+	}else if (dataElementType == "date")
+	{
+		selectString = "<input type=\"text\" id=\"" + datePSDataEntryId + "\" name=\"entryfield\" value=\"\">";	
+		id = datePSDataEntryId;
+	} else if ( dataElementType == "int" )
+	{
+		jQuery.each( categoryOptionCombos, function(i, item ){
+			optionComboName = item.name;
+			optionComboId = item.id;
+			var titleValue = "-- " + dataElementId + ". "+ dataElementName+" " + optionComboId + ". " + optionComboName+" ("+dataElementType+") --";
+			var displayName = dispName + " - " + optionComboName + " ]";
+			var dataEntryId = "value[" + associationId + "].value:value[" + dataElementId + "].value:value[" + optionComboId + "].value";
+			selectString += "<input title=\"" + titleValue + "\" view=\""+viewByValue+"\" value=\"" + displayName + "\" name=\"entryfield\" id=\"" + dataEntryId + "\" style=\"width:10em;text-align:center\"/><br/>";
+			id = dataEntryId;
+		});
+	}
+	
+	if( checkExisted( id ) )
+	{		
+		jQuery( source + " #message_").html( "<b>" + i18n_dataelement_is_inserted + "</b>" );
+		return;
+	}else{
+		jQuery( source + " #message_").html("");
+	}
+	
+	oEditor.InsertHtml( selectString );
+	
+}
+
+function getSelectedValues( jQueryString )
+{
+	var result = new Array();
+	jQuery.each( jQuery( jQueryString ).children(), function(i, item ){
+		if( item.selected==true){
+			result.push( JSON.parse( item.value ) );
+		}
+	});
+	
+	return result;
+}
+
+
+function checkExisted( id )
+{	
+	var result = false;
+	var html = FCKeditorAPI.GetInstance('designTextarea').GetHTML();
+	var input = jQuery( html ).find("select, :text");
+	input.each( function(i, item){		
+		if( id == item.id ) result = true;		
+	});
+	
+	return result;
+}
+
+function filterDataElements( filter, container, list )
+{
+	var filterLower = filter.toString().toLowerCase();
+	
+	var dataElementList = jQuery( container + " " + list );
+	dataElementList.empty();
+	
+	jQuery( container + " " + list + "Store" ).children().each( function(i, item){
+		item = jQuery( item );		
+		var toMatch = item.text().toString().toLowerCase();		
+        if( toMatch.indexOf(filterLower) != -1 ){
+			dataElementList.append( "<option value='" + item.attr('value') + "'>" + item.text() + "</option>" );
+		}
+	});	
+}
+
+
+function validateDataEntryForm( )
+{
+	$.postJSON(
+    	    'validateDataEntryForm.action',
+    	    {
+    	        dataEntryFormId: getFieldValue('dataEntryFormId'),
+				name: getFieldValue('name')
+    	    },
+    	    function( json )
+    	    {
+    	    	if ( json.response == "success" )
+    	    	{
+					byId( 'saveDataEntryForm' ).submit(); 
+    	    	}
+    	    	else if ( json.response == "error" )
+    	    	{
+    	    		setHeaderMessage( json.message );
+    	    	}
+    	    }
+    	);
+		
+		//checkValueIsExist( 'name', 'validateDataEntryForm.action', {dataEntryFormId:getFieldValue('dataEntryFormId')} );
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStageList.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStageList.vm	2010-11-21 15:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStageList.vm	2011-03-23 02:10:08 +0000
@@ -51,7 +51,7 @@
 				</td>
 				
 				<td style="text-align:center"#alternate( $mark )>
-				  <a href="viewDataEntryForm.action?associationId=$association.id" title="$i18n.getString( "design_data_entry_form" )"><img src="../images/edit_layout.png" alt="$i18n.getString( "design_data_entry_form" )"></a>
+				  <a href="viewDataEntryForm.action?programStageId=$association.id" title="$i18n.getString( "design_data_entry_form" )"><img src="../images/edit_layout.png" alt="$i18n.getString( "design_data_entry_form" )"></a>
 				</td>
 				
 			  </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm	2011-02-18 04:29:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm	2011-03-23 02:10:08 +0000
@@ -1,23 +1,4 @@
-<script type="text/javascript">   
-    var i18n_dataelement_is_inserted = '$encoder.jsEscape( $i18n.getString( "dataelement_is_inserted" ) , "'" )';
-	var i18n_specify_dataelememt = '$encoder.jsEscape( $i18n.getString( "specify_dataelememt" ) , "'" )';
-       
-	jQuery(document).ready(	function()
-	{		
-		validation( 'saveDataEntryForm', function( form ){ form.submit() } );		
-		
-		#if( $!dataEntryForm )
-			checkValueIsExist('name', 'validateDataEntryForm.action', {dataEntryFormId:$dataEntryForm.id});
-		#else
-			checkValueIsExist('name', 'validateDataEntryForm.action');
-		#end
-		
-	});
-	
-	var previousName = '';
 
-</script>
-     
 <style>
 
 #dataElementSelection,
@@ -61,10 +42,10 @@
 
 </style>
 
-<form id="saveDataEntryForm" name="saveDataEntryForm" action="saveDataEntryForm.action" method="post">
-<input type="hidden" name="programStageId" value="$!programStageId"/>
-<input type="hidden" name="associationIdField" id="associationIdField" value="$association.id" />
-<h3>$i18n.getString( "dataentryform_management_for_program_stage" ): $association.name </h3>
+<form id="saveDataEntryForm" name="saveDataEntryForm" action="saveDataEntryForm.action" method="post" onsubmit=' validateDataEntryForm(); return false;'>
+<input type="hidden" name="programStageId" id="programStageId" value="$!programStage.id"/>
+<input type="hidden" name="dataEntryFormId" id="dataEntryFormId"/>
+<h3>$i18n.getString( "dataentryform_management_for_program_stage" ): $programStage.name </h3>
 <div class="container" >
 	<table id="detailsList" width="100%">
 		<col/>
@@ -188,267 +169,40 @@
 				<input type="button" value="Insert" id="insert" name="insert" onclick="insertDataElement( '#otherProgramStageDataElements')"/>
 			</td>
 			<td>
-				<span id="message_"></span>
+				<span id="message"></span>
 			</td>
 		</tr>
 	</table>	
 </div>
 
 
-
 <div id="existedDataEntry">	
 	<select id="existedDataEntryId" style="width:300px;float:left">		
 		#foreach( $dataEntry in $existingDataEntryForms )
-			<option value="$dataEntry.id" >$encoder.htmlEncode( $dataEntry.name )</option>
+			<option value="$dataEntry.id" >$encoder.htmlEncode( $!dataEntry.name )</option>
 		#end
 	</select>
 	<input type="button" value="$i18n.getString( 'load' )" style="float:left" onclick="loadExistedForm()"/>	
 </div>
 
-
-<script>
-var dataElementSelector;
-var otherProgramStageDataElements;
-var existedDataEntry;
-
-jQuery(function(){
-	dataElementSelector = jQuery("#dataElementSelection").dialog({
-		title: "$i18n.getString( 'dataelement' )",
-		minWidth: 650,
-		minHeight: 250,
-		width:650,
-		autoOpen: false,
-		zIndex:99999
-	});
-	
-	otherProgramStageDataElements = jQuery("#otherProgramStageDataElements").dialog({
-		title: "$i18n.getString( 'dataelement_of_orther_program_stage' )",
-		minWidth: 650,
-		minHeight: 250,
-		width:650,
-		autoOpen: false,
-		zIndex:99999
-	});
-	
-	existedDataEntry = jQuery("#existedDataEntry").dialog({
-		title: "$i18n.getString( 'choose_existing_dataentry' )",
-		minWidth: 400,
-		minHeight: 80,
-		width:400,
-		autoOpen: false,
-		zIndex:99999
-	});	
-});
-
-function openOtherProgramStageDataElements()
-{
-	otherProgramStageDataElements.dialog("open");
-}
-	
-function openDataElementSelector()
-{
-	dataElementSelector.dialog("open");
-}	
-
-function openloadExistedForm()
-{
-	existedDataEntry.dialog("open");
-}
-
-function loadExistedForm()
-{
-	jQuery.post("showDataEntryForm.action",{
-		dataEntryFormId: getFieldValue( 'existedDataEntryId' )
-	}, function( html ){
-		FCKeditorAPI.GetInstance('designTextarea').SetHTML( html );
-	});
-}
-
-function deleteDataEntryForm( associationId )
-{
-	if( window.confirm( i18n_delete_confirm ) )
-	{
-		window.location = 'delDataEntryForm.action?associationId=' + associationId;
-	}
-}
-
-function getProgramStageDataElements( id )
-{
-	var dataElements = jQuery( "#otherProgramStageDataElements #dataElementIds" );
-	dataElements.empty();
-	var dataElementIdsStore = jQuery( "#otherProgramStageDataElements #dataElementIdsStore" );
-	dataElementIdsStore.empty();
-	
-	jQuery( "#otherProgramStageDataElements #optionComboIds" ).empty();
-	if( id != '' ){
-		jQuery.post("getSelectedDataElements.action",{
-			associationId: id
-		}, function( xml ){			
-			jQuery( xml ).find( 'dataElement' ).each( function(i, item ){			
-				dataElements.append("<option value='" + jQuery( item ).find( "json" ).text() + "'>" + jQuery( item ).find( "name" ).text() + "</option>");
-				dataElementIdsStore.append("<option value='" + jQuery( item ).find( "json" ).text() + "'>" + jQuery( item ).find( "name" ).text() + "</option>");
-			});
-		});
-	}
-}
-
-
-function getOptionCombos( dataElement, target )
-{
-	var dataElement = JSON.parse( dataElement );
-	
-	var optionCombo = jQuery( target );
-	
-	if( dataElement.type=='string' ){
-		optionCombo.attr("multiple", "multiple" );
-	}else{
-		optionCombo.removeAttr( "multiple" );
-	}
-	
-	jQuery.postJSON("../dhis-web-commons-ajax-json/getCategoryOptionCombos.action", {
-		id: dataElement.id
-	}, function( json ){		
-		optionCombo.empty();
-		jQuery.each( json.categoryOptionCombos, function(i, item ){
-			optionCombo.append( "<option value='{\"id\":\"" + item.id + "\",\"name\":\"" + item.name + "\",\"default\":\"" + item.default + "\"}' selected='true'>" + item.name + "</option>" );
-		});
-	});
-}
-
-function insertDataElement( source )
-{
-	var oEditor = FCKeditorAPI.GetInstance('designTextarea') ;
-	
-	var dataElement = JSON.parse( jQuery( source + ' #dataElementIds').val() );
-	if( dataElement == null )
-	{
-		jQuery( source + " #message_").html( "<b>" + i18n_specify_dataelememt + "</b>" );
-		return;
-	}else{
-		jQuery( source + " #message_").html( "" );
-	}
-	var categoryOptionCombos = getSelectedValues( source + ' #optionComboIds' );
-	
-	var associationId = $association.id;
-	
-	var dataElementId = dataElement.id;	
-	var dataElementName = dataElement.name;	
-	var dataElementType = dataElement.type;
-	var viewByValue = jQuery( source + ' #viewBySelector' ).val();	
-	
-	var strPSDataEntryId   = "value["+ associationId +"].value:value["+ dataElementId +"].value";
-    var comboPSDataEntryId = "value["+ associationId +"].combo:value["+ dataElementId +"].combo";
-    var boolPSDataEntryId  = "value["+ associationId +"].boolean:value["+ dataElementId +"].boolean";
-    var datePSDataEntryId  = "value["+ associationId +"].date:value["+ dataElementId +"].date";
-	
-	if(viewByValue == "deid") dispName = "[ " + dataElementId;
-	else if (viewByValue == "deshortname") dispName = "[ " + dataElement.shortName;
-	else dispName = "[ " + dataElementName;
-	
-	viewByValue = "@@" + viewByValue + "@@";
-	
-	var id = "";
-	
-	var selectString = "";
-	
-	if( dataElementType == "string" )
-	{
-		if( categoryOptionCombos[0].default == 'true' )
-		{			
-			strPSDataEntryId  = strPSDataEntryId + ":value["+ categoryOptionCombos[0].id +"].value";
-			selectString += "<input name=\"entryfield\" id=\""+strPSDataEntryId+"\" type=\"text\" value=\"\" onkeypress=\"return keyPress(event, this)\" >";			
-			id = strPSDataEntryId;
-		}else{			
-			selectString = "<select name=\"entryselect\" id=\"" + comboPSDataEntryId + "\" > <option value=\"\">i18n_select_value</option>";
-		
-			jQuery.each( categoryOptionCombos, function(i, item ){
-				selectString += "<option value=\""+ item.id +"\" id=\"combo[" + item.id + "].combo\" >(" + item.name + ")</option>";
-			});
-			
-			selectString += "</select>";
-			
-			id = comboPSDataEntryId;
-		}		
-		
-	}else if (dataElementType == "bool")
-	{
-		selectString = "<select name=\"entryselect\" id=\"" + boolPSDataEntryId + "\" > <option value=\"\">i18n_select_value</option>";
-		selectString += "<option value=\"true\" >i18n_yes</option>";
-		selectString += "<option value=\"false\" >i18n_no</option>";
-		selectString += "</select>";
-		
-		id = boolPSDataEntryId;
-	}else if (dataElementType == "date")
-	{
-		selectString = "<input type=\"text\" id=\"" + datePSDataEntryId + "\" name=\"entryfield\" value=\"\">";	
-		id = datePSDataEntryId;
-	} else if ( dataElementType == "int" )
-	{
-		jQuery.each( categoryOptionCombos, function(i, item ){
-			optionComboName = item.name;
-			optionComboId = item.id;
-			var titleValue = "-- " + dataElementId + ". "+ dataElementName+" " + optionComboId + ". " + optionComboName+" ("+dataElementType+") --";
-			var displayName = dispName + " - " + optionComboName + " ]";
-			var dataEntryId = "value[" + associationId + "].value:value[" + dataElementId + "].value:value[" + optionComboId + "].value";
-			selectString += "<input title=\"" + titleValue + "\" view=\""+viewByValue+"\" value=\"" + displayName + "\" name=\"entryfield\" id=\"" + dataEntryId + "\" style=\"width:10em;text-align:center\"/><br/>";
-			id = dataEntryId;
-		});
-	}
-	
-	if( checkExisted( id ) )
+<script type="text/javascript">   
+    var i18n_dataelement_is_inserted = '$encoder.jsEscape( $i18n.getString( "dataelement_is_inserted" ) , "'" )';
+	var i18n_specify_dataelememt = '$encoder.jsEscape( $i18n.getString( "specify_dataelememt" ) , "'" )';
+    var i18n_choose_existing_dataentry = "$i18n.getString( 'choose_existing_dataentry' )";
+	
+	jQuery(document).ready(	function()
 	{		
-		jQuery( source + " #message_").html( "<b>" + i18n_dataelement_is_inserted + "</b>" );
-		return;
-	}else{
-		jQuery( source + " #message_").html("");
-	}
-	
-	oEditor.InsertHtml( selectString );
-	
-}
-
-function getSelectedValues( jQueryString )
-{
-	var result = new Array();
-	jQuery.each( jQuery( jQueryString ).children(), function(i, item ){
-		if( item.selected==true){
-			result.push( JSON.parse( item.value ) );
-		}
-	});
-	
-	return result;
-}
-
-
-function checkExisted( id )
-{	
-	var result = false;
-	var html = FCKeditorAPI.GetInstance('designTextarea').GetHTML();
-	var input = jQuery( html ).find("select, :text");
-	input.each( function(i, item){		
-		if( id == item.id ) result = true;		
-	});
-	
-	return result;
-}
-
-function filterDataElements( filter, container, list )
-{
-	var filterLower = filter.toString().toLowerCase();
-	
-	var dataElementList = jQuery( container + " " + list );
-	dataElementList.empty();
-	
-	jQuery( container + " " + list + "Store" ).children().each( function(i, item){
-		item = jQuery( item );		
-		var toMatch = item.text().toString().toLowerCase();		
-        if( toMatch.indexOf(filterLower) != -1 ){
-			dataElementList.append( "<option value='" + item.attr('value') + "'>" + item.text() + "</option>" );
-		}
-	});	
-}
-
-
-	
+		validation( 'saveDataEntryForm', function( form ){ validateDataEntryForm();});		
+		
+		/* #if( $!dataEntryForm )
+			checkValueIsExist('name', 'validateDataEntryForm.action', {dataEntryFormId:getFieldValue('dataEntryFormId')});
+		#else
+			checkValueIsExist('name', 'validateDataEntryForm.action');
+		#end */
+		
+	});
+	
+	var previousName = '';
+
 </script>
-
+     
\ No newline at end of file