← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13102: finished supporting editing of ip header/comments

 

------------------------------------------------------------
revno: 13102
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-02 15:23:07 +0100
message:
  finished supporting editing of ip header/comments
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2013-12-01 22:32:50 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2013-12-02 14:23:07 +0000
@@ -28,14 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.chart.ChartService;
@@ -64,6 +56,13 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * @author Lars Helge Overland
  */
@@ -258,7 +257,8 @@
             return;
         }
 
-        if ( !currentUserService.getCurrentUser().equals( interpretation.getUser() ) )
+        if ( !currentUserService.getCurrentUser().equals( interpretation.getUser() ) &&
+            !currentUserService.currentUserIsSuper() )
         {
             throw new AccessDeniedException( "You are not allowed to delete this interpretation." );
         }
@@ -266,6 +266,30 @@
         interpretationService.deleteInterpretation( interpretation );
     }
 
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT )
+    public void updateInterpretation( @PathVariable( "uid" ) String uid, HttpServletResponse response, @RequestBody String content )
+    {
+        Interpretation interpretation = interpretationService.getInterpretation( uid );
+
+        if ( interpretation == null )
+        {
+            ContextUtils.conflictResponse( response, "Interpretation does not exist: " + uid );
+            return;
+        }
+
+        if ( !currentUserService.getCurrentUser().equals( interpretation.getUser() ) &&
+            !currentUserService.currentUserIsSuper() )
+        {
+            throw new AccessDeniedException( "You are not allowed to update this interpretation." );
+        }
+
+        System.err.println( content );
+
+        interpretation.setText( content );
+
+        interpretationService.updateInterpretation( interpretation );
+    }
+
     @RequestMapping( value = "/{uid}/comments/{cuid}", method = RequestMethod.DELETE )
     public void deleteComment( @PathVariable( "uid" ) String uid, @PathVariable( "cuid" ) String cuid, HttpServletResponse response )
     {
@@ -285,7 +309,8 @@
 
             if ( comment.getUid().equals( cuid ) )
             {
-                if ( !currentUserService.getCurrentUser().equals( comment.getUser() ) )
+                if ( !currentUserService.getCurrentUser().equals( comment.getUser() ) &&
+                    !currentUserService.currentUserIsSuper() )
                 {
                     throw new AccessDeniedException( "You are not allowed to delete this comment." );
                 }
@@ -297,6 +322,35 @@
         interpretationService.updateInterpretation( interpretation );
     }
 
+    @RequestMapping( value = "/{uid}/comments/{cuid}", method = RequestMethod.PUT )
+    public void updateComment( @PathVariable( "uid" ) String uid, @PathVariable( "cuid" ) String cuid, HttpServletResponse response,
+        @RequestBody String content )
+    {
+        Interpretation interpretation = interpretationService.getInterpretation( uid );
+
+        if ( interpretation == null )
+        {
+            ContextUtils.conflictResponse( response, "Interpretation does not exist: " + uid );
+            return;
+        }
+
+        for ( InterpretationComment comment : interpretation.getComments() )
+        {
+            if ( comment.getUid().equals( cuid ) )
+            {
+                if ( !currentUserService.getCurrentUser().equals( comment.getUser() ) &&
+                    !currentUserService.currentUserIsSuper() )
+                {
+                    throw new AccessDeniedException( "You are not allowed to update this comment." );
+                }
+
+                comment.setText( content );
+            }
+        }
+
+        interpretationService.updateInterpretation( interpretation );
+    }
+
     @RequestMapping( value = "/{uid}/comment", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
     public void postComment(
         @PathVariable( "uid" ) String uid,

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.js	2013-12-02 13:59:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.js	2013-12-02 14:23:07 +0000
@@ -113,7 +113,7 @@
   var textArea = jQuery("<textarea />")
     .css({ 'width': '100%', 'height': '80px' })
     .uniqueId()
-    .html(oldContent);
+    .val(oldContent);
 
   var container = jQuery("<div />")
     .uniqueId()
@@ -128,13 +128,13 @@
   var saveButton = jQuery("<button/>")
     .text(i18n_save)
     .on('click', function( e ) {
-      var content = textArea.html().trim();
+      var content = textArea.val().trim();
 
       if( ipCommentUid ) {
         $.ajax({
           url: '../api/interpretations/' + ipUid + '/comments/' + ipCommentUid,
           contentType: 'text/plain; charset=UTF-8',
-          type: 'POST',
+          type: 'PUT',
           data: content
         }).done(function() {
           $target.html(content);
@@ -145,7 +145,7 @@
         $.ajax({
           url: '../api/interpretations/' + ipUid,
           contentType: 'text/plain; charset=UTF-8',
-          type: 'POST',
+          type: 'PUT',
           data: content
         }).done(function() {
           $target.html(content);