← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15395: Apply web-api for search relationship of TEI in Find/Add instance.

 

------------------------------------------------------------
revno: 15395
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-05-25 18:52:53 +0800
message:
  Apply web-api for search relationship of TEI in Find/Add instance.
removed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateSearchRelationshipAction.java
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveRelationshipAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationship.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveRelationshipAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveRelationshipAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveRelationshipAction.java	2014-05-25 10:52:53 +0000
@@ -81,9 +81,9 @@
         this.entityInstanceId = entityInstanceId;
     }
 
-    private Integer partnerId;
+    private String partnerId;
 
-    public void setPartnerId( Integer partnerId )
+    public void setPartnerId( String partnerId )
     {
         this.partnerId = partnerId;
     }

=== removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateSearchRelationshipAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateSearchRelationshipAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateSearchRelationshipAction.java	1970-01-01 00:00:00 +0000
@@ -1,106 +0,0 @@
-package org.hisp.dhis.caseentry.action.trackedentity;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.i18n.I18n;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Abyot Asalefew Gizaw
- * @version $Id$
- */
-public class ValidateSearchRelationshipAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private String searchText;
-
-    public void setSearchText( String searchText )
-    {
-        this.searchText = searchText;
-    }
-
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private String message;
-
-    public String getMessage()
-    {
-        return message;
-    }
-
-    private I18n i18n;
-
-    public void setI18n( I18n i18n )
-    {
-        this.i18n = i18n;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {
-        if ( searchText == null )
-        {
-            message = i18n.getString( "specify_a_search_criteria" );
-
-            return INPUT;
-        }
-
-        else
-        {
-            searchText = searchText.trim();
-
-            if ( searchText.length() == 0 )
-            {
-                message = i18n.getString( "specify_a_search_criteria" );
-
-                return INPUT;
-            }
-
-        }
-
-        // ---------------------------------------------------------------------
-        // Validation success
-        // ---------------------------------------------------------------------
-
-        message = i18n.getString( "everything_is_ok" );
-
-        return SUCCESS;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2014-05-09 15:56:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2014-05-25 10:52:53 +0000
@@ -652,12 +652,6 @@
 			ref="org.hisp.dhis.relationship.RelationshipService" />
 	</bean>
 
-	<bean
-		id="org.hisp.dhis.caseentry.action.trackedentity.ValidateSearchRelationshipAction"
-		class="org.hisp.dhis.caseentry.action.trackedentity.ValidateSearchRelationshipAction"
-		scope="prototype">
-	</bean>
-
 	<!-- Reminder -->
 
 	<bean

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2014-05-09 15:56:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2014-05-25 10:52:53 +0000
@@ -668,21 +668,7 @@
 			<param name="page">/dhis-web-caseentry/addRelationshipForm.vm</param>
 			<param name="requiredAuthorities">F_RELATIONSHIP_ADD, F_TRACKED_ENTITY_INSTANCE_ADD</param>
 		</action>
-
-		<action name="validateSearchRelationship"
-			class="org.hisp.dhis.caseentry.action.trackedentity.ValidateSearchRelationshipAction">
-			<result name="success" type="velocity-xml">
-				/dhis-web-commons/ajax/xmlResponseSuccess.vm
-			</result>
-			<result name="error" type="velocity-xml">
-				/dhis-web-commons/ajax/xmlResponseError.vm
-			</result>
-			<result name="input" type="velocity-xml">
-				/dhis-web-commons/ajax/xmlResponseInput.vm
-			</result>
-			<param name="onExceptionReturn">plainTextError</param>
-		</action>
-
+		
 		<action name="searchRelationshipTrackedEntityInstance"
 			class="org.hisp.dhis.caseentry.action.trackedentity.SearchRelationshipEntityInstanceAction">
 			<result name="success" type="velocity">/content.vm</result>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm	2014-04-04 17:58:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm	2014-05-25 10:52:53 +0000
@@ -4,7 +4,7 @@
 		jQuery('name').focus();
 		
 		validation( 'relationshipSelectForm', function(form){
-			validateSearchPartner();
+			searchTEIForRelationship();
 		}); 
 		jQuery('[name=mainPagelink]').html(i18n_main_form_link);
 	});		
@@ -46,16 +46,16 @@
                                     
             <tr>           
                 <td colspan='2'>
-                    <select id="searchingAttributeId" name="searchingAttributeId" #if( $entityInstanceAttributes.size() == 0 ) disabled="disabled" #end style='width:200px;'>
+                    <select id="searchingAttributeId" name="searchingAttributeId" #if( $entityInstanceAttributes.size() == 0 ) disabled="disabled" #end style='width:200px;' class="{validate:{required:true}}" >
                         #foreach( $attribute in $attributes )
-                            <option value="$attribute.id" #if( $searchingAttributeId && $attribute.id == $searchingAttributeId ) selected="selected" #end>$encoder.htmlEncode( $attribute.displayName )</option>
+                            <option value="$attribute.uid" #if( $searchingAttributeId && $attribute.id == $searchingAttributeId ) selected="selected" #end>$encoder.htmlEncode( $attribute.displayName )</option>
                         #end
                     </select> 
                     <em title="$i18n.getString( 'required' )" class="required">*</em>
 				</td>
 				<td>
