← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14645: Approva UI. Basic function working.

 

------------------------------------------------------------
revno: 14645
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-03 20:20:05 +0200
message:
  Approva UI. Basic function working.
modified:
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.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-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm	2014-04-03 17:51:13 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm	2014-04-03 18:20:05 +0000
@@ -40,16 +40,20 @@
   padding-top: 7px;
   padding-bottom: 5px;
 }
+
+.approveButton {
+  display: none;
+}
 </style>
 
 <h3 id="dataSetReportHeader">$i18n.getString( "data_approval" )</h3>
 
 <div id="control">
 <input type="button" value='$i18n.getString( "data" )' style="width:140px" onclick="dhis2.dsr.showCriteria()">
-<input type="button" id="approveButton" value="$i18n.getString( 'approve' )" onclick="dhis2.dsr.approveData()" style="width:120px">
-<input type="button" id="unapproveButton" value="$i18n.getString( 'unapprove' )" onclick="dhis2.dsr.unapproveData()" style="width:120px">
-<input type="button" id="acceptButton" value="$i18n.getString( 'accept' )" onclick="dhis2.dsr.acceptData()" style="width:120px">
-<input type="button" id="unacceptButton" value="$i18n.getString( 'unaccept' )" onclick="dhis2.dsr.unacceptData()" style="width:120px">
+<input type="button" id="approveButton" value="$i18n.getString( 'approve' )" onclick="dhis2.appr.approveData()" class="approveButton" style="width:120px">
+<input type="button" id="unapproveButton" value="$i18n.getString( 'unapprove' )" onclick="dhis2.appr.unapproveData()" class="approveButton" style="width:120px">
+<input type="button" id="acceptButton" value="$i18n.getString( 'accept' )" onclick="dhis2.appr.acceptData()" class="approveButton" style="width:120px">
+<input type="button" id="unacceptButton" value="$i18n.getString( 'unaccept' )" onclick="dhis2.appr.unacceptData()" class="approveButton" style="width:120px">
 </div>
 
 <div id="criteria" class="inputCriteria" style="width:360px;">

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm	2014-04-03 17:22:46 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm	2014-04-03 18:20:05 +0000
@@ -62,14 +62,6 @@
 var i18n_share_your_interpretation = '$encoder.jsEscape( $i18n.getString( "share_your_interpretation" ), "'")';
 var i18n_interpretation_was_shared = '$encoder.jsEscape( $i18n.getString( "interpretation_was_shared" ), "'")';
 var i18n_select_option_view_all = '$encoder.jsEscape( $i18n.getString( "select_option_view_all" ) , "'")';
-var i18n_waiting_for_lower_level_approval = '$encoder.jsEscape( $i18n.getString( "waiting_for_lower_level_approval" ) , "'")';
-var i18n_ready_for_approval = '$encoder.jsEscape( $i18n.getString( "ready_for_approval" ) , "'")';
-var i18n_approved = '$encoder.jsEscape( $i18n.getString( "approved" ) , "'")';
-var i18n_approved_and_accepted = '$encoder.jsEscape( $i18n.getString( "approved_and_accepted" ) , "'")';
-var i18n_confirm_approval = '$encoder.jsEscape( $i18n.getString( "confirm_approval" ) , "'")';
-var i18n_confirm_unapproval = '$encoder.jsEscape( $i18n.getString( "confirm_unapproval" ) , "'")';
-var i18n_confirm_accept = '$encoder.jsEscape( $i18n.getString( "confirm_accept" ) , "'")';
-var i18n_confirm_unaccept = '$encoder.jsEscape( $i18n.getString( "confirm_unaccept" ) , "'")';
 </script>
 
 <style type="text/css">

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.js	2014-04-03 17:51:13 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.js	2014-04-03 18:20:05 +0000
@@ -66,10 +66,8 @@
 
 dhis2.appr.getDataReport = function()
 {
-	var ds = $( "#dataSetId" ).val();
-	
     var dataReport = {
-        ds: ds,
+        ds: $( "#dataSetId" ).val(),
         pe: $( "#periodId" ).val(),
         ou: selectionTreeSelection.getSelectedUid()[0]
     };
@@ -78,8 +76,8 @@
     var cogs = $( "#categoryOptionGroupId :selected" ).data( "dimension" );
     
     if ( cog && cogs ) {
-    	var item = cogs + ":" + cog;
-    	dataReport.dimension = item;
+    	dataReport.dimension = cogs + ":" + cog;
+    	dataReport.cog = cog;
     }
     
     return dataReport;
@@ -111,10 +109,12 @@
     showLoader();
     
     $.get( "generateDataSetReport.action", dataReport, function( data ) {
-    	$( '#content' ).html( data );
+    	$( "#content" ).html( data );
+    	$( "#shareForm" ).hide();
     	hideLoader();
     	$( "#content" ).show( "fast" );
     	setTableStyles();
+    	dhis2.appr.setApprovalState();
     } );
 }
 
