← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1880: Fix bug : Something wrong with Cancel and Save button in Editting Data entry.

 

------------------------------------------------------------
revno: 1880
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-07-27 10:51:10 +0700
message:
  Fix bug : Something wrong with Cancel and Save button in Editting Data entry.
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/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-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java	2010-07-01 10:08:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java	2010-07-27 03:51:10 +0000
@@ -27,6 +27,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.dataentryform.DataEntryFormAssociation;
 import org.hisp.dhis.dataentryform.DataEntryFormService;
@@ -105,11 +108,86 @@
         else
         {
             dataEntryForm.setName( nameField );
-            dataEntryForm.setHtmlCode( designTextarea );
+            dataEntryForm.setHtmlCode( prepareDataEntryFormInputs(designTextarea ));
             dataEntryFormService.updateDataEntryForm( dataEntryForm );
         }
 
         return SUCCESS;
     }
+    
+    private String prepareDataEntryFormInputs( String preparedCode )
+    {
+        // ---------------------------------------------------------------------
+        // Buffer to contain the final result.
+        // ---------------------------------------------------------------------
+        
+        StringBuffer sb = new StringBuffer();
+        
+        // ---------------------------------------------------------------------
+        // Pattern to match data elements in the HTML code.
+        // ---------------------------------------------------------------------
+ 
+        Pattern patDataElement = Pattern.compile( "(<input.*?)[/]?>" );
+        Matcher matDataElement = patDataElement.matcher( preparedCode );
+
+        // ---------------------------------------------------------------------
+        // Iterate through all matching data element fields.
+        // ---------------------------------------------------------------------
+        
+        boolean result = matDataElement.find();
+        
+        while ( result )
+        {
+            // -----------------------------------------------------------------
+            // Get input HTML code (HTML input field code).
+            // -----------------------------------------------------------------
+            
+            String dataElementCode = matDataElement.group( 1 );
+            
+            // -----------------------------------------------------------------
+            // Pattern to extract data element name from data element field
+            // -----------------------------------------------------------------
+            
+            Pattern patDataElementName = Pattern.compile( "value=\"\\[ (.*) \\]\"" );
+            Matcher matDataElementName = patDataElementName.matcher( dataElementCode );
+
+            Pattern patTitle = Pattern.compile( "title=\"-- (.*) --\"" );
+            Matcher matTitle = patTitle.matcher( dataElementCode );
+       
+            if ( matDataElementName.find() && matDataElementName.groupCount() > 0 )
+            {
+                String temp = "[ " + matDataElementName.group( 1 ) + " ]";
+                dataElementCode = dataElementCode.replace( temp, "" );
+
+                if ( matTitle.find() && matTitle.groupCount() > 0 )
+                {
+                    temp = "-- " + matTitle.group( 1 ) + " --";
+                    dataElementCode = dataElementCode.replace( temp, "" );
+                }
+
+                // -------------------------------------------------------------
+                // Appends dataElementCode
+                // -------------------------------------------------------------
+       
+                String appendCode = dataElementCode;
+                appendCode += "/>";
+                matDataElement.appendReplacement( sb, appendCode );
+            }
+
+            // -----------------------------------------------------------------
+            // Go to next data entry field
+            // -----------------------------------------------------------------
+   
+            result = matDataElement.find();
+        }
+
+        // -----------------------------------------------------------------
+        // Add remaining code (after the last match), and return formatted code.
+        // -----------------------------------------------------------------
+
+        matDataElement.appendTail( sb );
+
+        return sb.toString();
+    }    
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java	2010-07-27 03:51:10 +0000
@@ -194,7 +194,7 @@
         // -----------------------------------------------------------------
 
         matDataElement.appendTail( sb );
-       
+        
         return sb.toString();
     }    
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml	2010-07-07 10:22:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml	2010-07-27 03:51:10 +0000
@@ -280,7 +280,7 @@
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-maintenance-dataset/viewDataEntryForm.vm</param>
       <param name="javascripts">
-      javascript/FCK/fckeditor.js, javascript/dataEntryForm.js
+      javascript/FCK/fckeditor.js, javascript/FCK/editor/js/fckeditorcode_gecko.js, javascript/dataEntryForm.js
       ,../dhis-web-commons/util/validate/jquery.validate.js,../dhis-web-commons/util/jquery.metadata.js
       ,../dhis-web-commons/util/validate/additional-methods.js,../dhis-web-commons/validationMessages.action</param>
       <param name="stylesheets">css/cde.css</param>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js	2010-07-01 10:08:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js	2010-07-27 03:51:10 +0000
@@ -177,7 +177,6 @@
   }
 }
 
-var url;
 function autoSaveDataEntryForm(){
 	
 	var field = FCKeditorAPI.GetInstance('designTextarea');

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2010-07-24 15:40:31 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2010-07-27 03:51:10 +0000
@@ -1,5 +1,3 @@
- <script type="text/javascript" src="javascript/FCK/editor/js/fckeditorcode_gecko.js"></script>
-
 <script type="text/javascript">
     var stat = '$status';
     var dataEntryFormId = -1;