-				   <input type="text" id="searchText" name="searchText" maxlength="30" style='width:200px;'/>        
-                   <input type="button" value="$i18n.getString( 'search' )" onclick="validateSearchPartner();" class='large-button' />
+				   <input type="text" id="searchText" name="searchText" maxlength="30" style='width:200px;' class="{validate:{required:true}}" />        
+                   <input type="button" value="$i18n.getString( 'search' )" onclick="searchTEIForRelationship();" class='large-button' />
                 </td> 
             </tr>                  
         </table>
@@ -68,5 +68,12 @@
 
 <script type="text/javascript">
 	var i18n_please_select_relationship_type = '$encoder.jsEscape( $i18n.getString( "please_select_relationship_type" ) , "'" )';
-    var i18n_please_select_partner = '$encoder.jsEscape( $i18n.getString( "please_select_partner" ) , "'" )';    
+    var i18n_please_select_partner = '$encoder.jsEscape( $i18n.getString( "please_select_partner" ) , "'" )';
+	
+	var i18n_dashboard = '$encoder.jsEscape( $i18n.getString( "dashboard" ) , "'" )';
+	var i18n_assign_relationship = '$encoder.jsEscape( $i18n.getString( "assign_relationship" ) , "'" )';
+	var i18n_tracked_entity_instance_details_and_history = '$encoder.jsEscape( $i18n.getString( "tracked_entity_instance_details_and_history" ) , "'" )';
+	var i18n_please_select_partner = '$encoder.jsEscape( $i18n.getString( "please_select_partner" ) , "'" )';
+	var i18n_please_select_partner = '$encoder.jsEscape( $i18n.getString( "please_select_partner" ) , "'" )';
+	var i18n_please_select_partner = '$encoder.jsEscape( $i18n.getString( "please_select_partner" ) , "'" )';	
 </script>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationship.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationship.js	2014-02-08 15:19:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationship.js	2014-05-25 10:52:53 +0000
@@ -120,47 +120,129 @@
 // Search Relationship Partner
 //-----------------------------------------------------------------------------
 
-function validateSearchPartner()
+function searchTEIForRelationship()
 {
 	hideById('searchRelationshipDiv');
+	var params  = "ou=" + getFieldValue("orgunitId");
+		params += "&ouMode=ALL";
+		params += "&attribute=" + getFieldValue("searchingAttributeId") + ":LIKE:" + jQuery('#relationshipSelectForm [id=searchText]').val();
+	
+	var p = params;
+	$('#attributeIds option').each(function(i, item){
+		if ( p.indexOf(item.value) < 0 ) {
+			params += "&attribute=" + item.value;
+		}
+	});
+	
 	$.ajax({
-		url: 'validateSearchRelationship.action',
-		type:"POST",
-		data: getParamsForDiv('relationshipSelectForm'),
-		dataType: "xml",
-		success: searchValidationCompleted
-		}); 
+		type : "GET",
+		url : "../api/trackedEntityInstances.json",
+		data : params,
+		dataType : "json",
+		success : function(json) {
+			setInnerHTML('searchRelationshipDiv', showRelationShips( json ));
+			showById('searchRelationshipDiv');
+			setTableStyles();
+		}
+	});		
 }
 
