← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22053: attributes and data element labels in program and program stage custom forms can no have special tag

 

------------------------------------------------------------
revno: 22053
committer: Abyot Asalefew Gizaw <abyot@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-02-26 16:26:07 +0100
message:
  attributes and data element labels in program and program stage custom forms can no have special tag
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewDataEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewProgramEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewProgramEntryForm.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-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties	2016-02-26 10:08:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties	2016-02-26 15:26:07 +0000
@@ -334,7 +334,7 @@
 label_is_assigned_to = Label is already assigned to 
 please_insert_all_required_fields = Please insert all required fields
 required_fields_valivation = Required fields validation
-insert_labels = Insert labels
+insert_label = Insert label
 insert_properties = Insert properties
 insert_images = Insert images
 insert_data_elements = Insert data elements

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewDataEntryForm.js	2015-09-07 03:11:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewDataEntryForm.js	2016-02-26 15:26:07 +0000
@@ -123,6 +123,26 @@
 	return result;
 }
 
+function checkLabelAssigned( id )
+{	
+	var assigned = false;
+	var assignedTo = "";
+	
+	var html = jQuery("#designTextarea").ckeditor().editor.getData();
+	var labels = jQuery( html ).find("span[d2-input-label]");
+	
+	labels.each(function(i, item){		
+		var labelAtt = jQuery(item).attr('d2-input-label');
+		if( labelAtt != undefined && labelAtt == id){
+			assigned = true;
+			assignedTo = jQuery(item).text();
+			return false;
+		}
+	});
+	
+	return {assigned: assigned, assignedTo: assignedTo};
+}
+
 function checkExisted( id )
 {	
 	var result = false;
@@ -152,8 +172,8 @@
 	});	
 }
 
-function insertDataElement( source, programStageUid )
-{
+function insertDataElement( source, programStageUid, isLabel )
+{	
 	var dataElement = JSON.parse( jQuery( source + ' #dataElementIds').val() );
 
 	if( dataElement == null )
@@ -170,43 +190,64 @@
 	
 	var htmlCode = "";
 	var id = programStageUid + "-" + dataElementUid + "-val" ;
-	if( dataElementUid == "executionDate" )
-	{
-		id = dataElementUid;
-	}	
-	var titleValue = dataElementUid + " - " + dataElementName + " - " + dataElementValueType;
 	
-	if ( dataElementValueType == "BOOLEAN" )
-	{
-		var displayName = dataElementName;
-		htmlCode = "<input title=\"" + titleValue + "\" name=\"entryselect\" id=\"" + id + "\" value=\"[" + displayName + "]\" title=\"" + displayName + "\">";
-	} 
-	else if ( dataElementValueType == "TRUE_ONLY" )
-	{
-		var displayName = dataElementName;
-		htmlCode = "<input type=\"checkbox\" title=\"" + titleValue + "\" name=\"entryselect\" id=\"" + id + "\" title=\"" + displayName + "\">";
-	} 
-	else if ( dataElementValueType == "USERNAME" )
-	{
-		var displayName = dataElementName;
-		htmlCode = "<input title=\"" + titleValue + "\" value=\"[" + displayName + "]\" name=\"entryfield\" id=\"" + id + "\" username=\"true\" />";
-	} 
+	if( isLabel )
+	{
+		var selectedText = jQuery("#designTextarea").ckeditor().editor.getSelection().getSelectedText();
+		var element = jQuery('#dataElementSelection option:selected');
+		
+		if( element.length == 0 ) return;
+		
+		var assigned = checkLabelAssigned( id );
+		if( assigned && assigned.assigned ){
+			jQuery( " #message_").html( "<span class='bold'>" + i18n_label_is_assigned_to + ': ' + assigned.assignedTo + "</span>" );
+			return;
+		}
+		else{
+			var label = '<span title="' + selectedText + '" d2-input-label="' + id + '">' + selectedText + '</span>';		
+			var lEditor = jQuery("#designTextarea").ckeditor().editor;
+			lEditor.insertHtml( label );
+		}
+	}
 	else
 	{
-		var displayName = dataElementName;
-		htmlCode = "<input title=\"" + titleValue + "\" value=\"[" + displayName + "]\" name=\"entryfield\" id=\"" + id + "\" />";
-	}
-	
-	if( checkExisted( id ) )
-	{		
-		jQuery( " #message_").html( "<span class='bold'>" + i18n_dataelement_is_inserted + "</span>" );
-		return;
-	}else{
-		var oEditor = jQuery("#designTextarea").ckeditor().editor;
-		oEditor.insertHtml( htmlCode );
-		jQuery(" #message_").html("");
-	}
-
+		if( dataElementUid == "executionDate" )
+		{
+			id = dataElementUid;
+		}	
+		var titleValue = dataElementUid + " - " + dataElementName + " - " + dataElementValueType;
+		
+		if ( dataElementValueType == "BOOLEAN" )
+		{
+			var displayName = dataElementName;
+			htmlCode = "<input title=\"" + titleValue + "\" name=\"entryselect\" id=\"" + id + "\" value=\"[" + displayName + "]\" title=\"" + displayName + "\">";
+		} 
+		else if ( dataElementValueType == "TRUE_ONLY" )
+		{
+			var displayName = dataElementName;
+			htmlCode = "<input type=\"checkbox\" title=\"" + titleValue + "\" name=\"entryselect\" id=\"" + id + "\" title=\"" + displayName + "\">";
+		} 
+		else if ( dataElementValueType == "USERNAME" )
+		{
+			var displayName = dataElementName;
+			htmlCode = "<input title=\"" + titleValue + "\" value=\"[" + displayName + "]\" name=\"entryfield\" id=\"" + id + "\" username=\"true\" />";
+		} 
+		else
+		{
+			var displayName = dataElementName;
+			htmlCode = "<input title=\"" + titleValue + "\" value=\"[" + displayName + "]\" name=\"entryfield\" id=\"" + id + "\" />";
+		}
+		
+		if( checkExisted( id ) )
+		{		
+			jQuery( " #message_").html( "<span class='bold'>" + i18n_dataelement_is_inserted + "</span>" );
+			return;
+		}else{
+			var oEditor = jQuery("#designTextarea").ckeditor().editor;
+			oEditor.insertHtml( htmlCode );
+			jQuery(" #message_").html("");
+		}
+	}
 }
 
 function displayNameOnChange( div, displayName )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewProgramEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewProgramEntryForm.js	2016-02-26 10:08:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/viewProgramEntryForm.js	2016-02-26 15:26:07 +0000
