dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18976
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8097: WIP dynamic cde fields
------------------------------------------------------------
revno: 8097
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-09-15 13:19:46 +0200
message:
WIP dynamic cde fields
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.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-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2012-09-13 15:48:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2012-09-15 11:19:46 +0000
@@ -47,7 +47,8 @@
final Pattern IDENTIFIER_PATTERN = Pattern.compile( "(\\d+)-(\\d+)-val" );
final Pattern DATAELEMENT_TOTAL_PATTERN = Pattern.compile( "dataelementid=\"(.*?)\"" );
final Pattern INDICATOR_PATTERN = Pattern.compile( "indicatorid=\"(.*?)\"" );
- final Pattern DYNAMIC_ELEMENT_PATTERN = Pattern.compile( "categoryoptioncomboid=\"(.*?)\"" );
+ final Pattern DYNAMIC_INPUT_PATTERN = Pattern.compile( "(.*?)-(.*?)-dyninput" );
+ final Pattern DYNAMIC_SELECT_PATTERN = Pattern.compile( "(.*?)-(.*?)-dynselect" );
final Pattern VALUE_TAG_PATTERN = Pattern.compile( "value=\"(.*?)\"", Pattern.DOTALL );
final Pattern TITLE_TAG_PATTERN = Pattern.compile( "title=\"(.*?)\"", Pattern.DOTALL );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2012-09-13 15:48:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2012-09-15 11:19:46 +0000
@@ -37,7 +37,10 @@
import java.util.Set;
import java.util.regex.Matcher;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
@@ -57,6 +60,8 @@
public class DefaultDataEntryFormService
implements DataEntryFormService
{
+ private static final Log log = LogFactory.getLog( DefaultDataEntryFormService.class );
+
private static final String EMPTY_VALUE_TAG = "value=\"\"";
private static final String EMPTY_TITLE_TAG = "title=\"\"";
private static final String TAG_CLOSE = "/>";
@@ -176,7 +181,8 @@
Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
Matcher dataElementTotalMatcher = DATAELEMENT_TOTAL_PATTERN.matcher( inputHtml );
Matcher indicatorMatcher = INDICATOR_PATTERN.matcher( inputHtml );
- Matcher dynamicElementMatcher = DYNAMIC_ELEMENT_PATTERN.matcher( inputHtml );
+ Matcher dynamicInputMatcher = DYNAMIC_INPUT_PATTERN.matcher( inputHtml );
+ Matcher dynamicSelectMatcher = DYNAMIC_SELECT_PATTERN.matcher( inputHtml );
String displayValue = null;
String displayTitle = null;
@@ -214,19 +220,33 @@
displayValue = indicator != null ? "value=\"[ " + indicator.getDisplayName() + " ]\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
displayTitle = indicator != null ? "title=\"" + indicator.getDisplayName() + "\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
}
- else if ( dynamicElementMatcher.find() && dynamicElementMatcher.groupCount() > 0 )
+ else if ( dynamicInputMatcher.find() && dynamicInputMatcher.groupCount() > 0 )
{
- String categoryOptionComboUid = dynamicElementMatcher.group( 1 );
+ String categoryOptionComboUid = dynamicInputMatcher.group( 2 );
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( categoryOptionComboUid );
displayValue = categoryOptionCombo != null ? "value=\"[ " + categoryOptionCombo.getDisplayName() + " ]\"" : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
displayTitle = categoryOptionCombo != null ? "title=\"" + categoryOptionCombo.getDisplayName() + "\"" : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
}
+ else if ( dynamicSelectMatcher.find() && dynamicSelectMatcher.groupCount() > 0 )
+ {
+ String categoryComboUid = dynamicSelectMatcher.group( 2 );
+ DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( categoryComboUid );
+
+ displayValue = categoryCombo != null ? "value=\"[ " + categoryCombo.getDisplayName() + " ]\"" : "[ " + i18n.getString( "cat_combo_not_exist" );
+ displayTitle = categoryCombo != null ? "title=\"" + categoryCombo.getDisplayName() + "\"" : "[ " + i18n.getString( "cat_combo_not_exist" );
+ }
// -----------------------------------------------------------------
// Insert name of data element operand as value and title
// -----------------------------------------------------------------
+ if ( displayValue == null || displayTitle == null )
+ {
+ log.warn( "Ignoring invalid form markup: '" + inputHtml + "'" );
+ continue;
+ }
+
inputHtml = inputHtml.contains( EMPTY_VALUE_TAG ) ? inputHtml.replace( EMPTY_VALUE_TAG, displayValue ) : inputHtml + " " + displayValue;
inputHtml = inputHtml.contains( EMPTY_TITLE_TAG ) ? inputHtml.replace( EMPTY_TITLE_TAG, displayTitle ) : inputHtml + " " + displayTitle;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties 2012-09-13 15:48:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties 2012-09-15 11:19:46 +0000
@@ -99,3 +99,4 @@
cat_option_combo_not_exist=Category option combo does not exist
data_element_not_exist=Data element does not exist
indicator_not_exist=Indicator does not exist
+cat_combo_not_exist=Category combo does not exist
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js 2012-09-13 15:48:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js 2012-09-15 11:19:46 +0000
@@ -1,6 +1,7 @@
-var currentDynamicElementCode = "";
-var currentCategoryComboUid = "";
+var currentDynamicElementCode = null;
+var currentCategoryComboUid = null;
+var currentCategoryComboName = null;
$( document ).ready( function() {
@@ -368,9 +369,26 @@
/**
* A unique code is used to associate the data element drop down with the input
- * fields for each category option combo. The format for input field is:
- *
- * <input id="<unique code>-dynamic" categoryoptioncomboid="<category option combo uid>" />
+ * fields for each category option combo. The format for select / drop down list
+ * identifier is:
+ *
+ * "<unique code>-dyncselect"
+ */
+function insertDropDownList() {
+ var oEditor = $("#designTextarea").ckeditorGet();
+
+ if ( currentDynamicElementCode && currentCategoryComboUid ) {
+ var id = currentDynamicElementCode + "-" + currentCategoryComboUid + "-dynselect";
+ var template = '<input id="' + id + '" value="[ ' + currentCategoryComboName + ' ]" title="' + currentCategoryComboName + '" style="width:12em;" />';
+ oEditor.insertHtml( template );
+ }
+}
+
+/**
+ * A unique code is used to associate the data element drop down with the input
+ * fields for each category option combo. The format for input field identifier is:
+ *
+ * "<unique code>-<category option combo uid>-dyninput"
*/
function insertDynamicElement() {
var oEditor = $("#designTextarea").ckeditorGet();
@@ -379,26 +397,9 @@
if( $option.length !== 0 ) {
var categoryOptionComboUid = $option.val();
var categoryOptionComboName = $option.text();
- var id = currentDynamicElementCode + "-dynamic";
- var title = categoryOptionComboUid + " - " + categoryOptionComboName;
+ var id = currentDynamicElementCode + "-" + categoryOptionComboUid + "-dyninput";
- var template = '<input id="' + id + '" categoryoptioncomboid="' + categoryOptionComboUid + '" value="[ ' + categoryOptionComboName + ' ]" title="' + title + '" style="width:7em;text-align:center;" />';
- oEditor.insertHtml( template );
- }
-}
-
-/**
- * A unique code is used to associate the data element drop down with the input
- * fields for each category option combo. The format for select / drop down list
- * is:
- *
- * <select id="<unique code>-categorycombo" />
- */
-function insertDropDownList() {
- var oEditor = $("#designTextarea").ckeditorGet();
-
- if ( currentDynamicElementCode && currentCategoryComboUid ) {
- var template = '<select id="' + currentCategoryComboUid + '-categorycombo" style="width:15em;"></select>';
+ var template = '<input id="' + id + '" value="[ ' + categoryOptionComboName + ' ]" title="' + categoryOptionComboName + '" style="width:7em;text-align:center;" />';
oEditor.insertHtml( template );
}
}
@@ -412,10 +413,12 @@
$("#dynamicElementSelect").hide();
$("#dynamicElementInsert").show();
- var categoryComboUid = $("#categoryComboSelect").val();
+ var categoryComboUid = $("#categoryComboSelect option:selected").val();
+ var categoryComboName = $("#categoryComboSelect option:selected").text();
currentDynamicElementCode = getRandomCode();
currentCategoryComboUid = categoryComboUid;
+ currentCategoryComboName = categoryComboName;
clearListById( "dynamicElementSelector" );