-function searchValidationCompleted( messageElement )
-{
-	messageElement = messageElement.getElementsByTagName( 'message' )[0];
-	var type = messageElement.getAttribute( 'type' );
-	var message = messageElement.firstChild.nodeValue;
+function showRelationShips(json) {
+
+	// Header
+	var table = "";
+	if (json.rows.length == 0) {
+		table += "<p>" + i18n_no_result_found + "</p>";
+	}
+	else{
 	
-	if( type == 'success' )
-	{
-		jQuery('#loaderDiv').show();
-		$.ajax({
-			type: "GET",
-			url: 'searchRelationshipTrackedEntityInstance.action',
-			data: getParamsForDiv('relationshipSelectForm'),
-			success: function( html ) {
-				setInnerHTML('searchRelationshipDiv',html);
-				showById('searchRelationshipDiv');
-				jQuery('#loaderDiv').hide();
+		// TEI list
+		table += "<table class='listTable' width='100%'>";
+		
+		var idx = 4;
+		if(getFieldValue('program') != '') {
+			idx = 5;
+		}
+		
+		// Yes/No and Yes Only attributes in result
+		
+		var attList = new Array();
+		var attDate = new Array();
+		$('#attributeIds option').each(function(i, item) {
+			var valueType = $(item).attr('valueType');
+			var value = $(item).val();
+			if ( valueType == 'bool' || valueType == 'trueOnly' ) {
+				for (var i = idx; i < json.width; i++) {
+					if( value==json.headers[i].name ){
+						attList.push(i);
+					}
+					else if( valueType=='date'){
+						attDate.push(i);
+					}
+				}
+			}
+			else if ( valueType == 'date' ) {
+				for (var i = idx; i < json.width; i++) {
+					if( value==json.headers[i].name ){
+						attDate.push(i);
+					}
+				}
 			}
 		});
-		return false;
-	}
-	else if( type == 'error' )
-	{
-		setHeaderMessage( i18n_searching_tracked_entity_instance_failed + ':' + '\n' + message );
-	}
-	else if( type == 'input' )
-	{
-		setHeaderMessage( message );
-	}
+
+		// TEI List
+		
+		table += "<col width='30' />";
+		for (var i = idx; i < json.width; i++) {
+			table += "<col />";
+		}
+		table += "<col width='200' />";
+		table += "<thead><tr><th>#</th>";
+		for (var i = idx; i < json.width; i++) {
+			table += "<th>" + json.headers[i].column + "</th>";
+		}
+		table += "<th>" + i18n_operations + "</th>";
+		table += "</tr></thead>";
+		
+		table += "<tbody id='list'>";
+		for ( var i in json.rows) {
+			var cols = json.rows[i];
+			var uid = cols[0];
+			var no = i + 1;
+			table += "<tr id='tr" + uid + "'>";
+			table += "<td>" + no + "</td>";
+			for (var j = idx; j < json.width; j++) {
+				var colVal = cols[j];
+				if (j == 4) {
+					colVal = json.metaData.names[colVal];
+				}
+				
+				if( jQuery.inArray( j, attList )>=0 && colVal!="" ){
+					colVal = (colVal=='true')? i18n_yes : i18n_no;
+				}
+				else if( jQuery.inArray( j, attDate )>=0 && colVal!="" ){
+					colVal = colVal.split(' ')[0];
+				}
+				
+				table += "<td onclick=\"javascript:isDashboard=true;showTrackedEntityInstanceDashboardForm( '"
+					+ uid
+					+ "' )\" title='"
+					+ i18n_dashboard
+					+ "'>" + colVal + "</td>";
+			}
+			
+			// Operations column
+			table += "<td>";
+			table += "<a href=\"javascript:isDashboard=true;showTrackedEntityInstanceDashboardForm( '" + uid + "' )\" title='" + i18n_dashboard + "'><img src=\"../images/enroll.png\"></a>";
+			table += "<a href=\"javascript:validateAddRelationship('" + uid + "');\" title='" + i18n_assign_relationship + "' ><img src=\"../images/relationship.png\" ></a>";
+			table += "<a href=\"javascript:showTrackedEntityInstanceHistory('" + uid + "')\" title='" + i18n_tracked_entity_instance_details_and_history + "'><img src=\"../images/information.png\"></a>";
+			table += "</td>";
+			table += "</tr>";
+		}
+		table += "</tbody>";
+		table += "</table>";
+	}
+	return table;
 }
 
 function validateAddRelationship(partnerId)

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js	2014-05-25 09:27:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js	2014-05-25 10:52:53 +0000
@@ -348,24 +348,6 @@
 
 function advancedSearch( params, page )
 {
-	/* setFieldValue('listAll', "false");
-	$('#contentDataRecord').html('');
-	$('#listEventDiv').html('');
-	hideById('listEventDiv');
-	showLoader();
-	
-	$.ajax({
-		url : '../api/events.json',
-		type : "GET",
-		data : params,
-		success : function(json) {
-			setInnerHTML('listEventDiv', displayEvents(json, page));
-			showById('listEventDiv');
-			jQuery('#loaderDiv').hide();
-			setTableStyles();
-		}
-	}); */
-	
 	setFieldValue('listAll', "false");
 	$('#contentDataRecord').html('');
 	$('#listEventDiv').html('');
@@ -402,7 +384,6 @@
 			setTableStyles();
 		}
 	});
-	
 }
 
 function exportXlsFile()

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.vm	2014-05-25 10:52:53 +0000
@@ -20,7 +20,7 @@
 					#end
 					<tr>
 						<td>$!attributeValue.attribute.displayName:</td>
-						<td>$!attributeValue.value</td>
+						<td>$value</td>
 					</tr>
 				#end 
 			</table>
@@ -31,6 +31,7 @@
                
 	<tr>            
 		<th>$i18n.getString( "relationship" )</th>
+		<th>$i18n.getString( "profile" )<th>
 		<th style="text-align:center">$i18n.getString( "operations" )</th>
 	</tr>
 	
@@ -46,7 +47,18 @@
 					</td>
 								
 					<td>
-						$!encoder.htmlEncode( $relationship.entityInstanceB.name )
+						<table>
+							#foreach($attributeValue in $relationship.entityInstanceB.attributeValues)
+								#set($value=$attributeValue.value)
+							#if( $attribute.valueType == 'bool')
+								#set($value=$i18n.getString($attributeValue.value))
+							#end
+							<tr>
+								<td>$!encoder.htmlEncode( $attributeValue.attribute.displayName )</td>
+								<td>: $value</td>
+							</tr>
+						#end
+						</table>
 					</td>
 				#elseif($relationship.entityInstanceB.id == $entityInstance.id )
 					#set( $partnerId = $relationship.entityInstanceA.id )