@@ -122,108 +122,68 @@
 // Approval
 //------------------------------------------------------------------------------
 
-/**
- * Generates the URL for the approval of the given data set report.
- */
-dhis2.appr.getDataApprovalUrl = function( dataSetReport )
-{
-    var url = "../api/dataApprovals" +
-        "?ds=" + dataSetReport.ds +
-        "&pe=" + dataSetReport.pe +
-        "&ou=" + dataSetReport.ou;
-
-    return url;
-}
-
-/**
- * Generates the URL for the acceptance of the given data set report approval.
- */
-dhis2.appr.getDataApprovalAcceptanceUrl = function( dataSetReport )
-{
-    var url = "../api/dataApprovals/acceptances" +
-        "?ds=" + dataSetReport.ds +
-        "&pe=" + dataSetReport.pe +
-        "&ou=" + dataSetReport.ou;
-
-    return url;
-}
-
-dhis2.appr.showApproval = function()
-{
-	var dataSetReport = dhis2.dsr.getDataSetReport();
+dhis2.appr.setApprovalState = function()
+{
+	var data = dhis2.appr.getDataReport();
 	
-	var approval = $( "#dataSetId :selected" ).data( "approval" );
-
 	$( "#approvalNotification" ).hide();
     $( "#approvalDiv" ).hide();
-
-	if ( !approval ) {
-		return;
-	}
-	
-	var url = dhis2.appr.getDataApprovalUrl( dataSetReport );
-	
-	$.getJSON( url, function( json ) {
-	
-	if ( !json || !json.state ) {
-		return;
-	}
-
-	dhis2.appr.permissions = json;
-		
-	var state = json.state;
-
-    $( "#approveButton" ).hide();
-    $( "#unapproveButton" ).hide();
-    $( "#acceptButton" ).hide();
-    $( "#unacceptButton" ).hide();
-
-    switch (state) {
-    case "UNAPPROVED_WAITING":
-        $("#approvalNotification").show().html(i18n_waiting_for_lower_level_approval);
-        break;
-
-    case "UNAPPROVED_READY":
-        $("#approvalNotification").show().html(i18n_ready_for_approval);
-        
-        if (json.mayApprove) {
-            $("#approvalDiv").show();
-            $("#approveButton").show();
-        }
-        
-        break;
-
-    case "APPROVED_HERE":
-        $("#approvalNotification").show().html(i18n_approved);
-        
-        if (json.mayUnapprove)  {
-            $("#approvalDiv").show();
-            $("#unapproveButton").show();
-        }
-        
-        if (json.mayAccept)  {
-            $("#approvalDiv").show();
-            $("#acceptButton").show();
-        }
-        
-        break;
-
-    case "ACCEPTED_HERE":
-        $("#approvalNotification").show().html(i18n_approved);
-        
-        if (json.mayUnapprove)  {
-            $("#approvalDiv").show();
-            $("#unapproveButton").show();
-        }
-        
-        if (json.mayUnccept)  {
-            $("#approvalDiv").show();
-            $("#unacceptButton").show();
-        }
-        
-        break;
-    }
-    });	
+		
+	$.getJSON( "../api/dataApprovals", data, function( json ) {	
+		if ( !json || !json.state ) {
+			return;
+		}
+	
+		dhis2.appr.permissions = json;
+		
+	    $( ".approveButton" ).hide();
+	
+	    switch (json.state) {
+		    case "UNAPPROVED_WAITING":
+		        $("#approvalNotification").show().html(i18n_waiting_for_lower_level_approval);
+		        break;
+		
+		    case "UNAPPROVED_READY":
+		        $("#approvalNotification").show().html(i18n_ready_for_approval);
+		        
+		        if (json.mayApprove) {
+		            $("#approvalDiv").show();
+		            $("#approveButton").show();
+		        }
+		        
+		        break;
+		
+		    case "APPROVED_HERE":
+		        $("#approvalNotification").show().html(i18n_approved);
+		        
+		        if (json.mayUnapprove)  {
+		            $("#approvalDiv").show();
+		            $("#unapproveButton").show();
+		        }
+		        
+		        if (json.mayAccept)  {
+		            $("#approvalDiv").show();
+		            $("#acceptButton").show();
+		        }
+		        
+		        break;
+		
+		    case "ACCEPTED_HERE":
+		        $("#approvalNotification").show().html(i18n_approved);
+		        
+		        if (json.mayUnapprove)  {
+		            $("#approvalDiv").show();
+		            $("#unapproveButton").show();
+		        }
+		        
+		        if (json.mayUnccept)  {
+		            $("#approvalDiv").show();
+		            $("#unacceptButton").show();
+		        }
+		        
+		        break;
+		    }
+		} );	
 }
 
 dhis2.appr.approveData = function()
@@ -232,11 +192,8 @@
 		return false;
 	}
 	