@@ -10,7 +10,6 @@
 	$("#deleteButton").button("option", "icons", { primary: "ui-icon-trash" });
 	$("#insertButton").button("option", "icons", { primary: "ui-icon-plusthick" });
 	$("#propertiesButton").button("option", "icons", { primary: "ui-icon-newwin" });
-	$("#labelsButton").button("option", "icons", { primary: "ui-icon-newwin" });
 	$("#insertImagesButton").button("option", "icons", { primary: "ui-icon-newwin" });
 	$("#insertImageButton").button("option", "icons", { primary: "ui-icon-plusthick" });
 	
@@ -55,25 +54,6 @@
 		});
 }
 
-function openLabelsSelector()
-{	
-	$("#labelsButton").addClass("ui-state-active2");
-	$('#labelsDialog' ).dialog(
-		{
-			title:i18n_labels,
-			maximize:true, 
-			closable:true,
-			modal:false,
-			overlay:{background:'#000000', opacity:0.1},
-			minWidth: 595,
-			minHeight: 263,
-			position: [($("body").width() - 555) - 50, 50],
-			close: function(ev, ui) { 
-				$("#labelsButton").removeClass("ui-state-active2"); 
-			}
-		});
-}
-
 function fixAttrOnClick()
 {
 	$("#insertButton").click(function() {
@@ -342,7 +322,7 @@
 	
 	if(type == 'lbl') {
 		var selectedText = jQuery("#designTextarea").ckeditor().editor.getSelection().getSelectedText();
-		var element = jQuery('#labelsSelector option:selected');
+		var element = jQuery('#attributeTab option:selected');
 		
 		if( element.length == 0 ) return;		
 		

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewDataEntryForm.vm	2015-10-01 18:17:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewDataEntryForm.vm	2016-02-26 15:26:07 +0000
@@ -142,7 +142,7 @@
 		<tr>
 			<td colspan='2'>
 			
-				<select id="dataElementIds" name="dataElementIds" style="height:200px; width:100%;"  multiple="multiple" size="10" ondblclick="insertDataElement( '#dataElementSelection', '$programStage.uid')">
+				<select id="dataElementIds" name="dataElementIds" style="height:200px; width:100%;"  multiple="multiple" size="10" ondblclick="insertDataElement( '#dataElementSelection', '$programStage.uid', false)">
 				
 					#if( $programStage.program.programType.value=="WITHOUT_REGISTRATION" )
 						#set($name = "$encoder.htmlEncode($programStage.excecutionDateLabel)")
@@ -180,7 +180,7 @@
 								<option value='3'>$i18n.getString("code_and_name")</option>
 							</select>
 						</td>
-						<td style="padding-left:190px;"><td>
+						<td style="padding-left:190px;"></td>
 						<td>$i18n.getString("sort_by")</td>
 						<td>
 							<input type='radio' name='sortBy' value='1' onchange="sortByOnChange('dataElementSelection', '1')" checked >$i18n.getString("name")
@@ -195,7 +195,8 @@
 				#if(!$programStages.isEmpty())
 				<input type="button" value="$i18n.getString('other_program_stages')" onclick="hideById('dataElementSelection');showById('otherProgramStageDataElements');" >
 				#end
-				<input type="button" id="insertButton" value="$i18n.getString('insert')" onclick="insertDataElement( '#dataElementSelection', '$programStage.uid')" style="width:100px">
+				<input type="button" id="insertButton" value="$i18n.getString('insert')" onclick="insertDataElement( '#dataElementSelection', '$programStage.uid', false)" style="width:100px">
+				<input type="button" id="insertLabelButton" value="$i18n.getString('insert_label')" onclick="insertDataElement( '#dataElementSelection', '$programStage.uid', true)" style="width:100px">
 			</td>
 		</tr>
 	</table>
@@ -229,7 +230,7 @@
 		</tr>
 		<tr>
 			<td colspan='3'>
-				<select id="dataElementIds" name="dataElementIds" style="width:430px;"  multiple="multiple" size="10" ondblclick="insertDataElement( '#otherProgramStageDataElements', jQuery('#programStageIds option:selected').attr('uid') )"></select>
+				<select id="dataElementIds" name="dataElementIds" style="width:430px;"  multiple="multiple" size="10" ondblclick="insertDataElement( '#otherProgramStageDataElements', jQuery('#programStageIds option:selected').attr('uid'), false )"></select>
 				<select id="dataElementIdsStore" name="dataElementIdsStore" multiple="multiple" style="display:none"></select>
 			</td>
 		</tr>
@@ -259,7 +260,7 @@
 		<tr>
 			<td colspan='2'>
 				<input type="button" value="$i18n.getString('selected_program_stages')" onclick="hideById('otherProgramStageDataElements');showById('dataElementSelection');" >
-				<input type="button" value="Insert" id="insert" name="insert" onclick="insertDataElement( '#otherProgramStageDataElements', byId('programStageIds').value )"/>
+				<input type="button" value="Insert" id="insert" name="insert" onclick="insertDataElement( '#otherProgramStageDataElements', byId('programStageIds').value, false )"/>
 			</td>
 		</tr>
 	</table>	
@@ -292,4 +293,5 @@
 <script>
 	var i18n_delete_program_data_entry_confirm = '$encoder.jsEscape( $i18n.getString( "delete_program_data_entry_confirm" ) , "'" )';
 	var i18n_enter_a_name = '$encoder.jsEscape( $i18n.getString( "enter_a_name" ) , "'" )';
+	var i18n_label_is_assigned_to = '$encoder.jsEscape( $i18n.getString( "label_is_assigned_to" ) , "'" )';
 </script>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewProgramEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewProgramEntryForm.vm	2016-02-26 10:08:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewProgramEntryForm.vm	2016-02-26 15:26:07 +0000
@@ -39,7 +39,7 @@
 	padding: 2px;
 }
 
-#attributesSelector, #programSelector, #labelSelector {
+#attributesSelector, #programSelector {
 	padding: 2px;
 }
 
@@ -98,8 +98,7 @@
             <button type="submit" id="saveAndCloseButton" onclick="isSave='false';"/>$i18n.getString( 'save_and_close' )</button>
             <button type="button" id="cancelButton" onclick="window.location='program.action'">$i18n.getString( 'cancel' )</button>
 			&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
-		    <button type="button" id="propertiesButton" onclick="openPropertiesSelector()"/>$i18n.getString( 'insert_properties' )</button>
-			<button type="button" id="labelsButton" onclick="openLabelsSelector()"/>$i18n.getString( 'insert_labels' )</button>
+		    <button type="button" id="propertiesButton" onclick="openPropertiesSelector()"/>$i18n.getString( 'insert_properties' )</button>			
 			<button type="button" id="insertImagesButton">$i18n.getString( 'insert_images' )</button>
 			&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
 		    <button type="button" id="deleteButton" #if($!program.dataEntryForm) #else style='display:none;' #end onclick="javascript:deleteProgramEntryForm($program.id,'$program.displayName');"  />$i18n.getString( 'delete_this_form' )</button>
@@ -115,13 +114,15 @@
     <table id="attributeTab">
    		<tr>
    			<td>
-   				<input type='text' id='attributeFilter' placeholder="$i18n.getString('filter')" style="width:400px;" onchange="filterList( this.value, 'attributesSelector' )">
+   				<input type='text' id='attributeFilter' placeholder="$i18n.getString('filter')" style="width:380px;" onchange="filterList( this.value, 'attributesSelector' )">
+			</td>
+			<td>
    				<input type='button' value="$i18n.getString('filter')" style="width:80px;" onclick="filterList( getFieldValue('attributeFilter'), 'attributesSelector' )">
 				<input type='button' value="$i18n.getString('clear')" style="width:80px;" onclick="setFieldValue('attributeFilter','');filterList( '', 'attributesSelector' )">
    			</td>
    		</tr>
    		<tr>
-   			<td>
+   			<td colspan='2'>
    				<select id="attributesSelector" multiple="multiple" style="height:200px;width:100%;" ondblclick="insertElement( 'attr' )">
    				#foreach( $attribute in $attributes )
    					<option value="$attribute.uid" mandatory='false'>$encoder.htmlEncode($attribute.displayName)</option>
@@ -139,12 +140,14 @@
 		<tr>
 			<td>
 				<input type='text' id='programAttrKey' placeholder="$i18n.getString('filter')" style="width:400px;" onchange="filterList( this.value, 'programAttrSelector' )">
+			</td>
+			<td>
 				<input type='button' value="$i18n.getString('filter')" style="width:80px;" onclick="filterList( getFieldValue('programAttrKey'), 'programAttrSelector' )">
 				<input type='button' value="$i18n.getString('clear')" style="width:80px;" onclick="setFieldValue('programAttrKey','');filterList( '', 'programAttrSelector' )">
 			</td>
 		</tr>
 		<tr>
-			<td>
+			<td colspan='2'>
 				<select id="programAttrSelector" multiple="multiple" style="height:200px;width:100%;" ondblclick="insertElement( 'prg' )">
 					<option value="enrollmentDate" >$encoder.htmlEncode($program.enrollmentDateLabel)</option>
 					#if($program.displayIncidentDate=='true')
@@ -159,7 +162,8 @@
 	<table>
 		<tr>
 			<td>
-                <button type="button" id="attributesButton" onclick="attributesOnClick()">$i18n.getString( "attributes" )</button>
+				<button type="button" id="labelsButton" onclick="insertElement( 'lbl' )"/>$i18n.getString( 'insert_labels' )</button>
+                <button type="button" id="attributesButton" onclick="attributesOnClick()">$i18n.getString( "attributes" )</button>				
 				#if($!program)
 					<button type="button" id="programAttrButton" onclick="programAttrOnClick()">$i18n.getString( "program" )</button>
 				#end
@@ -171,31 +175,6 @@
 
 </div>
 
-<div id='labelsDialog' class='hidden'>
-  
-    <table>
-   		<tr>
-   			<td>
-   				<input type='text' id='labelFilter' placeholder="$i18n.getString('filter')" style="width:400px;" onchange="filterList( this.value, 'labelsSelector' )">
-   				<input type='button' value="$i18n.getString('filter')" style="width:80px;" onclick="filterList( getFieldValue('labelFilter'), 'labelsSelector' )">
-				<input type='button' value="$i18n.getString('clear')" style="width:80px;" onclick="setFieldValue('labelFilter','');filterList( '', 'labelsSelector' )">
-   			</td>
-   		</tr>
-   		<tr>
-   			<td>
-   				<select id="labelsSelector" multiple="multiple" style="height:200px;width:100%;" ondblclick="insertElement( 'lbl' )">
-				#foreach( $programAttribute in $programAttributes )
-   					<option value="$programAttribute.attribute.uid" mandatory='programAttribute.mandatory'>$encoder.htmlEncode($programAttribute.attribute.displayName)</option>
-   				#end
-   				</select>
-   			</td>
-   		</tr>
-   	</table>
-
-	<span id='message' style="width: 436px;"></span>
-
-</div>
-
 <div id="imageDialog" title="$i18n.getString( 'insert_images' )" class='hidden'>
 	<div style="margin:4px">
 		<div>
@@ -219,7 +198,6 @@
 	var i18n_required_fields_valivation = '$encoder.jsEscape( $i18n.getString( "required_fields_valivation" ) , "'" )';
 	var i18n_full_name = '$encoder.jsEscape( $i18n.getString( "full_name" ) , "'" )';
 	var i18n_properties = '$encoder.jsEscape( $i18n.getString( "properties" ) , "'" )';
-	var i18n_labels = '$encoder.jsEscape( $i18n.getString( "labels" ) , "'" )';
 	var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_prorgam_entry_form_form" ) , "'" )';
 	var i18n_save_unsuccess_please_insert_all_required_fields = '$encoder.jsEscape( $i18n.getString( "save_unsuccess" ) , "'" )' + '. ' + '$encoder.jsEscape( $i18n.getString( "please_insert_all_required_fields" ) , "'" )';
 	var i18n_validate_success = '$encoder.jsEscape( $i18n.getString( "validate_success" ) , "'" )';