-	var dataSetReport = dhis2.dsr.getDataSetReport();
-	var url = dhis2.appr.getDataApprovalUrl( dataSetReport );
-	
 	$.ajax( {
-		url: url,
+		url: dhis2.appr.getApprovalUrl(),
 		type: "post",
 		success: function() {
             $( "#approvalNotification" ).show().html( i18n_approved );
@@ -262,12 +219,9 @@
 	if ( !confirm( i18n_confirm_unapproval ) ) {
 		return false;
 	}
-	
-	var dataSetReport = dhis2.dsr.getDataSetReport();
-	var url = dhis2.appr.getDataApprovalUrl( dataSetReport );
-	
+
 	$.ajax( {
-		url: url,
+		url: dhis2.appr.getApprovalUrl(),
 		type: "delete",
 		success: function() {
             $( "#approvalNotification" ).show().html( i18n_ready_for_approval );
@@ -289,35 +243,33 @@
 
 dhis2.appr.acceptData = function()
 {
-  if ( !confirm( i18n_confirm_accept ) ) {
-      return false;
-  }
-
-  var dataSetReport = dhis2.dsr.getDataSetReport();
-  var url = dhis2.appr.getDataApprovalAcceptanceUrl( dataSetReport );
-
-  $.ajax( {
-      url: url,
-      type: "post",
-      success: function() {
-          $( "#approvalNotification" ).show().html( i18n_approved_and_accepted );
-          $( "#approvalDiv" ).hide();
-          $( "#acceptButton" ).hide();
-          
-          if ( dhis2.appr.permissions.mayUnapprove ) {
-              $( "#approvalDiv" ).show();
-              $( "#unapproveButton" ).show();
-          }
-          
-          if ( dhis2.appr.permissions.mayUnaccept ) {
-              $( "#approvalDiv" ).show();
-              $( "#unacceptButton" ).show();
-          }
-      },
-      error: function( xhr, status, error ) {
-          alert( xhr.responseText );
-      }
-  } );
+    if ( !confirm( i18n_confirm_accept ) ) {
+        return false;
+    }
+
+    $.ajax( {
+		url: dhis2.appr.getAcceptanceUrl(),
+		data: dataReport,
+        type: "post",
+        success: function() {
+            $( "#approvalNotification" ).show().html( i18n_approved_and_accepted );
+            $( "#approvalDiv" ).hide();
+            $( "#acceptButton" ).hide();
+          
+            if ( dhis2.appr.permissions.mayUnapprove ) {
+                $( "#approvalDiv" ).show();
+                $( "#unapproveButton" ).show();
+            }
+          
+            if ( dhis2.appr.permissions.mayUnaccept ) {
+                $( "#approvalDiv" ).show();
+                $( "#unacceptButton" ).show();
+            }
+        },
+        error: function( xhr, status, error ) {
+            alert( xhr.responseText );
+        }
+    } );
 }
 
 dhis2.appr.unacceptData = function()
@@ -326,11 +278,9 @@
         return false;
     }
 
-    var dataSetReport = dhis2.dsr.getDataSetReport();
-    var url = dhis2.appr.getDataApprovalAcceptanceUrl( dataSetReport );
-
     $.ajax( {
-        url: url,
+		url: dhis2.appr.getAcceptanceUrl(),
+		data: dataReport,
         type: "delete",
         success: function() {
             $( "#approvalNotification" ).show().html( i18n_approved );
@@ -350,3 +300,17 @@
         }
   } );
 }
+
+dhis2.appr.getApprovalUrl = function()
+{
+	var data = dhis2.appr.getDataReport();
+	var url = "../api/dataApprovals?ds=" + data.ds + "&pe=" + data.pe + "&ou=" + data.ou + "&cog=" + data.cog;	
+	return url;
+}
+
+dhis2.appr.getAcceptanceUrl = function()
+{
+	var data = dhis2.appr.getDataReport();
+	var url = "../api/dataApprovals/acceptances?ds=" + data.ds + "&pe=" + data.pe + "&ou=" + data.ou + "&cog=" + data.cog;	
+	return url;
+}